DSPRelated.com
Forums

Gaussian Noise Generation

Started by Chris Barrett July 31, 2007

Tim Wescott wrote:


>>>>>>I'm trying to generate noise within a certain spectral range. I >>>>>>believe >>>>>>such noise is called Gaussian noise. Is there a way I can do this >>>>>>other >>>>>>than by filtering white noise? >>>> >>>>Is there a way to generate colored noise other than by the filtration >>>>of white noise? >>> >>>Why take one random number, when you can take a dozen. Add them up. See >>>what the answer looks like. :-) >> >>Why taking a dozen numbers if you have to filter it anyway. A filter >>will take care of making it gaussian as well as colored. >> > > If it's filtered heavily enough, at least. If the filter doesn't have a > long impulse response then the result won't be terrifically Gaussian.
This is basically the same deal of 1/12 of the input bandwidth. VLV
On Jul 31, 11:15 am, cincy...@gmail.com wrote:
> On Jul 31, 11:01 am, Chris Barrett
> > Is there a way to generate colored noise other than by the filtration of > > white noise? >
i dunno why the aversion to filtering "white" noise to get colored noise. particularly when the p.d.f. of the noise is gaussian. linear filtering will not change that fact.
> > > How is Gaussian noise generated? My best guess is that I would need to > > a take a random number generator, r(i), where -1>r>1,
that's called "Uniform p.d.f. noise"
> > and plug it into some other function.
that is one way to do it.
> > I'm at a loss though, as to what function I should use.
here is something from Probability Theory: if a R.V. called "x" has p.d.f. of p_x(.) and that is passed through a known function, f(x), to get another R.V.(we'll call it "y") that is dependent on x: y = f(x) and has inverse function, g(y): x = g(y) = g( f(x) ) then, the p.d.f. of y is p_y(.) and is related to the p.d.f. of x as p_y(a) = p_x( g(a) ) * | 1/(f'( g(a) )) | where f'(x) = df(x)/dx, the derivative of f(x) and "*" means "multiply" so if you know your p_x(.) that you have, the p_y(.) that you want, and that g(.) is fully dependent upon f(.) as the inverse function, then you can try to come up with an expression for f(.) that will get you the p_y(.) you want. since p_x(b) is constant (equal to 1/2) for | b|<1 (and zero outside that interval), then you have: p_y(a) = p_x( g(a) ) * | 1/(f'( g(a) )) | 1/(sqrt(2*pi)*sigma) * exp(-(1/2)*(a/sigma)^2) = 1/2 * |1/ (f'( g(a) ))| f'( g(a) ) = sqrt(pi/2)*sigma * exp((1/2)*(a/sigma)^2) f'( b ) = sqrt(pi/2)*sigma * exp((1/2)*(f(b)/sigma)^2) but "b" never gets bigger than 1 in magnitude. hmmm. this is starting to look a little bitchy. can someone else finish this?
> You can generate a Gaussian noise sample by summing up a large number > of independent, identically distributed samples from any generator,
except an R.V. generator that has no finite variance. like the Cauchy R.V.: p_x(a) = (1/pi)/(1 + a^2) i think, if you keep adding these R.V.s up, you are stuck with Cauchy R.V. there are certain restrictions to the Central Limit Theorem. r b-j
On Aug 1, 12:36 am, Barry <barry...@gmail.com> wrote:
> On Jul 31, 8:01 am, Chris Barrett > > > > > Is there a way to generate colored noise other than by the filtration of > > white noise? > > > How is Gaussian noise generated? My best guess is that I would need to > > a take a random number generator, r(i), where -1>r>1, and plug it into > > some other function. I'm at a loss though, as to what function I should > > use.- Hide quoted text - > > > - Show quoted text - > > Google "Box-Muller transformation"; it converts two independent, > uniformly distributed random variables into two independent, normally > distributed ones.
Or the ziggurat method: http://en.wikipedia.org/wiki/Ziggurat_algorithm For a comparison of methods see: http://www.cse.cuhk.edu.hk/~phwl/mt/public/archives/papers/grng_acmcs07.pdf
Barry <barry374@gmail.com> writes:

> On Jul 31, 8:01 am, Chris Barrett >> >> Is there a way to generate colored noise other than by the filtration of >> white noise? >> >> How is Gaussian noise generated? My best guess is that I would need to >> a take a random number generator, r(i), where -1>r>1, and plug it into >> some other function. I'm at a loss though, as to what function I should >> use.- Hide quoted text - >> >> - Show quoted text - > > Google "Box-Muller transformation"; it converts two independent, > uniformly distributed random variables into two independent, normally > distributed ones.
I think that's what Park's implementation does. To the OP: You can use Park's C library that he's made available here: http://www.cs.wm.edu/~va/software/park/park.html --Randy -- % Randy Yates % "Rollin' and riding and slippin' and %% Fuquay-Varina, NC % sliding, it's magic." %%% 919-577-9882 % %%%% <yates@ieee.org> % 'Living' Thing', *A New World Record*, ELO http://home.earthlink.net/~yatescr
Randy Yates <yates@ieee.org> writes:

> Barry <barry374@gmail.com> writes: > >> On Jul 31, 8:01 am, Chris Barrett >>> >>> Is there a way to generate colored noise other than by the filtration of >>> white noise? >>> >>> How is Gaussian noise generated? My best guess is that I would need to >>> a take a random number generator, r(i), where -1>r>1, and plug it into >>> some other function. I'm at a loss though, as to what function I should >>> use.- Hide quoted text - >>> >>> - Show quoted text - >> >> Google "Box-Muller transformation"; it converts two independent, >> uniformly distributed random variables into two independent, normally >> distributed ones. > > I think that's what Park's implementation does.
No, the one below does not use Box-Muller. (Why couldn't I have looked BEFORE posting?!?) --Randy
> > To the OP: You can use Park's C library that he's made available here: > > http://www.cs.wm.edu/~va/software/park/park.html > > --Randy > > > -- > % Randy Yates % "Rollin' and riding and slippin' and > %% Fuquay-Varina, NC % sliding, it's magic." > %%% 919-577-9882 % > %%%% <yates@ieee.org> % 'Living' Thing', *A New World Record*, ELO > http://home.earthlink.net/~yatescr
-- % Randy Yates % "So now it's getting late, %% Fuquay-Varina, NC % and those who hesitate %%% 919-577-9882 % got no one..." %%%% <yates@ieee.org> % 'Waterfall', *Face The Music*, ELO http://home.earthlink.net/~yatescr
robert bristow-johnson wrote:
> On Jul 31, 11:15 am, cincy...@gmail.com wrote: >> On Jul 31, 11:01 am, Chris Barrett > >>> Is there a way to generate colored noise other than by the filtration of >>> white noise? > > i dunno why the aversion to filtering "white" noise to get colored > noise. particularly when the p.d.f. of the noise is gaussian. linear > filtering will not change that fact.
The "filtering white noise" approaches for commonly used things, like pink noise, are kind of clunky approximations. I'm always averse to clunky solutions. It would seem more elegant to use an algorithm which inherently (and hopefully directly) produces the desired result, if one exists. Sadly, it rarely does. Steve
On Jul 31, 3:14 pm, Vladimir Vassilevsky <antispam_bo...@hotmail.com>
wrote:
> Steve Underwood wrote: > > Chris Barrett wrote: > > >>>> I'm trying to generate noise within a certain spectral range. I > >>>> believe > >>>> such noise is called Gaussian noise. Is there a way I can do this > >>>> other > >>>> than by filtering white noise? > >> Is there a way to generate colored noise other than by the filtration > >> of white noise? > > > Why take one random number, when you can take a dozen. Add them up. See > > what the answer looks like. :-) > > Why taking a dozen numbers if you have to filter it anyway. A filter > will take care of making it gaussian as well as colored. >
Hello Vladimir, The reason for 12 is based upon adding up uniform variates that reside in [0,1]. What is the variance of a uniform deviant in [0,1]? (answer -
> var == 1/12) By adding up 12 of these and then subtracting 6 from
the total gives a result is a very good approximation to a standard normal variate with mean == 0 and variance == 1. Another reason for this approach, is generating uniform deviates is a very low cost function, and many environments have a uniform random number generator handy. If one is doing serious stats, then a better generator would be employed. But this method works well in some forms of Monte Carlo integration. Clay
Clay wrote:
> On Jul 31, 3:14 pm, Vladimir Vassilevsky <antispam_bo...@hotmail.com> > wrote: >> Steve Underwood wrote: >>> Chris Barrett wrote: >>>>>> I'm trying to generate noise within a certain spectral range. I >>>>>> believe >>>>>> such noise is called Gaussian noise. Is there a way I can do this >>>>>> other >>>>>> than by filtering white noise? >>>> Is there a way to generate colored noise other than by the filtration >>>> of white noise? >>> Why take one random number, when you can take a dozen. Add them up. See >>> what the answer looks like. :-) >> Why taking a dozen numbers if you have to filter it anyway. A filter >> will take care of making it gaussian as well as colored. >> > > Hello Vladimir, > > The reason for 12 is based upon adding up uniform variates that reside > in [0,1]. What is the variance of a uniform deviant in [0,1]? (answer - >> var == 1/12) By adding up 12 of these and then subtracting 6 from > the total gives a result is a very good approximation to a standard > normal variate with mean == 0 and variance == 1. Another reason for > this approach, is generating uniform deviates is a very low cost > function, and many environments have a uniform random number generator > handy. If one is doing serious stats, then a better generator would be > employed. But this method works well in some forms of Monte Carlo > integration. > > Clay >
It depends what you need. For many uses, adding 4 or 5 evenly distributed random numbers works OK, and the most elementary congruel generator is good enough for producing those number. The inner sense of Gaussianness just keeps on increasing with the number of random numbers you mix into the answer. 20 or 30 are often summed, often in places where it makes little sense to do so much computation. E.g. the reference code for G.729 uses 20 odd random numbers per Gaussian sample for its comfort noise stimulus. It would be pretty hard to hear a meaningful difference between that and using 5. Then again, it is By the way, I think Vladimir knows this. :-) Steve
Randy Yates <yates@ieee.org> writes:

> > (Why couldn't I have looked BEFORE posting?!?) >
Meet my friend: Murphy. He has a law. ;-) Ciao, Peter K. -- "And he sees the vision splendid of the sunlit plains extended And at night the wondrous glory of the everlasting stars."
Peter K. wrote:
> Randy Yates <yates@ieee.org> writes: > >> (Why couldn't I have looked BEFORE posting?!?) >> > > Meet my friend: Murphy. > > He has a law. > > ;-) > > Ciao, > > Peter K. >
Murphy - Its more than just a bad idea. Its the law. :-) Steve