Skip to content Skip to navigation

Connexions

You are here: Home » Content » FIR Filtering: Exercise for TI TMS320C54x (中文版 Chinese Version)

Navigation

Recently Viewed

This feature requires Javascript to be enabled.
 

FIR Filtering: Exercise for TI TMS320C54x (中文版 Chinese Version)

Module by: Douglas L. Jones, Swaroop Appadwedula, Matthew Berry, Mark Haun, Jake Janovetz, Michael Kramer, Dima Moussa, Daniel Sachs, Brian Wade, Patrick Frantz, Kanglin Wang. E-mail the authors

Based on: FIR Filtering: Exercise for TI TMS320C54x by Douglas L. Jones, Swaroop Appadwedula, Matthew Berry, Mark Haun, Jake Janovetz, Michael Kramer, Dima Moussa, Daniel Sachs, Brian Wade

Summary: You will implement band-pass finite impulse-response (FIR) filters with time-domain processing.

引言

在本练习中,你将使用DSP汇编语言来完成一个FIR(有限脉冲相应)滤波器。在开始之前,先来学习一个基本的FIR滤波器汇编代码 filter.asm

Figure 1
filter.asm

	   1	.copy "core.asm"  	; Copy in core file
	  2   					; This initializes DSP and jumps to "main"
	  3	
	  4  FIR_len .set   8			; This is an 8-tap filter.
	  5	
	  6          .sect ".data"		; Flag following as data declarations
	  7   
	  8    	    .align 16			; Align to a multiple of 16
	  9  coef					; assign label "coeff"
	  10	    .copy "coef.asm"		; Copy in coefficients
	  11
	  12	    .align 16
	  13 firstate
	  14 	    .space 16*8			; Allocate 8 words of storage for
	  15					; filter state.
	  16
	  17	    .sect ".text"		; Flag the following as program code
	  18  main
	  19      ; Initialize various pointers
	  20	    stm    #FIR_len,BK		; initialize circular buffer length
	  21	    stm    #coef,AR2    	; initialize coefficient pointer
	  22	    stm	   #firstate,AR3	; initialize state pointer
	  23	    stm    #1,AR0		; initialize AR0 for pointer increment
	  24	
	  25  loop
	  26      ; Wait for a new block of 64 samples to come in
	  27  	    WAITDATA
	  28	
	  29      ; BlockLen = the number of samples that come from WAITDATA (64)
	  30    	    stm     #BlockLen-1, BRC	; Put repeat count into repeat counter
	  31    	    rptb    endblock-1		; Repeat between here and 'endblock' 
	  32
	  33    	    ld	    *AR6,16, A		; Receive ch1 into A accumulator
	  34    	    mar     *+AR6(2)            ; Rcv data is in every other channel
	  35    	    ld      *AR6,16, B		; Receive ch2 into B accumulator
	  36    	    mar     *+AR6(2)            ; Rcv data is in every other channel
	  37    
	  38    	    ld	    A,B			; Transfer A into B for safekeeping
	  39
	  40      ; The following code executes a single FIR filter.
	  41	
	  42    	    sth     A,*AR3+%		; store current input into state buffer
	  43    	    rptz    A,(FIR_len-1)	; clear A and repeat
	  44    	    mac     *AR2+0%,*AR3+0%,A	; multiply coef. by state & accumulate
	  45    
	  46    	    rnd     A			; Round off value in 'A' to 16 bits                            
	  47    
	  48     ; end of FIR filter code. Output is in the high part of 'A.'
	  49
	  50    	    sth     A, *AR7+		; Store filter output (from A) into ch1
	  51    	    sth     B, *AR7+		; Store saved input (from B) into ch2
	  52    
	  53    	    sth     B, *AR7+		; Store saved input to ch3...ch6 also
	  54    	    sth     B, *AR7+		; ch4
	  55    	    sth     B, *AR7+		; ch5 
	  56    	    sth     B, *AR7+		; ch6
	  57   
	  58  endblock:
	  59      b loop
	

