Clear Filters
Clear Filters

fourier transform of a rect function

15 views (last 30 days)
justin stephens
justin stephens on 18 Mar 2018
Edited: Walter Roberson on 18 Mar 2018
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.

Answers (1)

Image Analyst
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;

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!