我正在对 STM32F407 进行一些 FFT 计算,我想比较 CMSIS DSP 库中可用的不同 FFT 函数。当我使用 f32 CFFT 函数时,它按预期工作,但是当我尝试使用 q31/q15 函数时,我收到一条错误消息,提示“arm_cfft_sR_q31_len4096”或 arm_cfft_sR_q15_len4096 在我调用它们各自的 cfft 函数时未声明。我已经将 arm_const_structs.h 包含在应该定义的地方,但显然不是?对于 f32 版本的函数,它与 arm_cfft_sR_f32_len4096 一起使用,那么可能是什么问题?
这是我的 fft 计算的 f32 版本的外观:
#include "arm_const_structs.h"
float32_t fft_data[FFT_SIZE * 2];
uint16_t util_calculate_fft_value(uint16_t *buffer, uint32_t len, uint32_t fft_freq, uint32_t fft_freq2)
{
uint16_t i;
float32_t maxValue; // Max FFT value is stored here
uint32_t maxIndex; // Index in Output array where max value is
tmStartMeasurement(&time); // Record clock cycles
// Ensure in buffer is not longer than FFT buffer
if (len > FFT_SIZE)
len = FFT_SIZE;
// Convert buffer uint16 to fft input float32
for (i = 0; i < len ; i++)
{
fft_data[i*2] = (float32_t)buffer[i] / 2048.0 - 1.0; // Real part
fft_data[i*2 + 1] = 0; // Imaginary part
}
// Process the data through the CFFT module intFlag = 0, doBitReverse = 1
arm_cfft_f32(&arm_cfft_sR_f32_len4096, fft_data, 0, 1);
// Process the data through the Complex Magniture Module for calculating the magnitude at each bin
arm_cmplx_mag_f32(fft_data, fft_data, FFT_SIZE / 2);
// Find maxValue as max in fft_data
arm_max_f32(fft_data, FFT_SIZE, &maxValue, &maxIndex);
if (fft_freq == 0)
{ // Find maxValue as max in fft data
arm_max_f32(fft_data, FFT_SIZE, &maxValue, &maxIndex);
}
else
{ // Grab maxValue from fft data at freq position
arm_max_f32(&fft_data[fft_freq * FFT_SIZE / ADC_SAMP_SPEED - 1], 3, &maxValue, &maxIndex);
if (fft_freq2 != 0)
{
// Grab maxValue from fft data at freq2 position
float32_t maxValue2; // Max FFT value is stored here
uint32_t maxIndex2; // Index in Output array where max value is
arm_max_f32(&fft_data[fft_freq * FFT_SIZE / ADC_SAMP_SPEED - 1], 3, &maxValue2, &maxIndex2);
maxValue = (maxValue + maxValue2) / 2.0;
}
}
tmStopMeasurement(&time); // Get number of clock cycles
// Convert output back to uint16 for plotting
for (i = 0; i < len / 2; i++)
{
buffer[i] = (uint16_t)(fft_data[i] * 10.0);
}
// Zero the rest of the buffer
for (i = len / 2; i < len; i++)
{
buffer[i] = 0;
}
LOG_INFO("FFT number of cycles: %i\n", time.worst);
return ((uint16_t)(maxValue * 10.0));
}