⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ex7p2fir.asm

📁 用于DSK5416的程序
💻 ASM
字号:
;----------------------------------------------------------------------------------
;Program: ex7p2FIR.asm
;Description:   This is an example to show how to implement an FIR filter.
;               It implements the following equation
;
;               y(n)=h(N-1)x(n-(N-1))+h(N-2)x(n-(N-2))+ ...h(1)x(n-1)+h(0)x(n)
;			  
;               where   N = Number of filter coefficients = 16. 
;                       h(N-1), h(N-2),...h(0) etc are filter coeffs (q15 numbers)
;                       The coefficients are available in file: coeff_fir.dat.
;                       x(n-(N-1)),x(n-(N-2),...x(n) are signal samples(integers).
;                       The input x(n) is received from the data file: data_in.dat.
;                       The computed output y(n) is placed in a data buffer.
;
;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,200,1                    ; Allocate space for y(n)s
SampleCnt       .set 200                        ; Number of samples to filter

                .bss CoefBuf, 16, 1             ; Memory for coeff circular buffer
                .bss SampleBuf, 16, 1           ; Memory for sample circular buffer

                .sect "FirCoeff"                ; Filter coeff (seq locations)
FirCoeff        .include "coff_fir.dat"

Nm1             .set 15                         ; N - 1


                .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 fir_init                   ; Init for filter calculations
                SSBX SXM                        ; Select sign extension mode
loop:
                LD *AR5+,A                      ; A = next input sample (integer)
                CALL fir_filter                 ; Call Filter Routine
                STH A,1,*AR6+                   ; Store filtered sample (integer)
                BANZ loop,*AR4-                 ; Repeat till all samples filtered
                nop
                nop
                nop

;----------------------------------------------------------------------------------
; FIR 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 - 1.
; AR0 = 1 = circular buffer pointer increment
;----------------------------------------------------------------------------------
		
fir_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 - 1                    ; Clear circular sample buffer
                ST #0h,*AR2+%	
                STM #1,AR0                      ; AR0 = 1 = CB pointer increment
                RET
                nop
                nop
                nop

;--------------------------------------------------------------------------------
; FIR Filter Routine
; Enter with A = the current sample x(n) - an integer,
;            AR2 pointing to the location for the current sample x(n),
;            and AR3 pointing to the q15 coefficient h(N-1). 
; Exit with A = y(n) as q15 number.
;--------------------------------------------------------------------------------

fir_filter:	
                STL A, *AR2+0%                  ; Place x(n)in the sample buffer					
                RPTZ A, #Nm1                    ; A = 0
                MAC *AR3+0%,*AR2+0%,A           ; A = filtered sum (q15)
                RET
                nop
                nop
                nop
	
                .end


	
	
	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -