07.03.2014 Views

IQmath Library

IQmath Library

IQmath Library

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

IQNtoIQ<br />

IQN number to GLOBAL_Q<br />

Description<br />

This Macro converts an IQ number in IQN format to the GLOBAL_Q<br />

format.<br />

Declaration _iq _IQNtoIQ( _iqN A)<br />

Input<br />

Output<br />

Usage<br />

IQ number in IQN format<br />

Equivalent value of input in GLOBAL_Q format<br />

This macro may be used in cases where the result of the calculation<br />

performed in different IQ resolution to be converted to GLOBAL_Q<br />

format.<br />

Example:<br />

Following example calculates the magnitude of complex number (X+jY)<br />

in Q26 format:<br />

Z = sqrt(X^2 + Y^2)<br />

The values Z, X, Y are given as GLOBAL_Q = 26, but the equation itself<br />

may generate an overflow.<br />

To guard against this, the intermediate calculations will be performed<br />

using Q = 23 and the value converted back at the end as shown below:<br />

_iq Z, Y, X; // GLOBAL_Q = 26<br />

_iq23 temp;<br />

temp = _IQ23sqrt( _IQ23mpy(_IQtoIQ23(X), _IQtoIQ23(X)) +<br />

_IQ23mpy(_IQtoIQ23(Y), _IQtoIQ23(Y)) );<br />

Y = _IQ23toIQ(temp);<br />

©Texas Instruments Inc., June 2002 20

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!