DSPRelated.com
Forums

Generating 1/f (flicker/pink) noise

Started by Unknown March 21, 2008
Dear All

After having spent a frustrating hour searching around to find some
simple code that would generate 1/f noise, or more generally 1/f^alpha
noise, I decided to write it myself. So here goes:

http://www.eng.ox.ac.uk/samp/powernoise_soft.html

I hope you enjoy it. Comments and feedback welcome.

All the best,
Max
max wrote:
> Dear All > > After having spent a frustrating hour searching around to find some > simple code that would generate 1/f noise, or more generally 1/f^alpha > noise, I decided to write it myself. So here goes: > > http://www.eng.ox.ac.uk/samp/powernoise_soft.html > > I hope you enjoy it. Comments and feedback welcome.
Hello Max You must have looked in the wrong places. Searching for "pink noise" I immediately found http://www.firstpr.com.au/dsp/pink-noise/ There's also [1], which is interesting. Regards, Andor [1] Kasdin, N.J., Discrete simulation of colored noise and stochastic processes and1/f� power law noise generation, Proceedings of the IEEE, Volume 83, Issue 5, May 1995 Page(s):802 - 827.
> > All the best, > Max
Andor wrote:

> You must have looked in the wrong places. Searching for "pink noise" I > immediately found > > http://www.firstpr.com.au/dsp/pink-noise/
Yep, thats a good easily accessible resource.
> [1] Kasdin, N.J., Discrete simulation of colored noise and stochastic > processes and1/f? power law noise generation, Proceedings of the IEEE, > Volume 83, Issue 5, May 1995 Page(s):802 - 827.
Unfortunately, that one is well hidden behind the IEEE knowledge firewall. Erik -- ----------------------------------------------------------------- Erik de Castro Lopo ----------------------------------------------------------------- "In my opinion, shareware tends to combine the worst of commercial software (no sources) with the worst of free software (no finishing touches). I simply do not believe in the shareware market at all." -- Linus Torvalds
On 22 Mar, 22:27, Erik de Castro Lopo <er...@mega-nerd.com> wrote:
> Andor wrote: > > You must have looked in the wrong places. Searching for "pink noise" I > > immediately found > > >http://www.firstpr.com.au/dsp/pink-noise/ > > Yep, thats a good easily accessible resource. > > > [1] Kasdin, N.J., Discrete simulation of colored noise and stochastic > > processes and1/f? power law noise generation, Proceedings of the IEEE, > > Volume 83, Issue 5, May 1995 Page(s):802 - 827. > > Unfortunately, that one is well hidden behind the IEEE knowledge firewall. > > Erik > -- > ----------------------------------------------------------------- > Erik de Castro Lopo > ----------------------------------------------------------------- > "In my opinion, shareware tends to combine the worst of > commercial software (no sources) with the worst of free > software (no finishing touches). I simply do not believe > in the shareware market at all." -- Linus Torvalds
Ah, well I did find those resources, but no simple "one pager" of Matlab code for generating perfect 1/f^alpha noise. These pages all seem to be geared to solving the problem with filters: nothing wrong in that of course for certain applications but it's a bit long-winded. The solution I'm proposing just constructs the appropriate power spectrum and randomised phases, then uses the IFFT to get the 1/ f^alpha signal. There is an interesting residual issue is the DC component or signal mean: should this be zero? If so, it violates the full power-law behaviour across the entire spectrum. The main problem though is that 1/f^alpha is undefined at f = 0. Max
maxlittle2007@googlemail.com wrote:
> On 22 Mar, 22:27, Erik de Castro Lopo <er...@mega-nerd.com> wrote: >> Andor wrote: >>> You must have looked in the wrong places. Searching for "pink noise" I >>> immediately found >>> http://www.firstpr.com.au/dsp/pink-noise/ >> Yep, thats a good easily accessible resource. >> >>> [1] Kasdin, N.J., Discrete simulation of colored noise and stochastic >>> processes and1/f? power law noise generation, Proceedings of the IEEE, >>> Volume 83, Issue 5, May 1995 Page(s):802 - 827. >> Unfortunately, that one is well hidden behind the IEEE knowledge firewall. >> >> Erik >> -- >> ----------------------------------------------------------------- >> Erik de Castro Lopo >> ----------------------------------------------------------------- >> "In my opinion, shareware tends to combine the worst of >> commercial software (no sources) with the worst of free >> software (no finishing touches). I simply do not believe >> in the shareware market at all." -- Linus Torvalds > > Ah, well I did find those resources, but no simple "one pager" of > Matlab code for generating perfect 1/f^alpha noise. These pages all > seem to be geared to solving the problem with filters: nothing wrong > in that of course for certain applications but it's a bit long-winded. > The solution I'm proposing just constructs the appropriate power > spectrum and randomised phases, then uses the IFFT to get the 1/ > f^alpha signal. > > There is an interesting residual issue is the DC component or signal > mean: should this be zero? If so, it violates the full power-law > behaviour across the entire spectrum. The main problem though is that > 1/f^alpha is undefined at f = 0.
There's an elegant non-filter approach that combines a series of PRNGs running at different rates. Each running at half the rate of the one just faster than it seems yo be an adequately small spread and easy to implement. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
On Sat, 22 Mar 2008 16:03:44 -0700 (PDT), maxlittle2007@googlemail.com
wrote:

