|

楼主 |
发表于 2021-1-18 17:13:24
|
显示全部楼层
你好,我根据你的建议将采样周期增加到4个左右,也就是20s左右进行一次FFT,这个时候的AD采样率变为了50hz,根据公式f=Fs/N*m,计算出来的频率幅度最大值大于25hz,能帮忙看下什么问题吗?
FFT的计算代码如下:
void FFTTask(void)
{
uint16_t i;
float f0;
fftSize = FFT_LENGTH;
float maxValue;
uint32_t maxIndex;
/*store the adc data as complex data*/
for(i=0;i<FFT_LENGTH;i++)
{
fft_input[2*i] = (float)ADC1ConvertedValue;
fft_input[2*i+1] = 0;
}
/* 1024 complex FFT caculation*/
arm_cfft_f32(&arm_cfft_sR_f32_len1024, fft_input, ifftFlag,doBitReverse); //run fft algrithm and store the data into fft_input
arm_cmplx_mag_f32(fft_input, testOutput, fftSize);//caculate the amplitude of the input data.
for(int i =0;i<1024;i++)
{
printf("%f\r\n",testOutput);
}
/* Calculates maxValue and retuns corresponding value */
arm_max_f32(testOutput, fftSize, &maxValue, &maxIndex);//calculate the max amplitude and corresponding index.
maxValue = maxValue*2/1024;
f0 = 50*maxIndex/1024;
printf("FFT(F32) maxValue %f, maxIndex %d,maxFreq %f\n\r",maxValue,maxIndex,f0);
/* print the fft data */
for(i=0; i<fftSize; i++)
{
//printf("%f\r\n", testOutput); //print the amplitude data
}
/*run the ifft caculate*/
ifftFlag = 1;
arm_cfft_f32(&arm_cfft_sR_f32_len1024,fft_input, ifftFlag,doBitReverse); //run ifft algrithm and store the data into fft_input array.
}
|
|