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

📄 ex7p3iir.asm

📁 用于DSK5416的程序
💻 ASM
字号:
;---------------------------------------------------------------------------
; Program Name: ex7p3IIR.asm
;
; Description:  This is an example to show how to implement an IIR filter.
;               It implements the transfer function 
;
;               H(z) = [b0 + b1.z**(-1)+ b2.z**(-2)]/[1- a1.z**(-1)- a2.z**(-2)]
;
;               which is equivalent to the equations:
;
;               w(n) = x(n) + a1.w(n-1) + a2.w(n-2)
;               y(n) = b0.w(n) + b1.w(n-1) + b2.w(n-2)
;
;               where 
;               w(n), w(n-1), and w(n-2) are the intermediate variables used
;               in computations (integers).
;               a1, a2, b0, b1, and b2 are the filter coefficients (q15 numbers). 
;               x(n) is the input sample (integer). Input samples are placed in
;               the buffer, InSamples, from a data file, data_in.dat
;               y(n) is the computed output (integer). The output samples are
;               placed in a buffer, OutSamples.
;
; 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 buffer for y(n)s
SampleCnt       .set 200                        ; Number of samples to filter

; Intermediate variables (sequential locations)
wn              .word 0                         ;initial w(n)
wnm1            .word 0                         ;initial w(n-1) =0
wnm2            .word 0                         ;initial w(n-2)=0


                .sect "coeff"
; Filter coefficients (sequential locations)
b0              .word 3431                      ;b0 = 0.104
b1              .word -3356                     ;b1 = -0.102
b2              .word 3431                      ;b2 = 0.104
a1              .word -32767                    ;a1 = -1
a2              .word 20072                     ;a2 = 0.612


                .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
loop:
                LD *AR5+,15,A                   ; A = next input sample (q15)
                CALL iir_filter                 ; Call Filter Routine
                STH A,1,*AR6+                   ; Store filtered sample (integer)
                BANZ loop,*AR4-                 ; Repeat till all samples filtered
                nop
                nop
                nop
	
	
;---------------------------------------------------------------------------------
; IIR Filter Subroutine
; Enter with A = x(n) as q15 number
; Exit with A = y(n) as q15 number
; Uses AR2 and AR3
;---------------------------------------------------------------------------------
	
iir_filter:
               SSBX SXM	                        ; Select sign extension mode
	
               ;w(n)=x(n)+ a1.w(n-1)+ a2.w(n-2)

               STM #a2,AR2                      ; AR2 points to a2
               STM #wnm2, AR3                   ; AR3 points to w(n-2)
               MAC *AR2-,*AR3-,A                ; A = x(n)+ a2.w(n-2)
                                                ; AR2 points to a1 & AR3 to w(n-1)
               MAC *AR2-,*AR3-,A                ; A = x(n)+ a1.w(n-1)+ a2.w(n-2)
                                                ; AR2 points to b2 & AR3 to w(n)
               STH A,1,*AR3                     ; Save w(n)


               ;y(n)=b0.w(n)+ b1.w(n-1)+ b2.w(n-2)	

               LD #0,A                          ; A = 0
               STM #wnm2,AR3                    ; AR3 points to w(n-2)

               MAC *AR2-,*AR3-,A                ; A = b2.w(n-2)
                                                ; AR2 points to b1 & AR3 to w(n-1)
               DELAY *AR3                       ; w(n-1) -> w(n-2)

               MAC *AR2-,*AR3-,A                ; A = b1.w(n-1)+ b2.w(n-2)
                                                ; AR2 points to b0 & AR3 to w(n)
               DELAY *AR3                       ; w(n) -> w(n-1)
	
               MAC *AR2,*AR3,A                  ; A = b0.w(n)+ b1.w(n-1)+ b2.w(n-2)	
		
               RET                              ; Return
               nop
               nop
               nop
	
               .end

⌨️ 快捷键说明

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