I want to write down the Fourier series for \$x(t)=1\$ for \$|t|\leq 1\$ and zero otherwise (which is expanded periodically to other intervals with this period of 1), and compare it graphically with \$x(t)\$, for different values for \$N\$, where \$x(t)=\sum_{-N}^{N} a_k e^{ j k\Omega_0 t}\$.
Here's the code I wrote, basically the interval should be between -2 and 2, but I get all the time an error, I hope someone can correct me or find a better way to do this.
n=linspace(-2,2,5);
x=abs(n)<=1;
y=symsum(exp(-1i*k*pi/4)*(sin(k*pi/4)/(k*pi))*exp(1i*k*pi*n/2),k,-1,1);
y2=symsum(exp(-1i*k*pi/4)*(sin(k*pi/4)/(k*pi))*exp(1i*k*pi*n/2),k,-3,3);
y3=symsum(exp(-1i*k*pi/4)*(sin(k*pi/4)/(k*pi))*exp(1i*k*pi*n/2),k,-7,7);
y4=symsum(exp(-1i*k*pi/4)*(sin(k*pi/4)/(k*pi))*exp(1i*k*pi*n/2),k,-19,19);
y5=symsum(exp(-1i*k*pi/4)*(sin(k*pi/4)/(k*pi))*exp(1i*k*pi*n/2),k,-79,79);
I get the following error:
??? Undefined function or variable 'k'. Error in ==> AS at 3 y=symsum(exp(-1i*k*pi/4)*(sin(k*pi/4)/(k*pi))*exp(1i*k*pi*n/2),k,-1,1);
??? Undefined function or variable 'k'.Error in ==> AS at 3 y=symsum(exp(-1ikpi/4)(sin(kpi/4)/(kpi))exp(1ikpi*n/2),k,-1,1);
– MathematicalPhysicist Dec 02 '12 at 09:51