dsp

Document Sample
dsp Powered By Docstoc
					                                                                                    07/30/03

Digital Signal Processing
David J. Mehrl and Marion O. Hagler
Digital Signal Processing (DSP) (Camtasia tutorial, 33665 KB) is an increasingly
important area of electrical and computer engineering, largely because of DSP
applications in telecommunications to improve the functionality of, for example, cellular
phones, wireless modems, and satellite communication systems. A specific major
application of DSP is the implementation of linear filters. In the past, analog circuits built
from electrical components such as resistors, inductors and capacitors generally
performed linear filtering. Recent advances in semiconductor technology, however, have
culminated in small, low power, self-contained and programmable DSP chips that are
essentially fast, highly specialized and efficient, programmable digital computers. For
low power audio frequency signals, these DSP chips can perform linear filtering more
accurately and cheaply than analog circuits. These DSP chips are fast enough to perform
linear filtering in real time, and offer greater flexibility (because they're programmable)
than analog circuitry. As a consequence, digital signal processing is replacing analog
signal processing in many applications. Digital cellular phones and computer sound
cards, for example, rely on DSP chips for much of their signal processing. Analog filters
must be used for high frequency or high power signals.
A key concept in digital signal processing is that practical signals can be represented
accurately by occasional samples of the signal value. Said another way, it is unnecessary
to know the value of a signal at every instant in time to retain all of the information in
that signal. This result, stated mathematically in the Whittaker-Shannon sampling
theorem, depends on the fact that practical signals have a highest sinusoidal frequency
component. Audio signals, for example, have essentially no frequencies greater than
20,000 Hz. This high frequency limit on the frequencies in practical signals means that
such signals can change (wiggle) only so fast. Therefore, we lose no information by
sampling a signal if we sample it frequently enough. Specifically, the Whittaker-Shannon
sampling theorem tells us that we lose no information if we sample the signal with a
frequency at least twice that of the highest frequency present in the signal. In effect, we
must sample a signal fast enough to catch both the positive and negative lobes of the
highest frequency sinusoidal component in the signal. For audio CDs, the standard
sample rate is 44,100 samples per second, comfortably more than twice the 20,000 Hz
upper frequency limit for audio signals.
Although types of linear filters include low-pass, high-pass, band-pass, and all-pass
filters, we focus on low-pass (or smoothing) filters as a specific example. One very
common use of low-pass filters is to filter high frequency noise out of a signal, without
appreciably affecting the signal itself.
An interesting feature of linear filters is that any particular linear filter is nothing more
than a specific weighted average of the sampled signal values. A very simple smoothing
(low-pass) filter, for example, can be implemented just by replacing each sample value
with the average of itself and the two samples that immediately precede it. This simple
averaging process tends to suppress high frequency wiggles, perhaps mainly noise.
Mathematically speaking, the nth sample of the filtered signal, y, in this simple filter is
calculated from the nth, (n-1)st and (n-2)nd samples of the unfiltered signal, x, as follows:
                  1         1            1
         y  n   x  n   x  n  1  x  n  2 
                  3         3            3
This filter is an example of a 3rd order FIR (Finite Impulse Response) filter, because it
averages over a finite number of signal samples, specifically, 3. In this case, the weights
used for the weighted averaging are all the same: (1/3).
Consider applying the filter described above to the following sampled signal:




(We can get a crude idea of the signal before sampling simply by connecting the sample
values with straight-line segments. The Whittaker-Shannon sampling theorem tells how
to accomplish an exact reconstruction of the signal as it was before it was sampled. Exact
reconstruction is unimportant for our present purposes, however.) By applying the
equation for the smoothing low-pass filter to the sampled signal, we calculate directly
that:
        y 3  y  4  y 5  0
        y  6  30
        y  7   60
        y 8  90
        y  9  90
        y 10  60
        y 11  30
        y 12  y 13  0
Note that there is a "start-up problem" in calculating y 1 and y  2 because, according
to our filter formula,
                   1         1       1
          y 1  x 1  x  0   x  1
                   3         3       3
                   1          1      1
          y  2   x  2   x 1  x  0 
                   3          3      3
The problem is that the values x  1 and x  0 are not specified by the original set of
samples. However, continuity of the signal suggests, and we assume, that
 x  0  x  1  0 . With these assumptions, the resulting filtered signal now looks like
this:
Because the sharp corners of the original signal now appear rounded, the term smoothing
filter seems appropriate. The resulting signal, y(n), is said to be a "low-pass" filtered
version of the original signal, x(n).

MATLAB Example
Among its many features, MATLAB offers powerful capabilities for DSP when the
samples of a signal are represented as a vector. In the example above, for instance, the
signal samples, x(n), can be represented by the following vector:
        x  0 0 0 0 0 90 90 90 90 0 0 0 0
To carry out digital filtering, MATLAB includes a built-in filter function, filter  b, a, x  ,
where b is a vector whose elements, beginning with the first, are the numerical weights
given to x  n , x  n 1 , x  n  2 , and so forth, and where for the simple filters we
consider, a  1 . For the simple 3rd order FIR (Finite Impulse Response) smoothing filter
with equal weighting,
         a 1
         b  1/ 3 1/ 3 1/ 3
If in the Command Window of MATLAB, we write
         y  filter b, a, x 
we obtain the same result we got earlier from direct calculation:
         y  0 0 0 0 0 30 60 90 90 60 30 0 0
The filter(b, a, x) function in MATLAB therefore makes it extremely easy to perform
linear filtering on a vector. It even takes care of the “start-up problem” automatically.

Practice Exercise
Use MATLAB to apply the 3rd order smoothing filter
                  1
         y  n    x  n   x  n  1  x  n  2 
                  3                                   
to the following sampled signal and plot the resulting y(n).
A more Sophisticated Smoothing Filter
An analog low-pass filter can be constructed with the following circuit:




Because it uses a single resistor, R, and a single capacitor, C, this circuit is often called an
RC low pass filter. Its low pass behavior results because at sufficiently high frequencies,
the impedance of the capacitor drops to such a low value that the capacitor is essentially a
short circuit in comparison with the resistor. High frequency components in the signal are
therefore shorted out by the capacitor, although low frequencies pass to the output
because the impedance of the capacitor is high at low frequencies.
The effect of an RC low-pass filter can be replicated by using an "exponentially
weighted" average of the sample values, an average in which the coefficients or weights
decreases in proportion to a decreasing exponential function. A fifth order exponentially
weighted digital filter that approximates the action of an RC low-pass filter is given by
the following equation:
         y  n   nf *  w0* x  n   w1* x  n 1  w2* x  n  2   w3* x  n  3  w4* x  n  4 
                                                                                                         

         y  n   0.42866*  x  n   0.6065* x  n 1  0.3679* x  n  2   0.2231* x  n  3  0.1353* x  n  4 
                                                                                                                         

where
         w0  exp  0
         w1  exp  0.5
         w2  exp  1
         w3  exp  1.5
        w4  exp  2
are the weighting factors appropriate for approximating the RC filter, and the
nomalization factor is chosen somewhat arbitrarily so that
                          1
        nf 
              w0  w1  w2  w3  w4
Since the normalization factor is merely a constant, choosing a different value simply
changes the amplitude scale of the filtered output.
Note that this filter gives more weight to recent samples and less weight to past samples.
Practice Exercise
Use MATLAB to apply the 5th order exponentially weighted digital filter
      y  n   nf *  w0* x  n   w1* x  n 1  w2* x  n  2   w3* x  n  3  w4* x  n  4 
                                                                                                      

         y  n   0.42866*  x  n   0.6065* x  n 1  0.3679* x  n  2   0.2231* x  n  3  0.1353* x  n  4 
                                                                                                                         

to the following sampled signal and plot the resulting y(n).