FIR+Filter

When designing the filter, remember that a 10th order filter has 11 taps!

The coefficients calculated have a symmetry that can be used by adding the tab values before multilpying. Ex: prod(0) = (tap[0] + tap[10]) * coff(0);

Use arrays of hold coefficients, taps and product values code subtype coeff_type is integer range -128 to 127; type coeff_array_type is array (0 to filterOrder/2) of coeff_type;

subtype tap_type is signed(inputWidth-1 downto 0); type tap_array_type is array (0 to filterOrder) of tap_type;

subtype prod_type is signed(inputWidth+coefWidth-1 downto 0); type prod_array_type is array (0 to filterOrder/2) of prod_type;

constant coeff : coeff_array_type := (-1, -3, 0, 27, 11, 19); signal tap    : tap_array_type; signal prod   : prod_array_type;

code To calculate the products you have to convert the integer to signed: code prod(tap_no) <= to_signed(coeff(tap_no),8) * tap(tap_no);

code

A good place to start, is to create a testbench that creates an impulse: code ... -- clock generation Clk <= not Clk after period/2; Clk48KHz <= not Clk48KHz after period48K/2;
 * Testing the design:**

AudioReset <= '0', '1' after 125 ns;

-- waveform generation WaveGen_Proc: process begin wait until AudioReset = '1'; wait until Clk48KHz = '1';

Audioin <= X"010000";              -- Impulse wait until Clk48KHz = '1'; Audioin <= X"000000";

wait; end process WaveGen_Proc; ... code As we recall from Matlab/Octave we should get a sinc-like output. Using an impulse as imput (value is high for one 48KHz clock period and otherwise zero), we get a value that walks down the delay line with the remaining taps being all zero. This gives an output which is: y[n] = x * tap[n]. The simulation below illustrates this:

The scaled (x8) coefficients are: {-1, -3, 0, 27, 73, 97}.

Using an impulse with amplitude of 0x10000 (=65535d) audioOut becomes {-32768, -98303, 0, 884735 etc}

This corresponds to :{ 65535*(-1)/256, 65535*(-3)/256, 65535*0/256, 65535*27/256 etc.}