DSPRelated.com
Forums

Avoiding Overflow

Started by aditya_naidu1 April 25, 2005


Hi all,

How to avoid the problem of overflow when doing the floating point to
fixed point conversion?

For eg. suppose a=b*c..if the product is out the range of 16bit
representation then there is a problem.Should a and b be scaled before
they are multiplied or 'a' be scaled after multiplication.

Can two numbers in different representation format(say Q1.4 and Q2.13)
be added/multiplied?

Any general rule as to how to avoid overflow?

Also when I compare the fixed point variable values with the
corresponding floating point values while debugging the sign is not
consustent i.e some fixed point are negative while their corresposing
floating point values are posistive.How to correct this problem?

Aditya




aditya_naidu1 wrote:

>
>
> Hi all,
>
> How to avoid the problem of overflow when doing the floating point to
> fixed point conversion?

Very careful use of scaling and choosing the correct fixed point format. > For eg. suppose a=b*c..if the product is out the range of 16bit
> representation then there is a problem.Should a and b be scaled before
> they are multiplied or 'a' be scaled after multiplication.

That depends on your algorithm. You must use different techniques for different
algorithms. For example, if you are calculating the gain, or power, of a speech
frame you can down-scale the input samples, calculate the gain, then up-scale
the gain value.

> Can two numbers in different representation format(say Q1.4 and Q2.13)
> be added/multiplied?

They cannot be added, but they can be multiplied as long as you rescale the product.

> Any general rule as to how to avoid overflow?

Generally, use as large a fixed point word as you can; 32 bit words in a 16.16
format require little scaling and is a good starting point, but I have also used
18.14 and 12.20 depending on the codec.

> Also when I compare the fixed point variable values with the
> corresponding floating point values while debugging the sign is not
> consustent i.e some fixed point are negative while their corresposing
> floating point values are posistive.How to correct this problem?

You must have a bug in your code, or you are misinterpreting your debugger values.

> Aditya

--
Phil Frisbie, Jr.
Hawk Software
http://www.hawksoft.com