From C to Assembly language - IIR
Filter Design Examples
There are 5 experiments in
this chapter:
1. Experiment 6A - IIR
Filter Implementation Using Floating-point C
2. Experiment 6B -
Fixed-point C Implementation Using Intrinsics
3. Experiment 6C -
Fixed-point C Programming Consideration
4. Experiment 6D - IIR
Filter Assembly Language Implementation
There are many paths you can
take to realize algorithms to applications. Figure E6-1 shows a commonly used
software development flow. In early day s, DSP development is heavily
concentrated in stage 3 while stage 1 and 2 are skipped. With the C compiler improving
rapidly in recent years, C compilers have been widely used in stage 1 and 2 of
the design flow. Aided by compiler optimization and special features like
intrinsics, and DSP processor speed, more and more real-time DSP applications
are implemented using mixed C and assembly code. In the first experiment, we
will use floating-point C code to implement an IIR filter as stage 1 of Figure
E6-1. Developing code in stage 1 does not require knowledge of the DSP
processors. The second and third experiments are emphasis the use of C compiler
optimization, data types, and intrinsics, as show in stage 2. The fourth
experiment is done by the assembly c ode. The stage 3 requires most of the time
because assembly programming is more difficult than C language programming. In
general, assembly code is proven to be the most efficient in digital signal
processing algorithms, like filters involving multiplication and accumulation
operations, while C code can do well in data manipulation, like data formatting
and arrangement. Finally, we show a special IIR filter application - resonator
in the last experiment.
Figure
E6-1 DSP software development flow chart.
Experiment 6A - IIR Filter Implementation
Using Floating-point C
This experiment demonstrates
the first stage of the design flow of a lowpass IIR filter using TMS320C55x.
The main C function exp6a.c
in Table E6-4 and software signal generator listed in Table E6-1 and Table E6-2
are used to aid the experiment. Table E6-5 gives the IIR Filter iir.c.
Table
E6-4 The list of C function for Experiment 6A.
Table
E6-5 The floating-point C IIR filter routine.
To conduct Experiment 6A,
following these steps:
1.Create
the project, exp6a and include
the linker command file exp6.cmd,
the C function exp6a.c, iir.c, signal_gen2.c,
and the assembly routine sine.asm.
The lowpass filter iir() will
remove high frequency components from the input signal generated by the signal
generator signal_gen2() which
uses the resonator sinewave function
sine() to generate three sinewaves in 800Hz, 1.8kHz, and 3.3 kHz.
2.Use
rts55.lib for the C function main()initialization and build the
project exp6a.
3.Enable
break point at the statement for(;;)of
the main() function and use CCS
graphic function to view the 16-bit integer output samples in the buffer out[], set data length to 128 for
viewing one block data a time. Animate the filtering process and observe the
filter output as a clean sine wave of 800 Hz.
4.Profile
IIR filter iir() performance and
record the memory space usage.
5.Check
the IIR filter function for possible overflow. Use CCS watch window to view w_max and w_min in animation.
Figure E6-1 and Figure E6-2
show the plots of the first block of input and output samples of Experiment 6A
in frequency and time domain.
Figure
E6-1 Input of the filter in frequency and time domain.
Figure
E6-2 Output of the filter in frequency and time domain.
1.Create
the project, exp6b and include
the linker command file exp6.cmd,
the C function exp6b.c, iir_i1.c, signal_gen2.c, and the assembly routine sine.asm.
2.Use
rts55.lib for the C function main()initialization and build the
project exp6b.
3.Enable
break point at the statement for(;;)of
the main() function and use CCS
graphic function to view the 16-bit integer output samples in the buffer out[], set data length to 128 for
viewing one block data a time. Animate the filtering process and observe the
filter output as a clean sine wave of 800 Hz.
4.Profile
the IIR filter iir_i1() and
compare the result with those obtained in Experiment 6A.
5.In
file iir_i1() set the scale
factor, SCALE, to 0 so the
samples will not be scaled. Rebuild the project and run the IIR filter
experiment in the ANIMATION mode. You will see the output waveform distortions
caused by the intermediate overflow.
1.Create
the project, exp6d and include
the linker command file exp6.cmd,
the C function exp6d.c, signal_gen2.c, the assembly
routine sine.asm, and the IIR
filter assembly routine iirform2.asm.
2.Use
rts55.lib for the C function main()initialization and build the
project exp6d.
3.Enable
break point at the statement for(;;)of
the main() function and use CCS
graphic function to view the 16-bit integer output samples in the buffer out[], set data length to 128 for
viewing one block data a time. Animate the filtering process and observe the
filter output as a clean sine wave of 800 Hz.
4.Profile
the IIR filter iirform2() and
compare the profile result with those obtained in Experiment 6B and 6C.