Based on: FIR Filtering: Exercise for TI TMS320C55x by Mark Butala, Thomas Shen
Summary: Students implement band-pass finite impulse response (FIR) filters on the TI TMS320C55X digital signal processor.
In this exercise, you will program in the Texas Instruments TMS320C55X DSP assembly language to create FIR filters. Begin by studying the assembly code for the basic FIR filter filtercode.asm.
| filtercode.asm |
|---|
|
The program
filtercode.asm applies a FIR filter to the signal
from input channel 1 and sends the resulting output to output
channel 1. It also sends the original signal to output
channel 2.
First, create a work directory on your network drive for the
files in this exercise and copy the filter folder from
c:\ece609\55x\filter to your work directory. Then, use MATLAB
to generate two 20-tap FIR filters. The first filter should
pass signals from 4 kHz to 8 kHz; the second filter should
pass from 8 kHz to 12 kHz. For both filters, allow a 1 kHz
transition band on each edge of the filter passband. To
create these filters, first convert these band edges to
digital frequencies based on the 48 kHz sample rate of the
system, then use the MATLAB Parks-McClellan equiripple design command firpm to
generate this filter; you can type help firpm for
more information. Use the save_coef command to
save each of these filters into different files. (Make sure
you reverse the vectors of filter coefficients before you save
them.) Also save your filters in MATLAB, because you
will need them later to generate test vectors. This can be
done using the MATLAB save command. Once this is
done, use the freqz command to plot the frequency
response of each filter.
For now, you will implement only the filter with a 4 kHz to 8
kHz passband. Edit filtercode.asm to use the
coefficients for this filter by making three changes.
First, the length of the FIR filter for this exercise is 20,
not 8. Therefore, you need to change FIR_len1 to
20. FIR_len1 is set using the .set
assembler directive, which assigns a number to a symbolic name.
Second, you will need to ensure that the .copy
directive brings in the correct coefficients. Change the
filename to point to the file that contains the coefficients
for your first filter.
Third, you will need to modify the .align and
.space directives appropriately. The TI
TMS320C55x DSP requires that circular buffers, which are used
for the FIR filter coefficient and state buffers, be aligned
so that they begin at an address that is a multiple of a power
of two greater than the length of the buffer. Since you are
using a 20-tap filter (which uses 20-element state and
coefficient buffers), the next greater power of two is 32.
Therefore, you will need to align both the state and
coefficient buffers to an address that is a multiple of 32.
(16-element buffers would also require alignment to a multiple
of 32.) This is done with the .align command. In
addition, memory must be reserved for the state buffer. This
is done using the .space directive, which takes
as its input the number of bits of space
to allocate. Therefore, to allocate 20 words of storage, use
the directive .space 16*20 as shown below:
1 .align 32 % Align to a multiple of 32
2 coef1 .copy "coef1.asm" % Copy FIR filter coefficients
3
4 .align 32 % Align to a multiple of 32
5 firState1 .space 16*20 % Allocate 20 words of data space
Assemble your code, load the output file, and run. Ensure that the filter implements the correct frequency response. After you have verified that this code works properly, proceed to the next step.
First, make a copy of your modified filtercode.asm
file from Part 1. Work from this
copy; do not modify your working filter from the previous
part. You will use that code again later.
Next, modify your code so that in addition to sending the
output of your first filter (with a 4 kHz to 8 kHz passband)
to output channel 1 and the unfiltered input to output channel
2, it sends the output of your second filter (with a 8 kHz to
12 kHz passband) to output channel 3. To do this, you will
need to use the .align and .copy
directives to load the second set of coefficients into data
memory. You will also need to add instructions to initialize
a pointer to the second set of coefficients and to perform the
calculations for the second filter.
Two extra credit points will be awarded to you and your
partner if you can implement the dual-channel system
without using the auxiliary registers AR4 and
AR5? Why is this more difficult? Renaming
AR4 and AR5 using the
.asg directive does not count!
Using the techniques introduced in DSP Development Environment: Introductory Exercise for TI TMS320C55x, generate an appropriate test vector and expected outputs in MATLAB. Then, using the test-vector core file also introduced in DSP Development Environment: Introductory Exercise for TI TMS320C55x, find the system's output given this test vector. In MATLAB, plot the expected and actual outputs of the both filters and the difference between the expected and actual outputs. Why is the output from the DSP system not exactly the same as the output from MATLAB?
An alternative method of implementing symmetric FIR filters
uses the firsadd instruction. Recall that the impulse response of a linear phase FIR filters exhibits a symmetry about the midpoint. The symmetry can be exploited to reduce by 50 percent the number of multiplications per output sample. Modify
your code from Part 1 to implement
a single-channel filter with a 4 kHz to 8 kHz passband using the
firsadd.
The modication of your code from Part 1 for use with the firsadd instruction requires the states
be broken up into two separate circular buffers. Refer to
the firsadd instruction on page 5-152 in
the Mnemonic
Instruction Set [link] manual.
1 mov *AR1, *AR2- ; write x(-N/2) over x(-N)
2 mov HI(AC0), *AR1 ; write x(0) over x(-N/2)
3 add *AR1-, *AR2-, AC0 ; add x(0) and x(-(N-1))
4 ; (to prepare for first multiply)
5 rpt #(FIR_len1/2-1)
6 firsadd *AR1-, *AR2-, *CDP+, AC0, AC1
7 round AC1
8 amar ????? ; Fill in these two instructions
9 amar ????? ; to modify AR1 and AR2
10 ; Note that the result is now
11 ; in the AC1 accumulator
Because states and coefficients are now treated differently than in your previous FIR implementation, you will need to modify the pointer initializations to
1 bset AR1LC ; sets circular addressing for AR1
2 bset AR2LC ; sets circular addressing for AR2
3 bset CDPLC ; sets circular addressing for CDP
4
5 mov #firState1, AR1
6 mov #firState1Index, AR4
7 mov mmap(AR1), BSA01
8 mov *AR4, AR1 ; get pointer to oldest delayBuf in AR1
9
10 mov #firState2, AR2
11 mov #firState2Index, AR5
12 mov mmap(AR2), BSA23
13 mov *AR5, AR2
14
15 mov #(FIR_len1/2), BKC
16 mov #(FIR_len1/2), BK03 ; initialize circular buffer length for register 0-3
17 mov #coef1, CDP ; CDP contains address of coefficients
Two additional changes must be made before the code will compile successfully. Read the comments carefully and understand how the firsadd instruction works to make the necessary changes. Hints: check the accumulator usage (AC0, AC1, AC2) and determine what value should be sent to the output.
Use the test-vector core file to find the output of this
system given the same test vector you used to test the
two-filter system. Compare the output of this code against the
output of the same filter implemented using the
mac instruction. Are the results the same? Why or
why not? Ensure that the filtered output is sent to output
channel 1, and that the unmodified output is still sent to
output channel 2.
The evaluation for Lab 1 is broken down as follows:
.asm file ready to
demonstrate each of your three filters: single channel 20-tap; two channel system; single channel symmetric filter using firsadd. The written quiz may cover signal processing material relating to FIR filters, including, but not limited to, the delay through FIR filters, generalized linear phase, and the differences between ideal FIR filters and realizable FIR filters. You may also be asked questions about digital sampling theory, including, but not limited to, the Nyquist sampling theorem and the relationship between the analog frequency spectrum and the digital frequency spectrum of a continuous-time signal that has been sampled.
The written quiz may cover the code that you have written during the lab. You are expected to understand, in detail, all of the code in the files you have worked on, even if your partner or a TA wrote it. (You are not expected to understand the core file in detail). The quiz may ask you to explain various lines of code as part of the quiz. Other possible topics include: 2's complement fractional arithmetic, circular buffers, alignment, and the mechanics of either of the two FIR filter implementations.
Your version of the quiz will be randomly selected from among several versions of the Lab 1 quiz.
Use the TI documentation, specifically the Mnemonic Instruction Set [link] manual. Also, feel free to ask the TAs to help explain the code that you have been given.