filter.asm 用FIR滤波器处理从输入通道1送来的信号,然后将结果送至输出通道2,并将未经处理原始信号送至输出通道2。

首先,在你的网络驱动器上创建一个工作目录来存放练习所需使用的文件,并将 filter.asmcore.asm 拷贝到该目录下。然后用MATLAB来产生两个20参数的FIR滤波器。第一个滤波器的通频带为4kHz至8kHz;第二个滤波器的通频带为8kHz至12kHz。两个滤波器频段边缘的过渡范围(transition band)都为1kHz。为生成滤波器,首先将频段边缘转化成基于44.1kHz系统采样率的数字频率(digital frequencies),然后用MATLAB的 remez 命令来产生滤波器;你可以键入 help remez 来获取帮助信息。用 save_coef 命令将所产生的滤波器存为不同的文件。(注意在保存之前要先将滤波器参数矢量倒置。)同时将你的滤波器存成MATLAB矩阵,以后用以产生检测矢量。这些可以用MATLAB命令 save 来完成。在完成这些操作后,用 freqz 命令来显示每个滤波器的频率响应。

第一部分:单通道FIR滤波器

现在来实现通频带为4kHz到8kHz的滤波器。你需要编辑 filter.asm 来将该滤波器所需使用的参数加入到程序代码中。

首先,本练习中FIR滤波器的长度是20而不是8。所以你需要将 FIR_len 改为20。使用 .set 指令来给符号名 FIR_len 分配一个数值。相应的操作为 FIR_len .set 20.

其次,你要确认 .copy 指令正确地将相应的的参数拷贝到程序代码中。将用以指示滤波器参数的文件名改为相应的实际包含参数的文件的名称。

最后,你要对 .align.space 指令作相应的调整。TI TMS320C54x DSP要求存放滤波器参数和状态的循环缓存(circular buffers)的起始地址是一个大于缓存长度的2的幂的整数倍。由于你现在所使用的是20参数的滤波器(相应的状态及参数缓存长度也为20),大于该数值的最小的2的幂的整数倍为32。所以你要将状态缓存和参数缓存的地址都设为32的倍数。(16元素缓存(16-element buffers)也要求地址为32的整数倍。)相应的操作可通过 .align 命令来实现。此外,要为状态缓存保留相应的内存空间。该操作可通过 .space 命令来实现,输入值为所要分配空间的位(bit)数。因此应使用指令 .space 16*20 来为20参数的滤波器分配空间,如下所示:


	1         .align 32             % Align to a multiple of 32
	2  coef   .copy  "filter1.asm"  % Copy FIR filter coefficients
	3
	4         .align 32             % Align to a multiple of 32
	5  state  .space 16*20          % Allocate 20 words of data space
      

汇编你的代码,将 PMST 设为 0xFFE0,将DSP复位(reset),然后运行。确认所得到的频率响应正确。在确信该程序代码工作正常后,进入下一步骤。

第二部分:双通道FIR滤波器

首先,拷贝一份在第一部分中修改过的文件filter.asm。在这个拷贝的基础上开始该部分的练习,上一部分中的滤波器以后还要用到,在这里不要作任何修改。

接下来,修改代码,使程序除了将经第一个滤波器(通频带4kHz到8kHz)处理的结果送至输出通道1以及将未经滤波处理的信号送至输出通道2外,还将经第二个滤波器(通频带8kHz到12kHz)处理的结果送到输出通道3。为此,你需要用 .align.copy 指令将第二套参数载入到数据内存中。你还需要生成一个指向第二套参数的指针并进行第二个滤波器的有关运算。

Exercise 1

一个富有挑战性的问题

你能不使用辅助寄存器 AR4AR5而实现双通道系统吗?问什么要作到这一点会更困难?注意不能通过用 .asg 指令将 AR4AR5 改名的方法来实现。

使用 DSP Development Environment: Introductory Exercise for TI TMS320C54x 中介绍的方法在MATLAB中产生一个合适的检测矢量和预期输出。然后使用 DSP Development Environment: Introductory Exercise for TI TMS320C54x中介绍的检测矢量核心文件来找出在给定该检测矢量时的系统输出。在MATLAB中画出两个滤波器的预期输出和实际输出以及它们之间的差别。为什么DSP系统的输出和MATLAB的输出会有所不同?

第三部分:实现单通道滤波器的备选方案

通过使用 firs 指令可通过另一途径实现单通道滤波器。修改 第一部分 中的代码,用 firs 来实现通频带为4kHz到8kHz的滤波器。

第一部分中的代码和现在你将要写的代码之间有两个区别:(1)使用 firs 指令时参数被载入程序内存(program memory)而非数据内存(data memory);(2)firs 要求状态(state)被分开存在两个循环缓存中。关于 firs 的详细用法请参阅 Mnemonic Instruction Set [link] 手册的 4-59页 以及位于 Applications Guide [link]4-5至4-8页 的关于 firs 的描述和示例(分别为 TMS320C54x DSP Reference SetVolume 2、Volume 4)。

AR0 需要设置成-1才能确保该代码正常工作。为什么?

注意:

现在 COEFF 是程序内存中的参数的标示。更多的信息请参阅关于 firs 的描述。


	
	 
	1	mvdd	*AR2,*AR3+0%		; write x(-N/2) over x(-N)
	2	sth	A,*AR2			; write x(0) over x(-N/2)
	3	add	*AR2+0%,*AR3+0%,A 	; add x(0) and x(-(N-1))
	4					;   (prepare for first multiply)
	5
	6	rptz	B,#(FIR_len/2-1)  	  
	7	firs	*AR2+0%,*AR3+0%,COEFF
	8	mar	??????? 		; Fill in these two instructions
	9	mar	???????			; They modify AR2 and AR3.
	10
	11					; note that the result is now in the
	12					;  B accumulator
      

由于现在对状态和参数使用与前面不同的处理方法,你需要对指针的初始化作如下修改:


	
	1	stm	#(FIR_len/2),BK		; initialize circular buffer length
	2	stm	#firstate_,AR2		; initialize location containing first 
	3					;   half of states
	4
	5	stm	#-1,AR0			; Initialize AR0 to -1
	6
	7	stm	#firstate2_,AR3	        ; initialize location containing last half
	
      

使用检测矢量核心文件来找到该系统在给定与前面所使用的相同的检测矢量时的输出。比较该代码的输出和使用 mac 指令的相同滤波器的输出。它们是否一致?原因是什么?确认滤波器输出被送至输出通道1,而未经处理的信号仍被送至输出通道2。

Content actions

Download module as:

PDF | EPUB (?)

What is an EPUB file?

EPUB is an electronic book format that can be read on a variety of mobile devices.

Downloading to a reading device

For detailed instructions on how to download this content's EPUB to your specific device, click the "(?)" link.

| More downloads ...

Add module to:

My Favorites (?)

'My Favorites' is a special kind of lens which you can use to bookmark modules and collections. 'My Favorites' can only be seen by you, and collections saved in 'My Favorites' can remember the last module you were on. You need an account to use 'My Favorites'.

| A lens I own (?)

Definition of a lens

Lenses

A lens is a custom view of the content in the repository. You can think of it as a fancy kind of list that will let you see content through the eyes of organizations and people you trust.

What is in a lens?

Lens makers point to materials (modules and collections), creating a guide that includes their own comments and descriptive tags about the content.

Who can create a lens?

Any individual member, a community, or a respected organization.

What are tags? tag icon

Tags are descriptors added by lens makers to help label content, attaching a vocabulary that is meaningful in the context of the lens.

| External bookmarks