Forum Discussion
Altera_Forum
Honored Contributor
16 years ago --- Quote Start --- Thanks Kaz! Like this:
module test_filter(clk,filter_in,filter_out);
parameter W=7; // bit width - 1
parameter signed a=10'b0100000000;
input clk;
input signed filter_in;
output signed filter_out;
reg signed x,y;
initial
begin
x=0;
y=0;
end
always@(posedge clk)
begin
x <= filter_in;
y <= ({x,10'b0000000000}) - (a*x) + (a*y); // y=(1-a)*x+(a*y)
end
assign filter_out=y;
endmodule // test_filterSee anything that looks wrong there? (think there might be as my audio output is now really noisy!) By the way, a=0.25 in this code. Thanks! --- Quote End --- Basically it looks ok. My mistake was the 20 bit width. we scaled (a) by 2^10 but scaled (y) by 2^-8 leading to 12 dB gain. so make y 18 bits and truncate feedback to 8 bits. also note 1-a can be precomputed and scaled to 1-.25 = .75 = .75*1024 check in matlab your filter cutoff: den = [1 -.25]; nu = .75; freqz(num,den)