Ploting a Fourier rectangular signal in Matlab

108 Views Asked by At

For my homework I got this problem to solve. I found the Fourier coeficients an and bn. an=1/(npi)*sin(n.pi);
bn=-1/(n
pi)*cos(n.*pi);
a0=1

* for my rectangular signal starting in t=0 with amplitude A=1, filling factor 1ms and T=2ms . I tried to implement this in Matlab but he plots only dots (1,1) ths is my code:
T=0.002;tau=0.001;alfa=tau/T;A=1;f=1/T;
n=1:1:150;
an=1./(n.*pi).*sin(n.*pi);
bn=-1./(n.*pi).*cos(n.*pi);
t=0:0.01:3*T;
s=1+an.*cos(n*2*pi*f*t)+bn.*sin(n*2*pi*f*t);
plot(t,s);

I'm pretty new in Matlab and Fourier series, I heard about them 1 week ago, so any help would be great.

Thank you :)