CMP EMBEDDED.COM

Login | Register     Welcome Guest  
HOME DESIGN PRODUCTS COLUMNS E-LEARNING CONFERENCES CODE FORUMS/BLOGS NEWSLETTERS CONTACT FEATURES RSS RSS





Spectra
Pink Noise

Don Morgan


Some noise is just too useful to eliminate. Pink noise is especially appropriate for audio applications.


N
oise is the name we normally give to something that we don't like, we don't want, we don't need, and we wish to get rid of. Noise can come from improper handling of signals or it can occur naturally as a part of nature. Often noise is something that exists without too much specification and is remedied blindly with capacitance in hardware or averaging in software.

But it turns out that noise can be useful in many contexts. In fact, last month, I described several kinds of noise that have been specified and categorized using colors. I also provided some uses for them and showed that noise can be described by the same technology as the stuff we prefer, which we call signals.

Besides white noise, one of the most useful and well known is pink. Pink noise is evident in all forms of engineering and science from solid-state circuits to astrophysics and music. Unlike white noise, it bears a logarithmic characteristic, and, as such, represents a psychoacoustic equivalent of white noise sweetened for human ears. This is the signal used to test speakers and set equalization in theaters and other venues. When you tune up your home multimedia system, the noise used to drive the speakers for the volume settings is probably pink noise.

White noise, like the color white, contains all the elements that other colors of noise are composed of. White noise is truly random in nature and will not correlate. It contains equal energy at all frequencies. This noise is useful for dithering to eliminate quantization distortions, music synthesis, and general audio effects, such as chorusing.

Both white and pink noises are useful for analyzing and measuring system characteristics. Pink noise is especially appropriate for perceptual measurements, as well as useful in synthesis of audio control and sound. In this column, I will review techniques for producing pink noise both in the analog and digital domains and present some algorithms you can use to produce your own noise.

Analog electronic noise
White noise has uses that range from mathematics, analysis (such as determining the frequency response of mechanical equipment), and creating voices in music to zero bias control signals. As you might guess, a signal that does not correlate would be produced by a generator capable of truly random outputs. But truly random signals are not so easy to produce.

There is a general misunderstanding about what a random value is. Random numbers are not arbitrary numbers. If you ask your friend for a random number, what you will probably get is an arbitrary number; this is something pulled out of a hat based on the context of the occasion. But for a number to be random, it must have an equal chance of being chosen out of some known range and precision. Machinery and electronic equipment (including computers) can do anything we want them to. Unfortunately, machines (and computers) can eventually become repetitive. That is, the sequence that we produce will eventually repeat. The trick is to build the machine so that the random sequence is long enough for our purposes.

Using simple digital techniques, we can generate plenty of noise. A common technique utilizes long shift registers. The input to the shift registers is the binary sum (modulo 2) of some of the later bitsıthe actual circuitry comprises shift registers and exclusive-or gates, since a sum modulo 2 results in an exclusive-or. This produces a pseudorandom sequence with a length that depends on the length of the shift registers. We then process this sequence with a lowpass filter to create white noise in the analog domain. You will see a similar technique in one of the algorithms that follow for generating white noise. If you prefer a single IC over three or four discrete ones, there's the MM5437. Of course, there are other means of generating random sequences, such as Fibonacci systems, which are capable of very long sequences. (At the end of the column is a short bibliography of references that provides much more detail on this and other techniques.)

Now, if we have a means to produce white noise, we can fashion some ways to also produce pink noise.

Analog pink noise
Pink noise has equal energy per octave instead of equal energy per frequency like white noise. In other words, its energy is equal to 1/f, which describes a -3dB/octave response. This means that each octave of increasing frequency should contain half the power of the preceding one.

In the analog domain, pink noise is often fashioned from white noise with filters. Since a simple RC filter drops off at -6dB/octave, we need something a bit more sophisticated to produce the response we are after.

Figure 1 illustrates a typical application generating pink noise. You see that a white noise generator is buffered and used to drive a parallel set of shelving type filters. The result is buffered and output.

FIGURE 1: A typical application generating pink noise

What is a shelving filter? It is a filter in which attenuation occurs as expected but instead of going on infinitely, it stops at a certain level, or shelf. To see how this works, realize that each RC combination shown is really a fixed resistor and a frequency variable resistor in series. The resistance of the capacitor varies with frequency:

equation 1

Here, of course, w is equal to 2πƒ, C is the value of the capacitor (in farads), and -i is equal to equation 2, which indicates that the phase of the current in the device is 90 degrees out of phase with the input. The voltage drop across the RC element will depend on the reactance (AC resistance) of the capacitor at any one frequency. A 1 microFarad capacitor will have an effective resistance of 2,653 ohms at 60Hz, 159 ohms at 1kHz, and 0.16 ohms at 1MHz.

Placing this in series with a fixed resistor and a voltage source means that we will be varying the load on the voltage source (through the 66.5K resistor) that depends entirely on the frequency. At a high frequency, the circuit will draw more current from the voltage source than at a low frequency.

In this way, we can program the response for each frequency band that we are interested in and see that the power output (through the 0.1 microFarad capacitor) is truly what we want.

Producing random numbers is no less difficult in software than in hardware. A good deal of study has gone into this field, from Von Neumann's middle square technique through the linear congruential algorithms described by Knuth.

