function Fourier_example(M)

if (nargin == 0)
    M = 200;
end

k = 1;

ax = -3;
bx = 3;

N = 500;
x = linspace(ax,bx,N);

figure(1);
clf

xlabel('x','fontsize',16);
ylabel('f(x)','fontsize',16);
xticks = pi*(ax:bx);
title(sprintf('Partial sum : S(%d)',1),'fontsize',18);

S =4*k/pi*(sin(pi*x));
h = plot(pi*x,S,'k.','markersize',10);


set(gca,'xtick',xticks);
av = ax:bx;
xticklabels = cell(length(av),1);
for i = 1:length(xticks)
    a = av(i);
    if a == 0
        xticklabels{i} = '0';
    elseif (a == 1)
        xticklabels{i} = sprintf('\\pi');
    elseif (a == -1)
        xticklabels{i} = sprintf('-\\pi');
    else
        xticklabels{i} = sprintf('%d\\pi',a);
    end
end
set(gca,'xticklabels',xticklabels);
set(gca,'fontsize',16);

hold on;
plot(pi*[ax,bx],[0,0],'k');
plot([0,0],ylim,'k');

for i = 1:length(av)-1
    v = (-1)^(av(i))*k;
    plot(pi*[av(i),av(i+1)],[v,v],'r','linewidth',2);
end

for i = 1:M
    n = 2*i + 1;
    S = S + 4*k/pi*(sin(n*pi*x)/n);
    title(sprintf('Partial sum : S(%d)',i),'fontsize',18);
    set(h,'ydata',S);
    pause(0.05);
end

    










end