📄 lmsfilt.asm
字号:
.mmregs
.global start
.def start,_c_int00
.copy "lmsdata.inc"
.copy "xhin.inc"
.copy "xwin.inc"
.data
OUTBUF .space N*16
INBUF .space N*16
ADAPT_DP .usect "adpt_var",0
d_primary .usect "adpt_var",1
d_output .usect "adpt_var",1
d_error .usect "adpt_var",1
d_mu .usect "adpt_var",1
d_mu_e .usect "adpt_var",1
d_new_x .usect "adpt_var",1
d_adapt_count .usect "adpt_var",1
k_mu .set 327
hcoff .usect "bufferh",N ;H(Z)coeffs
wcoff .usect "bufferw",N ;W(Z)coeffs
xh .usect "bufferx",N ;input data to H(Z)
xw .usect "bufferp",N ;input data-adaptive filter
.text
;*************************************************
;
;Functional Description
;
;This subroutine moves filter coefficients from program to data space.
;Initialize the adaptive coefficients,buffers,vars,and sets the curcular
;buffer address for processing.
;*************************************************
.asg AR0,INDEX_P ;initialize buffer pointer
.asg AR1,INIT_P ;data coeff buffer pointer
.asg AR3,XH_DATA_P ;data coeff buffer pointer
.asg AR5,XW_DATA_P ;for cal.y output
_c_int00
b start
nop
nop
start:
;initialize input data location,input to hybrid,with zero.
STM #xh,INIT_P
RPTZ A,#N
STL A,*INIT_P+
;initialize input data location,input to hybrid,with zero.
STM #xw,INIT_P
RPTZ A,#N
STL A,*INIT_P+
;initialize adaptive coefficient with zero.
STM #wcoff,INIT_P
RPTZ A,#N
STL A,*INIT_P+
;initialize temporary storage locations with zero.
STM #d_primary,INIT_P
RPTZ A,6
STL A,*INIT_P+
;copy system coefficient into RAM location,reverse order
STM #hcoff,INIT_P
RPT #N-1
MVPD #scoff,*INIT_P+
STM #wcoff,INIT_P
RPT #N-1
MVPD #scoff,*INIT_P+
STM #INBUF,INIT_P
RPT #N-1
MVPD #INPUT,*INIT_P+
STM #xh,INIT_P
RPT #N-1
MVPD #INPUT,*INIT_P+
STM #xw,INIT_P
RPT #N-1
MVPD #INPUTW,*INIT_P+
LD #ADAPT_DP,DP ;set DP now and not worry about it
ST #k_mu,d_mu
STM #1,INDEX_P ;increment value to be used by dual address
;associate auxiliary registers for circular computation
STM #xh+N-1,XH_DATA_P ;last input of hybrid buffer
; RETD
STM #xw+N-1,XW_DATA_P ;last element of input buffers
;***********************************************************
;Functional Description
;This subroutine performs the adaptive filtering.The newest sample is stored
;in a separate location since filtering and adaptation are perform at the
;same time.Other the oldest sample is over writtrn before updating
;the w (N-1) coefficient.
;
;d_primary=xh*hcoff
;d_output=xw*wcoff
;LMS algorithm:
;w(i+1)=w(i)+d*mu_error*xw(n-i) for i=0,1,...,127 and n=0,1,...
;***********************************************************
.asg AR2,H_COFF_P ;H(Z) coeff buffer pointer
.asg AR3,XH_DATA_P ;data coeff buffer pointer
.asg AR6,INBUF_P ;input buffer address pointer
.asg AR7,OUTBUF_P ;output buffer address pointer for cal.primary input
.asg AR4,W_COFF_P ;W(Z) coeff buffer pointer
.asg AR5,XW_DATA_P ;data coeff buffer pointer
STM #INBUF,INBUF_P
STM #xw, XW_DATA_P
STM #OUTBUF,OUTBUF_P
STM #xh,XH_DATA_P
adapt_task:
STM #N,BK ;first circular buffer size
STM #hcoff,H_COFF_P ;H_COFF_P->last of sys coeff
ADDM #1,d_adapt_count
LD *INBUF_P+,A ;load the input sample
STM #wcoff,W_COFF_P ;reset coeff buffer
STL A,d_new_x ;read in new data
LD d_new_x,A
STL A,*XH_DATA_P+0% ;store in the buffer
RPTZ A,#N-1 ;Repeat 128 times
MAC *H_COFF_P+0%,*XH_DATA_P+0%,A ;mult & acc:a=a+(h*x)
STH A,d_primary ;primary signal
;start simultaneous filtering and updating the adaptive filter here.
LD d_mu_e,T ;T=step_size*error
SUB B,B ;zero acc B
STM #(N-2),BRC ;set block repeat counter
RPTBD lms_end-1
MPY *XW_DATA_P+0%,A ;error*oldest sample
LMS *W_COFF_P,*XW_DATA_P ;B=filtered output (y) Update filter coeff
ST A,*W_COFF_P+ ;save update filter coeff
||MPY *XW_DATA_P+0%,A ;error*x[n-(N-1)]
LMS *W_COFF_P,*XW_DATA_P ;B=accum filtered output y Update filter coeff
lms_end
STH A,*W_COFF_P ;final coeff
MPY *XW_DATA_P,A ;x(0)*h(0)
MVKD #d_new_x,*XW_DATA_P ;store the newest sample
LMS *W_COFF_P,*XW_DATA_P+0%
STH B,d_output ;store the filter output
LD d_primary,A
SUB d_output,A
STL A,d_error ;store the residual error signal
LD d_mu,T
MPY d_error,A ;A=u*e
STH A,d_mu_e ;save the error*step_size
LD d_error,A ;residual error signal
STL A,*OUTBUF_P+
LD #N,A ;check if a frame of samples
SUB d_adapt_count,A ;have been processed
BC adapt_task,AGT
RETD
ST #0,d_adapt_count ;restore the count
.end
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -