FPGA Intellectual Property
PCI Express*, Networking and Connectivity, Memory Interfaces, DSP IP, and Video IP
6512 Discussions

FIR Filter II, not able to get unity gain

ArthurDent
New Contributor I
1,471 Views

Hi

I have designed a 26 taps FIR filter in Matlab. The coefficients are float (between -1 to 1) and the sum of the coefficient is close to 1 ( sum(taps) = 0.9991 ).

In FIR II IP generator (Quartus 17.1) the filter is set up with:

- 24b coefficients signed binary with auto scale

- 24b input signed binary

- 24b output signed binary, where the LSBs are removed to get 24b

 

The problem is that the filter does not have unity gain. Simulations (Matlab and ModelSim) show that the output level is approximately 1/16 of the input level at low frequencies signals (i.e. signals well within the passband).

Why? Can anyone share some insight here? Have I configured Fir II incorrectly?

I can of course remove some of the MSB bits but I did not think that should be necessary, and one need to be careful to avoid saturation. The FIR filter is part of a 3 stage decimation filter, and if each step has gain loss the dynamic range will suffer.

BR

AD

0 Kudos
6 Replies
CheePin_C_Intel
Employee
1,136 Views

Hi AD,

 

As I understand it, you seems to have some inquiries related to design implementation. Generally we would use this Forum to address specific inquiry related to FPGA but not design implementation. However, I will try my best to assist to my best knowledge. Hope you could understand it.

 

As I understand it, you are trying to design a FIR with unity gain. Just would like to check with you if you are able to get a FIR running with unity gain in Matlab? You might need a filter work in Matlab before we could continue to port over to FPGA. 

 

As I search through the web, I come across a post in the following link related to scaling required. Probably you could take a look to see if it is helpful.

 

https://www.mathworks.com/matlabcentral/answers/89435-normalization-of-a-given-filter-to-have-unity-gain-at-dc

 

Please let me know if there is any concern. Thank you.

 

Best regards,

Chee Pin

0 Kudos
ArthurDent
New Contributor I
1,136 Views

Hi Chee,

thanks for your reply. 

My filter is working fine in Matlab. What I am trying to figure out is how to use the FIR II IP correctly: I.e. how to select the 24bit output range from the filter which gives me maximum dynamic without overflow.

 

The DC (zero Hz) gain of the filter equals the sum of the filter taps (SUM(h(n)). If SUM(h(n)) = 1 then filter has gain=1 at DC. This is the case for my filter.

In FIR II I have this setup: 

24bit input

24bit coefficients

Number of coefficients: 26

 

With these numbers in FIR II the full output range is 53.

I assume this is based on: 24 + 24 + ceil(log2(26)) = 24 + 24 + 5 = 53. Is this correct?

 

I notice in FIR II that if one enables the auto-scale the center tap is scaled to 2^23 when using 24bit filter taps. SUM(h(n)) then typical gets larger than 2^24.

In my case the sum of the filter coefficients after the FIR II auto scaling is approximately: +29E6 

Assuming a range for both + and - values this adds 2 bits. (26bit : +/- 33E6)

 

Based on these numbers the 24bit output range with max resolution without overflow is:

MSB to remove: 3 (5-2)

LSB to remove: 26 (53-3-24)

Is this the correct understanding of the FIR II IP filter?

 

BR

AD

0 Kudos
CheePin_C_Intel
Employee
1,136 Views
Hi AD, Thanks for your update and clarification that your filter is working fine in Matlab. Would you mind to share with me the FIR design of your in Matlab together with steps to simulate the unity gain? This would be helpful for us to further look into how to port to FIR IP accordingly. Also, please help to share us a simple Quartus design which you mentioned simulating 1/16 gain in Modelsim. Thank you. Best regards, Chee Pin
0 Kudos
CheePin_C_Intel
Employee
1,136 Views

Hi AD,

 

For your information, I have had some discussion with peers on this. Based on our discussion, the your undersing on the calculation on the full output range and the number of bits for representing sum of coefficients seems correct.

 

Regarding your specific inquiries on the MSB and LSB to remove, sorry as I do not have much insight into this and thus might not be able to provide any helpful comment. As a workaround, it is recommended for you to try with different truncation in simulation to see if can achieve your target requirement. Sorry for the inconvenience.

 

 

Please let me know if there is any concern. Thank you.

 

Best regards,

Chee Pin

0 Kudos
ArthurDent
New Contributor I
1,136 Views

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

0 Kudos
CheePin_C_Intel
Employee
1,136 Views
Hi AD, Glad to hear that you have managed to resolve the issue and thanks lot for your sharing on the detailed implementation. It is really helpful. Thank you. Best regards, Chee Pin
0 Kudos
Reply