%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%Université de Lille 1
%MAO 2004/2005
%
%                       Phénomène de Gibbs
%
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

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

%*************** Evaluation de la somme partielle en chaque x(j)
theta=2*pi/T;
for j=1:length(x)
    y(j)=sum(ck.*sin(theta*K*x(j)));
end
figure(1)
plot(x,real(y))
%lissage (comme une image)
filtre=(1-K/M);
fck=ck.*filtre;
for j=1:length(x)
    z(j)=sum(fck.*sin(theta*K*x(j)));
end
figure(2)
plot(x,real(z))