- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello everyone!
I need some help on trying to understand the Output Number System for the FIR Compiler 8.0. My filter design is giving me an output of 34 bits, which is way to much. How do I go about deciding what MSBs and LSBs to keep and whether to Truncate, Saturate, or Round? My bit scaling is 20 bits with a 12 bit input width. I would like to get down to 12-15 output bits if possible while maintaining the best filter response that I can. If you have a resource that describes how to decide those methods, that would be great. Thank you!Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
If your filter is LPF then it is easy to precalculate the maximum output value and this equals input maximum dc x (sum of coefficients). You will then know which MSBs are never used and discard safely. You may choose to discard a further MSB if it is only occasionally used by peaks. This is undesirable but may be inevitable. The best way is to rescale the coefficients so that the output swings in the relevant MSBs. Once you know how many MSBs to discard then you will know how many LSBs to truncate off. In this case rounding may be done but it is trivial.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks Kaz for replying.
I added up my coeffients and the sum is 1.00144718. Using your equation, I only need 12 bits. So, do I only keep the lower 12 bits? I've never designed a FIR filter before so I have lot's of questions. What about the LSBs? Thanks- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
I don't mean that 1.0000 filter design tools produce coeffs normalised to a sum of 1. This guaratees a dc gain of 1 in a pc model (or in DSP), but in FPGA hardware they are scaled up to say 12 bits signed. It is this scaled sum that I am talking about. All coefficients will be rounded integers with the maximum occuping up to the roof. So add up the scaled coefficients and multiply their sum by maximum input value then it tells you how many bits you need...this decides MSB discarding. At the output you truncate off 11 LSB bits. This gives you back the unitary dc gain because you scale up then down equally.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi All,
This thread is very interesting to me I too am designing a filter in quartus 8 dsp builder. and wondered how you extract the coefficients generated by the FIR compiler into excel to add them up and calculate the gain of the filter. I have tried to cut and paste into excel from the parameters window without success. Plese do you have any tips? In my filter I have multiple sets of, megawizard generated, coefficients so I guess I will have to apply different scaling to each set of coefficients to get the gain of the system the same for all sets? Thanks Dave- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I guess, there are any report files that show the coefficients?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes thanks. I've just found the .txt file, pasted into excel and the eight different sets of coefficients all sum to different values. This ties in with the different gains I was measuring for each of the coefficient sets. I wonder if there is a way of generating the coeffs so that they all have the same sum/gain?
Thanks again Dave- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
A recap: A tool(or equation) produces coeffs as fractions of 1. In hardware there are 3 approaches for scaling(assuming result is wide to accomodate all values): 1) scale coeffs maximally e.g max coeff to be 32767 for 16 bits signed. This approach makes most of bits for coeffs but you can't get unitary gain easily. h = h * 32767/max(h); 2) scale sum of coeffs maximally e.g sum to equal 32768 for 16 bits signed. This method allows for unitary gain readily by chopping off 15 LSB bits from result . h = h * 32768/sum(h); 3) scale coeffs as you like, useful to fine control power level. In all cases of truncation(= division) you may round up the result. For a LPF the maximm convolution result value = sum of coeffs x maximum signal value. So you know how many MSBs can be discarded. If you choose to discard an occasionally used MSB then you need to clip the signal though this is undesirable. There is not much point in having coeff bits more than signal itself. You can use Matlab to study the effect of bit resolution on filter response.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all,
First of all Kaz thank you very much. I have used excel to scale eight different sets of coeffs by your method 2). I now have filters all with the same gain. Perhaps it would help dtscindel if I told you how I managed to do it using the Altera fir compiler. In my system I have one low pass filter but with eight different cut-off frequencies and I wanted to get the same dc gain for each set of coefficients. I have 12 bit signed input. First I used the wizard and added eight sets of coefficients with the coefficient scaling set to auto with a bit width of 12. At this time the wizard told me that the ouput would be 30 bits wide. I then generated the filter. The generate process produced a .txt file called filename_coef_int.txt. This file contained the eight sets of coeffs in a form that I could then paste into excel. In excel I summed all eight sets of coeffs individually and got a different sum for each set. As Kaz says the gain of the filter is simply the sum of all the coeffs so to get the gains the same I realized I needed to get the sums the same. So in excel I inserted a new column for each set of coeffs. In this column I calculated a new set of scaled coefs by muliplying each unscaled coeff by the required new sum (in my case 16384) and dividing it by the original sum for that set of coeffs. ( as in Kazs method 2)). I then pasted each set of scaled coeffs into eight .txt files, one for each set. Finally I reopened the FIR compiler and imported each set of scaled coeffs, one by one, in the 'edit coeffs' window. All I had to do then was set the coeffs scaling bit width back to twelve and re generate the filter. Job done eight low pass filters all with the same gain and scaled to fit nicely in the 26 lower bits of the 30 bits the filter compiler allowed. I will probably drop off the lower 14 bits to give me back a twelve bit result. I hope this helps. Thanks again Kaz & FvM Cheers Dave
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page