>On 22 Mar, 22:27, Erik de Castro Lopo <er...@mega-nerd.com> wrote: >> Andor wrote: >> > You must have looked in the wrong places. Searching for "pink noise" I >> > immediately found >> >> >http://www.firstpr.com.au/dsp/pink-noise/ >> >> Yep, thats a good easily accessible resource. >> >> > [1] Kasdin, N.J., Discrete simulation of colored noise and stochastic >> > processes and1/f? power law noise generation, Proceedings of the IEEE, >> > Volume 83, Issue 5, May 1995 Page(s):802 - 827. >> >> Unfortunately, that one is well hidden behind the IEEE knowledge firewall. >> >> Erik >> -- >> ----------------------------------------------------------------- >> Erik de Castro Lopo >> ----------------------------------------------------------------- >> "In my opinion, shareware tends to combine the worst of >> commercial software (no sources) with the worst of free >> software (no finishing touches). I simply do not believe >> in the shareware market at all." -- Linus Torvalds > >Ah, well I did find those resources, but no simple "one pager" of >Matlab code for generating perfect 1/f^alpha noise. These pages all >seem to be geared to solving the problem with filters: nothing wrong >in that of course for certain applications but it's a bit long-winded. >The solution I'm proposing just constructs the appropriate power >spectrum and randomised phases, then uses the IFFT to get the 1/ >f^alpha signal. > >There is an interesting residual issue is the DC component or signal >mean: should this be zero? If so, it violates the full power-law >behaviour across the entire spectrum. The main problem though is that >1/f^alpha is undefined at f = 0.
Max, Thanks for the free toy. I thought it would be interesting to listen to the noises and look at them, so I made one-second bursts for a Windows system ... for alpha = 1:3; mySound = powernoise(alpha , 44100); m = mean(mySound) rms = norm(mySound)/sqrt(44100) wavwrite(mySound,44100,strcat('PN', num2str(alpha), '.wav')); plot(1:44100,mySound); hold all; end I found that the darker-colored noises (alpha = 2 or 3) were inaudible, until I later multiplied them by quite a bit. The rms amplitude was lots smaller than for the white noise, and maybe the sound system or ear doesn't respond as well either. On the DC question, I found that the DC level was always positive, always at a mean of .0048. Shouldn't the DC polarity be random? -- John
On Sat, 22 Mar 2008 22:23:59 -0400, Jerry Avins <jya@ieee.org> wrote:

>maxlittle2007@googlemail.com wrote: >> On 22 Mar, 22:27, Erik de Castro Lopo <er...@mega-nerd.com> wrote: >>> Andor wrote: >>>> You must have looked in the wrong places. Searching for "pink noise" I >>>> immediately found >>>> http://www.firstpr.com.au/dsp/pink-noise/ >>> Yep, thats a good easily accessible resource. >>> >>>> [1] Kasdin, N.J., Discrete simulation of colored noise and stochastic >>>> processes and1/f? power law noise generation, Proceedings of the IEEE, >>>> Volume 83, Issue 5, May 1995 Page(s):802 - 827. >>> Unfortunately, that one is well hidden behind the IEEE knowledge firewall. >>> >>> Erik >>> -- >>> ----------------------------------------------------------------- >>> Erik de Castro Lopo >>> ----------------------------------------------------------------- >>> "In my opinion, shareware tends to combine the worst of >>> commercial software (no sources) with the worst of free >>> software (no finishing touches). I simply do not believe >>> in the shareware market at all." -- Linus Torvalds >> >> Ah, well I did find those resources, but no simple "one pager" of >> Matlab code for generating perfect 1/f^alpha noise. These pages all >> seem to be geared to solving the problem with filters: nothing wrong >> in that of course for certain applications but it's a bit long-winded. >> The solution I'm proposing just constructs the appropriate power >> spectrum and randomised phases, then uses the IFFT to get the 1/ >> f^alpha signal. >> >> There is an interesting residual issue is the DC component or signal >> mean: should this be zero? If so, it violates the full power-law >> behaviour across the entire spectrum. The main problem though is that >> 1/f^alpha is undefined at f = 0. > >There's an elegant non-filter approach that combines a series of PRNGs >running at different rates. Each running at half the rate of the one >just faster than it seems yo be an adequately small spread and easy to >implement.
That's known as the Voss pink noise generator. It's described here: http://www.firstpr.com.au/dsp/pink-noise/ I wrote this about it: http://www.firstpr.com.au/dsp/pink-noise/allan-2/spectrum2.html Regards, Allan
Allan Herriman wrote:
> On Sat, 22 Mar 2008 22:23:59 -0400, Jerry Avins <jya@ieee.org> wrote:
...
>> There's an elegant non-filter approach that combines a series of PRNGs >> running at different rates. Each running at half the rate of the one >> just faster than it seems yo be an adequately small spread and easy to >> implement. > > That's known as the Voss pink noise generator. It's described here: > http://www.firstpr.com.au/dsp/pink-noise/ > > I wrote this about it: > http://www.firstpr.com.au/dsp/pink-noise/allan-2/spectrum2.html
Thanks, Allan. I knew it was one of the real smart guys here, but I couldn't remember which one. It tickled me when you showed it to us. Jerry -- Engineering is the art of making what you want from things you can get. &#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;&#4294967295;
maxlittle2007@googlemail.com wrote:

