0

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);

clabacchio
  • 13,501
  • 4
  • 42
  • 80

1 Answers1

2
  • add syms k; at the beginning
  • sin(k*pi/4)/(k*pi) should be sin(k*pi/4)/(k*pi+eps) to avoid division by zero.
  • legned should be legend
  • you can't place 5 subplots in a 2x2 figure