DSPRelated.com
Forums

Generate Pink Noise Efficiently

Started by Robert Scott March 19, 2013
On Thu, 21 Mar 2013 04:23:47 +0000 (UTC), glen herrmannsfeldt
<gah@ugcs.caltech.edu> wrote:

>Eric Jacobsen <eric.jacobsen@ieee.org> wrote: > >(snip) > >> What does "noise in the frequency content" mean wrt a tone? > >(snip, someone wrote) >>>I think if you add phase noise to a sine generator it will do something >>>like you want, no? The sine generator can be easily tuned. The noise >>>amplitude may have to be adjusted for the frequency to give a constant >>>relative bandwidth. > >> A complex tone has constant magnitude and with completely random phase >> will not produce gaussian or uniform distribution of the magnitude in >> the real or imaginary parts, so that must be considered. In other >> words, it is not the equivalent of mixing a desired noise distribution >> or spectrum to the frequency of the tone. > >Okay, but say only slightly random phase. Since it is hard to do the >lookup in radians, consider the phase in cycles, so a binary number >from 0 to almost 1. Now, say you add random noise with amplitude 1/32 >or even 1/64 or 1/128. (Other values will require a multiply.) > >> Since the OP seems interested in some "hump" of noise at a particular >> frequency, I'd suggest generating complex noise at baseband, apply a >> low-pass filter of the desired shape, and then apply a complex mix to >> the desired frequency. If complex noise is desired then that should >> get you there, if real-valued noise is desired, then take the real >> part of the result. > >The OP seems to want to minimize the amount of computation required. >Shifts and adds are still, on most processors, faster than multiplies >and divides. > >-- glen
Probably depends on how limited the limited resources are. It's hard to pick the tradeoffs with much detail without knowing that. Making a spectral bump in the noise might be as easy as repeating samples, which will create a sinx/x frequency response at baseband (and however many are repeated also reduces the computational load). Mixing the baseband LPF repeated samples to a higher frequency isn't all that computationally intensive, but does take some effort. Taking just the real part of the mixed signal saves a fair amount of the computation in the mixing process. Eric Jacobsen Anchor Hill Communications http://www.anchorhill.com
As the OP author stated, the memory is not an issue, so it might also be able to precompute the noise, and apply only necessary IIR-filtering to the precomputed noise sample vector. At least you could save some computing power by this approach. If the precomputed noise should give any artifacts by repeating (resusing) the buffer over and over again, one could start the buffer from random postions after each repetition. 

my 2c.

-Kalvin
On 3/21/13 1:20 AM, Eric Jacobsen wrote:
> > Making a spectral bump in the noise might be as easy as repeating > samples, which will create a sinx/x frequency response at baseband
it's still periodic. you will have discrete line spectra and the sinc(f) function is an envelope to the line spectra. the fundamental frequency is the spacing of the lines, and even if it is far below the 20 Hz hearing limit, it would have to be some pretty clever noise for a person to not hear it cycle. -- r b-j rbj@audioimagination.com "Imagination is more important than knowledge."
Spread Spectrum techniques are an interesting idea for solving the problem.
 Both Frequency and Phase modulation seem like good candidates that could
be implemented without using multiplies.  I will say that if you don't
control the spectrum of the modulating signal, the frequency content of the
output may be a bit wild.  I'm not saying it can't be done, but I wouldn't
be surprised if you didn't get what you expected on the first go. If the
spectrum of your modulating signal is wide, I would keep it's amplitude
low.

Honestly though, how scary are multiply operations on the target processor?
 I thought that ARM core (at least Cortex M series that I know of)
processors bang out multiplies in one or two clocks (with pipelining
latencies anyway)?  Didn't the OP say this thing is running on a smart
phone with a floating point unit?

I'd be throwing a biquad IIR filter at some generated noise.  I can at
least get my head around what its output would look like without racking my
brain too hard.
Thanks for all the great suggestions.  I will to do some
experimentation with these ideas to see which works best.

For those who are curious about the application, it is for blind piano
tuners.  I already have a line of electronic piano tuning apps for
sighted piano tuners.  These applications feature a strobe-like
display that rotates left or right for flat or sharp.  The goal for
the user is to tune the piano until strobe pattern stops moving.  The
strobe display provides immediate analog feedback to the user.

I now want to adapt these applications for use by blind piano tuners.
Just like sighted piano tuners these guys sense the need to make their
job easier by using an electronic aid.  The most obvious method is to
generate a tone of the correct pitch and have the user match it.  But
that method is not very accurate for reasons that I don't want to go
into now.  It would be better if a blind-accessible version of the
strobe display could be provided.

