Main Archive Specials Wiki | FAQ Links Submit Forum

Gaussian White noise

References : Posted by Alexey Menshikov

Notes :
Code I use sometimes, but don't remember where I ripped it from.

- Alexey Menshikov

Code :
#define ranf() ((float) rand() / (float) RAND_MAX)

float ranfGauss (int m, float s)
static int pass = 0;
static float y2;
float x1, x2, w, y1;

if (pass)
y1 = y2;
} else {
do {
x1 = 2.0f * ranf () - 1.0f;
x2 = 2.0f * ranf () - 1.0f;
w = x1 * x1 + x2 * x2;
} while (w >= 1.0f);

w = (float)sqrt (-2.0 * log (w) / w);
y1 = x1 * w;
y2 = x2 * w;
pass = !pass;

return ( (y1 * s + (float) m));


Added on : 29/01/04 by davidchristenATgmxDOTnet
Comment :
White Noise does !not! consist of uniformly distributed values. Because in white noise, the power of the frequencies are uniformly distributed. The values must be normal (or gaussian) distributed. This is achieved by the Box-Muller Transformation. This function is the polar form of the Box-Muller Transformation. It is faster and numeriacally more stable than the basic form. The basic form is coded in the other (second) post.
Detailed information on this topic:

Cheers David

Added on : 06/09/07 by nick[ DOT ]a[ DOT ]shaw[ AT ]btopenworld[ DOT ]com
Comment :
I'm trying to implement this in C#, but y2 isn't initialized. Is this a typo?        

Added on : 17/07/10 by foo[ AT ]bar[ DOT ]de
Comment :
@nick: Way to late, but y2 will always be initialized as in the first run "pass" is 0 (i.e. false). The C# compiler just can't prove it.

Added on : 03/09/11 by asynth[ AT ]gmail[ DOT ]com
Comment :
David is wrong. The distribution of the sample values is irrelevant. 'white' simply describes the spectrum. Any series of sequentially independent random values -- whatever their distribution -- will have a white spectrum.

Added on : 06/01/17 by aleyuwo[ AT ]popp[ DOT ]eamale[ DOT ]com
Comment :
[url=][/url] <a href=""></a>

Added on : 06/01/17 by oboqamego[ AT ]g[ DOT ]eamale[ DOT ]com
Comment :
[url=][/url] <a href=""></a>

Add your own comment
Comments are displayed in fixed width, no HTML code allowed!


Are you human?

Site created and maintained by Bram
Graphic design by line.out | Server sponsered by fxpansion