📄 ex7p5dec.asm
字号:
;-----------------------------------------------------------------------------
; Program Name: ex7p5DEC.asm
;
; Description: This is an example to show how to implement a decimation
; filter. It implements the following equation
;
; y(m) = h(4)x(3n-4) + h(3)x(3n-3) + h(2)x(3n-2) +
; h(1)x(3n-1) + h(0)x(3n)
;
; followed by the equation
;
; y(m+1) = h(4)x(3n-1) + h(3)x(3n) + h(2)x(3n+1) +
; h(1)x(3n+2) + h(0)x(3n+3)
;
; and so on for a decimation factor of 3 and a filter length of 5.
;
; where
; h(0), h(1), h(2), h(3), and h(4) are the filter coefficients.
; x(3n), x(3n-1), x(3n-2), x(3n-3), and x(3n-4) are signal samples.
; x(3n+1), x(3n+2), x(3n+3) are incoming signal samples.
; y(m), y(m+1) ... etc. are the output signal samples.
; Signal samples are integers and
; the filter coefficients are q15 numbers.
;
; Author: Avtar Singh, SJSU
;---------------------------------------------------------------------------
; Definitions
.mmregs
.def _c_int00
.sect "samples"
InSamples .include "data_in.dat" ; Allocate space for x(n)s
OutSamples .bss y,80,1 ; Allocate space for y(n)s
SampleCnt .set 240 ; Number of samples to decimate
.sect "FirCoeff" ; Filter coeff (sequential)
FirCoeff .include "coeff_dec.dat"
Nm1 .set 4 ; Number of filter taps - 1
.bss CoefBuf, 5, 1 ; Memory for coeff circular buffer
.bss SampleBuf, 5, 1 ; Memory for sample circular buffer
.text
_c_int00:
STM #OutSamples, AR6 ; Clear output sample buffer
RPT #SampleCnt
ST #0, *AR6+
STM #InSamples, AR5 ; AR5 points to InSamples buffer
STM #OutSamples, AR6 ; AR6 points to OutSample buffer
STM #SampleCnt, AR4 ; AR4 = Number of samples to filter
CALL dec_init ; Init for filter calculations
loop:
CALL dec_filter ; Call Filter Routine
STH A,1,*AR6+ ; Store filtered sample (integer)
BANZ loop,*AR4- ; Repeat till all samples filtered
nop
nop
nop
;-----------------------------------------------------------------------------
; Decimation Filter Initialization Routine
; This routine sets AR2 as the pointer for the sample circular buffer, and
; AR3 as the pointer for coefficient circular buffer.
; BK = Number of filter taps.
; AR0 = 1 = circular buffer pointer increment.
;-----------------------------------------------------------------------------
dec_init:
ST #CoefBuf,AR3 ; AR3 is the CB Coeff Pointer
ST #SampleBuf,AR2 ; AR2 is the CB sample pointer
STM #Nm1,BK ; BK = number of filter taps
RPT #Nm1
MVPD #FirCoeff, *AR3+% ; Place coeff in circular buffer
RPT #Nm1 ; Clear circular sample buffer
ST #0h,*AR2+%
STM #1,AR0; ; AR0 = 1 = CB pointer increment
RET ; Return
nop
nop
nop
;----------------------------------------------------------------------------
; FIR Filter Routine
; Enter with A = x(n), AR2 pointing to the circular sample buffer,
; and AR3 to the circular coeff buffer. AR0 = 1.
; Exit with A = y(n) as q15 number.
;----------------------------------------------------------------------------
dec_filter:
LD *AR5+,A ; Place next 3 input samples
STL A, *AR2+0% ; into the signal buffer
LD *AR5+,A
STL A, *AR2+0%
LD *AR5+,A
STL A, *AR2+0%
RPTZ A, #Nm1 ; A = 0
MAC *AR3+0%,*AR2+0%,A ; A = filtered signal
RET ; Return
nop
nop
nop
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -