Logo
MSP DSP Library
Fixed-Point Data Types

DSP library for MSP devices uses the same fixed-point types as the IQmathLibry, Q15 and IQ31. The fixed-point Q15 type is defined as _q15 and stored as a 16-bit signed integer. Similarly, the IQ31 type is defined as _iq31 and stored as a 32-bit signed integer. The following equations show the fractional fixed-point representation and can be used to convert between the integer value stored in memory and the corresponding Q15 or IQ31 value.

fixed_q15.svg
fixed_iq31.svg

The Q15 and IQ31 formats can both be used to represent fractional decimal numbers, the difference is the resolution of the data. The tables below show the properties of both formats as well as several standard data types.

Type Integer bits Fractional bits Minimum Maximum Resolution
int16_t 16 0 -32768 32767 1
int32_t 32 0 -2147483648 2147483648 1
_q15 1 15 -1.0 0.9999695 0.00003051758
_iq31 1 31 -1.0 0.9999999995 0.00000000046

Macros

To help work with fixed-point number the DSP library defines C macros to quickly convert from decimal to fixed point. The example below shows how constants can be defined using the _Q15 and _IQ31 macros and used to initialize a complex data sample.

// Constant definition
#define MY_CONST 0.0125
#define MY_CONST_Q15 _Q15(MY_CONST)
#define MY_CONST_IQ31 _IQ31(MY_CONST)
// Sample function
void myFunction(_iq31 *cmplxData)
{
cmplxData[0] = _IQ31(0.0);
cmplxData[1] = MY_CONST_IQ31;
return;
}

For more details on available macro functions see the support api documentation section.