AFBR-S50 API Reference Manual v1.5.6
AFBR-S50 Time-of-Flight Sensor SDK for Embedded Software
|
A basic math library for fixed point number in the Qx.y fomat. More...
Macros | |
#define | UQ6_2_MAX ((uq6_2_t)UINT8_MAX) |
#define | UQ6_2_ONE ((uq6_2_t)(1U<<2U)) |
#define | UQ4_4_MAX ((uq4_4_t)UINT8_MAX) |
#define | UQ4_4_ONE ((uq4_4_t)(1U<<4U)) |
#define | UQ2_6_MAX ((uq2_6_t)UINT8_MAX) |
#define | UQ2_6_ONE ((uq2_6_t)(1U<<6U)) |
#define | UQ1_7_MAX ((uq1_7_t)UINT8_MAX) |
#define | UQ1_7_ONE ((uq1_7_t)(1U<<7U)) |
#define | UQ0_8_MAX ((uq0_8_t)UINT8_MAX) |
#define | Q3_4_MIN ((q3_4_t)INT8_MIN) |
#define | Q3_4_MAX ((q3_4_t)INT8_MAX) |
#define | UQ3_4_ONE ((q3_4_t)(1 << 4)) |
#define | Q1_6_MIN ((q1_6_t)INT8_MIN) |
#define | Q1_6_MAX ((q1_6_t)INT8_MAX) |
#define | UQ1_6_ONE ((q1_6_t)(1 << 4)) |
#define | UQ12_4_MAX ((uq12_4_t)UINT16_MAX) |
#define | UQ12_4_ONE ((uq12_4_t)(1U<<4U)) |
#define | UQ10_6_MAX ((uq10_6_t)UINT16_MAX) |
#define | UQ10_6_ONE ((uq10_6_t)(1U << 6U)) |
#define | UQ1_15_MAX ((uq1_15_t)UINT16_MAX) |
#define | UQ1_15_ONE ((uq1_15_t)(1U << 15U)) |
#define | UQ0_16_MAX ((uq0_16_t)UINT16_MAX) |
#define | Q11_4_MIN ((q11_4_t)INT16_MIN) |
#define | Q11_4_MAX ((q11_4_t)INT16_MAX) |
#define | Q11_4_ONE ((q11_4_t)(1 << 4)) |
#define | Q7_8_MIN ((q7_8_t)INT16_MIN) |
#define | Q7_8_MAX ((q7_8_t)INT16_MAX) |
#define | Q7_8_ONE ((q7_8_t)(1 << 8)) |
#define | Q3_12_MIN ((q3_12_t)INT16_MIN) |
#define | Q3_12_MAX ((q3_12_t)INT16_MAX) |
#define | Q3_12_ONE ((q3_12_t)(1 << 12)) |
#define | Q0_15_MIN ((q0_15_t)INT16_MIN) |
#define | Q0_15_MAX ((q0_15_t)INT16_MAX) |
#define | UQ28_4_MAX ((uq28_4_t)UINT32_MAX) |
#define | UQ28_4_ONE ((uq28_4_t)(1U<<4U)) |
#define | UQ16_16_MAX ((uq16_16_t)UINT32_MAX) |
#define | UQ16_16_ONE ((uq16_16_t)(1U << 16U)) |
#define | UQ16_16_E (0x2B7E1U) |
#define | UQ10_22_MAX ((uq10_22_t)UINT32_MAX) |
#define | UQ10_22_ONE ((uq10_22_t)(1U << 22U)) |
#define | Q27_4_MIN ((q27_4_t)INT32_MIN) |
#define | Q27_4_MAX ((q27_4_t)INT32_MAX) |
#define | UQ27_4_ONE ((q27_4_t)(1 << 4)) |
#define | Q16_15_MIN ((q16_15_t)INT32_MIN) |
#define | Q16_15_MAX ((q16_15_t)INT32_MAX) |
#define | Q15_16_MIN ((q15_16_t)INT32_MIN) |
#define | Q15_16_MAX ((q15_16_t)INT32_MAX) |
#define | Q15_16_ONE ((q15_16_t)(1 << 16)) |
#define | Q9_22_MIN ((q9_22_t)INT32_MIN) |
#define | Q9_22_MAX ((q9_22_t)INT32_MAX) |
#define | Q9_22_ONE ((q9_22_t)(1 << 22)) |
#define | USE_HW_DIV 0 |
#define | USE_64BIT_MUL 0 |
Typedefs | |
typedef uint8_t | uq6_2_t |
Unsigned fixed point number: UQ6.2. | |
typedef uint8_t | uq4_4_t |
Unsigned fixed point number: UQ4.4. | |
typedef uint8_t | uq2_6_t |
Unsigned fixed point number: UQ2.6. | |
typedef uint8_t | uq1_7_t |
Unsigned fixed point number: UQ1.7. | |
typedef uint8_t | uq0_8_t |
Unsigned fixed point number: UQ0.8. | |
typedef int8_t | q3_4_t |
Signed fixed point number: Q3.4. | |
typedef int8_t | q1_6_t |
Signed fixed point number: Q1.6. | |
typedef uint16_t | uq12_4_t |
Unsigned fixed point number: UQ12.4. | |
typedef uint16_t | uq10_6_t |
Unsigned fixed point number: UQ10.6. | |
typedef uint16_t | uq1_15_t |
Unsigned fixed point number: UQ1.15. | |
typedef uint16_t | uq0_16_t |
Unsigned fixed point number: UQ0.16. | |
typedef int16_t | q11_4_t |
Signed fixed point number: Q11.4. | |
typedef int16_t | q7_8_t |
Signed fixed point number: Q7.8. | |
typedef int16_t | q3_12_t |
Signed fixed point number: Q3.12. | |
typedef int16_t | q0_15_t |
Signed fixed point number: Q0.15. | |
typedef uint32_t | uq28_4_t |
Unsigned fixed point number: UQ28.4. | |
typedef uint32_t | uq16_16_t |
Unsigned fixed point number: UQ16.16. | |
typedef uint32_t | uq10_22_t |
Unsigned fixed point number: UQ10.22. | |
typedef int32_t | q27_4_t |
Signed fixed point number: Q27.4. | |
typedef int32_t | q16_15_t |
Signed fixed point number: Q16.15. | |
typedef int32_t | q15_16_t |
Signed fixed point number: Q15.16. | |
typedef int32_t | q9_22_t |
Signed fixed point number: Q9.22. | |
Functions | |
int32_t | fp_div16 (int32_t a, q15_16_t b) |
32-bit implementation of an Q15.16 division. | |
uq1_15_t | fp_ema15c (uq1_15_t mean, uq1_15_t x, uq0_8_t weight) |
Circular exponentially weighted moving average using UQ1.15 format. | |
q11_4_t | fp_ema4 (q11_4_t mean, q11_4_t x, uq0_8_t weight) |
Exponentially weighted moving average using the Q11.4 format. | |
q7_8_t | fp_ema8 (q7_8_t mean, q7_8_t x, uq0_8_t weight) |
Exponentially weighted moving average using the Q7.8 format. | |
uint32_t | uint_ema32 (uint32_t mean, uint32_t x, uq0_8_t weight) |
Exponentially weighted moving average using the Q15.16 format. | |
int32_t | int_ema32 (int32_t mean, int32_t x, uq0_8_t weight) |
Exponentially weighted moving average using the Q15.16 format. | |
q15_16_t | fp_ema16 (q15_16_t mean, q15_16_t x, uq0_8_t weight) |
Exponentially weighted moving average using the Q15.16 format. | |
uq16_16_t | fp_exp16 (q15_16_t x) |
Calculates the exponential of an fixed point number Q15.16 format. | |
q15_16_t | fp_log16 (uq16_16_t x) |
Calculates the natural logarithm (base e) of an fixed point number. | |
void | muldwu (uint32_t w[], uint32_t u, uint32_t v) |
Long multiplication of two unsigned 32-bit into an 64-bit value on 32-bit architecture. | |
uint32_t | fp_mulu (uint32_t u, uint32_t v, uint_fast8_t shift) |
64-bit implementation of an unsigned multiplication with fixed point format. | |
int32_t | fp_muls (int32_t u, int32_t v, uint_fast8_t shift) |
64-bit implementation of a signed multiplication with fixed point format. | |
uint32_t | fp_mul_u32_u16 (uint32_t u, uint16_t v, uint_fast8_t shift) |
48-bit implementation of a unsigned multiplication with fixed point format. | |
int32_t | fp_mul_s32_u16 (int32_t u, uint16_t v, uint_fast8_t shift) |
48-bit implementation of an unsigned/signed multiplication with fixed point format. | |
uint32_t | fp_rndu (uint32_t Q, uint_fast8_t n) |
Converting with rounding from UQx.n1 to UQx.n2. | |
int32_t | fp_rnds (int32_t Q, uint_fast8_t n) |
Converting with rounding from Qx.n1 to Qx.n2. | |
uint32_t | fp_truncu (uint32_t Q, uint_fast8_t n) |
Converting with truncation from UQx.n1 to UQx.n2. | |
int32_t | fp_truncs (int32_t Q, uint_fast8_t n) |
Converting with truncation from Qx.n1 to Qx.n2. | |
A basic math library for fixed point number in the Qx.y fomat.
This module contains common fixed point type definitions as well as some basic math algorithms. All types are based on integer types. The number are defined with the Q number format.
#define Q0_15_MAX ((q0_15_t)INT16_MAX) |
Maximum value of Q0.15 number format.
#define Q0_15_MIN ((q0_15_t)INT16_MIN) |
Minimum value of Q0.15 number format.
#define Q11_4_MAX ((q11_4_t)INT16_MAX) |
Maximum value of Q11.4 number format.
#define Q11_4_MIN ((q11_4_t)INT16_MIN) |
Minimum value of Q11.4 number format.
#define Q11_4_ONE ((q11_4_t)(1 << 4)) |
The 1/one/unity in Q11.4 number format.
#define Q15_16_MAX ((q15_16_t)INT32_MAX) |
Maximum value of Q15.16 number format.
#define Q15_16_MIN ((q15_16_t)INT32_MIN) |
Minimum value of Q15.16 number format.
#define Q15_16_ONE ((q15_16_t)(1 << 16)) |
The 1/one/unity in Q15.16 number format.
#define Q16_15_MAX ((q16_15_t)INT32_MAX) |
Maximum value of Q16.15 number format.
#define Q16_15_MIN ((q16_15_t)INT32_MIN) |
Minimum value of Q16.15 number format.
#define Q1_6_MAX ((q1_6_t)INT8_MAX) |
Maximum value of Q1.6 number format.
#define Q1_6_MIN ((q1_6_t)INT8_MIN) |
Minimum value of Q1_6 number format.
#define Q27_4_MAX ((q27_4_t)INT32_MAX) |
Maximum value of Q27.4 number format.
#define Q27_4_MIN ((q27_4_t)INT32_MIN) |
Minimum value of Q27.4 number format.
#define Q3_12_MAX ((q3_12_t)INT16_MAX) |
Maximum value of Q3.12 number format.
#define Q3_12_MIN ((q3_12_t)INT16_MIN) |
Minimum value of Q3.12 number format.
#define Q3_12_ONE ((q3_12_t)(1 << 12)) |
The 1/one/unity in Q3.12 number format.
#define Q3_4_MAX ((q3_4_t)INT8_MAX) |
Maximum value of Q3.4 number format.
#define Q3_4_MIN ((q3_4_t)INT8_MIN) |
Minimum value of Q3.4 number format.
#define Q7_8_MAX ((q7_8_t)INT16_MAX) |
Maximum value of Q7.8 number format.
#define Q7_8_MIN ((q7_8_t)INT16_MIN) |
Minimum value of Q7.8 number format.
#define Q7_8_ONE ((q7_8_t)(1 << 8)) |
The 1/one/unity in Q7.8 number format.
#define Q9_22_MAX ((q9_22_t)INT32_MAX) |
Maximum value of Q9.22 number format.
#define Q9_22_MIN ((q9_22_t)INT32_MIN) |
Minimum value of Q9.22 number format.
#define Q9_22_ONE ((q9_22_t)(1 << 22)) |
The 1/one/unity in Q9.22 number format.
#define UQ0_16_MAX ((uq0_16_t)UINT16_MAX) |
Maximum value of UQ0.16 number format.
#define UQ0_8_MAX ((uq0_8_t)UINT8_MAX) |
Maximum value of UQ0.8 number format.
#define UQ10_22_MAX ((uq10_22_t)UINT32_MAX) |
Maximum value of UQ10.22 number format.
#define UQ10_22_ONE ((uq10_22_t)(1U << 22U)) |
The 1/one/unity in UQ10.22 number format.
#define UQ10_6_MAX ((uq10_6_t)UINT16_MAX) |
Maximum value of UQ10.6 number format.
#define UQ10_6_ONE ((uq10_6_t)(1U << 6U)) |
The 1/one/unity in UQ10.6 number format.
#define UQ12_4_MAX ((uq12_4_t)UINT16_MAX) |
Maximum value of UQ12.4 number format.
#define UQ12_4_ONE ((uq12_4_t)(1U<<4U)) |
The 1/one/unity in UQ12.4 number format.
#define UQ16_16_E (0x2B7E1U) |
Euler's number, e, in UQ16.16 format.
#define UQ16_16_MAX ((uq16_16_t)UINT32_MAX) |
Maximum value of UQ16.16 number format.
#define UQ16_16_ONE ((uq16_16_t)(1U << 16U)) |
The 1/one/unity in UQ16.16 number format.
#define UQ1_15_MAX ((uq1_15_t)UINT16_MAX) |
Maximum value of UQ1.15 number format.
#define UQ1_15_ONE ((uq1_15_t)(1U << 15U)) |
The 1/one/unity in UQ1.15 number format.
#define UQ1_6_ONE ((q1_6_t)(1 << 4)) |
The 1/one/unity in UQ1.6 number format.
#define UQ1_7_MAX ((uq1_7_t)UINT8_MAX) |
Maximum value of UQ1.7 number format.
#define UQ1_7_ONE ((uq1_7_t)(1U<<7U)) |
The 1/one/unity in UQ1.7 number format.
#define UQ27_4_ONE ((q27_4_t)(1 << 4)) |
The 1/one/unity in UQ27.4 number format.
#define UQ28_4_MAX ((uq28_4_t)UINT32_MAX) |
Maximum value of UQ28.4 number format.
#define UQ28_4_ONE ((uq28_4_t)(1U<<4U)) |
The 1/one/unity in UQ28.4 number format.
#define UQ2_6_MAX ((uq2_6_t)UINT8_MAX) |
Maximum value of UQ2.6 number format.
#define UQ2_6_ONE ((uq2_6_t)(1U<<6U)) |
The 1/one/unity in UQ2.6 number format.
#define UQ3_4_ONE ((q3_4_t)(1 << 4)) |
The 1/one/unity in UQ3.4 number format.
#define UQ4_4_MAX ((uq4_4_t)UINT8_MAX) |
Maximum value of UQ4.4 number format.
#define UQ4_4_ONE ((uq4_4_t)(1U<<4U)) |
The 1/one/unity in UQ4.4 number format.
#define UQ6_2_MAX ((uq6_2_t)UINT8_MAX) |
Maximum value of UQ6.2 number format.
#define UQ6_2_ONE ((uq6_2_t)(1U<<2U)) |
The 1/one/unity in UQ6.2 number format.
#define USE_64BIT_MUL 0 |
Set to use hardware division (Cortex-M3/4) over software division (Cortex-M0/1).
#define USE_HW_DIV 0 |
Set to use hardware division (Cortex-M3/4) over software division (Cortex-M0/1).
typedef int16_t q0_15_t |
Signed fixed point number: Q0.15.
A signed fixed point number format based on the 16-bit integer type with 0 integer and 15 fractional bits.
typedef int16_t q11_4_t |
Signed fixed point number: Q11.4.
A signed fixed point number format based on the 16-bit signed integer type with 11 integer and 4 fractional bits.
typedef int32_t q15_16_t |
Signed fixed point number: Q15.16.
A signed fixed point number format based on the 32-bit integer type with 15 integer and 16 fractional bits.
typedef int32_t q16_15_t |
Signed fixed point number: Q16.15.
A signed fixed point number format based on the 32-bit integer type with 16 integer and 15 fractional bits.
typedef int8_t q1_6_t |
Signed fixed point number: Q1.6.
A signed fixed point number format based on the 8-bit signed integer type with 1 integer and 6 fractional bits.
typedef int32_t q27_4_t |
Signed fixed point number: Q27.4.
A signed fixed point number format based on the 32-bit signed integer type with 27 integer and 4 fractional bits.
typedef int16_t q3_12_t |
Signed fixed point number: Q3.12.
A signed fixed point number format based on the 16-bit integer type with 3 integer and 12 fractional bits.
typedef int8_t q3_4_t |
Signed fixed point number: Q3.4.
A signed fixed point number format based on the 8-bit signed integer type with 3 integer and 4 fractional bits.
typedef int16_t q7_8_t |
Signed fixed point number: Q7.8.
A signed fixed point number format based on the 16-bit signed integer type with 7 integer and 8 fractional bits.
typedef int32_t q9_22_t |
Signed fixed point number: Q9.22.
A signed fixed point number format based on the 32-bit integer type with 9 integer and 22 fractional bits.
typedef uint16_t uq0_16_t |
Unsigned fixed point number: UQ0.16.
An unsigned fixed point number format based on the 16-bit unsigned integer type with 0 integer and 16 fractional bits.
typedef uint8_t uq0_8_t |
Unsigned fixed point number: UQ0.8.
An unsigned fixed point number format based on the 8-bit unsigned integer type with 1 integer and 7 fractional bits.
typedef uint32_t uq10_22_t |
Unsigned fixed point number: UQ10.22.
An unsigned fixed point number format based on the 32-bit unsigned integer type with 10 integer and 22 fractional bits.
typedef uint16_t uq10_6_t |
Unsigned fixed point number: UQ10.6.
An unsigned fixed point number format based on the 16-bit unsigned integer type with 10 integer and 6 fractional bits.
typedef uint16_t uq12_4_t |
Unsigned fixed point number: UQ12.4.
An unsigned fixed point number format based on the 16-bit unsigned integer type with 12 integer and 4 fractional bits.
typedef uint32_t uq16_16_t |
Unsigned fixed point number: UQ16.16.
An unsigned fixed point number format based on the 32-bit unsigned integer type with 16 integer and 16 fractional bits.
typedef uint16_t uq1_15_t |
Unsigned fixed point number: UQ1.15.
An unsigned fixed point number format based on the 16-bit unsigned integer type with 1 integer and 15 fractional bits.
typedef uint8_t uq1_7_t |
Unsigned fixed point number: UQ1.7.
An unsigned fixed point number format based on the 8-bit unsigned integer type with 1 integer and 7 fractional bits.
typedef uint32_t uq28_4_t |
Unsigned fixed point number: UQ28.4.
An unsigned fixed point number format based on the 32-bit unsigned integer type with 28 integer and 4 fractional bits.
typedef uint8_t uq2_6_t |
Unsigned fixed point number: UQ2.6.
An unsigned fixed point number format based on the 8-bit unsigned integer type with 2 integer and 6 fractional bits.
typedef uint8_t uq4_4_t |
Unsigned fixed point number: UQ4.4.
An unsigned fixed point number format based on the 8-bit unsigned integer type with 4 integer and 4 fractional bits.
typedef uint8_t uq6_2_t |
Unsigned fixed point number: UQ6.2.
An unsigned fixed point number format based on the 8-bit unsigned integer type with 6 integer and 2 fractional bits.
|
inline |
32-bit implementation of an Q15.16 division.
Algorithm to evaluate a/b, where b is in Q15.16 format, on a 32-bit architecture with maximum precision. The result is correctly rounded and given as the input format. Division by 0 yields max. values determined by signs of numerator. Too high/low results are truncated to max/min values.
Depending on the architecture, the division is implemented with a 64-bit division and shifting (Cortex-M3/4) or as a fast software algorithm (Cortex-M0/1) wich runs fast on processors without hardware division.
a | Numerator in any Qx.y format |
b | Denominator in Q15.16 format |
Circular exponentially weighted moving average using UQ1.15 format.
Evaluates the moving average (exponentially weighted) for circular data in UQ1.15 format. Circular data is that MAX_VALUE + 1 == MIN_VALUE. For example the usual phase information.
Problem: Due to circularity of phase values, i.e. 0+x and 2PI+x are the same, the usual EMA has issues with the wrap around effect. Especially for vectors with phase around 0 (or 2PI), two values like 0 + x and PI - y are averaged to something around PI instead of 0 which would be more correct.
Solution: Assume that phase jumps of more than PI are not allowed or possible. If a deviation of the new value to the smoothed signal occurs, it is clear that this stems from the wrap around effect and can be caught and correctly handled by the smoothing algorithm.
Caution: If a target comes immediately into the field of view, phase jumps of > PI are indeed possible and volitional. However, the averaging break there anyway since the smoothed signal approaches only with delay to the correct values. The error made here is, that the smoothed signal approaches from the opposite direction. However, is approaches even faster since it always takes the shortest direction.
mean | The previous mean value in UQ1.15 format. |
x | The current value to be added to the average UQ1.15 format. |
weight | The EMA weight in UQ0.7 format. |
Exponentially weighted moving average using the Q15.16 format.
Evaluates the moving average (exponentially weighted) for data in Q15.16 format.
mean | The previous mean value in Q15.16 format. |
x | The current value to be added to the average Q15.16 format. |
weight | The EMA weight in UQ0.7 format. |
Exponentially weighted moving average using the Q11.4 format.
Evaluates the moving average (exponentially weighted) for data in Q11.4 format.
mean | The previous mean value in Q11.4 format. |
x | The current value to be added to the average Q11.4 format. |
weight | The EMA weight in UQ0.7 format. |
Exponentially weighted moving average using the Q7.8 format.
Evaluates the moving average (exponentially weighted) for data in Q7.8 format.
mean | The previous mean value in Q7.8 format. |
x | The current value to be added to the average Q7.8 format. |
weight | The EMA weight in UQ0.7 format. |
Calculates the exponential of an fixed point number Q15.16 format.
Calculates y = exp(x) in fixed point representation.
Note that the result might not be 100 % accurate and might contain a small error! @see https://www.quinapalus.com/efunc.html
x | The input parameter in unsigned fixed point format Q15.16. |
Calculates the natural logarithm (base e) of an fixed point number.
Calculates y = ln(x) = log_e(x) in fixed point representation.
Note that the result might not be 100 % accurate and might contain a small error! @see https://www.quinapalus.com/efunc.html
x | The input parameter in unsigned fixed point format Q15.16. |
|
inline |
48-bit implementation of an unsigned/signed multiplication with fixed point format.
Algorithm to evaluate a*b, where a and b are arbitrary fixed point numbers with 32-bit signed and 16-bit unsigned format respectively. The multiplication is done in two 16x16-bit operations and the result is shifted down by the passed shift parameter in order to return a 32-bit value. The shift is executed with correct rounding.
Note that the result must fit into the 32-bit value. An assertion error occurs otherwise (or undefined behavior of no assert available).
u | The left parameter in Qx1.y1 format |
v | The right parameter in Qx2.y2 format |
shift | The final right shift (rounding) value. |
|
inline |
48-bit implementation of a unsigned multiplication with fixed point format.
Algorithm to evaluate a*b, where a and b are arbitrary fixed point numbers with 32-bit unsigned and 16-bit unsigned format respectively. The multiplication is done in two 16x16-bit operations and the result is shifted down by the passed shift parameter in order to return a 32-bit value.
Note that the result must fit into the 32-bit value. An assertion error occurs otherwise (or undefined behavior of no assert available).
u | The left parameter in Qx1.y1 format |
v | The right parameter in Qx2.y2 format |
shift | The final right shift (rounding) value. |
|
inline |
64-bit implementation of a signed multiplication with fixed point format.
Algorithm to evaluate a*b, where a and b are arbitrary fixed point number of 32-bit width. The multiplication is done in 64-bit and the result is shifted down by the passed shift parameter in order to return a 32-bit value. The shift is executed with correct rounding.
Note that the result must fit into the 32-bit value. An assertion error occurs otherwise (or undefined behavior of no assert available).
u | The left parameter in Qx1.y1 format |
v | The right parameter in Qx2.y2 format |
shift | The final right shift (rounding) value. |
|
inline |
64-bit implementation of an unsigned multiplication with fixed point format.
Algorithm to evaluate a*b, where a and b are arbitrary fixed point number of 32-bit width. The multiplication is done in 64-bit and the result is shifted down by the passed shift parameter in order to return a 32-bit value. The shift is executed with correct rounding.
Note that the result must fit into the 32-bit value. An assertion error occurs otherwise (or undefined behavior of no assert available).
u | The left parameter in UQx1.y1 format |
v | The right parameter in UQx2.y2 format |
shift | The final right shift (rounding) value. |
|
inline |
Converting with rounding from Qx.n1 to Qx.n2.
Equivalent to dividing by 2^n with correct rounding to integer values.
Q | The number in (U)Qx.n1 fixed point format to be rounded. |
n | The number of bits to be rounded, e.g. Q7.8 -> Q11.4 => n = 8 - 4 = 4. |
|
inline |
Converting with rounding from UQx.n1 to UQx.n2.
Equivalent to dividing by 2^n with correct rounding to unsigned integer values.
Q | The number in (U)Qx.n1 fixed point format to be rounded. |
n | The number of bits to be rounded, e.g. UQ8.8 -> UQ12.4 => n = 8 - 4 = 4. |
|
inline |
Converting with truncation from Qx.n1 to Qx.n2.
Equivalent to dividing by 2^n with truncating (throw away) the fractional part, resulting in a signed integer/fixed-point value.
Q | The number in (U)Qx.n1 fixed point format to be truncated. |
n | The number of bits to be truncated, e.g. Q7.8 -> Q11.4 => n = 8 - 4 = 4. |
|
inline |
Converting with truncation from UQx.n1 to UQx.n2.
Equivalent to dividing by 2^n with truncating (throw away) the fractional part, resulting in an unsigned integer/fixed-point value.
Q | The number in (U)Qx.n1 fixed point format to be truncated. |
n | The number of bits to be truncated, e.g. UQ8.8 -> UQ12.4 => n = 8 - 4 = 4. |
|
inline |
Exponentially weighted moving average using the Q15.16 format.
Evaluates the moving average (exponentially weighted) for data in Q15.16 format.
mean | The previous mean value in Q15.16 format. |
x | The current value to be added to the average Q15.16 format. |
weight | The EMA weight in UQ0.7 format. |
|
inline |
Long multiplication of two unsigned 32-bit into an 64-bit value on 32-bit architecture.
w (two words) gets the product of u and v (one word each). w[0] is the most significant word of the result, w[1] the least. (The words are in big-endian order). It is Knuth's Algorithm M from [Knu2] section 4.3.1.
w | The result (u * v) value given as two unsigned 32-bit numbers: w[0] is the most significant word of the result, w[1] the least. (The words are in big-endian order). |
u | Left hand side of the multiplication. |
v | Right hand side of the multiplication. |
|
inline |
Exponentially weighted moving average using the Q15.16 format.
Evaluates the moving average (exponentially weighted) for data in Q15.16 format.
mean | The previous mean value in Q15.16 format. |
x | The current value to be added to the average Q15.16 format. |
weight | The EMA weight in UQ0.7 format. |