% Sum of independent RVs demo % % Brian D. Jeffs 10/26/05 echo on x = [-1.1:.001:1.1]; f_X = 1/2*(abs(x) <= 1); plot(x, f_X) a = axis; axis(1.1*a); title('pdf for X ~ U(-1,1)'); xlabel('x'); ylabel('f_X(x)'); pause f_Y = f_X; y = x; N = 1; again = 1; while again N = N + 1; f_Y = conv(f_Y, f_X)./1000; y = [min(y)-1.1:.001:max(y)+1.1]'; f_Gauss = normpdf(y, 0, 2*N/12); plot(y, f_Y(1:length(y)), y, f_Gauss) a = axis; axis(1.1*a); title(['pdf for f_X * f_X(x) * ... ',num2str(N),' times']); xlabel('y'); ylabel('f_Y(y)'); legend('Sequence of convolved unforms','Gaussian with matching variance') again = input('Convolve f_Y with f_X again? (1/0): '); end echo off