Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
16 years ago

input to IIR filter in Verilog

Just a quick question regarding implementing an IIR filter in Verilog...

At the moment, I am using the Wolfson ADC on the DE2-70 to convert analogue sound input from Line In to digital bits - that's all working perfectly (with a sample rate of 8000 kHz and 24-bit resolution).

I understand that these 24-bit values from the ADC are in two's complement form - i.e. each sample is represented by a number between -2^23 and (2^23)-1.

My question is, can this two's complement value be fed directly into a fixed-point IIR filter designed in Matlab's FDAtool?

Looking at FDAtool, there are options to set the "Input Word Length" & "Input Fraction Length"... This leads me to believe that I have to convert my 24-bit two's complement value from the ADC to a fixed point value that will be 24 + no. of fraction bits long...

Is this reasoning correct?

It would be much appreciated if someone could point me in the right direction on this one!

Cheers

14 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    How's this now:

    module test_filter(clk,filter_in,filter_out);
    parameter W=7;    // bit width - 1
    parameter signed a=10'b0100000000; //256
    parameter signed one_minus_a=10'b1100000000; //768
    input   clk; 
    input   signed  filter_in; 
    output  signed  filter_out;
    reg signed  y;
    reg signed  x;
    initial
    begin
        x=0;
        y=0;
    end
        
    always@(posedge clk)
        begin
        x <= filter_in;
        y <= (one_minus_a*x) + (a*y);    // y=(1-a)*x+(a*y)
        end
            
    assign filter_out=y;
    endmodule  // test_filter
    Thanks again!
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    My only worry is that 1100000000 assumed 768, but you made it negative.

    add sign bit, keep your scaling.

    I checked your filter in Matlab. it cuts off at(say .2 FS) and stop band attenuation is 4.5 dB. Is that what you want?
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Thanks again Kaz!

    Basically I want a filter that, for example, can attenuate 160Hz more so than 80Hz (second and first harmonics of E string respectively).

    I was planning on expanding on the IIR code above to get an appropriate filter response to acheive this (so those values of "a" are just values to test with at this stage) - however that code is still giving me a VERY noisy output - something is not right.

    Interestingly enough, if I set "one_minus_a" to zero, I still have the input passing through the filter to the output - how can this be?

    module test_filter(clk,filter_in,filter_out);
    parameter W=7;    // bit width - 1
    parameter signed a=10'b0100000000; //256
    parameter signed one_minus_a=11'b01100000000; //768
    input   clk; 
    input   signed  filter_in; 
    output  signed  filter_out;
    reg signed  y;
    reg signed  x;
    initial
    begin
        x=0;
        y=0;
    end
        
    always@(posedge clk)
        begin
        x <= filter_in;
        y <= (one_minus_a*x) + (a*y);    // y=(1-a)*x+(a*y)
        end
            
    assign filter_out=y;
    endmodule  // test_filter
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    You can't expect anything but "VERY noisy output" with 8 bit data length, particularly, when the ADC input level keeps a headroom. I don't understand the purpose of using such a low resolution. 12 bit would be fair, 16 bit standard CD audio quality.

    --- Quote Start ---

    if I set "one_minus_a" to zero, I still have the input passing through the filter to the output

    --- Quote End ---

    Doesn't sound reasonable with the shown code.

    Regarding the said application, a first order low-pass isn't a very selective filter.