📄 ex7p7adp.asm
字号:
;-------------------------------------------------------------------------------
; Program Name: ex7p7ADP.asm
;
; Description: This is an example to show how to implement an adaptive
; filter. It implements a 9-tap adaptive filter using the following
; equations
;
; y(n) = b0(n)x(n) + b1(n)x(n-1) + b2(n)x(n-2) +
; b3(n)x(n-3) + b4(n)x(n-4) + b5(n)x(n-4)+
; b7(n)x(n-7) + b7(n)x(n-7) + b8(n)x(n-8)
;
; b0(n+1) = b0(n) + erf(n).x(n)
; b1(n+1) = b1(n) + erf(n).x(n-1)
; .
; .
; b8(n+1) = b8(n) + erf(n).x(n-8)
;
; where
; b0(n), b1(n), ... etc. are filter coeff at n, and
; b0(n+1), b1(n+1), ... etc. are same filter coeff at n+1.
; These coefficients are q15 numbers and are stored in a
; circular buffer (CoefBuf).
;
; x(n), x(n-1), ... etc. are input samples (integers) stored
; in a signal circular buffer (SampleBuf).
;
; y(n) is the filtered output (integer).
; d(n) is the desired output (integer).
; e(n) = d(n) - y(n) (integer)
; erfn = e(n) * mu (integer)
; mu is the adaptation coefficient (q15 number).
;
; Author: Avtar Singh, SJSU
;----------------------------------------------------------------------------
; Definitions
.mmregs
.def _c_int00
.sect "samples"
InSamples .include "data_in.dat" ; Input samples to be filtered
OutSamples .bss y,400,1 ; Output samples
SampleCnt .set 400 ; Input sample buffer size
.bss CoefBuf,9,1 ; Coeff circular buffer
.bss SampleBuf,9,1 ; Sample circular buffer
FilterSize .set 9 ; Filter size
mu .set 328 ; mu = 0.01 (as q15 number)
dn .word 0 ; Desired Signal d(n)
en .word 0 ; Error Signal e(n)
yn .word 0 ; Filtered Signal y(n)
erfn .word 0 ; erfn = e(n).mu
.text
_c_int00:
SSBX SXM ; select sign extension mode
STM #OutSamples, AR6 ; AR6 points to out sample buffer
RPT #SampleCnt-1
ST #0, *AR6+ ; Reset the output sample buffer
STM #OutSamples, AR6 ; Reset out sample buffer pointer
STM #InSamples, AR5 ; AR5 points to in sample buffer
STM #SampleCnt-1, AR4 ; AR4 = the sample count
STM #FilterSize-1, BK ; BK = filter size
STM #SampleBuf, AR3 ; AR3 points to the sample CB
STM #CoefBuf, AR2 ; AR2 points to the coeff CB
RPT #FilterSize-1 ; Reset coeff buffer (CoefBuf)
ST #0h,*AR2+%
RPT #FilterSize-1 ; Reset sample buffer (SampleBuf)
ST #0h,*AR3+%
loop:
CALL adaptive_filter ; Do adaptive filtering
BANZ loop, *AR4- ; Repeat for all samples
nop
nop
nop
adaptive_filter:
; Compute y(n) using current filter coefficients
STM #1, AR0 ; AR0 = 1 for increment
RPTZ A, #FilterSize-1 ; y(n) = b0(n)x(n) .. b8(n)x(n-8)
MAC *AR3+0%, *AR2+0%, A
STM #yn, AR1
STH A, 1, *AR1 ; Save y(n) as an integer
STH A, 1, *AR6+ ; Save filtered signal
; Generates d(n) from the computed y(n).
; d(n) can be generated (or obtained) in many different ways.
; Generation of d(n) depends on the problem at hand.
LD *AR1, B ; B = y(n)
STM #dn, AR1 ; AR1 points to the d(n)
BC high, bgt ; Branch to high if y(n) > 0
low: ST #0c000h, *AR1 ; d(n) = c000h if y(n) < 0
B end_dn
high: ST #4000, *AR1 ; d(n) = 4000h if y(n) > 0
end_dn:
; Compute the error e(n)
STM #dn, AR1 ; e(n) = d(n) - y(n)
LD *AR1, A
STM #yn, AR1
SUB *AR1, A
STM #en, AR1
STL A, *AR1
; Update coefficients
STM #mu, T ; erfn = mu.e(n)
MPY *AR1, A
STM #erfn, AR1
STH A, 1, *AR1
STM #FilterSize-1, BRC ; BRC = No of Taps - 1
LD *AR1, T ; T = erfn
RPTB end_update ; Update coefficients
MPY *AR3+0%, A ; A = erfn*x(n)
ADD *AR2,15, A ; Update coefficient
end_update:
STH A,1, *AR2+0% ; Save the updated coefficient
; Obtain new input sample
LD *AR5+, B ; Get the new Input sample
STL B, *AR3+0% ; Put new sample in sample buffer
RET ; Return
nop
nop
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -