Digital Signal Processing

By Steven W. Smith, Ph.D.

- 1: The Breadth and Depth of DSP
- 2: Statistics, Probability and Noise
- 3: ADC and DAC
- 4: DSP Software
- 5: Linear Systems
- 6: Convolution
- 7: Properties of Convolution
- 8: The Discrete Fourier Transform
- 9: Applications of the DFT
- 10: Fourier Transform Properties
- 11: Fourier Transform Pairs
- 12: The Fast Fourier Transform
- 13: Continuous Signal Processing
- 14: Introduction to Digital Filters
- 15: Moving Average Filters
- 16: Windowed-Sinc Filters
- 17: Custom Filters
- 18: FFT Convolution
- 19: Recursive Filters
- 20: Chebyshev Filters
- 21: Filter Comparison
- 22: Audio Processing
- 23: Image Formation & Display
- 24: Linear Image Processing
- 25: Special Imaging Techniques
- 26: Neural Networks (and more!)
- 27: Data Compression
- 28: Digital Signal Processors
- 29: Getting Started with DSPs
- 30: Complex Numbers
- 31: The Complex Fourier Transform
- 32: The Laplace Transform
- 33: The z-Transform
- 34: Explaining Benford's Law

Your laser printer will thank you!

Polar Nuisances

There are many nuisances associated with using polar notation. None of these are overwhelming, just really annoying! Table 8-3 shows a computer program for converting between rectangular and polar notation, and provides solutions for some of these pests.

Nuisance 1: Radians vs. Degrees

It is possible to express the phase in either *degrees* or *radians*. When expressed
in degrees, the values in the phase signal are between -180 and 180. Using
radians, each of the values will be between -π and π, that is, -3.141592 to
3.141592. Most computer languages require the use radians for their
trigonometric functions, such as cosine, sine, arctangent, etc. It can be irritating
to work with these long decimal numbers, and difficult to interpret the data you
receive. For example, if you want to introduce a 90 degree phase shift into a
signal, you need to add 1.570796 to the phase. While it isn't going to kill you
to type this into your program, it does become tiresome. The best way to handle
this problem is to define the constant, *P*I = 3.141592, at the beginning of your
program. A 90 degree phase shift can then be written as . Degrees and
radians are both widely used in DSP and you need to become comfortable with
both.

Nuisance 2: Divide by zero error

When converting from rectangular to polar notation, it is very common to find
frequencies where the real part is zero and the imaginary part is some nonzero
value. This simply means that the phase is exactly 90 or -90 degrees. Try to tell
your computer this! When your program tries to calculate the phase from: *Phase X*[*k*] = arctan(*ImX*[*k*]/*ReX*[*k*]), a *divide by zero error* occurs. Even if the program execution doesn't halt, the phase you obtain for this frequency won't
be correct. To avoid this problem, the real part must be tested for being zero
before the division. If it is zero, the imaginary part must be tested for being
positive or negative, to determine whether to set the phase to π/2 or -π/2,
respectively. Lastly, the division needs to be bypassed. Nothing difficult in all
these steps, just the potential for aggravation. An alternative way to handle this
problem is shown in line 250 of Table 8-3. If the real part is zero, change it to
a negligibly small number to keep the math processor happy during the division.

Nuisance 3: Incorrect arctan

Consider a frequency domain sample where *ReX*[*k*] = 1 and *ImX*[*k*] = 1.
Equation 8-6 provides the corresponding polar values of *Mag X*[*k*] = 1.414 and *Phase X*[*k*] = 45°. Now consider another sample where *ReX*[*k*] = -1 and *ImX*[*k*] = -1. Again, Eq. 8-6 provides the values of *Mag X*[*k*] = 1.414 and *Phase X*[*k*] = 45?. The problem is, the phase is wrong! It should be -135°.
This error occurs whenever the real part is negative. This problem can be
corrected by testing the real and imaginary parts after the phase has been
calculated. If both the real and imaginary parts are negative, subtract 180° (or
π radians) from the calculated phase. If the real part is negative and the
imaginary part is positive, add 180° (or π radians). Lines 340 and 350 of the
program in Table 8-3 show how this is done. If you fail to catch this problem,
the calculated value of the phase will only run between -π/2 and π/2, rather than
between -π and π. Drill this into your mind. If you see the phase only
extending to ±1.5708, you have forgotten to correct the ambiguity in the
arctangent calculation.

Nuisance 4: Phase of very small magnitudes

Imagine the following scenario. You are grinding away at some DSP task, and
suddenly notice that part of the phase doesn't look right. It might be noisy,
jumping all over, or just plain *wrong*. After spending the next hour looking
through hundreds of lines of computer code, you find the answer. The
corresponding values in the magnitude are so small that they are buried in
round-off noise. If the magnitude is negligibly small, the phase doesn't have
any meaning, and can assume unusual values. An example of this is shown in
Fig. 8-11. It is usually obvious when an *amplitude* signal is lost in noise; the
values are so small that you are forced to suspect that the values are
meaningless. The phase is different. When a polar signal is contaminated with
noise, the values in the phase are random numbers between -π and π.
Unfortunately, this often *looks* like a real signal, rather than the nonsense it
really is.

Nuisance 5: 2π ambiguity of the phase

Look again at Fig. 8-10d, and notice the several discontinuities in the data.
Every time a point looks as if it is going to dip below -3.14592, it snaps back
to 3.141592. This is a result of the periodic nature of sinusoids.

For example, a phase shift of *θ*, is exactly the same as a phase shift of *θ*+2π,
*θ*+4π, *θ*+6π, etc. Any sinusoid is unchanged when you add an integer multiple
of 2π to the phase. The apparent discontinuities in the signal are a result of the
computer algorithm picking its favorite choice from an infinite number of
equivalent possibilities. The smallest possible value is always chosen, keeping
the phase between -π and π.

It is often easier to understand the phase if it does not have these discontinuities, even if it means that the phase extends above π, or below -π. This is called unwrapping the phase, and an example is shown in Fig. 8-12. As shown by the program in Table 8-4, a multiple of 2π is added or subtracted from each value of the phase. The exact value is determined by an algorithm that minimizes the difference between adjacent samples.

Nuisance 6: The magnitude is always positive (π ambiguity of the phase)

Figure 8-13 shows a frequency domain signal in rectangular and polar form.
The real part is smooth and quite easy to understand, while the imaginary part
is entirely zero. In comparison, the polar signals contain abrupt

discontinuities and sharp corners. This is because the magnitude must always
be positive, *by definition*. Whenever the real part dips below zero, the
magnitude remains positive by changing the phase by π (or -π, which is the
same thing). While this is not a problem for the mathematics, the irregular
curves can be difficult to interpret.

One solution is to allow the magnitude to have *negative* values. In the example
of Fig. 8-13, this would make the magnitude appear the same as the real part,
while the phase would be entirely zero. There is nothing wrong with this if it
helps your understanding. Just be careful not to call a signal with negative
values the "magnitude" since this violates its formal definition. In this book we
use the weasel words: *unwrapped magnitude* to indicate a "magnitude" that is
allowed to have negative values.

Nuisance 7: Spikes between π and -π

Since π and -π represent exactly the same phase shift, round-off noise can cause
adjacent points in the phase to rapidly switch between the two values. As
shown in (d), this can produce sharp breaks and spikes in an otherwise smooth
curve. Don't be fooled, the phase isn't really this discontinuous.