电子科大毕设——基于FPGA的FIR滤波器的设计.doc

上传人:doc321 文档编号:12766085 上传时间:2021-12-06 格式:DOC 页数:13 大小:162.50KB
返回 下载 相关 举报
电子科大毕设——基于FPGA的FIR滤波器的设计.doc_第1页
第1页 / 共13页
电子科大毕设——基于FPGA的FIR滤波器的设计.doc_第2页
第2页 / 共13页
电子科大毕设——基于FPGA的FIR滤波器的设计.doc_第3页
第3页 / 共13页
电子科大毕设——基于FPGA的FIR滤波器的设计.doc_第4页
第4页 / 共13页
电子科大毕设——基于FPGA的FIR滤波器的设计.doc_第5页
第5页 / 共13页
点击查看更多>>
资源描述

《电子科大毕设——基于FPGA的FIR滤波器的设计.doc》由会员分享,可在线阅读,更多相关《电子科大毕设——基于FPGA的FIR滤波器的设计.doc(13页珍藏版)》请在三一文库上搜索。

1、第4章 FIR滤波器的VHDL描述及仿真描述一个FIR滤波器最简单的方法,就是用卷积和表示20: ( 4.1) N阶FIR直接型结构如图4.1所示:图4。1 N阶FIR直接型结构图而线性FIR滤波器的实现结构可进一步简化为图4.2所示模型(以N=6阶为例)图4。2 FIR滤波器简化模型VHDL源程序如下:library ieee;use ieee.std_logic_1164。all;use ieee。std_logic_unsigned。all;entity add4 is port ( a , b : in std_logic_vector(11 downto 0) ; ci: in st

2、d_logic; co: out std_logic; sum: out std_logic_vector ( 11 downto 0) );end add4 ;architecture behav of add4 is signal sint : std_logic_vector ( 12 downto 0); signal aa, bb: std_logic_vector ( 12 downto 0);begin aa<=0'a; 将4位加数矢量扩为5位,为进位提供空间 bb=0'b; -将4位被加数矢量扩为5位,为进位提供空间 sint<=aa+bb+ci;

3、std_logic_unsigned包定义了“+”运算 sum=sint (11 downto 0); co=sint(12); -最高位形成进位end behav; library ieee;use ieee.std_logic_1164.all;use ieee。std_logic_unsigned.all;entity add12 is -端口说明 port ( a , b : in std_logic_vector(11 downto 0) ; ci: in std_logic; co: out std_logic; sum: out std_logic_vector ( 11 dow

4、nto 0) );end add12;architecture stru of add12 is Component add4 port ( a , b : in std_logic_vector(11 downto 0) ; ci: in std_logic; co: out std_logic; sum: out std_logic_vector ( 11 downto 0) ); end component; 也可以放在程序包中定义 signal carry_out1,carry_out2 : std_logic ;begin 用元件例化语句级联4位加法器 u1: add4 port m