> After having spent a frustrating hour searching around to find some > simple code that would generate 1/f noise, or more generally 1/f^alpha > noise, I decided to write it myself. So here goes: > > http://www.eng.ox.ac.uk/samp/powernoise_soft.html > > I hope you enjoy it. Comments and feedback welcome.
Nice tool, thanks! I do, anyway, have a question. How did you test the function in order to be sure it is generating the noise shape you wanted? Thanks again, bye, -- piergiorgio
On Mar 23, 6:06 am, John O'Flaherty <quias...@yeeha.com> wrote:
> On Sat, 22 Mar 2008 16:03:44 -0700 (PDT), maxlittle2...@googlemail.com > wrote: > > > > >On 22 Mar, 22:27, Erik de Castro Lopo <er...@mega-nerd.com> wrote: > >> Andor wrote: > >> > You must have looked in the wrong places. Searching for "pink noise" I > >> > immediately found > > >> >http://www.firstpr.com.au/dsp/pink-noise/ > > >> Yep, thats a good easily accessible resource. > > >> > [1] Kasdin, N.J., Discrete simulation of colored noise and stochastic > >> > processes and1/f? power law noise generation, Proceedings of the IEEE, > >> > Volume 83, Issue 5, May 1995 Page(s):802 - 827. > > >> Unfortunately, that one is well hidden behind the IEEE knowledge firewall. > > >> Erik > >> -- > >> ----------------------------------------------------------------- > >> Erik de Castro Lopo > >> ----------------------------------------------------------------- > >> "In my opinion, shareware tends to combine the worst of > >> commercial software (no sources) with the worst of free > >> software (no finishing touches). I simply do not believe > >> in the shareware market at all." -- Linus Torvalds > > >Ah, well I did find those resources, but no simple "one pager" of > >Matlab code for generating perfect 1/f^alpha noise. These pages all > >seem to be geared to solving the problem with filters: nothing wrong > >in that of course for certain applications but it's a bit long-winded. > >The solution I'm proposing just constructs the appropriate power > >spectrum and randomised phases, then uses the IFFT to get the 1/ > >f^alpha signal. > > >There is an interesting residual issue is the DC component or signal > >mean: should this be zero? If so, it violates the full power-law > >behaviour across the entire spectrum. The main problem though is that > >1/f^alpha is undefined at f = 0. > > Max, > > Thanks for the free toy. I thought it would be interesting to listen > to the noises and look at them, so I made one-second bursts for a > Windows system ... > > for alpha = 1:3; > mySound = powernoise(alpha , 44100); > m = mean(mySound) > rms = norm(mySound)/sqrt(44100) > wavwrite(mySound,44100,strcat('PN', num2str(alpha), '.wav')); > plot(1:44100,mySound); > hold all; > end > > I found that the darker-colored noises (alpha = 2 or 3) were > inaudible, until I later multiplied them by quite a bit. The rms > amplitude was lots smaller than for the white noise, and maybe the > sound system or ear doesn't respond as well either. > On the DC question, I found that the DC level was always positive, > always at a mean of .0048. Shouldn't the DC polarity be random? > > -- > John
Thanks John. All this is to be expected: by definition, increasing alpha means that higher frequency components fall off more and more rapidly with increasing frequency. Eventually all the very low frequencies around DC dominate, so I wouldn't expect good reproduction from a sound system. The DC level is fixed in the algorithm, regardless of alpha. My question was more: how should we expect to deal with the issue that if f=0, 1/f^alpha is undefined? I've settled for |P(0)|^2 = 1, where P(f) is the Fourier transform of the signal, and that makes the entire power spectrum follow the power law. But often, signals people prefer mean zero, so no DC component. This seems to be more a matter of convenience/application/convention rather than mathematical consistency. Max