%
%  Generation of Gaussian cdf with mean mu, standard deviation sigma
%
function F = gauss_cdf(Npoints,Nbins,mu,sigma);
%
%  generate the gaussian density
%
  data = mu+sigma*randn(Npoints,1);
  min_data = min(data);
  max_data = max(data);
  dx = linspace(min_data,max_data,Nbins+1);
%
% Now construct the cdf
%
  x = [dx(1)];
  F = [y(data,dx(1))];
  for i=2:length(dx)
     F = [F y(data,dx(i))];
     x = [x dx(i)];
  end;
%
%  get the true values
%
  Ftrue = [];
  u = (x-mu)/(sqrt(2)*sigma);
  for i=1:length(u)
     if( u(i) <= 0 ) Ftrue = [Ftrue 0.5-0.5*erf(abs(u(i)))]; end;
     if( u(i) > 0 )  Ftrue = [Ftrue 0.5+0.5*erf(u(i))]; end;
   end;
   plot(x,F,'r-',x,Ftrue,'k:','Linewidth',1.5); grid;
   legend('Estimated cdf','Exact cdf');
   ylabel('F_X(x)'); xlabel('x');
    title(['Gaussian cdf with \mu = ', num2str(mu,3) ', \sigma = ' ...
        num2str(sigma,4) ', Npoints = ' num2str(Npoints) ', Nbins = ' num2str(Nbins) ]);
   return;
%
%  the function y determines number of data values of X less than x
%    divided by the number of sample points
%
function F = y(X,x);
%
  F = sum(X<=x)/length(X);
  return;
  
  
