📄 alp.asm
字号:
;
; alp.asm - Self-tuned Adaptive linear predictor (Leaky LMS)
;
; Prototype: unsigned int anc_lms(int *in, int *y, int *e, int *d, int *w,
; unsigned int Ns, unsigned int N, unsigned int index)
;
; Entry: in[]- input buffer contains wide & narrow band signals
; y[] - output of the filter narrow band signal
; e[] - output of the filter wide band signal
; d[] - adaptive filter delay-line buffer
; w[] - adaptive filter coefficient buffer
; Ns - number of samples per block
; N - order of the adaptive filter
; index - index to d[]
;
; Return: T0 = Adaptive filter delay-line buffer index
;
TWOMU .set 0x70 ; 2*MU
ALPHA .set 0x7ff0 ; Leaky factor
;
; Declare local variables in SP address mode for C-callable
;
ARGS .set 1 ; Number of variables passed via stack
ANC_var .struct ; Define local variable structure
d_ST1 .int ; Used to save content of ST1
d_ST2 .int ; Used to save content of ST2
d_ST3 .int ; Used to save content of ST3
return_addr .int ; Return address
d_index .int ; Function argument passed via stack
Size .endstruct
anc .set 0
anc .tag ANC_var
.def _alp
.sect "lms_code"
_alp
aadd #(ARGS-Size+1),SP ; Adjust SP for local vars
mov mmap(AR4),BSA45 ; Configure for circular buffers
mov mmap(T1),BK47
mov mmap(AR3),BSA23
mov mmap(T1),BK03
mov anc.d_index,AR3 ; AR3 -> x[] as circular buffer
mov #0,AR4 ; AR4 -> w[] as circular buffer
mov mmap(ST1_55),AC0 ; Save ST1, ST2, and ST3
mov AC0,anc.d_ST1
mov mmap(ST2_55),AC0
mov AC0,anc.d_ST2
mov mmap(ST3_55),AC0
mov AC0,anc.d_ST3
or #0x340,mmap(ST1_55); Set FRCT,SXMD,SATD
or #0x18,mmap(ST2_55) ; Enable circular addressing mode
bset SATA ; Set SATA
sub #1,T0
mov mmap(T0),BRC0 ; Set Sample block loop counter
sub #2,T1
mov mmap(T1),BRC1 ; Counter for LMS update loop
mov mmap(T1),CSR ; Counter for FIR filter loop
mov #ALPHA,T0 ; T0=leaky alpha
|| rptblocal loop-1 ; for (n=0; n<Ns; n++)
mpym *AR3+,*AR4+,AC0 ; temp = w[0]*x[0]
|| rpt CSR ; for (i=0; i<N-1; i++)
macm *AR3+,*AR4+,AC0 ; temp = w[i]*x[i]
mov rnd(hi(AC0)),*AR1 ; y[t] = temp;
sub *AR0,*AR1+,AC0
mov rnd(hi(AC0)),*AR2+ ; e[n]=in[n]-y[n]
|| mpyk #TWOMU,AC0
mov rnd(hi(AC0)),mmap(T1); T1=2*mu*e[n]
mpym *AR4,T0,AC0
|| rptblocal lms_loop-1 ; for(j=0; i<N-2; i++)
macm *AR3+,T1,AC0 ; w[i]=alpha*w[i]+2*mu*e*x[i]
mov rnd(hi(AC0)),*AR4+
mpym *AR4,T0,AC0
lms_loop
macm *AR3,T1,AC0 ; w[N-1]=alpha*w[N-1]+2*mu*e[n]*x[N-1]
mov rnd(hi(AC0)),*AR4+ ; Store the last w[i]
mov *AR0+,*AR3 ; x[n]=in[n]
loop
mov anc.d_ST1,AR4 ; Restore ST1, ST2, and ST3
mov ar4,mmap(ST1_55)
mov anc.d_ST2,AR4
mov ar4,mmap(ST2_55)
mov anc.d_ST3,AR4
mov AR4,mmap(ST3_55)
aadd #(Size-ARGS-1),SP ; Reset SP
mov AR3,T0 ; Retrun T0=index
|| ret
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -