You are on page 1of 3

-------------------------------------------------------------------------------

FFTfilter Chameleon Example


-------------------------------------------------------------------------------
This example shows how to use the FFT transformation into the DSP to implement
a stereo graphic equalizer employing large FIR filters. Although present-day
graphic equalizers typically are realized with second order IIR filters,
there is no reason not to use FIR filters.
The method used to implement these filters is the Overlap-Add FFT
Convolution. The example is based in the known property for which the
convolution of two sequences h and x is equivalent to the complex
multiplication of the respective DTFTs:
y = IDTFT(DTFT(h))*DTFT(x))
We have used a more practical method of computing 'y' by replacing all the
DTFTs and IDTFTs by N-point FFTs and IFFTs respectively. Thus the DSP portion
of the example implements the following equations:
out_left = IFFT(FFT(h)*FFT(in_left ))
out_right = IFFT(FFT(h)*FFT(in_right))
where h is the impulse response of the FIR filter of order M.
In the overlap-add method, an input block of L samples is processed by the
filter kernel generating a new block of L+M samples, from which the first L
samples will be sent to the output. The rest M samples will be saved
temporarily to be added with the next L output samples generated.
The FFT length N must satisfy N=L+M in order for the output blocks to be
correct. In the example, the size of the FFT has been fixed to 256 points and
the audio blocks to 64 samples, leaving a maximum of 192 coefficients for the
FIR filter.
The FFT implementation is a slightly modified version of the macro contained in
the FFTR2A.ASM file included in the DrBub archives and supplied with the
Chameleon SDK (for more information, see the APR4.PDF application note). This
macro performs a complete Fast Fourier Transform on complex data using a radix
2, decimation in time, in place algorithm for 24 bit fixed-point arithmetic, and
it needs a sine/cosine table stored in DSP memory. The same macro is used to
calculate the IFFT simply by using a modified sine/cosine table.
It's not optimized for speed, code size or accuracy. The macro is used five
times in each processing pass (FFT(h), FFT(in_left), FFT(in_right),
IFFT(H*IN_LEFT) and IFFT(H*IN_RIGHT)). A lot of improvements could be made such
as using a modified FFT version optimized for real input data (using then an
N/2 point FFT instead of a N point FFT) and prepared for automatic scaling
(block floating point) in order get best SNR, using subroutines for FFT, BITREV
(instead macros) and complex product (optimizing then the code size), or
computing FFT(h) only once when h changes, instead of calculate it on each
pass.
The initialization code and routines found in file MAIN.ASM are practically the
same used in the monosynth example (DMA for audio transfers, and interrupts for
Host communications).
The processing code is located in the file CODE.ASM. All data used by the FFT
routines are complex and they are referenced by locating the real part into the
internal X memory and the imaginary part into the internal Y memory. Also the
input and output audio buffers are located in internal memory, mapping the left
and right channels to X and Y memory respectively.
The ColdFire portion of the example is divided into two different concurrent
tasks (as usual in the Chameleon examples):
- The panel task is dedicated to control the user interface, reacting to input
control messages and sending output control data for showing related
information in the display.
- The dsp task manages the communications with the DSP, sending messages to it
to change the volume value or the filter coefficients.
Intertask communications are RTEMS message queue based: the panel task send
messages to the DSP message queue when any parameter changes, so the DSP
processes the incoming messages sending data to the DSP.
The equalization filter has been pre-calculated over 8 fixed bands (125Hz,
250Hz, 500Hz, 1KHz, 2KHz, 4KHz, 8KHz, 16KHz) and the file EQDATA.H holds the
coefficients obtained for each band. These coefficients has been computed using
Scilab, the mathematical utility supplied with the Chameleon SDK. When the
panel task notifies the DSP task that a band gain has changed, the DSP task
computes a 192 order FIR filter by mixing the 8 pre-calculated FIR filters
weighted with the individual gains, and then it sends the resulting filter
coefficients to the DSP across the host port to be used in the next processing
pass.
The Scilab files used to compute the filter coefficients are also provided in
the folder scilab of the example. The main file is EQDEMO.SCI; this file sets
the gains of each band (from 0=-15dB to 127=+15dB) and plot the frequency
response of the calculated filter after applying the individual gains (each
band with a different color, the resulting filter with a black thick line),
generating also the coefficient files EQn.h to be used by the example (included
by EQDATA.H). At the end, an input wav file called EQ-INPUT.WAV is loaded,
processed using the calculated filter and an output file called EQ-OUTPUT.WAV
is generated with the results (the processed data is also played if you have a
soundcard in your computer configuration).
To run the Scilab demo type the following commands in the Scilab command
window:
chdir('C:\XXXpathXXX\fftfilter\scilab');
exec('eqdemo.sci');
You can try different filter configurations by editing the file and changing
the gains for the equalizer bands.
The application running in the Chameleon displays 8 vertical graph bars which
are used to show the actual gain for each one of the equalizer bands (the middle
position indicates 0dB gain). Bellow these bars exist three arrows which point
out to the current assigment of the 3 realtime controllers (potentiometers) of
the Chameleon (each potentiometer controls the value of the gain in the assigned
bar):
[--------]
^^^
You can move the three arrows to the right with the PART UP key, and to the left
with the PART DOWN key, changing the assigment of the realtime controllers.

-------------------------
Soundart Development Team

You might also like