DSPRelated.com
Forums

Gaussian Noise Generation

Started by Chris Barrett July 31, 2007
Steve Underwood <steveu@dis.org> writes:

> 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. :-)
I've spoken with Officer Murphy on many occasions... -- % Randy Yates % "And all that I can do %% Fuquay-Varina, NC % is say I'm sorry, %%% 919-577-9882 % that's the way it goes..." %%%% <yates@ieee.org> % Getting To The Point', *Balance of Power*, ELO http://home.earthlink.net/~yatescr
cincydsp@gmail.com wrote:
> On Jul 31, 11:01 am, Chris Barrett > <"chrisbarret"@0123456789abcdefghijk113322.none> wrote: > >>julius wrote: >> >>>On Jul 31, 9:05 am, Chris Barrett >>><"chrisbarret"@0123456789abcdefghijk113322.none> 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? >> >>>"White"-ness and "Gaussian"-ness are two orthogonal properties. >>>One describes the correlation property of a stochastic sequence >>>and the other describes the stationary distribution of a random >>>variable (or sequence, if it's stationary). >> >>>All I'm saying is that your "white noise" may have be Laplacian, >>>or any other distribution. >> >>>Would you like to re-think your question? :-) >> >>>Julius >> >>Is there a way to generate colored noise other than by the filtration of >>white noise? > > > Sure you can; the "color" of noise just refers to the shape of its > PSD, which is defined by the noise's autocorrelation function. Some > colors of noise might have easier generation methods, but for an > arbitrary PSD shape, the easiest way is to generate white noise and > design a filter to give you the output PSD that you want. > > >>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. > > > You can generate a Gaussian noise sample by summing up a large number > of independent, identically distributed samples from any generator, > subtracting the mean (expected value) of the sum, and dividing by the > standard deviation of the sum: > > http://en.wikipedia.org/wiki/Central_limit_theorem > > Jason >
So for a Gaussian noise sequence y[i], would I write that as x[i] - M y[i] = ----------- , sigma where x[i] are the identically distributed samples, M is the mean of x[i], and sigma is the standard deviation of x[i]?
On Aug 1, 9:09 am, Chris Barrett
<"chrisbarret"@0123456789abcdefghijk113322.none> wrote:
> So for a Gaussian noise sequence y[i], would I write that as > > x[i] - M > y[i] = ----------- , > sigma > > where x[i] are the identically distributed samples, M is the mean of > x[i], and sigma is the standard deviation of x[i]?
You need to sum up some (finite variance) IID samples before subtracting the mean and dividing by the standard deviation. So, x[i] is your collection of random samples and each sample has mean M and variance sigma^2, your Gaussian sample would be: [ sum_(i=0)^(N-1) x[i] ] - NM y[i] = ------------------------------------------- sigma * sqrt(N) where N is the number of samples in your sum. As others have recommended, 8-12 is a decent number. Jason
cincydsp@gmail.com wrote:
> On Aug 1, 9:09 am, Chris Barrett > <"chrisbarret"@0123456789abcdefghijk113322.none> wrote: > >>So for a Gaussian noise sequence y[i], would I write that as >> >> x[i] - M >>y[i] = ----------- , >> sigma >> >>where x[i] are the identically distributed samples, M is the mean of >>x[i], and sigma is the standard deviation of x[i]? > > > You need to sum up some (finite variance) IID samples before > subtracting the mean and dividing by the standard deviation. So, x[i] > is your collection of random samples and each sample has mean M and > variance sigma^2, your Gaussian sample would be: > > [ sum_(i=0)^(N-1) x[i] ] - NM > y[i] = ------------------------------------------- > sigma * sqrt(N) > > where N is the number of samples in your sum. As others have > recommended, 8-12 is a decent number. > > Jason
But this only gives one sample. Do I do this for sets of 8-12 samples? In other words, should I use this equation: [ sum_(i=0)^(N-1) x[i+Nj] ] - NM y[j] = ------------------------------------------- sigma * sqrt(N) where x[i] has been replaced by x[i+Nj] ?
On Aug 1, 10:39 am, Chris Barrett
<"chrisbarret"@0123456789abcdefghijk113322.none> wrote:
> cincy...@gmail.com wrote: > > On Aug 1, 9:09 am, Chris Barrett > > <"chrisbarret"@0123456789abcdefghijk113322.none> wrote: > > >>So for a Gaussian noise sequence y[i], would I write that as > > >> x[i] - M > >>y[i] = ----------- , > >> sigma > > >>where x[i] are the identically distributed samples, M is the mean of > >>x[i], and sigma is the standard deviation of x[i]? > > > You need to sum up some (finite variance) IID samples before > > subtracting the mean and dividing by the standard deviation. So, x[i] > > is your collection of random samples and each sample has mean M and > > variance sigma^2, your Gaussian sample would be: > > > [ sum_(i=0)^(N-1) x[i] ] - NM > > y[i] = ------------------------------------------- > > sigma * sqrt(N) > > > where N is the number of samples in your sum. As others have > > recommended, 8-12 is a decent number. > > > Jason > > But this only gives one sample. Do I do this for sets of 8-12 samples? > In other words, should I use this equation: > > [ sum_(i=0)^(N-1) x[i+Nj] ] - NM > y[j] = ------------------------------------------- > sigma * sqrt(N) > > where x[i] has been replaced by x[i+Nj] ?
Like others have suggested, you can use a linear filter (i.e. a boxcar filter) to generate the running sum of the last N samples from your random generator, then apply the mean/variance correction once for each sample. You can implement this more efficiently so you don't have to compute the full sum for every output sample. Jason
On Jul 31, 11:47 pm, Steve Underwood <ste...@dis.org> wrote:
> 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 don't get why. gaussian "white" noise goes in (it's white up to Nyquist); pdf is gaussian, spectrum is white. gaussian pink noise comes out; pdf is gaussian, spectrum is pink (or whatever spectrum you design the filter for). what else (higher order moments??) are salient properties of the random signal? if we get the pdf and the spectrum (or autocorrelation) we want, what's wrong with that? i don't see why that is clunky or kludgy or sub-standard or anything like that. r b-j
On Aug 1, 7:56 am, cincy...@gmail.com wrote:
> On Aug 1, 10:39 am, Chris Barrett > > > > <"chrisbarret"@0123456789abcdefghijk113322.none> wrote: > > cincy...@gmail.com wrote: > > > On Aug 1, 9:09 am, Chris Barrett > > > <"chrisbarret"@0123456789abcdefghijk113322.none> wrote: > > > >>So for a Gaussian noise sequence y[i], would I write that as > > > >> x[i] - M > > >>y[i] = ----------- , > > >> sigma > > > >>where x[i] are the identically distributed samples, M is the mean of > > >>x[i], and sigma is the standard deviation of x[i]? > > > > You need to sum up some (finite variance) IID samples before > > > subtracting the mean and dividing by the standard deviation. So, x[i] > > > is your collection of random samples and each sample has mean M and > > > variance sigma^2, your Gaussian sample would be: > > > > [ sum_(i=0)^(N-1) x[i] ] - NM > > > y[i] = ------------------------------------------- > > > sigma * sqrt(N) > > > > where N is the number of samples in your sum. As others have > > > recommended, 8-12 is a decent number. > > > > Jason > > > But this only gives one sample. Do I do this for sets of 8-12 samples? > > In other words, should I use this equation: > > > [ sum_(i=0)^(N-1) x[i+Nj] ] - NM > > y[j] = ------------------------------------------- > > sigma * sqrt(N) > > > where x[i] has been replaced by x[i+Nj] ? > > Like others have suggested, you can use a linear filter (i.e. a boxcar > filter) to generate the running sum of the last N samples from your > random generator, then apply the mean/variance correction once for > each sample. You can implement this more efficiently so you don't have > to compute the full sum for every output sample. > > Jason
Using separate sums of uniform deviates generates samples of an iid gaussian approximation. The filter process applied next colors the samples. Performing the first summation as part of a running filter strongly colors the samples in a strongly low pass manner. You can always fix this by desampling by N as that would take you back to the first case and the same efficiency. If you want the coloration from the boxcar filter for your samples there is a savings. Dale B. Dalrymple http://dbdimages.com
cincydsp@gmail.com wrote:
> On Aug 1, 10:39 am, Chris Barrett > <"chrisbarret"@0123456789abcdefghijk113322.none> wrote: >> cincy...@gmail.com wrote: >>> On Aug 1, 9:09 am, Chris Barrett >>> <"chrisbarret"@0123456789abcdefghijk113322.none> wrote: >>>> So for a Gaussian noise sequence y[i], would I write that as >>>> x[i] - M >>>> y[i] = ----------- , >>>> sigma >>>> where x[i] are the identically distributed samples, M is the mean of >>>> x[i], and sigma is the standard deviation of x[i]? >>> You need to sum up some (finite variance) IID samples before >>> subtracting the mean and dividing by the standard deviation. So, x[i] >>> is your collection of random samples and each sample has mean M and >>> variance sigma^2, your Gaussian sample would be: >>> [ sum_(i=0)^(N-1) x[i] ] - NM >>> y[i] = ------------------------------------------- >>> sigma * sqrt(N) >>> where N is the number of samples in your sum. As others have >>> recommended, 8-12 is a decent number. >>> Jason >> But this only gives one sample. Do I do this for sets of 8-12 samples? >> In other words, should I use this equation: >> >> [ sum_(i=0)^(N-1) x[i+Nj] ] - NM >> y[j] = ------------------------------------------- >> sigma * sqrt(N) >> >> where x[i] has been replaced by x[i+Nj] ? > > Like others have suggested, you can use a linear filter (i.e. a boxcar > filter) to generate the running sum of the last N samples from your > random generator, then apply the mean/variance correction once for > each sample. You can implement this more efficiently so you don't have > to compute the full sum for every output sample.
A boxcar filter highly correlates successive outputs. After all, N-1 out of N addends are unchanged, so the next number can't differ much from the present one. The noise may be Gaussian, but it isn't white. To retain whiteness, don't reuse any of the linearly distributed inputs. Jerry -- Engineering is the art of making what you want from things you can get.
On Aug 2, 12:04 am, Jerry Avins <j...@ieee.org> wrote:
> cincy...@gmail.com wrote: > > On Aug 1, 10:39 am, Chris Barrett > > <"chrisbarret"@0123456789abcdefghijk113322.none> wrote: > >> cincy...@gmail.com wrote: > >>> On Aug 1, 9:09 am, Chris Barrett > >>> <"chrisbarret"@0123456789abcdefghijk113322.none> wrote: > >>>> So for a Gaussian noise sequence y[i], would I write that as > >>>> x[i] - M > >>>> y[i] = ----------- , > >>>> sigma > >>>> where x[i] are the identically distributed samples, M is the mean of > >>>> x[i], and sigma is the standard deviation of x[i]? > >>> You need to sum up some (finite variance) IID samples before > >>> subtracting the mean and dividing by the standard deviation. So, x[i] > >>> is your collection of random samples and each sample has mean M and > >>> variance sigma^2, your Gaussian sample would be: > >>> [ sum_(i=0)^(N-1) x[i] ] - NM > >>> y[i] = ------------------------------------------- > >>> sigma * sqrt(N) > >>> where N is the number of samples in your sum. As others have > >>> recommended, 8-12 is a decent number. > >>> Jason > >> But this only gives one sample. Do I do this for sets of 8-12 samples? > >> In other words, should I use this equation: > > >> [ sum_(i=0)^(N-1) x[i+Nj] ] - NM > >> y[j] = ------------------------------------------- > >> sigma * sqrt(N) > > >> where x[i] has been replaced by x[i+Nj] ? > > > Like others have suggested, you can use a linear filter (i.e. a boxcar > > filter) to generate the running sum of the last N samples from your > > random generator, then apply the mean/variance correction once for > > each sample. You can implement this more efficiently so you don't have > > to compute the full sum for every output sample. > > A boxcar filter highly correlates successive outputs. After all, N-1 out > of N addends are unchanged, so the next number can't differ much from > the present one. The noise may be Gaussian, but it isn't white. To > retain whiteness, don't reuse any of the linearly distributed inputs. > > Jerry > -- > Engineering is the art of making what you want from things you can get.
Right. He never said he wanted white noise, just Gaussian. It's fairly obvious that using a boxcar filter will yield correlated (colored) output samples. Jason
On Aug 2, 4:25 am, cincy...@gmail.com wrote:
>
...
> > Right. He never said he wanted white noise, just Gaussian. It's fairly > obvious that using a boxcar filter will yield correlated (colored) > output samples. > > Jason
Jason Actually, the OP's first post said 'a certain spectral range'. The first question in the OP's second post was about 'a way to generate colored noise' and only the second question in that post was about 'Gaussian noise'. This isn't the first time an OP has picked a title that doesn't closely match the extent of the query. So, he said he wanted a 'certain' colored noise, not just Gaussian. It is not clear the it would be obvious -to the OP- how the boxcar filter would color noise. Don't be surprised if a few of the posts on comp.dsp are actually in response to the OP, even if this one isn't. Dale B. Dalrymple http://dbdimages.com