| #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 ATANHALF_Q29 0xed63383 |
| #define PIHALF_Q29 0x3243f6a9 |
| #define PIQ29 0x6487ed51 |
|
|
| #define ATAN2_NB_COEFS_Q31 13 |
|
|
| static const q31_t atan2_coefs_q31[ATAN2_NB_COEFS_Q31]={0x00000000 |
| ,0x7ffffffe |
| ,0x000001b6 |
| ,0xd555158e |
| ,0x00036463 |
| ,0x1985f617 |
| ,0x001992ae |
| ,0xeed53a7f |
| ,0xf8f15245 |
| ,0x2215a3a4 |
| ,0xe0fab004 |
| ,0x0cdd4825 |
| ,0xfddbc054 |
| }; |
|
|
|
|
| __STATIC_FORCEINLINE q31_t arm_atan_limited_q31(q31_t x) |
| { |
| q63_t res=(q63_t)atan2_coefs_q31[ATAN2_NB_COEFS_Q31-1]; |
| int i=1; |
| for(i=1;i<ATAN2_NB_COEFS_Q31;i++) |
| { |
| res = ((q63_t) x * res) >> 31U; |
| res = res + ((q63_t) atan2_coefs_q31[ATAN2_NB_COEFS_Q31-1-i]) ; |
| } |
|
|
| return(clip_q63_to_q31(res>>2)); |
| } |
|
|
|
|
| __STATIC_FORCEINLINE q31_t arm_atan_q31(q31_t y,q31_t x) |
| { |
| int sign=0; |
| q31_t res=0; |
|
|
| if (y<0) |
| { |
| |
| #if defined (ARM_MATH_DSP) |
| y = __QSUB(0, y); |
| #else |
| y = (y == INT32_MIN) ? INT32_MAX : -y; |
| #endif |
|
|
| sign=1-sign; |
| } |
|
|
| if (x < 0) |
| { |
| sign=1 - sign; |
|
|
| |
| #if defined (ARM_MATH_DSP) |
| x = __QSUB(0, x); |
| #else |
| x = (x == INT32_MIN) ? INT32_MAX : -x; |
| #endif |
| } |
|
|
| if (y > x) |
| { |
| q31_t ratio; |
| int16_t shift; |
|
|
| arm_divide_q31(x,y,&ratio,&shift); |
|
|
| |
| if (shift >= 0) |
| { |
| ratio = clip_q63_to_q31((q63_t) ratio << shift); |
| } |
| else |
| { |
| ratio = (ratio >> -shift); |
| } |
| |
| res = PIHALF_Q29 - arm_atan_limited_q31(ratio); |
| |
| } |
| else |
| { |
| q31_t ratio; |
| int16_t shift; |
|
|
| arm_divide_q31(y,x,&ratio,&shift); |
|
|
| |
| if (shift >= 0) |
| { |
| ratio = clip_q63_to_q31((q63_t) ratio << shift); |
| } |
| else |
| { |
| ratio = (ratio >> -shift); |
| } |
| |
|
|
| res = arm_atan_limited_q31(ratio); |
|
|
| } |
|
|
|
|
| if (sign) |
| { |
| |
| #if defined (ARM_MATH_DSP) |
| res = __QSUB(0, res); |
| #else |
| res = (res == INT32_MIN) ? INT32_MAX : -res; |
| #endif |
| } |
|
|
| return(res); |
| } |
|
|
|
|
| |
| |
| |
|
|
|
|
| |
| |
| |
| |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
|
|
| arm_status arm_atan2_q31(q31_t y,q31_t x,q31_t *result) |
| { |
| if (x > 0) |
| { |
| *result=arm_atan_q31(y,x); |
| return(ARM_MATH_SUCCESS); |
| } |
| if (x < 0) |
| { |
| if (y > 0) |
| { |
| *result=arm_atan_q31(y,x) + PIQ29; |
| } |
| else if (y < 0) |
| { |
| *result=arm_atan_q31(y,x) - PIQ29; |
| } |
| else |
| { |
| if (y<0) |
| { |
| *result= -PIQ29; |
| } |
| else |
| { |
| *result= PIQ29; |
| } |
| } |
| return(ARM_MATH_SUCCESS); |
| } |
| if (x == 0) |
| { |
| if (y > 0) |
| { |
| *result=PIHALF_Q29; |
| return(ARM_MATH_SUCCESS); |
| } |
| if (y < 0) |
| { |
| *result=-PIHALF_Q29; |
| return(ARM_MATH_SUCCESS); |
| } |
| } |
| |
|
|
| return(ARM_MATH_NANINF); |
|
|
| } |
|
|
| |
| |
| |
|
|
| #endif |
|
|