Advertisement
Guest User

Untitled

a guest
Apr 10th, 2020
206
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.53 KB | None | 0 0
  1. for M=[5 10 20 40 80 160]
  2.   t=0:0.001:2*pi;
  3.   e=exp(1);
  4.   N=length(t);
  5.   x=zeros(1,N);
  6.   x(1:N/2)=1;
  7.   xa=zeros(1,N);
  8.   for k=-M:M
  9.       if (k==0)  
  10.           a=0.5;
  11.       elseif (floor(k/2)*2==k)  
  12.           a=0;
  13.       else  
  14.           a=-i/(pi*k);
  15.       end
  16.       xa=xa+a*e.^(i*t*k);    
  17.   end;
  18.   xa=real(xa);
  19.   max(xa)  
  20.   figure
  21.   plot(t,x,t,xa)
  22.   axis([0,2*pi,-0.2,1.2]);
  23.   title(strcat('Partial sum of Fourier series M = '...
  24.       ,int2str(M)),'FontName', 'Arial CE');
  25.   xlabel('t');ylabel('x(t), x_a(t)');
  26. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement