## General Technical Discussion

Showing results for
Do you mean
Regular Visitor
Posts: 55
Registered: ‎08-01-2012

# Document on Fixed Point arithmetic

Hi ,

I have to do a DSP algorithm with two 16 2's compliment bit numbers A (Q1.15 format ) and B(12.4 format) . I need to have the result in Q1.15 format . Can anyone suggest me a good concrete document on this topic.

With regards

Vintu

Expert Contributor
Posts: 2,517
Registered: ‎08-14-2007

# Re: Document on Fixed Point arithmetic

Hi Vintu,

very basic and formally you can do it like this:

Expand both numbers to 12.15 fixed format with respect ot the signedness.

Forget about the decimal point and do integer math. (there is no difference)

Snip out the 1.15 Result , which will be the 16 LSBs of the 12.15 number.

Done.

There may be potential to optimize the wordwidth, but you can also leave this to the logic optimization tools.

You have to be carefull if you are using  algorithms like CORDIC which might change the decimal point position in the result.

Also in multiplications you have to care about taking the right bits from the result which will have 24.30 format.

Have a nice synthesis

Eilert

Expert Contributor
Posts: 2,188
Registered: ‎03-31-2012

# Re: Document on Fixed Point arithmetic

Consider the two types of operators you can use on Q numbers: addition/subtraction and multiplication (division is more complicated):
If you add two aligned Q numbers (ie the binary point is at the same location) you just add the regular bit patterns and adjust for growth like you would regular integers ie every N element addition gives you log2(N) extra bits. If numbers are not aligned (ala your example) you need to align them ie 1.15 + 12.4,11'b0 if that makes sense to you (or you need to add 11 zeros to the right of the number in 12.4 number to add it to 1.15 number).
Multiplication is somewhat easier. There is no need to align but the result grows by the sum of the inputs sizes ie:
1.15 x 12.4 = 13.19 ie you add whole sizes and fractional sizes separately. Of course then you have to round it back to your desired output or say you want the result in 1.15. You need to divide the result by 16 (to get rid of the 4 bits at the bottom) and truncate the number to 16 bits. Of course there is no guarantee that the result will fit into 16 bits.

This looks like a nice document: http://courses.cs.washington.edu/courses/cse467/08au/pdfs/lectures/11-FixedPointArithmetic.pdf
---------------------------------------------------------------------------------------------

Give Kudos to a post which you think is helpful and reply oriented.
---------------------------------------------------------------------------------------------
Expert Contributor
Posts: 497
Registered: ‎09-16-2009

# Re: Document on Fixed Point arithmetic

Thanks for the reference muzaffer.

I've recommended the below reference multiple times.  It's written by a DSP guy more angled towards software, but I find the representation he uses is very useful for HW.  His paper lists some fundamental rules of fixed-point arithmetic - showing bit growth under common operations, and signedness concerns.

http://www.digitalsignallabs.com/fp.pdf

Regards,

Mark

Expert Contributor
Posts: 2,188
Registered: ‎03-31-2012

# Re: Document on Fixed Point arithmetic

I like Randy's work a lot. He is active comp.dsp too.

---------------------------------------------------------------------------------------------