Experiments for Chapter 6

Download Chapter 6 experimental software programs

Back to Top


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.

 

Table E6-1 The software signal generator for Experiment 6A, 6B, 6C and 6D.

 

Table E6-1 shows the software signal generator signal_gen2.c for the experiments in this section. It is written using fixed-point C . The assembly routine sine.asm used by the signal_gen2() is given in Table E6-2. The command file exp6.cmd is given in Table E6-3.

 

Table E6-2 The IIR second-order resonator.

Table E6-3 The linker command file.

 


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.

Back to Top


Experiment 6B - Fixed-point C Implementation Using Intrinsics

Experiment 6B introduces the C intrinsics for TMS320C55x programming in C. Using C intrinsics is an efficient way to prototype the DSP applications. In some cases, it may provide the performance efficient enough for use. The programs using intrinsics can be used as a design reference for bit-exactness verification between C and assembly languages. The use of intrinsics is similar to a C function call. The specific computation is carried out as assembly instructions and inserted to the code directly. The C function exp6b.c for Experiment 6B is listed in Table E6-6 for reference. The IIR filter C function that uses intrinsics iir_i1.c, which uses intrinsics is given in Table E6-7.

 

Table E6-6 List of C function for Experiment 6B.

 

Table E6-7 IIR filter using C intrinsics.

 

To conduct Experiment 6B, following these steps:

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.

Back to Top


Experiment 6C - Fixed-point C Programming Implementation Consideration

Familiar with the assembly code generated by the TMS320C55x C compiler can help us to understand and write a better-structured C code for C compiler. Some basic considerations when programming in C are the use of build-in library functions, loop counters, loops and local -repeat loop, as well as compiler optimization options. Experiment 6C demonstrates how an IIR filter can be better written for the C compiler. Table E6-8 and Table E6-9 give the function exp6c.c and modified IIR function iir_i2.c, respectively.

 

Table E6-8 List of C function for Experiment 6C.

 

Table E6-9 Modified IIR filter function.

 

To conduct Experiment 6C, following these steps:

1.     Create the project, exp6c and include the linker command file exp6.cmd, the C function exp6c.c, iir_i2.c, signal_gen2.c, and the assembly routine sine.asm. The C routine iir_i2.c uses unsigned integer for trip counters and replaced the MOD operation with AND operation for the delay-line buffer.

2.     Use rts55.lib for the C function main()initialization and build the project exp6c.

3.     Relocate the C program and data variables into different named SARAM and DARAM sections defined by the linker command files.

4.     Enable –o3 and –mp options to rebuild the project.

5.     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.

6.     Profile the IIR filter iir_i2() and compare the result with those obtained in Experiment 6B.

Back to Top


Experiment 6D - IIR Filter Assembly Language Implementation

The hand-coded assembly code for the TMS320C55x DSP processor will give us the best performance although it generally takes longer time to write and debug. We can write an efficient IIR filter assembly routine that uses only seven DSP cycles to compute each output. Table E6-10 and Table E6-11 give the function exp6d.c and modified IIR function iirform2.asm, respectively.

 

Table E6-10 List of C function for Experiment 6D.

 

Table E6-11 Modified IIR filter function.

 

To conduct Experiment 6D, following these steps:

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.

Back to Top


copyright © 2001 by Sen M. Kuo and Bob H. Lee
website last updated Jan 2, 2001