DSPRelated.com
Forums

floating to fixed point conversion

Started by brisker October 7, 2015
hello,
I am working on IIR filter to implement on DSP which is fixed point , but
coefficients of filter I am getting is floating point from MATLAB say one
of them is for example: 0.000000058323780584287955
Now how should I convert this to fixed point value? I dont have fixed
point toolbar in MATLAB.

please help me with my queries.
Thank you in advance.


---------------------------------------
Posted through http://www.DSPRelated.com
On 07.10.2015 13:18, brisker wrote:
> hello, > I am working on IIR filter to implement on DSP which is fixed point , but > coefficients of filter I am getting is floating point from MATLAB say one > of them is for example: 0.000000058323780584287955 > Now how should I convert this to fixed point value? I dont have fixed > point toolbar in MATLAB. > > please help me with my queries. > Thank you in advance. > > > --------------------------------------- > Posted through http://www.DSPRelated.com >
Depends on your fixed point format. If you are on fract 32 bits, one would just calculate 0.000000058323780584287955 * 2^31 and round. Gets you 125. If you are on 16 bits, this coefficient is below quantization anyway...
On Wed, 07 Oct 2015 06:18:03 -0500, brisker wrote:

> hello, > I am working on IIR filter to implement on DSP which is fixed point , > but coefficients of filter I am getting is floating point from MATLAB > say one of them is for example: 0.000000058323780584287955 Now how > should I convert this to fixed point value? I dont have fixed point > toolbar in MATLAB.
Man, that has so many implied problems rolled into one statement it's hard to even start. Possibly the most important implied problem is that you are equating the ability to do something with having the right Matlab feature. If you can't do it with paper and pencil and time, then you shouldn't do it with Matlab. The next implied problem that I see is that you are not giving enough information, and you don't seem to realize it. What sort of fixed point? Fractional? Qn.m, what? What is your data path width? What is your coefficient width? In general if you have a coefficient in floating point and you want to convert it to fixed point, you figure out what a fixed-point number means in your context. Thus, if you're putting the coefficients into a C program as signed integers but using them as fractionals, then you need to multiply your given coefficients by 2^(word_width-1). But if you're using some other scaling, or block floating point, or some such, you need to do something different. I really think you need to work to better understand both your problem and DSP in general; I suspect that if you don't you'll end up flailing around randomly without getting much done. -- Tim Wescott Wescott Design Services http://www.wescottdesign.com
Tim Wescott <seemywebsite@myfooter.really> writes:

> On Wed, 07 Oct 2015 06:18:03 -0500, brisker wrote: > >> hello, >> I am working on IIR filter to implement on DSP which is fixed point , >> but coefficients of filter I am getting is floating point from MATLAB >> say one of them is for example: 0.000000058323780584287955 Now how >> should I convert this to fixed point value? I dont have fixed point >> toolbar in MATLAB. > > Man, that has so many implied problems rolled into one statement it's > hard to even start. > > Possibly the most important implied problem is that you are equating the > ability to do something with having the right Matlab feature. If you > can't do it with paper and pencil and time, then you shouldn't do it with > Matlab. > > The next implied problem that I see is that you are not giving enough > information, and you don't seem to realize it. > > What sort of fixed point? Fractional? Qn.m, what? > > What is your data path width? > > What is your coefficient width? > > In general if you have a coefficient in floating point and you want to > convert it to fixed point, you figure out what a fixed-point number means > in your context. Thus, if you're putting the coefficients into a C > program as signed integers but using them as fractionals, then you need > to multiply your given coefficients by 2^(word_width-1). But if you're > using some other scaling, or block floating point, or some such, you need > to do something different. > > I really think you need to work to better understand both your problem > and DSP in general; I suspect that if you don't you'll end up flailing > around randomly without getting much done.
To the OP: I second what Tim has stated here. I read your inquiry and it was so vague I didn't know where to start. -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com
"brisker" <108316@DSPRelated> writes:

> hello, > I am working on IIR filter to implement on DSP which is fixed point , but > coefficients of filter I am getting is floating point from MATLAB say one > of them is for example: 0.000000058323780584287955 > Now how should I convert this to fixed point value? I dont have fixed > point toolbar in MATLAB. > > please help me with my queries. > Thank you in advance.
Hi, As Tim stated, you have omitted some important information regarding the problem. I'll make some comments that may help get you going, or at least help you ask the right questions: 1. For general fixed-point arithmetic, you can check out my (aging, but I still think relevent) paper on the topic: http://www.digitalsignallabs.com/fp.pdf 2. Usually IIRs of any length are split into second-order seconds (SOS). Are you doing that? 3. There are several architectures for implementing SOSs, e.g., direct form I and direct form II (re: [proakis]). If you are using a direct form I, then the first half is essentially an FIR. For that half you can use some of the pointers I give in my paper on fixed-point FIR filter implementations: http://www.digitalsignallabs.com/fir.pdf 4. Since an IIR filter has feedback, fixed-point IIRs require some sort of internal requantization. Some people just truncate; some round; some get fancy and noise-shape. Do you know how you intend to do this requantization? I hope this is food for thought. --Randy @BOOK{proakis, title = "{Digital Signal Processing: Principles, Algorithms, and Applications}", author = "John~G.~Proakis and Dimitris~G.~Manolakis", publisher = "Prentice Hall", edition = "third", year = "1996"} -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com
In article <87zizt5r66.fsf@digitalsignallabs.com>,
Randy Yates  <yates@digitalsignallabs.com> wrote:
> >1. For general fixed-point arithmetic, you can check out my (aging, >but I still think relevent) paper on the topic: > > http://www.digitalsignallabs.com/fp.pdf
Randy - I'm delurking here for just a quick comment - and thanks - regarding your paper above. "Aging" document - Bah! It's very relevent. I don't know how many people I've steered toward your document in the past. It's a great reference for those getting familiar ( or re-familiar ) with fixed point. Great for anyone - software types, hardware wonks, etc. I still to this day use your notation. Much better IMHO, than the Qn format. Thanks again - Mark. And to the OP - go read it!
gtwrek@sonic.net (Mark Curry) writes:

> In article <87zizt5r66.fsf@digitalsignallabs.com>, > Randy Yates <yates@digitalsignallabs.com> wrote: >> >>1. For general fixed-point arithmetic, you can check out my (aging, >>but I still think relevent) paper on the topic: >> >> http://www.digitalsignallabs.com/fp.pdf > > Randy - I'm delurking here for just a quick comment - and thanks - regarding > your paper above. "Aging" document - Bah! It's very relevent. I don't > know how many people I've steered toward your document in the past. It's > a great reference for those getting familiar ( or re-familiar ) with > fixed point. Great for anyone - software types, hardware wonks, etc. > > I still to this day use your notation. Much better IMHO, than the Qn format. > > Thanks again - Mark. > > And to the OP - go read it!
Hey, thanks for that, Mark! Good to know. -- Randy Yates Digital Signal Labs http://www.digitalsignallabs.com