Electronic – How to scale output of FIR filter implemented in VHDL

filterfirfpgascalingvhdl

For a DSP school project we need to implement sound effects in a SPARTAN 6 FPGA using VHDL.

We tried to keep it simple and start off with a simple (100Tab) FIR filter.

As coefficients we used those created by the MATLAB FDATool.

The MATLAB output are 8bit hex values (like:01,fa,00,fd,fb,03,f4,0b,ed,…).

The filter seems to be functioning. The impulse response looks like one of a FIR filter and the music does sound filtered.

But the distortion is big and the music doesn't sound good.

We think this is due to 'bad' scaling.


The CODEC output (filter input) is 18bit wide, the filter output is 48bit. But the CODEC input (scaled filter output) is only 18bit.

How should we scale the 48bit output to make it fit the 18bit CODEC input?

We tried dividing the 48bit output by a scalar (more or less the same as shifting).
We also tried just removing some MSB values (which we estimated would never be used) and then dividing by a scalar.

None of these methods seems satisfactory and the signal gets distorted.

Would there be a better method to scale the output? We thought of scaling the coefficients but in their current form they just become 0 (sum all coefficients and divide every single coefficient with this value, good for fixed point values but not with these (MATLAB) values?).

EDIT:

After more investigation it appears that all distortion is due to the scaling.
I think this is caused by the removal of MSB when a small scalar is chosen (not enough shifting, so some MSB's containing info are removed). But also due to the removal of LSB's when keeping all MSB'S.

So my question still stands: What would be the optimal way of implementing scaling?

Best Answer

Normally there should not be any scaling to be done.. Just make your filter In/out 18 bit wide...

also , do not forget the anti-aliasing filter at the output...