5、ap( a( 3 downto 0), b(3 downto 0), ci, carry_out1, sum(3 downto 0)); u2: add4 port map( a( 7 downto 4), b(7 downto 4), carry_out1, carry_out2, sum(7 downto 4)); u3: add4 port map( a(11 downto 8), b(11 downto 8),carry_out2,co, sum(11 downto 8);end stru;生成的原理图如图4.3所示:图4.3 12位加法器原理图通过仿真得到12位加法器波形如下图4。4

6、所示: 图4。4 12位加法器波形图4.1。2 24位加法器的实现在12位加法器的基础上,我们可以直接将两个12位加法器级联,得到24位加法器,VHDL源程序如下:library ieee; use ieee。std_logic_1164.all;use ieee.std_logic_unsigned。all;entity add24 is port ( a , b : in std_logic_vector(23 downto 0) ; -端口说明 ci: in std_logic; co: out std_logic; sum: out std_logic_vector ( 23 down

7、to 0) );end add24;architecture stru of add24 is component add12 port ( a , b : in std_logic_vector(11 downto 0) ; ci: in std_logic; co: out std_logic; sum: out std_logic_vector ( 11 downto 0) ); end component; signal carry_out: std_logic ;begin -元件例化级联两个12位加法器 U1: add12 port map( a( 11 downto 0), b(

8、11 downto 0), ci, carry_out, sum(11 downto 0)); U2: add12 port map( a( 23 downto 12), b(23 downto 12), carry_out, co, sum(23 downto 12);end stru;24位加法器生成的原理图如下图4.5所示:图4。5 24位加法器原理图通过仿真得到24位加法器波形如下图4。6所示:图4.6 24位加法器波形图4.1。3 12位乘法器的实现为了实现两个用12位二进制补码表示的有符号的相乘,可以仿效布斯(Booth)乘法器的原理,用移位相加的方式实现。VHDL源程序如下:li

9、brary ieee;use ieee。std_logic_1164.all,use ieee.numeric_std。all;entity mul12 is port(ain: in std_logic_vector(11 downto 0); bin: in std_logic_vector(11 downto 0); qout: out std_logic_vector(23 downto 0);end mul12;architecture rtl of mul12 isbegin process(ain,bin) variable pa: signed(24 downto 0); va

10、riable a_1: std_logic; alias p: signed(12 downto 0) is pa(24 downto 12); begin p:=(others='0'); pa(11 downto 0):=signed(ain); a_1:='0; for i in 1 to 12 loop case std_logic_vector(pa(0),a_1) is when ”01” => p:=p+signed(bin); when "10" => p:=psigned(bin); when others = null

11、; end case; a_1:=pa(0); pa:=shift_right(pa,1); end loop; qout<=std_logic_vector(pa(23 downto 0); end process;end rtl;该乘法器的原理图如图4。7:图4.7 12位乘法器原理图通过仿真得到12位乘法器波形如下图4。8所示:图4。8 乘法器仿真图此时,ain=1,bin=1,输出qout= 1,显然是正确的.4。1.4 延时器的实现延时器可以用寄存器实现,VHDL源程序如下:library ieee; use ieee.std_logic_1164.all;entity del

12、ayer is port(a: in std_logic_vector(11 downto 0); clk:in std_logic; reset:in std_logic; b: out std_logic_vector(11 downto 0));end entity delayer;architecture rtl of delayer isbegin process(clk,reset) begin if reset='1' then b<=”000000000000"; 异步复位 elsif clkevent and clk='1' t

13、hen 时钟上升沿 b=a; end if; end process;end architecture rtl;延时器的基本逻辑单元是上升沿触发的D触发器,其原理图如下图4。9所示:图4。9 延时器原理图仿真波形如4.10所示: 图4.10 延时器仿真图4.2 FIR带通滤波器的顶层实现利用上面所编写的12位加法器,24位加法器,12位乘法器及延时器,我们可以组合出所需的FIR带通滤波器。程序中主要是运用元件例化语句来实现一个结构化的描述,系统函数通过调用12位加法器,24位加法器,12位乘法器及延时器等模块来FIR带通滤波器。具体的调用层次见图4.11所示。图4.11 FIR滤波器的结构图滤

14、波器顶层源程序如下.顶层源程序;library ieee; -库包说明use ieee.std_logic_1164.all;use ieee.std_logic_unsigned。all;use ieee。numeric_std。all;entity filter is port( x: in std_logic_vector (11 downto 0); -端口说明 clk: in std_logic; reset: in std_logic; y: out std_logic_vector (23 downto 0);end entity filter;architecture stru

15、 of filter is component add12 is -12位加法器 port ( a , b : in std_logic_vector(11 downto 0) ; ci: in std_logic; co: out std_logic; sum: out std_logic_vector ( 11 downto 0) ); end component add12; component add24 is 24位加法器 port ( a , b : in std_logic_vector(23 downto 0) ; ci: in std_logic; co: out std_l

16、ogic; sum: out std_logic_vector ( 23 downto 0) ); end component add24; component mul12 is -12位乘法器 port(ain: in std_logic_vector(11 downto 0); bin: in std_logic_vector(11 downto 0); qout: out std_logic_vector(23 downto 0)); end component mul12; component delayer is -延时器 port(a: in std_logic_vector(11

17、 downto 0); clk:in std_logic; reset:in std_logic; b: out std_logic_vector(11 downto 0)); end component delayer; type delaytype is array (0 to 21) of std_logic_vector(11 downto 0); -自定义数据类型 type sumtype is array (0 to 10) of std_logic_vector(11 downto 0); type multype is array (0 to 10) of std_logic_

18、vector(23 downto 0); signal delay:delaytype; -定义信号 signal sum:sumtype; signal mul,sum2:multype; constant h:sumtype:=("000000100011", -系统函数 "111111010010”, "111111110011”, "111111011000”, ”000000110110”, "001100010110", "111110101010", "000110101110”,

19、 "111111101000”, ”110000011100”, "110011100100");begin delay(0)<=x; g1:for i in 0 to 20 generate de:delayer port map(delay(i),clk,reset,delay(i+1)); end generate g1; g2:for i in 0 to 10 generate ad12:add12 port map(delay(i),delay(21-i),'0,open,sum(i)); end generate g2; g3:for i

20、 in 0 to 10 generate mu:mul12 port map(sum(i),h(i),mul(i); end generate g3; sum2(0)=mul(0); g4:for i in 0 to 9 generate ad24:add24 port map(sum2(i),mul(i+1),'0',open,sum2(i+1); end generate g4; y=sum2(10);end architecture stru;点击Files下的Create/UpdateCreate Symbol Files for Current File,可以生成滤波

21、器模块及各独立元件(加法器,乘法器,延时器等)的模块。可建立模型如图4。12所示:图4。12 FIR滤波器模型图为了验证生成的模型是否满足设计的性能指标,必须进行时序仿真,而其中最有效最全面的方法就是加入一个冲激信号,看滤波器的单位冲激响应。让输入x在第一个时钟有效沿为12位的二进制脉冲,即冲激信号。编辑波形文件,进行仿真,得到仿真报告如图4。13下:图4。13 仿真报告当输入为任意值时仿真波形图如4。14所示: 图4.14 总仿真波形图当输入为高电平或低电平时仿真波形图如4.15所示:图4。15 总仿真波形图 从波形可以看出:当输入为任意值时,有选择性的输出。当为输入为高电平时输出为高电平:

22、当输入为低电平时输出为低电平.可以看出符合设计要求.在进行系统仿真时,有以下几点体会:(1)系统模块化分的重要性 对于一个系统的开发,最初的模块划分是非常重要的。随着系统的复杂度的增大,模块划分对于系统的后续开发显示出越来越大的重要性。随着自顶向下设计方法的广泛采用,把一个系统划分为几个子模块,然后各个子模块分别设计的方法也越来越多的被广大设计者所使用。一个系统模块划分的好坏,模块间接口设计得是否合理,将直接影响到整个系统的开发,甚至会决定系统开发的成功与否。一个良好的系统模块划分,合理的模块间接口设计会使后续的系统开发事半功倍.反之则使得后续的系统开发步履艰难.因而,系统开发人员把越来越多的

23、时间和精力投入到系统的模块划分和接口设计当中.具体到本设计的开发,由于开发的经验不足,模块间的接口设计不是很合理,等到开发到具体的子模块时,才发现了问题,使得系统综合与仿真无法进行下去,从而不得不重新设计模块间的接口,耽误了整个系统开发的速度。 (2)器件延时对系统实现的影响器件延时对一个实际系统来说是客观存在的,它对系统实现的影响是不可避免的,同时也是很难预测的.因而在实现系统时,要想把器件对系统实现的影响完全消除)L乎是不可能的.如果完全忽视它,很可能会导致系统无法正确实现.比较好的做法是把器件延时的影响控制在一个系统可以允许的范围内,使得它不至于对系统实现产生决定性的影响。在本系统的开发

24、过程当中,刚开始由于对器件延时的影响考虑不足,所以导致了程序仿真结果与预先设想的不一致,使得系统仿真无法实现预定的功能.后经过修改程序,考虑了器件延时对同步的影响,才最终实现了系统预定的功能。可见,考虑器件延时的影响对一个系统设计者来说是非常重要的.4.3 硬件下载 将编译产生的SOF格式配置文件配置进FPGA中。硬件测试步骤如下:(1)打开编译好的文件,将实验系统和并口通信线接好,打开电源.先对引脚进行锁定。再选择ToolProgrammer命令,在Mode列表中选JTAG,单击左侧的Add File按钮,手动选择配置文件. (2)设置编程器.单击Hardware Setup按钮在弹出的Hardware Setup对话框中双击ByteBlasterMV,单击Close即可. (3)选择编程器。根据试验箱选择编程口.本次设计选择ByBtII,最后单击Start即可,当Programme显示出100时,编译成功。(4)硬件测试。根据仿真结果输入脉冲。观察结果正确。下载成功。联想商务网 http:/www。timetoprotect。com cjb13x

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 社会民生


经营许可证编号:宁ICP备18001539号-1