fourier transform of a rect function
25 views (last 30 days)
Show older comments
i am having some issues with trying to compute the Fourier transform of a rectangular function.
the period is 4 and i am trying to use the trigonometric representation of the fourier series to calculate it. my a0=1/2, ak= (sin((k*pi)/2)/k*pi) and the final result should be this. N= 10
here is the code i have written but it does not give the wave form that i would expect.
function x= fs(N)
t= -5:.1:5;
T=4;
w=(2*pi)/T;
a0=1/2;
for k=1:2:N
ak=sin((k*pi)/2)/(k*pi);
x=a0+2*abs(ak)*cos(k*w*t);
end
plot(t,x)
Any help would be greatly appreciated.
0 Comments
Answers (1)
Image Analyst
on 18 Mar 2018
Try this:
t= -5:.1:5;
T=4;
w=(2*pi)/T;
a0=1/2;
x = a0;
for k=1:N
ak = sin((k*pi)/2)/(k*pi);
x = x + 2*abs(ak)*cos(k*w*t);
end
plot(x);
grid on;
0 Comments
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!