Forum Discussion
Hi Chee
I think I have figured out how to use the FIR II IP to generate a LP filter with:
- Unity gain (or close to, will depend on passband ripple)
- Max calculation resolution in FIR II
- Max dynamic on the output
Here is my approach:
Generates the filter taps. E.g Matlab. Make sure sum(h(n)) = 1.
E.g. taps = 0.0001 0.0006 0.0020 0.0036 0.0028 -0.0040 -0.0173 -0.0288 -0.0212 0.0220 0.1006 0.1897 0.2493 0.2493 0.1897 0.1006 0.0220 -0.0212 -0.0288 -0.0173 -0.0040 0.0028 0.0036 0.0020 0.0006 0.0001
Pre-scaling is the trick. Do not use FIR II auto scale. This will give a non-integer scaling, and unity gain is not achieved.
To get max FIR II calculation resolution scale the taps with: 2^M / Max_filter_ripple.
Max_filter_ripple is a “compensation factor” needed to avoid overflow for frequencies matching the ripple peaks for the filter, and will typical be slightly above 1.
M = Coeffs_resolution-1 + floor(log2(0.5/max(taps)))
Max_filter_ripple = 10^(Max_filter_ripple_in_dB/2/20), Max_filter_ripple_in_dB is peak-to_peak.
MSBs to remove = ceil(log2(length(taps))) + 1 - floor(log2(0.5/max(taps)))
For the filter above, with Coeffs_resolution = 24
M=24, Max_filter_ripple = 1.0058 (with Max_filter_ripple_in_dB=0.1dB)
->
At the output:
Remove 5 MSB
Remove 24 LSB
I have tested this approach on a 3-stage decimation filter and I get a gain of 0.98.
BR
AD