sinc function doesnt work...
Show older comments
My main code
clear all
close all
clc
T=0.1;
A=1;
tau=T/2;
kmax=20;
t0=tau/2;
%%
f0=1/T;
t=(0:0.0001:1)*5*T;
xsin=sin(2*pi*f0*t);
x=zeros(size(t));
ii1=find(xsin>=0);
x(ii1)=1;
figure(1)
plot(t,x), ylim([-0.5 1.5])
kk=-kmax:1:kmax;
Xk=func_Fourier_series_periodic_pulse(T,tau,t0,A,kk);
figure(2)
stem(kk,abs(Xk))
And my function code for "func_Fourier_series_periodic_pulse"
function Xk=func_Fourier_series_periodic_pulse(T,tau,t0,A,k)
f0=1/T;
Xk=(A*tau/T)*(sinc(k*f0*tau)).*exp(-j*2*pi*k*f0*t0);
There was an error saying
Incorrect number or types of inputs or outputs for function 'sinc'
I don't know what I did wrong... can someone help me...
Accepted Answer
More Answers (1)
The code runs fine here.
clear all
close all
clc
T=0.1;
A=1;
tau=T/2;
kmax=20;
t0=tau/2;
%%
f0=1/T;
t=(0:0.0001:1)*5*T;
xsin=sin(2*pi*f0*t);
x=zeros(size(t));
ii1=find(xsin>=0);
x(ii1)=1;
figure(1)
plot(t,x), ylim([-0.5 1.5])
kk=-kmax:1:kmax;
Xk=func_Fourier_series_periodic_pulse(T,tau,t0,A,kk);
figure(2)
stem(kk,abs(Xk))
Perhaps you have a version of the sinc function shadowing the Matlab function and defined with a different signature? What is the output of
which sinc -all
function Xk=func_Fourier_series_periodic_pulse(T,tau,t0,A,k)
f0=1/T;
Xk=(A*tau/T)*(sinc(k*f0*tau)).*exp(-j*2*pi*k*f0*t0);
end
1 Comment
Seungjun Lee
on 13 Oct 2022
Categories
Find more on Code Performance in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
