19-11-2012, 06:02 PM
DSP Lab I - FIR Filter Implementation
DSP Lab I.pdf (Size: 178.99 KB / Downloads: 42)
Introduction
The purpose of this lab is to familiarize yourself with the DSP board and implementation
of simple DSP algorithms in C. The task for this lab is to remove noise (though actually a
sine wave) from a signal using both a simple second-order lter, and then a more complex
higher-order lter.
The noisy signal
The signal is a speech signal sampled at 8000 Hz (telephone quality, which also implies a
bandwidth of 300 Hz 3300 Hz), mixed with a idealized \hum". In this case the hum is
simply a pure sine wave at 60 Hz. This noise is not very audible but can cause problems
due to signal overload or non-linearities. The presence of hum is a common problem in
audio circuits, for example in badly shielded microphone cables. Fortunately, hum is easy to remove with an appropriate lter, at least in the case of a speech signal, which does not
have much relevant energy at that frequency. Thus, the lter needs to be either a bandstop
or highpass lter.
Designing the simple lter
For the rst experiment, we want the simplest possible digital lter that completely removes
a 60 Hz sine wave from a 8000 Hz sampled signal. Such a lter can be created by placing
nulls on the appropriate places onto the unit circle in the Z-Plane.
Better lters using MATLAB
For the second task, the methods described in chapter six of the course textbook [2] should
be used. In particular, the goal is to design and implement an FIR lter of much higher
order (may be from 20-200: part of the task is choosing an appropriate order) using
MATLAB, specically, the FDATool. In this task, there should be no modication to
the speech portion of the signal.
Lab preparation
The preparation for this lab is simply to calculate the coecients of the 2 lters you are
going to use in the lab. Bring your results on your rst lab period.
Implementation
Within the context of this experiment, programming the DSP chip is not much dierent
than programming a regular general-purpose computer (with the exception of the sound
I/O). Thus much of the programming can be done (and debugged) using any C-compiler,
such as GCC or Visual C++.
However, there are restrictions. There is only a limited amount of RAM, and one
actually has to pay attention on where the linker places various data arrays, code segments,
and stacks. Furthermore, the DSK has no local mass storage. Disk reading and writing is
emulated via the Host-to-DSK USB interface and is thus very slow.
For the rst lab, skeleton C les will be provided to you. These les will take care
of conguring most of the features mentioned above (sound I/O, linker settings, etc.).
Implementing the simple lter
The above second-order lter in Eq. (1) can be implemented with very little eort in C.
For the rst task, write a function that takes a single float value (a sample from the input
le) and returns a single
oat output sample. Call this function from a main() function
that reads the samples from the input le and writes the output samples to a le or the
audio output device.
Implementing a lter of higher order
For the implementation of the higher order lter in C, the code should be written such that
the header le generated from MATLAB (the coecients of the lter) can be included into
your project without modication. Thus, the function should accept an arbitrary lter tap
length. Furthermore, the program should work on blocks of samples. This means that you
read the le in sections, rather than reading each sample individually. How many samples
you read at once (the block size) is a design decision | the larger your block, the more
memory is used, but processing speed is increased.
Real-time audio I/O
While reading from disk and writing back to disk is useful for debugging, the real purpose
of a dedicated DSP system is to perform the processing continuously in real-time. Thus,
your code should be able to read a sample of the audio input on the DSK board, process
it, and then write the resulting output sample to the audio output. The attached sample
code shows how to initialize the I/O circuitry and read and write samples.
The eect of the lter can then be observed using the oscilloscope, but by bringing a
set of stereo headphones to the lab, you can listen to the result as well. (If you consider
using your own headphones, bring a cheap pair: bugs in your program have the potential
to damage the headphones! It is also recommended to put o the headphones before each
run of your recompiled program not to damage your ears.)
Interrupt-driven I/O
The attached code works well for simple processing, but is not very ecient | a more
important technique is interrupt-driven I/O. In interrupt-driven I/O, the hardware access
is performed in a routine triggered by the hardware itself, upon the arrival of a new sample.
The interrupt routine (which you will have to write) stores the sample in a buer. The
main program needs to monitor this buer and process the entire contents of the buer
once it is full.