jpglotzer
Newbie level 5
Hi everyone!
I'm doing a project on altera quartus, where I need to implement a fir low pass filter in direct form. I was just about finishing writing it up, when I came to the realization that what I've done is not direct form (I don't think). My code is below, and I was wondering if anyone could suggest how to change it to get a direct form structure? Any help would be much appreciated!
---------- Post added at 23:38 ---------- Previous post was at 23:37 ----------
oops, I've just noticed one mistake, there should be a bitwise inversion:
x_2comp<={~scaled_x[9]}{scaled_x[8:0]};
I'm doing a project on altera quartus, where I need to implement a fir low pass filter in direct form. I was just about finishing writing it up, when I came to the realization that what I've done is not direct form (I don't think). My code is below, and I was wondering if anyone could suggest how to change it to get a direct form structure? Any help would be much appreciated!
Code:
module fir_filter(x,rst,y)
input [7:0] x;
input rst;
output [24:0] y;
parameter signed c0=16b'1111100110110001,
c1=16b'0001111100000100,
c2=16b'0100011010100101,
c3=16b'0110111010100111,
c4=16b'0111111101010101;
reg [9:0] scaled_x;
reg signed [9:0] tap0,tap1,tap2,tap3,tap4,tap5,tap6,tap7,tap8;
reg signed [25:0] product0,product1,product2,product3,product4;
reg signed [26:0] sum;
always@(posedge clk)
begin
if(rst)
begin
tap8<=0;
tap7<=0;
tap6<=0;
tap5<=0;
tap4<=0;
tap3<=0;
tap2<=0;
tap1<=0;
tap0<=0;
end
t0<=tap0+tap8;
t1<=tap1+tap7;
t2<=tap2+tap6;
t3<=tap3+tap5;
t4<=tap4;
product0<=c0*t0;
product1<=c1*t1;
product2<=c2*t2;
product3<=c3*t3;
product4<=c4*t4;
sum<=product0+product1+product2+product3+product4;
scaled_x<={x[7]}{x[7]}{x[7:0]};
x_2comp<={scaled_x[9]}{scaled_x[8:0]};
tap8<=tap7;
tap7<=tap6;
tap6<=tap5;
tap5<=tap4;
tap4<=tap3;
tap3<=tap2;
tap2<=tap1;
tap1<=tap0;
tap0<=x_2comp;
y<=sum;
end
endmodule
---------- Post added at 23:38 ---------- Previous post was at 23:37 ----------
oops, I've just noticed one mistake, there should be a bitwise inversion:
x_2comp<={~scaled_x[9]}{scaled_x[8:0]};