前言
使用170M主频M4f核芯片(STM32G431),启用浮点加速,启用arm_dsp库。
对比条件:
方式 | 输入 | 输出 |
---|---|---|
cordic | q15 | q15 |
arm_dsp_q15 | q15 | q15 |
arm_dsp_q31 | q31 | q31 |
arm_dsp_f32 | float | float |
math | float | float |
math | double | double |
taylor6 | float | float |
测试代码
硬件cordic
/**
* @brief Trigonometrical functions type definition
*/
typedef struct
{
int16_t hCos;
int16_t hSin;
} Trig_Components;
/* CORDIC FUNCTION: COSINE q1.15 */
#define CORDIC_CONFIG_COSINE (LL_CORDIC_FUNCTION_COSINE | LL_CORDIC_PRECISION_6CYCLES | LL_CORDIC_SCALE_0 |\
LL_CORDIC_NBWRITE_1 | LL_CORDIC_NBREAD_1 |\
LL_CORDIC_INSIZE_16BITS | LL_CORDIC_OUTSIZE_16BITS)
__weak Trig_Components MCM_Trig_Functions(int16_t hAngle)
{
union u32toi16x2 {
uint32_t CordicRdata;
Trig_Components Components;
} CosSin;
WRITE_REG(CORDIC->CSR, CORDIC_CONFIG_COSINE);
LL_CORDIC_WriteData(CORDIC, ((uint32_t)0x7FFF0000) + ((uint32_t)hAngle));
CosSin.CordicRdata = LL_CORDIC_ReadData(CORDIC);
return (CosSin.Components);
}
泰勒展开函数
float factorial(int n) {
if (n == 0) {
return 1.0f;
} else {
return n * factorial(n - 1);
}
}
float taylor_sin(float x, int n) {
float result = 0.0f;
float sign = 1.0f;
for (int i = 0; i < n; i++) {
result += (sign * powf(x, 2 * i +