ECE4703 Laboratory Assignment 3 for the dsPIC33F
Last updated: 2009-12-04
The goals of this laboratory assignment are as follows:
• to familiarize you with the fixed-point digital filter design tools in Matlab and
• to familiarize you with fixed-point real-time FIR and IIR filtering on the DSPIC33F,
This assignment extends the work that you did in Lab 2 to redesign your filters to use only fixed-point calculations. Fixed-point processing is used in many applications requiring high speed, low power, and/or low cost. The dsPIC33F processor has no hardware floating point unit and as you saw in Lab 2, has extremely poor floating point performance. By switching to fixed point, you will be able to create much higher order filters than in floating point. The goal is to realize exactly why fixed-point is preferable and so prevalent in most DSP applications: you can use very inexpensive parts to create high order, effective filters.
1 Filter Specifications
While the code you write for this assignment will allow you to realize almost any type of filter, you will be evaluated on your ability to realize a band-stop filter that satisfies the following requirements:
• First passband: 7200 Hz
• First stopband: 9600 Hz
• Second stopband: 12000 Hz
• Second passband: 14400 Hz
Use the Matlab filter design tools, e.g. fdatool, to design filters for each part below that satisfy all of the requirements. Be sure to note your design choices in your report. Use fdatool to plot the impulse response, magnitude response, and phase response of your filter. As shown in class, you can export your filter coefficients to C header files from fdatool. To do this correctly, please make sure you have selected the correct filter realization structure first, and that you are exporting the filter coefficients as the correct data type. All filter coefficients in this assignment should be generated as single precision floats.
You may use any FIR type this time and 44100 Hz sampling rate. This is a major change from the previous lab, and further demonstrates the performance advantage of fixed-point calculations!
By D.Cullen and J.DeFeo. Based on Dr. Brown’s ECE 4703 B-Term 2008 lab documents.
Prior to the generation of the header files, your coefficients should be quantized to a coefficient word length of 16 bits (including the sign bit), i.e. the data type for all filter coefficients should be signed integer. Double check the header files that Matlab generates to be sure that all of the integer filter coefficients fall in the range -128 to +127. You should also confirm that Matlab is giving the best Q-representation that will allow you to represent your filter coefficients with minimum quantization error while also avoiding overflow. Note that the optimum number of fractional bits might be a negative number. This is ok it just means that you are shifting the decimal point to the right rather than to the left. Be sure to note the number of fractional bits implicit in your fixed-point filter coefficients and comment your code with this information. Use fdatool to plot the impulse response, magnitude response, and phase response of your filter with quantized coefficients.
Compare these results to the unquantized coefficients and discuss any differences in your report.
2 Prerequisites
This lab assumes the following:
• The hardware has already been properly set up and it has been verified that it works properly.
Hardware setup on a breadboard or on an actual PCB board are both acceptable.
• That you are using the PICkit2 programmer.
• The latest versions of MPLAB, the MPLAB C30 Compiler, and the PICkit2 software have already been installed.
3 Programming Assignments
Please create separate MPLAB projects for each of the following programs. Your code should work correctly and must be liberally commented to receive full credit. Your code should compile without any errors or warnings.
3.1 Part 1: Floating Point DF-I FIR filtering
Create a new MPLAB project and write source code that satisfies the filter constraints described in the Filter Specifications section using a direct form I FIR filter with16 big signed integer coefficients.
coefficients. Your filter should run in real-time on the DSK at a sampling frequency of 44100kHz.
You may want to do this in two steps:
1. Use the quantized filter coefficients. Like Lab 2, include some code to keep track of the largest positive and largest negative valued intermediate results (including the final output) in the filter.
Test your code with full-scale sinusoids in the passband and stopband, as well as with white noise.
You shouldnt have any overflow when using floating point intermediate results (except perhaps at the output), but this step will help to determine if you will need to perform any scaling to avoid overflow when the intermediate results are fixed-point.
2. Make the code 100results. How many fractional bits should your intermediate results have?
Use your results from the previous part to perform any scaling as needed to avoid overflow in all intermediate results and at the output.
3.2 Part2: Floating-point DF-II Second-Order-Sections IIR filtering
Create a new MPLAB project and write source that satisfies the filter constraints described in the Fil- ter Specifications section using a direct form II second-order-sections IIR filter with single-precision floating point coefficients and single single-precision floating point intermediate results. You can use fdatool to generate appropriate filter coefficients in the appropriate filter structure and export these coefficients to a header file for use in your MPLAB project. Your filter should run in real-time on the dsPIC. Please write one DF-II SOS function that you can call multiple times from your interrupt service routine. It is up to you how to do this, but the idea here is that your overall filter can be realized by calling the DF-II SOS function several times, each time passing the output from the last DF-II SOS to the input of the next DF-II SOS. All intermediate results should be kept as single precision floats. The usual difficulty with this part of the assignment is in interpreting the header files that Matlab generates for DF-II SOS filters. Please see the course web site links and files page for some information on how to correctly interpret these header files.
4 In Lab
Teams of two are permitted. In the case of an odd number of students in the course, one team of one/three will be formed with permission of the instructor. You will keep these lab partner(s) for all of the laboratory assignments in this course. You and your lab partner(s) will submit joint project code and lab reports that receive a single grade.
5 Specific Items to Discuss in Your Report
In your report, provide theoretical and experimental magnitude response results in the same plot (use different colors or line styles) for each part of the assignment. Your plots should look profes-sional with axis labels, grid lines, and legends as necessary. Your plots should provide immediately convincing evidence to the grader that your filter running on the dsPIC satisfies the requirements and that that it agrees with the magnitude response predictions from Matlab. Be sure to explain any discrepancies (there may not be any). Discuss any scaling considerations that you used to get your filters working correctly and to avoid overflow in the intermediate results and the output.
Please comment about the performance differences between floating and fixed point. Why use fixed point when you have to worry about overflow, fractional bits, and quantization? What did moving to fixed point allow you to do that you could not accomplish with floating point?
6 Final Remarks
Please be aware that each of the laboratory assignments in ECE4703 will require a significant investment in time and preparation if you expect to have a working system by the signoff period on the assignment’s due date. This course is run in “open lab” mode where it is not expected that you will be able to complete the laboratory in the scheduled official lab time. It is in your best interest to plan ahead so that you can use the TA and instructor’s office hours most efficiently.