I plan on using an audio output stream to synthesize this strobe
display information.  The user would wear headphones so that the
synthesized sound would not feed back into the microphone which is
listening to the piano.  I plan on mapping the strobe display position
to the center frequency of this filtered noise signal I have been
talking about.  When the frequency is moving upward that corresponds
to the strobe display indicating "sharp".  When the frequency moves
downward, the note is "flat".  Obviously there is a wrap-around event
that happens when the frequency gets to the end of the design range.
But I don't think this is too disconcerting, and the user should be
able to derive the same information that a sighted user would get from
looking at a strobe display, and just as quickly.  The feedback must
be immediate or else use becomes too frustrating.  That rules out any
kind of synthesized voice reading numbers that the user has to parse.
The reason I have chosen to use filtered noise rather than a simple
tone is that the user may also want to listen to the piano directly
and combine aural tuning skills with the electronically enhanced
tuning.  By using filtered noise I prevent any spectrally pure
competition to the piano sounds.  It is why a piano tuner can tune a
piano in a crowded restraunt with lots of talking going on, but he
will have a much harder time if there is music playing in the
background.  So now you know the whole story.

Robert Scott
Hopkins, MN

Neat!  I would love to know how it works out!  Do you have a link to the
products you've already developed?
On 3/21/2013 12:59 PM, dszabo wrote:
> Spread Spectrum techniques are an interesting idea for solving the problem. > Both Frequency and Phase modulation seem like good candidates that could > be implemented without using multiplies. I will say that if you don't > control the spectrum of the modulating signal, the frequency content of the > output may be a bit wild. I'm not saying it can't be done, but I wouldn't > be surprised if you didn't get what you expected on the first go. If the > spectrum of your modulating signal is wide, I would keep it's amplitude > low. > > Honestly though, how scary are multiply operations on the target processor? > I thought that ARM core (at least Cortex M series that I know of) > processors bang out multiplies in one or two clocks (with pipelining > latencies anyway)? Didn't the OP say this thing is running on a smart > phone with a floating point unit? > > I'd be throwing a biquad IIR filter at some generated noise. I can at > least get my head around what its output would look like without racking my > brain too hard.
It's interesting to see everyone's angle on this problem. In many respects this is a systems engineering problem because I don't think the technical requirements given are a good match to the what I believe the user requirements to be. Without digging up the original post, I think the OP is asking for a "noise" sounding signal that has tonal quality. I think this is so it can be passed off as background noise, but at the same time will convey some sort of information without being disruptive to the signal is it riding on. Ok, I went back to the original post and here is what he says about the signal he wants... "noise is to serve as an analog indicator of a measured parameter for a vision-impaired user" Yes, the signal should not have any strong tones in it. But I think you guys are used to working in a domain where you deal with every little nit because it is important to the problem you are solving. This is noise. I don't think it matters if it is pink or white or even if it is black noise... (artistic license here). It needs to have a tonal character that can be perceived by a listener. I think the simplest solution will be quite good enough without putting too fine a point on it. It will be interesting to see (or hear) what the OP comes up with. I would like to hear a sample of what any of these noise generation techniques produce because that is what is important... Has anyone tried doing some of this in a signal processing workstation? My workstation is OpenOffice Calc... lol But I might just try generating sound clips for some of this. -- Rick
On 3/20/2013 7:54 PM, glen herrmannsfeldt wrote:
> rickman<gnuarm@gmail.com> wrote: > >> Maybe there is another way of thinking about this. Instead of creating >> noise and then shaping the spectrum, why not generate a tone with noise >> in the frequency content? > > That is that I was trying to think of, but didn't. I had some ideas > of adding and subtracting LFSR outputs, but that didn't seem to get > close. > >> I think if you add phase noise to a sine generator it will do something >> like you want, no? The sine generator can be easily tuned. The noise >> amplitude may have to be adjusted for the frequency to give a constant >> relative bandwidth. > > OK, so run a phase accumulator, add the output of an LFSR, and > then into a sine LUT. Or use the LFSR output as input to the phase > accumulator.
That's what I'm thinking. I'm just not sure what it will sound like and the sound is the key.
> But back to my previous thought. If you take two uniform random > numbers and add them, then the sum is not uniform. The more you > add, the closer you get to Gaussian shape. A favorite way to generate > random Gaussians is to add uniformly distributed random numbers, > multiply by a constant (which might be 1) then subtract the mean. > > The LFSR needs AND, table lookup, and XOR. A few of those and some > adders doesn't take much (computational) work. > > If you add that to a constant, and use the constant as input to the > phase accumulator, the mean phase increment can change instantly. > I would have to think at least a little bit to know what the > power spectrum would look like. > > Actually, I just realized that this is what they do to reduce RFI > from computers. A single frequency clock has a nice big peak in > its power spectrum. By randomizing the clock rate, even a little > bit, the spectrum is spread out and much less of a problem.
That is what I was mentioning. I've never been convinced that this is an entirely valid way of meeting an RFI spec. If the frequency is just being moved during the measurement period, does that mean the amplitude is reduced? I don't think so. At any given moment the amplitude is still the higher value. So whether it impacts other equipment (the purpose of the RFI spec) depends on how fast the frequency is being moved. I remember reading a spec on a PCI bus chip with a spread spectrum PLL clock the dither rate was rather low to minimize the jitter on the clock period. So in reality this was just a moving tone, not really a "spread" signal. Think in terms of frequency hopping. A frequency hopper still interferes the same as a stationary transmitter, just less often. If the computer clock period was *randomly* distorted I would call that truly spread spectrum because at no time would there be a significant tone. I expect they don't do this for any number of practical reasons.
>> As it turns out, there are a number of ways of easily generating a tone >> from a phase sequence. > > You mean like a sine LUT with or without interpolation? > > And speed vs. time trade-off in table size vs. interpolation.
I meant literally that there are a number of ways of doing that. Recently someone gave me a link to a very nice paper by Jouko Vankka of Helsinki University on DDS techniques. It covers several approaches LUT, CORDIC, complex oscillator. I think any of these could have a random phase/frequency modulated on it. BTW, I doubt interpolation would be needed for this project. The rounding would just result in more noise... lol -- Rick
On 3/21/2013 3:16 PM, Robert Scott wrote:
> Thanks for all the great suggestions. I will to do some > experimentation with these ideas to see which works best. > > For those who are curious about the application, it is for blind piano > tuners. I already have a line of electronic piano tuning apps for > sighted piano tuners. These applications feature a strobe-like > display that rotates left or right for flat or sharp. The goal for > the user is to tune the piano until strobe pattern stops moving. The > strobe display provides immediate analog feedback to the user. > > I now want to adapt these applications for use by blind piano tuners. > Just like sighted piano tuners these guys sense the need to make their > job easier by using an electronic aid. The most obvious method is to > generate a tone of the correct pitch and have the user match it. But > that method is not very accurate for reasons that I don't want to go > into now. It would be better if a blind-accessible version of the > strobe display could be provided. > > I plan on using an audio output stream to synthesize this strobe > display information. The user would wear headphones so that the > synthesized sound would not feed back into the microphone which is > listening to the piano. I plan on mapping the strobe display position > to the center frequency of this filtered noise signal I have been > talking about. When the frequency is moving upward that corresponds > to the strobe display indicating "sharp". When the frequency moves > downward, the note is "flat". Obviously there is a wrap-around event > that happens when the frequency gets to the end of the design range. > But I don't think this is too disconcerting, and the user should be > able to derive the same information that a sighted user would get from > looking at a strobe display, and just as quickly. The feedback must > be immediate or else use becomes too frustrating. That rules out any > kind of synthesized voice reading numbers that the user has to parse. > The reason I have chosen to use filtered noise rather than a simple > tone is that the user may also want to listen to the piano directly > and combine aural tuning skills with the electronically enhanced > tuning. By using filtered noise I prevent any spectrally pure > competition to the piano sounds. It is why a piano tuner can tune a > piano in a crowded restraunt with lots of talking going on, but he > will have a much harder time if there is music playing in the > background. So now you know the whole story.
Great idea! You might try generating some samples of the colored noise you think you want to make sure it sounds the way you need. No point in doing work on the algorithms until you have some idea of how well it will work for your users. BTW, this may have its own problems, but I know blind people sometimes use devices that vibrate. If your first approach doesn't work so well, you might consider a set of three or four gentle vibrators that the user rests three or four fingers on with the same rolling effect of amplitude, up or down. Of course, this has obvious issues with interfering with the piano signal if not done very quietly. -- Rick
Robert Scott <no-one@notreal.invalid> wrote:
> Thanks for all the great suggestions. I will to do some > experimentation with these ideas to see which works best.
(snip)
> I plan on using an audio output stream to synthesize this strobe > display information. The user would wear headphones so that the > synthesized sound would not feed back into the microphone which is > listening to the piano. I plan on mapping the strobe display position > to the center frequency of this filtered noise signal I have been > talking about. When the frequency is moving upward that corresponds > to the strobe display indicating "sharp". When the frequency moves > downward, the note is "flat". Obviously there is a wrap-around event > that happens when the frequency gets to the end of the design range.
(snip) This reminds me of one I heard once called "continuously rising tone." I am not sure the name of the book now, but it came with what was once called a "floppy ROM" in another context, but in any case, an analog recording. The wrap is probably fine, but it isn't necessary. Consider a musical tone with harmonics that is rising slowly. Now, in DSP terms, window it. That is, smoothly reduce the amplitude at lower and higher frequencies. You can now continuously increase the tone without a wrap. The listener won't be able to hear any discontinuity, yet will percieve it as increasing. In terms of tonal noise sources, consider two slowly increasing such sources where the higher one slowly decreases in amplitude and the lower slowly increases, keeping the sum constant, and at the same time both slowly increasing in frequency. It isn't hard at all to generate WAV files given appropriate samples. Should be able to make ones that we could listen to. -- glen