MSP DSP Library
|
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.
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 |
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.
For more details on available macro functions see the support api documentation section.