Digital Signal Processing Laboratory 7: IIR Notch Filters Using the TMS320C6711 Thursday, 4 November 2010 Objective: To implement a simple filter using a digital signal processing microprocessor using the TI Code Composer development tools. To compare the performance of different filter designs using inputs from a signal generator and viewing outputs on an oscilloscope To filter audio signals. Introduction: A signal processing microprocessor is a special purpose processor with an architecture designed to efficiently implement DSP operations in real time for embedded applications. For this lab and the following labs we will use a development kit board with a TI tms320c6416 and ADCs and DACs for real time signal processing. A block diagram taken from the second reference is shown here. The AIC23 Codec includes the conversions between digital and analog signals. The Code Composer Studio development tools allow you to create programs that can be downloaded to the dsk6416 board. The compiler interprets the C code instructions and creates a sequence of assembly language instructions which will accomplish the desired operations. The.asm file, which is created by the compiler, is then used by the linker to create a corresponding set of binary machine instructions. When these instructions are loaded into the DSK processor, executing them implements the original C code instructions. In this laboratory we will use interrupts to respond to the analog interface ADC and DAC at 8000 samples per second. At each interrupt a data sample is read and added to a queue. The queue, which is implemented using a circular buffer, is used to compute the filtered output for an FIR filter. An IIR filter will have a queue for the input and a separate queue for the output. The frequency selective behavior of the filter is determined by its coefficients. The filter will be implemented using floating point arithmetic, but its output will be converted to a short integer before it is sent to the DAC. Laboratory Procedure:
Step 1: Set up the equipment and create a project with Code Composer. 1. Turn on the signal generator and the oscilloscope so they can warm up. 2. Connect the DSK board to the computer using the USB cable and connect power to the board. 3. Follow the setup instructions for Code Composer and the 6416 DSK board. Use the version of fir.c below which includes test.cof, not ave5.cof. 4. Set up the signal generator to produce a 500 Hz sinusoidal signal with an amplitude of 0.5 V peak to peak. Using a BNC T connector, connect the output of the signal generator to an oscilloscope input and to the DSK board input. Display the signal on the scope and verify the amplitude and frequency. Set this channel up to be the sync trigger for the scope. 5. Connect the analog output from the DSK board to a second scope input. Step 2: Use the DSK board to sample a signal from the signal generator and output it to the oscilloscope. 1. Run the program and view the input and output DSK signals on the scope. Be sure that the sync is set up to trigger on the signal generator signal for both displays. 2. Verify that the DSK output signal looks like the signal generator signal. 3. From the scope display measure the time between the peak of the signal generator signal and the DSK output signal. Record this value. This measure the time it takes to capture a discrete time signal and then output it through a D/A when there is no discrete time processing. Step 3: Explore the effect of the analog anti-aliasing and anti-imaging filters on the frequency range of the system. 1. Decrease the frequency of the signal generator signal until the output is less than half the amplitude of the 500Hz output. Record this value. 2. Change the signal frequency to 3500Hz and then increase the frequency until the output is less than half the amplitude of the 500Hz output. Record this frequency value. 3. Set the frequency of the signal generator to 200 Hz and verify that you can see the output signal. 4. Change the signal generator waveform to a square wave. Sketch the output waveform shape. 5. Increase the signal generator frequency to 500 Hz. Sketch the output waveform shape. 6. Slowly increase the frequency to 1000 Hz. How does the output waveform change? Explain what you see. 7. Slowly increase the frequency to 2000 Hz. How does the output waveform change? Sketch the output waveform. Explain what you see.
8. Repeat steps3.3 to 3.7 using a triangular waveshape. How does this result compare to the square wave results? 9. Set the wave shape back to sinusoidal at 500 Hz. 10. Change the coefficients in test.cof to all be zero except for the fourth value which will be one. Repeat Step 2.3. How does this time interval compare to the interval measured in Step 2.3? Step 4: After Step 3 is complete, explore the effect of the five sample moving average by including ave5.cof file instead of test.cof and rebuilding the project. 1. With a sinusoidal signal input, observe the amplitude of the output signal as you change the frequency. 2. Record the amplitude of the output when the frequency is 500 Hz, 1 KHz, 1.5 KHz, and 2KHz. 3. Find two frequencies below 3.5 KHz where the output is zero and record the frequency values. Step 5: Build and test a new project for a notch filter. 1. The notch filter should have two poles and two zeros. Use the notch filter C code from your prelab work and set the notch filter parameters to create a notch at 1KHz when the sampling rate is 8KHz. The poles should have a magnitude of 0.9. 2. Test and debug your code. Be very careful that the data stored in the queues is the correct data located at the correct index. 3. Find a frequency less than 3.5 KHz which produces an output of 0. How close is it to 1 KHz? 4. Find the frequencies above and below the notch frequency where the amplitude is 50% of the output level at 300 Hz. How wide is the notch? Questions: 1. What changes would be needed in the fir program to output the average of the last 15 inputs instead of the last 5? 2. How long a queue would be needed for the input if the fir filter would add an echo with a delay of 0.5 s? 3. Why do the square wave and triangle wave change shape as the frequency is increased? At what frequency would you expect them both to look like a sinusoidal signal? Why? 4. At what frequencies would you expect to see an output of zero from the filter which averages 5 input values? How does this compare to the results you observed in Step 4.3? 5. How would you modify your C code to implement your notch filter in a Direct Form II transpose form.
Submit the answers to the questions above and the questions in the laboratory procedure as well as the data and sketches requested in the procedure. Submit a listing of C code instructions for Question 5. The two files shown below will be provided in the laboratory. File fir.c // program fir.c #include "DSK6416_AIC23.h" // codec support Uint32 fs=dsk6416_aic23_freq_8khz; //set sampling rate #define DSK6416_AIC23_INPUT_MIC 0x0015 #define DSK6416_AIC23_INPUT_LINE 0x0011 Uint16 inputsource=dsk6416_aic23_input_line; // select line in #include "test.cof" float x[n]; //filter coefficient file //filter delay line interrupt void c_int11() //ISR - AIC23 codec interrupts at 8kHz { short i; float yn = 0.0; } x[0] = (float)(input_left_sample()); //get new input into delay line for (i=0 ; i<n ; i++) //calculate filter output yn += h[i]*x[i]; for (i=(n-1) ; i>0 ; i--) //shuffle delay line contents x[i] = x[i-1]; output_left_sample((short)(yn)); //output to codec return; void main() //main body of program does nothing { comm_intr(); //initialise DSK while(1); //infinite loop } File ave5.cof //ave5.cof Coefficient file for use with programs fir.c and firprn.c //Implements five point moving average filter #define N 5 float h[n] = {0.2, 0.2, 0.2, 0.2, 0.2}; File test.cof //test.cof Coefficient file for use with programs fir.c //outputs sample values with no digital processing #define N 5
float h[n] = {1.0, 0.0, 0.0, 0.0, 0.0}; (c) Copyright 2000-2010 Sally Wood