




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、dsp应用系统设计综合设计报告题目:fir低通数字滤波器器设计 姓名 xxx 学号 xxx 手机 xxx email 专 业 电子信息工程 班级 09-1 开课学期 2012 至 2013 学年 1 学期提交时间 2012 年 06 月 28 日摘 要 数字滤波器在数字信号处理的各种应用中有着广泛的应用。数字滤波器分为低通,高通,带通,带阻等。低通滤波器是一个通过低频信号而衰减或抑制高频信号的部件。本文以fir低通数字滤波器为例,研究有限冲击响应(fir)滤波器的基本原理,通过matlab软件和code composer studio v4软件来实现。关键词
2、:fir低通滤波器;matlab;code composer studio v4一、引言 在现代通信系统中,由于信号中经常混有各种复杂成分,说以很多信号的处理和分析都是基于数字滤波器而进行的。数字滤波器按照其响应方式可分为有限脉冲响应(fir)滤波器和无限脉冲响应(iir)滤波器两种。iir 滤波器的特征是具有无限持续时间冲激响应,这种滤波器一般需要用递归模型来实现,因而有时也称之为递归滤波器,而fir滤波器的冲激响应只能延续一定时间,在工程实际中可以采用递归的方式实现,也可以采用非递归的方式实现,但其结构主要还是是非递归结构,没有输出到输入的反馈,并且fir滤波器很容易获得严格的线性相位特性
3、,避免被处理信号产生相位失真,而线性相位体现在时域中仅仅是h( n)在时间上的延迟,这个特点在图像信号处理、数据传输等波形传递系统中是非常重要的,且不会发生阻塞现象,能避免强信号淹没弱信号,因此特别适合信号强弱相差悬殊的情况。目前fir滤波器的实现方法大致可分为三种:利用单片通用数字滤波器集成电路、dsp器件和可编程逻辑器件实现。单片通用数字滤波器使用方便,但由于字长和阶数的规格较少,不能完全满足实际需要,使用以串行运算为主导的通用dsp芯实现要简单,是一种实时、快速、特别适合于实现各种数字信号处理运算的微处理器,借助于通用数字计算机按滤波器的设计算法编出程序进行数字滤波计算 。由于它由具有丰
4、富的硬件资源、改进的哈佛结构、高速数据处理能力和强大的指令系统而在通信、航空、航天、雷达、工业控制、网络及家用电器等各个领域得到广泛应用。 数字处理器(dsp)有很强的数据处理能力,它在高速数字信号处理领域有广泛的用用,例如数字滤波、音频处理、图像处理等。相对于模拟滤波器,数字滤波器没有漂移,能够处理低频信号,频率响应特性可做成非常接近于理想的特性,且精度可以达到很高,容易集成等。使用可编程的dsp芯片实现数字滤波可以通过修改滤波器的参数十分方便地改变滤波器的特性,下面主要说明利用tms320vc54x dsp芯片设计实现fir数字滤波器。设计目的意义一个实际的应用系统中,总存在各种干扰,所以
5、在系统设计中,滤波器的好坏将直接影响系统的性能。使用dsp进行数字处理,可以对一个具有噪声和信号的混合信号源进行采样,再经过数字滤波,滤除噪声,就可以提取有用信号了。所以说,数字滤波器是dsp最基本的应用领域,熟悉基于dsp的数字滤波器能为dsp应用系统开发提供良好的基础。二、系统方案数字滤波器有多种设计方法,如双线性变换法、窗函数设计法、插值逼近法和chebyshev逼近法等等,但是通常采用窗函数法设计。窗函数法设计fir滤波器的基本思想是:根据给定的滤波器技术指标选择滤波器长度n和窗函数(n),使其具有最窄宽度的主瓣和最小的旁瓣,其核心是从给定的频率特性,通过加窗确定有限长单位脉冲响应序列
6、h(n)。一般采用以下四种窗函数:矩形窗、hanning窗、hamming窗、blackmen窗。在实际的fir滤波器的设计中,一般采用计算机辅助设计。matlab是一套功能强大的适应于科学工程计算的可视化高性能语言,它不但提供了fir1、fir2两种窗函数方法设计fir滤波器的函数,而且其本身所附带的simlink工具更是能很方便的设计低通、高通、带通、带阻、陷波等各种类型的数字滤波器。三、算法设计1采用matlab设计fir数字滤波器 采用matlab设计fir数字滤波器的方法有多种,本实验采用fir1函数,使用方法简介如下:(1)设计低通滤波器,格式为:b=fir1(n,wn)或b =
7、fir1(n,wn,low)其中n+1为滤波器阶数,b为返回的长度为n+1的系数向量。wn为归一化边界频率,0 wn 1.0,wn 处增益为-6db。wn =1.0对应的非归一化频率为fs/2,其中fs为采样频率。 例,设fs=8000hz,低通滤波器的边界频率fp=1000hz,则对应的归一化数字角频率为wn=fp/(fs/2)=0.25,取n=31(对应的滤波器阶数为32)。于是,该低通fir滤波器的设计指令为b=fir1(31,0.25)。执行该指令得到的系数为:b=-0.000630469148644,-0.001818568124278,-0.002561941612458,-0.0
8、01587493994396,0.002369512668975,0.008332496978353,0.011803612855041,0.00675929677933,-0.009174511997729,-0.029730906886036,-0.039816452266422,-0.022301647638688,0.031027965907247,0.111143500492515,0.192455402100706,0.243730203886485,0.243730203886485,0.192455402100706,0.111143500492515,0.0310279659
9、07247,-0.022301647638688,-0.039816452266422,-0.029730906886036,-0.009174511997729,0.00675929677933,0.011803612855041,0.008332496978353,0.002369512668975,-0.001587493994396,-0.002561941612458,-0.001818568124278,-0.000630469148644注意: 上述滤波器系数为浮点格式,当dsp程序中采用整数格式时。滤波器系数需相应地变为整数,方法为乘以32768并取整。(2)设计高通滤波器,格
10、式为:b = fir1(n,wn,high) 参数意义同上。(3)设计带通滤波器,格式为:b = fir1(n,wn, bandpass) 其中wn = w1 w2, w1、w2为边界频率。(4)设计带阻滤波器,格式为:b = fir1(n,wn, stop) 其中wn = w1 w2, w1、w2为边界频率。 采用函数plot(b)可以绘制滤波器的冲击响应图:采用函数freqz(b)可以绘制滤波器的频率响应图:四、软件实现 本实验通过利用matlab设计滤波器,通过code composer studio v4软件来实现。实验步骤:1.双击桌面图标,启动code composer studi
11、o,选择工作目录。2建立工程lab5。3. 向工程lab5中加载文件lab5.c、fir.asm、lab5.cmd,修改lab5.c中的滤波器系数数据。4建立配置文件lab5.ccxml(选择vc5509a simulater模式)。5. 编译、链接工程,下载程序。6运行程序至主程序的“index-”语句,打开图形观察窗口。观察滤波器系数波形、观察滤波器输入信号、输出信号波形。7全速运行程序,数秒钟后暂停。观察滤波器输入信号、输出信号波形。8. 改变输入信号参数(信号频率、幅度等),重复上述第6、7、8步操作。9退出ccs。五、实验结果与分析取输入信号如图,频率为200和2000.生成信号图为
12、通过dsp 滤波后得到输出波形入下图六、结论低通滤波器将高频量滤去,留下低频量。通过dsp芯片滤波作用将频率为2000的正弦波滤去,只留下频率为200的波形。七、附件:源程序清单#include math.h#include mysysconfig.h#include myfilter.h#include #include #include #define nbiq 9#define nx 64#define l 36/*定义句柄*/ externclk_init();mcbsp_handle hmcbsp0;timer_handle mhtimer0;int16 innx,outnx; /i
13、nput buffer&output bufferint16 dbuffernx;int16 xtemp,temp;int16 nout=0;uint16 timer0_cnt=0;uint16 eventid0; uint16 old_intm;uint16 tim_val;extern uint16 fir(int16 *, int16 *,uint16);void taskfxn(void); /定时器设置子程序interrupt void timer0isr(void); /中断服务子程序/* reference start of interrupt vector table */*
14、this symbol is defined in file, vectors.s55 */extern void vecstart(void);/* low-pass fir filter coefficients*/ int16 coeffl=-34, -49, -73, -103, -133, -149, -133, -62, 82, 312, 632, 1031, 1486, 1964, 2422, 2816, 3105, 3257, 3257, 3105, 2816, 2422, 1964, 1486, 1031, 632, 312, 82, -62, -133, -149, -13
15、3, -103, -73, -49, -34 ; /* create a timer configuration structure that can be passed */* to timer_config csl function for initialization of timer */* control registers. */timer_config timcfg0 = timer_ctrl, /* tcr0 */ 0x4650, /* prd0 */ 0x0000 /* prsc */; /定时器设置void main(void)uint32 aic23data;int16
16、i=0; clk_init();/ 初始化dsp运行时钟 /emif为全emif接口初始化emif接口 chip_rset(xbsr,0x0a01); /*初始化dsp的emif*/ emif_config(&emiffig); irq_setvecs(uint32)(&vecstart); /获取中断向量myfilter_init();/aic23b初始化taskfxn(); /定时器设置hmcbsp0 = mcbsp_open(mcbsp_port0,mcbsp_open_reset);/打开mcbsp0mcbsp_config(hmcbsp0,&mcbspconfig);/配置mcbsp
17、0mcbsp_start(hmcbsp0, mcbsp_rcv_start | mcbsp_xmit_start , /开启mcbsp0发送和接收 0x3000); for(i=0;i16) & 0xffff); /aic23b1的左声道数据for(i=nx;i0;i-) ini = ini-1; in0=xtemp;outnout=fir(in,coeff,l); while(!mcbsp_xrdy(hmcbsp0);/判断是否准备好发送数据,若没有,则等待 mcbsp_write16(hmcbsp0,outnout); /发送数据 nout-;/* break point */if ( n
18、out=-1 )nout=nx-1;timer0_cnt=0; /*/interrupt void timer0isr(void)/中断服务程序 timer0_cnt=2; /*/void taskfxn(void) /定时器设置子程序 /* temporarily disable all maskable interrupts */ old_intm = irq_globaldisable(); /* open timer 0, set registers to power on defaults */ mhtimer0 = timer_open(timer_dev0, timer_open
19、_reset); /* get event id associated with timer 0, for use with */ /* csl interrupt enable functions. */ eventid0 = timer_geteventid(mhtimer0); /* clear any pending timer interrupts */ irq_clear(eventid0); /* place interrupt service routine address at */ /* associated vector location */ irq_plug(even
20、tid0,&timer0isr); /* write configuration structure values to timer control regs */ timer_config(mhtimer0, &timcfg0); /* enable timer interrupt */ irq_enable(eventid0); /* enable all maskable interrupts */ irq_globalenable(); /* start timer */ timer_start(mhtimer0); #ifndef myfilter_h_#define myfilte
21、r_h_/ myfilter各控制寄存器的地址#define myfilter_lt_line_ctl 0x00 / 0#define myfilter_rt_line_ctl 0x02 / 1#define myfilter_lt_hp_ctl 0x04 / 2#define myfilter_rt_hp_ctl 0x06 / 3#define myfilter_analog_audio_ctl 0x08 / 4#define myfilter_digital_audio_ctl 0x0a / 5#define myfilter_power_down_ctl 0x0c / 6#define
22、myfilter_digital_if_format 0x0e / 7#define myfilter_sample_rate_ctl 0x10 / 8#define myfilter_dig_if_activate 0x12 / 9#define myfilter_reset_reg 0x1e / f - writing 0 to this reg triggers reset/ myfilter control register settings#define lt_ch_vol_ctrl 0x0017 /* 0 */#define rt_ch_vol_ctrl 0x0017 /* 1 *
23、/#define lt_ch_headph_ctrl 0x0079 /* 2 */#define rt_ch_headph_ctrl 0x0079 /* 3 */#define alog_au_path_ctrl 0x0000 /* 4 */#define digi_au_path_ctrl 0x0000 /* 5 */#define pow_mgt_ctrl_ctrl 0x0002 /* 6 */#define digi_au_intf_ctrl 0x000d /* 7 */#define au_fs_tim_ctrl 0x0000 /* 8 mclk=12mhz, sample rate
24、setting */#define digi_intf1_ctrl 0x0001 /* 9 */#define digi_intf2_ctrl 0x00ff /* 10 */digif_fmt寄存器各位的掩码#define digif_fmt_ms 0x40#define digif_fmt_lrswap 0x20#define digif_fmt_lrp 0x10#define digif_fmt_iwl 0x0c#define digif_fmt_for 0x03/采样分辨率#define digif_fmt_iwl_16 0x00#define digif_fmt_iwl_20 0x04
25、#define digif_fmt_iwl_24 0x08#define digif_fmt_iwl_32 0xc0/数据格式#define digif_fmt_for_msbright 0x00#define digif_fmt_for_msleft 0x01#define digif_fmt_for_i2s 0x02#define digif_fmt_for_dsp 0x03/power寄存器各位的掩码#define power_dev 0x80#define power_clk 0x40#define power_osc 0x20#define power_out 0x10#define
26、 power_dac 0x08#define power_adc 0x04#define power_mic 0x02#define power_line 0x01/src寄存器各位的掩码#define src_clkout 0x80#define src_clkin 0x40#define src_sr 0x3c#define src_bosr 0x02#define src_mo 0x01/各个波特率对应的取值#define src_sr_8 0x0c #define src_sr_32 0x18#define src_sr_44 0x20#define src_sr_96 0x1c/an
27、apctl寄存器各位的掩码#define anapctl_sta 0xc0#define anapctl_ste 0x20#define anapctl_dac 0x10#define anapctl_byp 0x08#define anapctl_insel 0x00#define anapctl_micm 0x02#define anapctl_micb 0x01 /digpctl寄存器各位的掩码#define digpctl_dacm 0x08#define digpctl_deemp 0x06#define digpctl_adchp 0x01#define digpctl_deemp
28、_dis 0x00#define digpctl_deemp_32 0x02#define digpctl_deemp_44 0x04#define digpcrl_deemp_48 0x06#define digifact_act 0x01#define lt_hp_ctl_lzc 0x80#define rt_hp_ctl_rzc 0x80/myfilter.c中定义的函数声明void myfilter_init();/myfilter初始化函数void myfilter_config(unsigned int regaddr, unsigned int data);/myfilter寄存
29、器配置#endif /*myfilter_h_*/#include #include #include myfilter.h#include myi2c.huint16 x,y;/myfilter初始化函数void myfilter_init() /* initialize i2c, using parameters in init structure */ myi2c_init(); / reset the myfilter and turn on all power myfilter_config(myfilter_reset_reg, 0x02); myfilter_config(myf
30、ilter_power_down_ctl, 0); myfilter_config(myfilter_analog_audio_ctl, 0x10);/使能dac;若为传声器输入,0x10,若为mic输入,则为0x14 myfilter_config(myfilter_digital_audio_ctl, 0); / turn on volume for line inputs myfilter_config(myfilter_lt_line_ctl,0x18);/0x1f=12db 最大输入 myfilter_config(myfilter_rt_line_ctl,0x18); / conf
31、igure the myfilter for master mode, 8khz stereo, 16 bit samples / use 12mhz usb clock myfilter_config(myfilter_digital_if_format, digif_fmt_ms | digif_fmt_iwl_16 | digif_fmt_for_dsp); myfilter_config(myfilter_sample_rate_ctl, src_sr_44 | src_bosr | src_mo);/usb模式,272次过采样,采样率为8k / turn on headphone v
32、olume and digital interface myfilter_config(myfilter_lt_hp_ctl, 0x7d); /0x7f=6db 最大输出 myfilter_config(myfilter_rt_hp_ctl, 0x7d); myfilter_config(myfilter_dig_if_activate, digifact_act); /myfilter寄存器配置void myfilter_config(unsigned int regaddr, unsigned int data) uint16 buf2; buf0 = regaddr; buf1 = da
33、ta;x = i2c_write( buf,/pointer to data array 2,/length of data to be transmitted 1,/master or slaver i2c_aic23_0, /slave address to transmit to 1,/transfer mode of operation 30000/time out for bus busy );y = i2c_write( buf,/pointer to data array 2,/length of data to be transmitted 1,/master or slave
34、r i2c_aic23_1, /slave address to transmit to 1,/transfer mode of operation 30000/time out for bus busy );/* end of myfilter.c*/#include #include #include myfilter.h#include myi2c.huint16 x,y;/myfilter初始化函数void myfilter_init() /* initialize i2c, using parameters in init structure */ myi2c_init(); / r
35、eset the myfilter and turn on all power myfilter_config(myfilter_reset_reg, 0x02); myfilter_config(myfilter_power_down_ctl, 0); myfilter_config(myfilter_analog_audio_ctl, 0x10);/使能dac;若为传声器输入,0x10,若为mic输入,则为0x14 myfilter_config(myfilter_digital_audio_ctl, 0); / turn on volume for line inputs myfilte
36、r_config(myfilter_lt_line_ctl,0x18);/0x1f=12db 最大输入 myfilter_config(myfilter_rt_line_ctl,0x18); / configure the myfilter for master mode, 8khz stereo, 16 bit samples / use 12mhz usb clock myfilter_config(myfilter_digital_if_format, digif_fmt_ms | digif_fmt_iwl_16 | digif_fmt_for_dsp); myfilter_confi
37、g(myfilter_sample_rate_ctl, src_sr_44 | src_bosr | src_mo);/usb模式,272次过采样,采样率为8k / turn on headphone volume and digital interface myfilter_config(myfilter_lt_hp_ctl, 0x7d); /0x7f=6db 最大输出 myfilter_config(myfilter_rt_hp_ctl, 0x7d); myfilter_config(myfilter_dig_if_activate, digifact_act); /myfilter寄存器
38、配置void myfilter_config(unsigned int regaddr, unsigned int data) uint16 buf2; buf0 = regaddr; buf1 = data;x = i2c_write( buf,/pointer to data array 2,/length of data to be transmitted 1,/master or slaver i2c_aic23_0, /slave address to transmit to 1,/transfer mode of operation 30000/time out for bus b
39、usy );y = i2c_write( buf,/pointer to data array 2,/length of data to be transmitted 1,/master or slaver i2c_aic23_1, /slave address to transmit to 1,/transfer mode of operation 30000/time out for bus busy );/* end of myfilter.c*/#ifndef myi2c_h_#define myi2c_h_/ i2c values#define icoar_mask_7 0x007f
40、#define icoar_mask_10 0x03ff#define icsar_mask_7 0x007f#define icsar_mask_10 0x03ff#define icoar_oaddr 0x007f#define icsar_saddr 0x0050#define i2c_srom 0x0050#define i2c_aic23_0 0x001a/aic23的i2c地址#define i2c_aic23_1 0x001b/修改地址#define i2c_ads7823 0x0048#define icstr_bb 0x1000#define icstr_rsfull 0x0
41、800#define icstr_xsmt 0x0400#define icstr_aas 0x0200#define icstr_ad0 0x0100#define icstr_icxrdy 0x0010#define icstr_icrrdy 0x0008#define icstr_ardy 0x0004#define icstr_nack 0x0002#define icstr_al 0x0001#define icmdr_free 0x4000#define icmdr_stt 0x2000#define icmdr_idleen 0x1000#define icmdr_stp 0x0
42、800#define icmdr_mst 0x0400#define icmdr_trx 0x0200#define icmdr_xa 0x0100#define icmdr_rm 0x0080#define icmdr_dlb 0x0040#define icmdr_irs 0x0020#define icmdr_stb 0x0010#define icmdr_fdf 0x0008#define icmdr_bc_mask 0x0007voidmyi2c_init(void);/i2c初始化函数#endif /*myi2c_h_*/#ifndef mysysconfig_h_#define
43、mysysconfig_h_#include #include #include #include #define timer_ctrl timer_tcr_rmk( timer_tcr_idleen_default, /* idleen = 0 */ timer_tcr_func_of(0), /* func = 0 */ timer_tcr_tlb_reset, /* tlb = 1 */ timer_tcr_soft_brkptnow, /* soft = 0 */ timer_tcr_free_withsoft, /* free = 0 */ timer_tcr_pwid_of(0),
44、 /* pwid = 0 */ timer_tcr_arb_reset, /* arb = 1 */ timer_tcr_tss_start, /* tss = 0 */ timer_tcr_cp_pulse, /* cp = 0 */ timer_tcr_polar_low, /* polar = 0 */ timer_tcr_datout_0 /* datout = 0 */ ) emif_config emiffig = 0x221, /egcr : the memfreq = 00,the clock for the memory is equal to cpu frequence / the wpe = 0 ,forbiden the writing posting when we debug the emif / the memcen = 1,the memory clock is reflected on the clkmem pin / the nohold = 1,hold request
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
评论
0/150
提交评论