| #include "edge-impulse-sdk/dsp/config.hpp" |
| #if EIDSP_LOAD_CMSIS_DSP_SOURCES |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #include "edge-impulse-sdk/CMSIS/DSP/Include/dsp/fast_math_functions.h" |
| #include "edge-impulse-sdk/CMSIS/DSP/Include/dsp/utils.h" |
|
|
| |
| |
| |
| |
| |
|
|
|
|
| |
| #define ATANHALFQ13 0xed6 |
| #define PIHALFQ13 0x3244 |
| #define PIQ13 0x6488 |
|
|
| #define ATAN2_NB_COEFS_Q15 10 |
|
|
| static const q15_t atan2_coefs_q15[ATAN2_NB_COEFS_Q15]={0x0000 |
| ,0x7fff |
| ,0xffff |
| ,0xd567 |
| ,0xff70 |
| ,0x1bad |
| ,0xfd58 |
| ,0xe9a9 |
| ,0x1129 |
| ,0xfbdb |
| }; |
|
|
| __STATIC_FORCEINLINE q15_t arm_atan_limited_q15(q15_t x) |
| { |
| q31_t res=(q31_t)atan2_coefs_q15[ATAN2_NB_COEFS_Q15-1]; |
| int i=1; |
| for(i=1;i<ATAN2_NB_COEFS_Q15;i++) |
| { |
| res = ((q31_t) x * res) >> 15U; |
| res = res + ((q31_t) atan2_coefs_q15[ATAN2_NB_COEFS_Q15-1-i]) ; |
| } |
|
|
| res = __SSAT(res>>2,16); |
|
|
| |
| return(res); |
| } |
|
|
|
|
| __STATIC_FORCEINLINE q15_t arm_atan_q15(q15_t y,q15_t x) |
| { |
| int sign=0; |
| q15_t res=0; |
|
|
| if (y<0) |
| { |
| |
| #if defined (ARM_MATH_DSP) |
| y = __QSUB16(0, y); |
| #else |
| y = (y == (q15_t) 0x8000) ? (q15_t) 0x7fff : -y; |
| #endif |
|
|
| sign=1-sign; |
| } |
|
|
| if (x < 0) |
| { |
| sign=1 - sign; |
| |
| |
| #if defined (ARM_MATH_DSP) |
| x = __QSUB16(0, x); |
| #else |
| x = (x == (q15_t) 0x8000) ? (q15_t) 0x7fff : -x; |
| #endif |
| } |
|
|
| if (y > x) |
| { |
| q15_t ratio; |
| int16_t shift; |
|
|
| arm_divide_q15(x,y,&ratio,&shift); |
|
|
| |
| if (shift >=0) |
| { |
| ratio = __SSAT(((q31_t) ratio << shift), 16); |
| } |
| else |
| { |
| ratio = (ratio >> -shift); |
| } |
| |
| res = PIHALFQ13 - arm_atan_limited_q15(ratio); |
| |
| } |
| else |
| { |
| q15_t ratio; |
| int16_t shift; |
|
|
| arm_divide_q15(y,x,&ratio,&shift); |
|
|
| |
| if (shift >=0) |
| { |
| ratio = __SSAT(((q31_t) ratio << shift), 16); |
| } |
| else |
| { |
| ratio = (ratio >> -shift); |
| } |
| |
|
|
| res = arm_atan_limited_q15(ratio); |
|
|
| } |
|
|
|
|
| if (sign) |
| { |
| |
| #if defined (ARM_MATH_DSP) |
| res = __QSUB16(0, res); |
| #else |
| res = (res == (q15_t) 0x8000) ? (q15_t) 0x7fff : -res; |
| #endif |
| } |
|
|
| return(res); |
| } |
|
|
|
|
| |
| |
| |
|
|
|
|
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| arm_status arm_atan2_q15(q15_t y,q15_t x,q15_t *result) |
| { |
| if (x > 0) |
| { |
| *result=arm_atan_q15(y,x); |
| return(ARM_MATH_SUCCESS); |
| } |
| if (x < 0) |
| { |
| if (y > 0) |
| { |
| *result=arm_atan_q15(y,x) + PIQ13; |
| } |
| else if (y < 0) |
| { |
| *result=arm_atan_q15(y,x) - PIQ13; |
| } |
| else |
| { |
| if (y<0) |
| { |
| *result= -PIQ13; |
| } |
| else |
| { |
| *result= PIQ13; |
| } |
| } |
| return(ARM_MATH_SUCCESS); |
| } |
| if (x == 0) |
| { |
| if (y > 0) |
| { |
| *result=PIHALFQ13; |
| return(ARM_MATH_SUCCESS); |
| } |
| if (y < 0) |
| { |
| *result=-PIHALFQ13; |
| return(ARM_MATH_SUCCESS); |
| } |
| } |
| |
|
|
| return(ARM_MATH_NANINF); |
|
|
| } |
|
|
| |
| |
| |
|
|
| #endif |
|
|