FIR滤波器设计

目录

1、FIR滤波器原理

 2、FIR滤波器的数字设计


1、FIR滤波器原理

        滤波器就是对特定的频率或者特定频率以外的频率进行消除的电路,被广泛运用于通信系统和信号处理系统中。从功能而言,数字滤波器对输入离散信号的数字代码进行运算处理,以达到滤除频带外信号的目的。

        有限冲激响应(FIR)滤波器就是一种常用的数字滤波器,采用对已输入样值的加权和来形成他的输出。其系统函数为

        对于输入序列X(n)的FIR滤波器,可用下图所示结构示意图来进行表示,其中X(n)是输入数据流。各级的输入链接和输出连接被称为抽头,系数(a0,a1,a2......an)被称为抽头系数。一个M阶的FIR滤波器有M+1个抽头。通过移位寄存器用每个时钟边沿n处的数据流采样值乘以抽头系数并相加,得到输出y(n)。

 2、FIR滤波器的数字设计

        FIR滤波器电路主要有两个主要功能模块:移位寄存器shift_register用于存储串行进入滤波器的信号数据;乘加模块计算模块caculator用于进行FIR计算。因此,在顶层模块采用结构化建模设计。

以一个4bit8阶FIR滤波器为例

//4bit8阶FIR滤波器设计

//part1、移位寄存器模块用于存储输入的信号序列
module shift_register(clk,rst_n,din,dout1,dout2,dout3,dout4,dout5,dout6,dout7,dout8,dout9);
	input clk,rst_n;
	input[3:0] clk;
	output[3:0] dout1,dout2,dout3,dout4,dout5,dout6,dout7,dout8,dout9;
	reg [3:0] dout1,dout2,dout3,dout4,dout5,dout6,dout7,dout8,dout9;
	
	always@(posedge clk or negedge rst_n)
		if(!rst_n)
			begin
				dout1<=0;
				dout2<=0;
				dout3<=0;
				dout4<=0;
				dout5<=0;
				dout6<=0;
				dout7<=0;
				dout8<=0;
				dout9<=0;
			end
		else
			begin
				dout1<=din;
				dout2<=dout1;
				dout3<=dout2;
				dout4<=dout3;
				dout5<=dout4;
				dout6<=dout5;
				dout7<=dout6;
				dout8<=dout7;
				dout9<=dout8;
			end
endmodule

//part2、caculator模块用于进行8输入信号与抽头系数的乘法相加,并产生滤波之后的输出信号
module caculator(din1,din2,din3,din4,din5,din6,din7,din8,din9,dout);
	input[3:0] din1,din2,din3,din4,din5,din6,din7,din8,din9;
	output[9:0] dout;
	wire [9:0] dout;
	wire[3:0] out1,out2,out3,out4;
	wire[9:0] out_temp1,out_temp2,out_temp3,out_temp4,out_temp5;
	parameter b0 = 4'b0010;
	parameter b1 = 4'b0011;
	parameter b2 = 4'b0110;
	parameter b3 = 4'b1010;
	parameter b4 = 4'b1100;
	
	
	assign out1=din1+din9;
	assign out2=din2+din8;
	assign out3=din3+din7;
	assign out4=din4+din6;
	
	mul_addtree M1(.mul_a(b0),.mul_b(out1),out(out_temp1));
	mul_addtree M1(.mul_a(b1),.mul_b(out2),out(out_temp2));
	mul_addtree M1(.mul_a(b2),.mul_b(out3),out(out_temp3));
	mul_addtree M1(.mul_a(b3),.mul_b(out4),out(out_temp4));
	mul_addtree M1(.mul_a(b4),.mul_b(din5),out(out_temp5));
	
	assign dout = out_temp1+out_temp2+out_temp3+out_temp4+out_temp5;
	
endmodule

//part3、乘法器树模块
module mul_addtree(mul_a,mul_b,out);
	input[3:0] mul_a,mul_b;
	output[7:0] out;
	wire[7:0] out;
	wire[7:0] store1,store2,store3,store4;
	wire[7:0] add12,add34;
	
	assign store1 = mul_b[3]?{1'b0,mul_a,3'b0}:8'b0;
	assign store2 = mul_b[2]?{2'b0,mul_a,2'b0}:8'b0;
	assign store3 = mul_b[1]?{3'b0,mul_a,1'b0}:8'b0;
	assign store4 = mul_b[0]?{4'b0,mul_a}:8'b0;
	assign add12 = store1+store2;
	assign add34 = store3+store4;
	assign out = add12+add34;
	
endmodule

//part4、FIR filter顶层模块
module FIR_filter(data_in,clk,rst_n,data_out);
	input[3:0] data_in;
	input clk,rst_n;
	output[9:0] data_out;
	
	wire[3:0] sample0,sample1,sample2,sample3,sample4,sample5,sample6,sample7,sample8;
	wire[9:0] data_out;
	
	shift_register S1(.din(data_in),.dout1(sample0),
					  .dout2(sample1),.dout3(sample2),
					  .dout4(sample3),.dout5(sample4),
					  .dout6(sample5),.dout7(sample6),
					  .dout8(sample7),.dout9(sample8));
	caculator C1(.din1(sample0),.din2(sample1),
	             .din3(sample2),.din3(sample3),
				 .din4(sample3),.din5(sample4),
				 .din6(sample5),.din7(sample6),
				 .din8(sample7),.din9(sample8));
				 
endmodule

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值