cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Anonymous
Not applicable
3,609 Views

Convert Decimal to fixed point

Jump to solution

I have coefficients to use for filtering and I would like to convert them into fixed point (hoping that it will decrease the implementation resources):

const ap_ufixed<125,1,AP_TRN_ZERO,AP_SAT> H[256] = {
... 0.00000000000000000000091449017339064687, 0.00000000000000000000062116230274780313, 0.00000000000000000000042127263672158805, 0.00000000000000000000028526830531801544, 0.00000000000000000000019287498479639181
...
};

Is this an acceptable way to define an array, or I have to explicitly convert the coefficients to fixed point numbers. If conversion is necessary, then how to do that?

0 Kudos
1 Solution

Accepted Solutions
jprice
Scholar
Scholar
6,255 Views
Registered: ‎01-28-2014

Given that, that should work but you'll find pretty heavy DSP usage though overall less logic resources (I think, I never tried arithmetic with coefficients that large that weren't floating point). Your syntax is correct, I do that with smaller bit widths frequently. 

View solution in original post

0 Kudos
4 Replies
jprice
Scholar
Scholar
3,577 Views
Registered: ‎01-28-2014

To answer your actual question, that should work fine. However looking at your bit widths (125) I suspect you'll end up using way more resources than you care to. However looking at your examples I don't know if you need that many bits. I'd normalize your coefficients and try a few different bit widths and pick smaller ones that still perform acceptably. What kind of a filter is this? 

Anonymous
Not applicable
3,541 Views

@jprice I am trying to implement a bilateral filter. The coefficients that you saw are the smallest five: they are normalized and the range is 10^-22 : 1. I may be able to decrease the precision, but first I want to succeed with full precision.

0 Kudos
jprice
Scholar
Scholar
6,256 Views
Registered: ‎01-28-2014

Given that, that should work but you'll find pretty heavy DSP usage though overall less logic resources (I think, I never tried arithmetic with coefficients that large that weren't floating point). Your syntax is correct, I do that with smaller bit widths frequently. 

View solution in original post

0 Kudos
Anonymous
Not applicable
3,527 Views
Yep, I decreased width from 125 to 24 bit and it has a similar effect. At least, now the implementation fits on the device.
0 Kudos