FIR滤波器的设计
2、在设置mult ip核的时候,在设置里面会有乘法是否设置 unsigned和signed,那在第一个问题的基础上,我是设置unsigned还是signed?
3、滤波器的设计,我要给他什么样子的输入,仿真看得出什么样子的结果?
部分代码如下
module fir(
input clk,
input rst_n,
input [11:0] fir_in, // 12位输入
output reg [26:0] fir_out //27位输出
);
//------------------------------------------------
parameter cof1 = 12'd41;
parameter cof2 = 12'd132;
parameter cof3 = 12'd341;
parameter cof4 = 12'd510;
//------------------------------------------------
reg [11:0] fir_in_reg;
reg [12:0] shift_buf [7:0];//定义8个13位寄存器
//------------------------------------------------
wire [12:0] add07;
wire [12:0] add16;
wire [12:0] add25;
wire [12:0] add34;//对称性前后两个相加
wire [24:0] mul1;
wire [24:0] mul2;
wire [24:0] mul3;
wire [24:0] mul4;//系数相乘(12位)
//------------------------------------------------
integer i,j;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
fir_in_reg <= 12'd0;
else
fir_in_reg <= fir_in;
end
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
for(i=0;i <= 7;i=i+1)
shift_buf[i] <= 13'd0;
else
begin
for(j=0;j < 7;j=j+1)
shift_buf[j+1] <= shift_buf[j];
shift_buf[0] <= {fir_in_reg[11],fir_in_reg};
end
end
//----------------------------------------------------
assign add07 = shift_buf[0] + shift_buf[7];
assign add16 = shift_buf[1] + shift_buf[6];
assign add25 = shift_buf[2] + shift_buf[5];
assign add34 = shift_buf[3] + shift_buf[4];
//----------------------------------------------------
mult1 mult_inst1(
.dataa(cof1),
.datab(add07),
.result(mul1)
);
mult1 mult_inst2(
.dataa(cof2),
.datab(add16),
.result(mul2)
);
mult1 mult_inst3(
.dataa(cof3),
.datab(add25),
.result(mul3)
);
mult1 mult_inst4(
.dataa(cof4),
.datab(add34),
.result(mul4)
);
//---------------------------------------------
wire [25:0] add_mul12 = {mul1[24],mul1}+{mul2[24],mul2};
wire [25:0] add_mul34 = {mul3[24],mul3}+{mul4[24],mul4};//26位
//---------------------------------------------
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
fir_out <= 27'd0;
else
fir_out <= {add_mul12[25],add_mul12}+{add_mul34[25],add_mul34};
end
endmodule
module fir(
input clk,
input rst_n,
input [11:0] fir_in, // 12位输入
output reg [26:0] fir_out //27位输出
);
//------------------------------------------------
parameter cof1 = 12'd41;
parameter cof2 = 12'd132;
parameter cof3 = 12'd341;
parameter cof4 = 12'd510;
//------------------------------------------------
reg [11:0] fir_in_reg;
reg [12:0] shift_buf [7:0];//定义8个13位寄存器
//------------------------------------------------
wire [12:0] add07;
wire [12:0] add16;
wire [12:0] add25;
wire [12:0] add34;//对称性前后两个相加
wire [24:0] mul1;
wire [24:0] mul2;
wire [24:0] mul3;
wire [24:0] mul4;//系数相乘(12位)
//------------------------------------------------
integer i,j;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
fir_in_reg <= 12'd0;
else
fir_in_reg <= fir_in;
end
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
for(i=0;i <= 7;i=i+1)
shift_buf[i] <= 13'd0;
else
begin
for(j=0;j < 7;j=j+1)
shift_buf[j+1] <= shift_buf[j];
shift_buf[0] <= {fir_in_reg[11],fir_in_reg};
end
end
//----------------------------------------------------
assign add07 = shift_buf[0] + shift_buf[7];
assign add16 = shift_buf[1] + shift_buf[6];
assign add25 = shift_buf[2] + shift_buf[5];
assign add34 = shift_buf[3] + shift_buf[4];
//----------------------------------------------------
mult1 mult_inst1(
.dataa(cof1),
.datab(add07),
.result(mul1)
);
mult1 mult_inst2(
.dataa(cof2),
.datab(add16),
.result(mul2)
);
mult1 mult_inst3(
.dataa(cof3),
.datab(add25),
.result(mul3)
);
mult1 mult_inst4(
.dataa(cof4),
.datab(add34),
.result(mul4)
);
//---------------------------------------------
wire [25:0] add_mul12 = {mul1[24],mul1}+{mul2[24],mul2};
wire [25:0] add_mul34 = {mul3[24],mul3}+{mul4[24],mul4};//26位
//---------------------------------------------
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
fir_out <= 27'd0;
else
fir_out <= {add_mul12[25],add_mul12}+{add_mul34[25],add_mul34};
end
endmodule
module fir(
input clk,
input rst_n,
input [11:0] fir_in, // 12位输入
output reg [26:0] fir_out //27位输出
);
//------------------------------------------------
parameter cof1 = 12'd41;
parameter cof2 = 12'd132;
parameter cof3 = 12'd341;
parameter cof4 = 12'd510;
//------------------------------------------------
reg [11:0] fir_in_reg;
reg [12:0] shift_buf [7:0];//定义8个13位寄存器
//------------------------------------------------
wire [12:0] add07;
wire [12:0] add16;
wire [12:0] add25;
wire [12:0] add34;//对称性前后两个相加
wire [24:0] mul1;
wire [24:0] mul2;
wire [24:0] mul3;
wire [24:0] mul4;//系数相乘(12位)
//------------------------------------------------
integer i,j;
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
fir_in_reg <= 12'd0;
else
fir_in_reg <= fir_in;
end
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
for(i=0;i <= 7;i=i+1)
shift_buf[i] <= 13'd0;
else
begin
for(j=0;j < 7;j=j+1)
shift_buf[j+1] <= shift_buf[j];
shift_buf[0] <= {fir_in_reg[11],fir_in_reg};
end
end
//----------------------------------------------------
assign add07 = shift_buf[0] + shift_buf[7];
assign add16 = shift_buf[1] + shift_buf[6];
assign add25 = shift_buf[2] + shift_buf[5];
assign add34 = shift_buf[3] + shift_buf[4];
//----------------------------------------------------
mult1 mult_inst1(
.dataa(cof1),
.datab(add07),
.result(mul1)
);
mult1 mult_inst2(
.dataa(cof2),
.datab(add16),
.result(mul2)
);
mult1 mult_inst3(
.dataa(cof3),
.datab(add25),
.result(mul3)
);
mult1 mult_inst4(
.dataa(cof4),
.datab(add34),
.result(mul4)
);
//---------------------------------------------
wire [25:0] add_mul12 = {mul1[24],mul1}+{mul2[24],mul2};
wire [25:0] add_mul34 = {mul3[24],mul3}+{mul4[24],mul4};//26位
//---------------------------------------------
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
fir_out <= 27'd0;
else
fir_out <= {add_mul12[25],add_mul12}+{add_mul34[25],add_mul34};
end
endmodule
部分代码呢?在哪儿
always@(posedge clk or negedge rst_n)
begin
if(!rst_n)
for(i=0;i <= 7;i=i+1)
shift_buf[i] <= 13'd0;
else
begin
for(j=0;j < 7;j=j+1)
shift_buf[j+1] <= shift_buf[j];
shift_buf[0] <= {fir_in_reg[11],fir_in_reg};
end
end
//----------------------------------------------------
assign add07 = shift_buf[0] + shift_buf[7];
assign add16 = shift_buf[1] + shift_buf[6];
assign add25 = shift_buf[2] + shift_buf[5];
assign add34 = shift_buf[3] + shift_buf[4];
//----------------------------------------------------
mult1 mult_inst1(
.dataa(cof1),
.datab(add07),
.result(mul1)
);
不知道 为什么要审核