randg_yp

PURPOSE ^

SYNOPSIS ^

function [y] = randg_yp(N,av,fwhm,display_mode)

DESCRIPTION ^

 White gaussian noise generator, with given mean and FWHM values.

   INPUTS: 

       - N: number of trials [1,N]
       (default = 100000)
       - av: average value [m,1]
       (default = 0)
       - fwhm: fullwidth at half maximum value [m,1]
       (default = 0.5)
       - display_mode: display the distribution is > 0 and is the number of bin of the histogram  [1,1]
       (default = 0)


   OUTPUTS: [qe,me,mp,mn,e0,mu0,re,mc2,clum,alpha,kB]
   
   - y: white gaussian noise [1,N]

 by Yves Peysson <yves.peysson@cea.fr> (CEA/DSM/IRFM) and Joan Decker <joan.decker@cea.fr> (CEA/DSM/IRFM)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [y] = randg_yp(N,av,fwhm,display_mode)
0002 %
0003 % White gaussian noise generator, with given mean and FWHM values.
0004 %
0005 %   INPUTS:
0006 %
0007 %       - N: number of trials [1,N]
0008 %       (default = 100000)
0009 %       - av: average value [m,1]
0010 %       (default = 0)
0011 %       - fwhm: fullwidth at half maximum value [m,1]
0012 %       (default = 0.5)
0013 %       - display_mode: display the distribution is > 0 and is the number of bin of the histogram  [1,1]
0014 %       (default = 0)
0015 %
0016 %
0017 %   OUTPUTS: [qe,me,mp,mn,e0,mu0,re,mc2,clum,alpha,kB]
0018 %
0019 %   - y: white gaussian noise [1,N]
0020 %
0021 % by Yves Peysson <yves.peysson@cea.fr> (CEA/DSM/IRFM) and Joan Decker <joan.decker@cea.fr> (CEA/DSM/IRFM)
0022 %
0023 if nargin == 0, 
0024     N = 100000;
0025     av = 0;
0026     fwhm = 0.5;
0027     display_mode = 100;
0028 end
0029 %
0030 if nargin == 1, 
0031     av = 0;
0032     fwhm = 0.5;
0033     display_mode = 0;
0034 end
0035 %
0036 if nargin == 2, 
0037     fwhm = 0.5;
0038     display_mode = 0;
0039 end
0040 %
0041 if nargin == 3, 
0042     display_mode = 0;
0043 end
0044 %
0045 fwhm = fwhm(:);
0046 av = av(:);
0047 if size(av) ~= size(fwhm), error('Inconsistent size of av and hwhm in randg_yp.m');end
0048 %
0049 sigma = fwhm/sqrt(2*log(2))/2;%standard deviation
0050 Xsigma = repmat(sigma,[1,N]);
0051 Xav = repmat(av,[1,N]);
0052 %
0053 y = sqrt(-2*log(rand(size(Xav,1),N))).*cos(2*pi*rand(size(Xav,1),N)).*Xsigma + Xav;
0054 %
0055 if nargin == 4,
0056     if display_mode,
0057         if display_mode < round(N/100),
0058             disp(['WARNING: display_mode parameter must exceed be of the order of ',int2str(round(N/100)),' for a correct histogramm.']);
0059             display_mode = round(N/100);
0060         else
0061             disp(['WARNING: not enough trials for drawing a correct histogramm -> display_mode parameter set to zero.']);
0062             display_mode = 0;
0063         end
0064     end
0065 end
0066 %
0067 if display_mode,
0068     [z,x] = hist(y,display_mode);%display_mode is the number of bin for the histogram
0069     normz = sum(z)*(x(2)-x(1));
0070     figure(1),plot(x,z/normz,'b',x,exp(-(x - av).^2/2/sigma^2)/sqrt(2*pi)/sigma,'r');
0071     norm_th = sum(exp(-(x - av).^2/2/sigma^2))/sqrt(2*pi)/sigma*(x(2)-x(1));
0072     title('Gaussian white noise distribution function (normalized to 1)')
0073     xlabel('y');ylabel('f(y)')
0074     legend('Numerical','Theoretical')
0075     hold off
0076 end

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.