<< Chapter < Page | Chapter >> Page > |
In this exercise, you will program in the DSP's assembly language and C to create FIR filters. Begin by studying theassembly code for the basic FIR filter filtercode.asm . For help with circular addressing, view Addressing Modes for TI TMS320C55x .
Filtercode.asm
.ARMS_off ;enable assembler for ARMS=0
.CPL_on ;enable assembler for CPL=1.mmregs ;enable mem mapped register names
.global _filter.global _inPtr
.global _outPtr.copy "macro.asm" ; Copy in macro declaration
.sect ".data"FIR_len1 .set 8 ; This is a 8-tap filter
.align 32 ; Align to a multiple of 16coef1 ; assign label "coef1"
.copy "coef.asm" ; Copy in coefficients.align 32
inputBuffer .space 16*FIR_len1 ; Allocate 8 words of storage for filter statenew_sample_index ; Allocate storage to save index in inputBuffer
.word 0.copy "testvect.asm"
.sect ".text2"_filter
ENTER_ASM ; Call macro. Prepares registers for assemblyMOV #0, AC0 ; Clears AC0 and XAR3MOV AC0, XAR3 ; XAR3 needs to be cleared due to a bug
MOV dbl (*(#_inPtr)), XAR6 ; XAR6 contains address to inputMOV dbl (*(#_outPtr)), XAR7 ; AR7 contains address to output
BSET AR2LC ; sets circular addressing for AR2MOV #inputBuffer, AR2 ; State pointer is in AR2
MOV mmap(AR2), BSA23 ; BSA23 contains address of inputBufferMOV #new_sample_index, AR4 ; State index pointer is in AR4
MOV *AR4, AR2 ; AR2 contains the index of oldest stateMOV #coef1, AR1 ; initialize coefficient pointerMOV #FIR_len1, BK03 ; initialize circular buffer length for register 0-3
MOV *AR6+<<#16, AC0 ; Receive ch1 into AC0 accumulator
MOV AC0, AC1 ; Transfer AC0 into AC1 for safekeepingMOV HI(AC0), *AR2+ ; store current input into state bufferMOV #0, AC0 ; Clear AC0
RPT #FIR_len1-1 ; Repeat next instruction FIR_len1 timesMACM *AR1+,*AR2+,AC0,AC0 ; multiply coef. by state&accumulate
round AC0 ; Round off value in 'AC0' to 16 bitsMOV HI(AC0), *AR7+ ; Store filter output (from AC0) into ch1
MOV HI(AC1), *AR7+ ; Store saved input (from AC1) into ch2MOV HI(AC0), *AR7+
MOV HI(AC1), *AR7+MOV AR2, *AR4 ; Save the index of the oldest state back into new_sample_index
LEAVE_ASM ; Call macro to restore registersRET
filtercode.asm
applies an FIR filter to the signal
from input channel 1 and sends the resulting output to outputchannel 1. It also sends the original signal to output
channel 2.
First, use the MATLAB command
firpm
to generate a 20-tap FIR filter. Type
doc firpm
for information on how to use this command. The filter should pass signals from 4 kHz to 8 kHz. Allow a 1 kHz transition band on each edge of the filter passband. Remember to convert these band edges to digital frequencies based on the 48 kHz sample rate of the system.
Use the
save_coef
command to save the filter. (Make sure you reverse the vector of filter coefficients before you save them.) Also save your filter as a MATLAB matrix, since 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 the filter.
Notification Switch
Would you like to follow the 'Ece 420 fall 2013' conversation and receive update notifications?