White noise with software
Producing random numbers is no less difficult in software than in hardware. A good deal of study has gone into this field, from Von Neumann's middle square technique through the linear congruential algorithms described by Knuth. The reason for this effort is that so many random number generators have a high serial correlation (sequential dependence); this is a bias in the generator that results in non-white sequences. This bias can be subtle but deleterious. To test a math package I once wrote, I also developed a program that tests random number generators by mapping the sequence to x/y locations on a computer monitor to see if patterns appear. It isn't very scientific, but it does allow you to pick out clusters or lines or other artifacts of bias that might appear. You can then run the chi-square test for a more complete and accurate evaluation.

In software, the most common random number generators derive from the linear congruential generators. These devices generate long sequences of random numbers based on an input seed. Given the same seed, the same series will always be produced. However, it's useful to randomize the seed, somehow, from a clock source or independent counter.

Listings 1 and 2 show two random number generators based on the shift register device described in the analog section. Both listings are in assembly language for the DSP56xxx series DSPs. The first is from Motorola; it is based on the shift register technique I described previously. Following is the method that describes the code in Listing 1:

1. We clear the B register and move the last random number to the A register

2. Test the A register. This instruction sets the flags in the status register by comparing the contents of the A register with zeroınothing actually occurs to the contents of the A register. In the same instruction cycle, move the immediate value 1h to the X0 register

3. Perform a conditional transfer of the X0 (containing the immediate value just loaded) to B if the status flags say that the number in A is indeed normalized

4. Add the last random number with the contents of B. This will be zero if the last random number wasn't normalized, or it will be the immediate value loaded into X0 if the last random number was normalized

5. Shift this value left one time

6. Move the new random number to storage

7. Return from the subroutine

Basically, this code is a 15-bit shift register in the A register. If it is normalized, a one is input to the shift register. Either way the value is shifted and saved.

As an enhancement, in Listing 2, we use a larger immediate value, and change the add to an exclusive-or :

The longer the shift register the better. The DSP56xxx series has a 24-bit word length, enough bits to create a very long series. If your DSP does not have 24 bits, it can easily be constructed in memory, though it will slow the routine.

Digital pink noise
You can implement a pink noise generator in DSP in the same way you do it in the analog domain. Once we have a sufficient white noise source, we could concatenate a series of first-order shelving filters with the same characteristics as the one in Figure 1. Using a DSP with a 24-bit word, we could generate pink noise accurate to approximately ı0.25dB, 10Hz to 40kHz.

Since pink noise is of such great interest (for audio purposes, an excellent source is important), a great deal of study has gone into the production of such a source. Other means are also available to produce pink noise. Interestingly enough, they do not stray far from the basic method. I present two here. (Again, for further detail on these and for other techniques, refer to the References section.)

The first technique is a simple sum. It's based on a technique that uses a weighted sum of low-pass filters. Please note that the coefficients must be scaled to fit your applicationıthat is, the amplitude of your white noise and the output level you need.

The following is pseudocode for the procedure:

white=(whichever method you choose);
buf0=0.997 * buf0 + 0.029591 * white;
buf1=0.985 * buf1 + 0.032534 * white;
buf2=0.950 * buf2 + 0.048056 * white;
buf3=0.850 * buf3 + 0.090579 * white;
buf4=0.620 * buf4 + 0.108990 * white;
buf5=0.250 * buf5 + 0.255784 * white;
pink=buf0 + buf1 + buf2 + buf3 + buf4 
+ buf5;

The second method is well known. It's based on an algorithm by Voss and is mentioned in many publications. This algorithm is based on similar ideas but is more efficient than the explicit instantiation of filter after filter. It's based on the assumption that noise consists of a sum of several white noise processes that are filtered through first-order low-pass filters having time constants that are successively larger and larger. These spreading time constants form a geometric progression. You will notice how this idea reflects the analog version I presented.

The difference lies in the fact that instead of low-passing the white noise, you take the average of several periodically sampled random numbers with periods that form a geometric progression. A geometric progression is a sequence in which each term bears a constant ratio to the preceding term, that is a, ar, ar2, ar3K. In this case, we are using base 2, so GP2 = 2b and b = 0, 1, 2, 3, K, B - 1. And the actual generator becomes:

equation 3

And each yb term is one of the periodic samples taken from the random number generator at interval GP2 = 2b. Simple, right? Next month, we'll continue to look at the uses of DSP in creating sound, with and without noise.

Don Morgan is senior engineer at Ultra Stereo Labs and a consultant with 25 years experience in signal processing, embedded systems, hardware, and software. Morgan recently completed a book about numerical methods, featuring multi-rate signal processing and wavelets, called Numerical Methods for DSP Systems in C. He is also the author of Practical DSP Modeling, Techniques, and Programming in C , published by John Wiley & Sons, and Numerical Methods for Embedded Systems from M&T.

References

Orfanidis, Sophocles J. Introduction to Signal Processing. Inglewood Cliffs, NJ: Prentice-Hall, 1996.

Park, S.K. and K.W. Miller, 3Random Number Generators: Good Ones Are Hard to Find2 Communications of the ACM 31:10, October 1988.

If you are interested in more material on pink noise, see www.firstpr.com.au/dsp/pink-noise/ .

Back

Embedded.com Career Center
Looking for a new job?
SEARCH JOBS

Browse all jobs

SPONSOR
RECENT JOB POSTINGS





 :