![]() |
|
ADSP 21xx
Have you found this site useful? Did we save you time? Did we cure your head-ache? Is your hair growing back now? Please make a donation to help with maintenance. |
Objective Real-Time Software on the ADSP21XXThe Very Basics on FIR FiltersGeneralA major reason for the appeal of digital filtering techniques is the fact that one can do things with digital filters that will be well nigh impossible when using analogue techniques. This, coupled with the increasing speed and decreasing cost of Digital Signal Processors, caused a surge in interest in DSP applications. The result is a dramatic increase in consumer communication toys, such as cell phones, which were unthinkable 30 years ago.It is therefore imperative that digital filtering techniques be demistified. Many DSP courses still concentrate only on the Laplace and Fourier transforms lurking behind digital filters, without teaching students how to create practical filters, quickly and easily. We assume that you are not working on a very specialised system, but only wants to filter audio and that it does not need to be high fidility, but only acceptable. That should cover about 80% of all applications. If you are designing a radar system or a nuclear missile, I'd be very worried if you would need to read this book... In this chapter, we shall attempt to define a few Rules of Thumb for digital Finite Impulse Response (FIR) filter design and create some examples that you can build upon, without the use of any Greek characters (They are hard to do in HTML anyway!). While serious academics may squirm at the thought, some real world effects are bound to have such a big impact on a system, that there is usually not much need for a detailed filter design effort. It may be better to perform a quick design and then go and test it properly. The basic rules defined here, will usually suffice to get you going. Optimization should only be performed where needed, thus saving you a lot of design time. Detailed DesignOur friend H.Acker attended a DSP course at a major institution in preparation for the design of his multi channel data recorder. He figured that to get a maximally flat frequency response, with no funny group delay effects, he needed a 200 tap low pass FIR filter, with a cutoff frequency of 3kHz. After fourteen days of fighting MatLab (please forgive the pun), he finally managed to frequency sweep the filter and draw his first graph. Beautiful! Exactly what he needed - sharp cutoff down to infinity and beyond, with only the tiniest of tiny side lobes...Hmmm, what is the problem with this? Processing speed requirements for one and memory use for another. As soon as H.Acker coded the monster filter up, he found that there
is no way that it would possibly execute in real time on one channel, never
mind four channels simultaneously, plus all the other things the system
has to do. H.Acker learned a valuable lesson, somehow he needs to use as
few taps as possible, to conserve processing cycles.
That is great, but how many are "as few as possible" anyway?
It appears that practical filters can be realised with 10 to 30 taps.
Hey! Wait a minute, what is this talk about "taps"!!?? Oops, pardon, I thought I'll dive right in first and then surface for breath a while later, just to get your attention. A Simple FIR FilterMost text books start with a description of the moving average filter. There is a good reason for it: All the filter coefficients are the same, so even if you get things backwards, it still works. So, who am I to argue?Great, but what exactly is a "filter coefficient" and where do you get them? You can't get them at a drug store yet, though I fail to see why not - we've had Logarithm Books and Handbooks of Formulas and Tables for centuries already it seems, so what is wrong with publishing filter coefficients? Nothing really, but they tend to be easier to calculate than look up in a book... Let us calculate the average of 3 and 5:
In simple English, a FIR filter is the sum of the products of the signal samples and the filter coefficients, while the number of samples processed at any one time is the number of filter taps, in this case 2 taps, but please read on. From this example it is clear that if we wanted to have a 10 tap filter, the coefficients would be 1/10, or .1 each. Move it alongThere are two things wrong still with the above. A filter is only useful if it operates on a continuous stream of signal samples. We do that, by subtracting the oldest sample product in the block and adding in the new sample product, for every sample received from the Analogue to Digital converter. Thereby, we end up with a moving filter.Another way, is to shift the data in the block up by one, dropping the
oldest sample and adding a new one, then performing the whole calculation
all over again. This may appear to be inefficient at first glance, but
it really depends upon the architecture of the processor. On a Texas Instruments
processor and with a small number of taps (10 to 20), this may work very
well.
What is the other thing that is wrong? The coefficients should be taken in reverse order. With an averaging filter, all the coefficients are the same, so it does not matter, but the order of the coefficients is mighty important with any other filter! The Black Art of digital filter design lies in the choice of the filter coefficients. Tap DancingThe number of taps, determines the smoothness of the filter and it also determines the delay, or the length of time it takes for the first result to pop out the other side of the filter block.
We can see this with our moving average, pencil and paper, but a spread
sheet works a whole lot better. (In fact, a spread sheet is an extremely
valuable tool in DSP design, since it can readily create graphs from number
sequences. As one can copy blocks of text from a Windows 95 DOS box and
paste it into a modern spread sheet, it is also a valuable debugging tool.
If the graph looks funny, you can be sure that your design won't work...).
The example spread sheet is in the Microsoft Excel file realtime\avg.xls and shows two moving average examples, in which I simply fed a somewhat random sequence of numbers. The example above is a 2 tap filter. Note that the 5 tap filter below, has a much more smooth output, as intuitively expected. This very same effect holds true for all proper FIR filters. The more taps, the more delay and the smoother the output.
So, if the operation of a FIR filter is this simple, then what is
the problem with designing digital filters? Just a lack of simple tools,
that's all.
To address the design problem, we have included a very easy to use program on the CD-ROM, called DSPlay. Professor Roger Cattin designed this program for a graduate course. It will create the filter coefficients, based upon a simple specification. You can then sweep the filter with a signal, to see the resulting effect on screen. The program will also generate sample filter code in C or assembler, for a number of DSPs. Let's DSPlayWe can do serious playing with this program. Let us assume that we need a 3300 Hz low pass filter for telephony use. A telephone circuit has a bandwidth of 300 Hz to 3300 Hz and is usually sampled at a rate of 8000 Hz. That allows one to transmit 8 bit compressed PCM voice at a rate of 64000 bits per second.How did that come about? Somebody liked the 64000 bit rate and
divided down from there - honest, no fancy design here!
Why sample at 8000 Hz? Well, according to the Nyquist criterion,
one has to sample at, at least double the rate of the highest frequency
one wants to represent. In practice, sampling at a rate of 3 times the
highest frequency is recommended. Sampling a 3300 Hz signal at 8000 Hz
is pushing one's luck a bit and you only need to talk on a phone to realise
that it really does not sound very good, but it is understandable.
Before one can convert an analogue signal to digital form, one first
has to analogue filter it. It is important to remove all high frequency
components from the signal, since sampling and filtering is somewhat like
a mixer. When one samples a tone with a frequency higher than half the
sampling rate, it will cause the high frequency components to fold back
into your signal, an effect known as aliasing and it sounds somewhat like
ET phoning home - an effect best avoided.
Now, to get DSPlay up and running. Drag and drop the dsplay directory from the CD-ROM onto your hard disk, then go to the dsplay directory and run the program. There is a shortcut in the dsplay directory and the CD comes set up with a work directory and an initialisation file, pointing to this directory, so it should work as is. Design a FIR filter using DSPlayOK, we have DSPlay up and running. Click on the File menu, Design FIR, Design FIR using WindowSelect the following:
Up pops a filter screen. Now we need a signal to pass through the filter. A frequency chirp would be useful, since it could be used to show the cutoff response of the FIR filter. Select the File menu, New Sequence:
Here comes the tricky part. We have to submit the time sequence to the filter. To do that, Right Click on the wheeooooeee graph you just created (Inside the window, on the graph itself). This will cause a new line to appear at the bottom of the screen, which should look something like this:
Up pops the output from the FIR filter. The high frequency wheee part of the time sequence should be severely attenuated by the low pass filter. Let's Get Serious with DSPlayThat was fun, you can just as well admit it. This was surely a lot easier than H.Acker's fight with MatLab and even easier than using a spread sheet. Now, would it not be nice if the program could generate us the coefficients needed to create the filter? In fact, it is a lot better than that, DSPlay can generate sample code in C or assembler!
FIR Menu, Generate ADSP Code then lpf3300, OK OK Nothing much will happen...
and here is your example header file contents:
As easy as that and we didn't even use a single Greek character! Now the fun can start and you can work your way to more complicated designs. IIR FiltersOK, this chapter is about FIR filters, but what is an IIR filter? At the risk of getting stoned by somebody - An Infinite Impulse Response filter is a recursive version of a FIR filter. This means that the output is fed back to the input.
IIR filters are simpler than FIR filters when high order filters are needed (more than 30 taps), but they are potentially unstable. That is, they can whistle quite nastily in your ears if you are not careful. DSPlay can do those too, so have fun! |
|
Copyright © 1996-2008, Aerospace Software Ltd., GPL. |