%Université de Lille 1
%MAO 2004/2005
%
%                       Fourier animé
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

T=2*pi;
NMAX=20;

x=-T/2:0.1:T/2;

for M=2:2:NMAX
%*************** Calcul des coefficients de Fourier du creneau c_k, k=-M..M
K=1:M;
ck=-2./(K*pi).*(1-cos(pi*K));%-(2./(pi*K)).*(cos(pi*K))

%*************** Evaluation de la somme partielle en chaque x(j)
theta=2*pi/T;

     S=0;
     for k=1:M
     S=S+ck(k)*sin(theta*k*x);
    end
     y=S;


plot(x,real(y))
xlabel('x')
ylabel('SF(f)')
drawnow
pause(1)
end