
% An illustration for central limit theorem
% Shengli Zhou, 09/04/2002

clear

% 10 samples from the uniform p.d.f.
stepsize=0.1;
t=-0.4:0.1:0.5;	  
x=ones(1,length(t))*stepsize;
x=[0 x 0];

% gaussian p.d.f.
t0=[-4:0.1:4];	% stepsize 0.1
y0=1/sqrt(2*pi)*exp(-t0.^2/2)*stepsize;

y=1;
for i=1:12
    y=conv(y,x);
    hold off
    plot(((1:length(y))-length(y)/2)*stepsize,y,'-k'); hold on
    plot(t0,y0,'--k'); hold on
    hold off 
    set(gca,'xlim',[-4 4]);
    set(gca,'ylim',[0 0.12]);
    grid;
    legend('CLT approximation','Gaussian distribution');
    str=strcat('print -deps -f1 conv',num2str(i),'.eps');
    eval(str);
    pause 
end
