Last active
September 19, 2022 05:59
-
-
Save nickfox-taterli/f0bce613b799200a5eaee0db500c0a40 to your computer and use it in GitHub Desktop.
FFT arm_math
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
float32_t pSrc[2048]; | |
float32_t pDstFreq[1024]; | |
float32_t pDstPhase[1024]; | |
void MainCode(void *pvParameters) | |
{ | |
uint16_t i; | |
for(i = 0;i < 1024;i++){ | |
// 直流分量 1 + 50Hz且初始相位60度. | |
pSrc[i*2] = 1 + arm_cos_f32((2 * 3.1415926f * 50 * i) / 1024 + (3.1415926f * 60/180)); | |
pSrc[i*2 + 1] = 0; | |
} | |
arm_cfft_f32(&arm_cfft_sR_f32_len1024,pSrc,0,1); | |
arm_cmplx_mag_f32(pSrc,pDstFreq,1024); | |
// 求对应的相位 | |
for(i = 0;i < 1024;i++){ | |
if(0.5 > pDstFreq[i]){ | |
pDstPhase[i] = 0; | |
}else{ | |
arm_atan2_f32(pSrc[i*2+1],pSrc[i*2],&pDstPhase[i]); | |
pDstPhase[i] = pDstPhase[i]*180/3.1415926f; | |
} | |
} | |
for (;;) | |
{ | |
} | |
} | |
// 如果是实数FFT,计算量减半. | |
float32_t pSrc[1024]; | |
float32_t pDst[1024]; | |
float32_t pDstFreq[1024]; | |
float32_t pDstPhase[1024]; | |
void MainCode(void *pvParameters) | |
{ | |
uint16_t i; | |
for(i = 0;i < 1024;i++){ | |
// 直流分量 1 + 50Hz且初始相位60度. | |
pSrc[i] = 1 + arm_cos_f32((2 * 3.1415926f * 50 * i) / 1024 + (3.1415926f * 60/180)); | |
} | |
// 实数FFT输出一半的频谱,但是只需要输入实数部分 | |
arm_rfft_fast_instance_f32 S; | |
arm_rfft_fast_init_f32(&S,1024); | |
arm_rfft_fast_f32(&S,pSrc,pDst,0); | |
arm_cmplx_mag_f32(pDst,pDstFreq,1024); | |
// 求对应的相位 | |
for(i = 0;i < 1024;i++){ | |
if(0.5 > pDstFreq[i]){ | |
pDstPhase[i] = 0; | |
} else{ | |
arm_atan2_f32(pDst[i*2+1],pDst[i*2],&pDstPhase[i]); | |
pDstPhase[i] = pDstPhase[i]*180/3.1415926f; | |
} | |
} | |
for (;;) | |
{ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment