Pethead
Pethead

Reputation: 178

arm_cfft_sR_q31_len4096 undeclared

I am doing some FFT calculations on a STM32F407 and I want to compare the different FFT functions that is available in the CMSIS DSP library. When I am using the f32 CFFT functions it works as one would expect but when I try to use the q31/q15 functions I get an error saying "arm_cfft_sR_q31_len4096" or arm_cfft_sR_q15_len4096 undeclared when I call their respective cfft functions. I have included arm_const_structs.h where it should be defined but apparently it isn't? It works with arm_cfft_sR_f32_len4096 for the f32 version of the functions so what might be the problem?

Here is how the f32 version of my fft calculations look:

#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));
}

Upvotes: 0

Views: 448

Answers (1)

kkrambo
kkrambo

Reputation: 7057

I found a copy of arm_const_structs.h online. It includes the following line:

extern const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096;

The extern keyword means that this line is a declaration of arm_cfft_SR_q31_len4096, not a definition. The variable must also be defined somewhere else in your code.

I found the definition in arm_const_structs.c.

const arm_cfft_instance_q31 arm_cfft_sR_q31_len4096 = {
    4096, twiddleCoef_4096_q31, armBitRevIndexTable_fixed_4096, ARMBITREVINDEXTABLE_FIXED_4096_TABLE_LENGTH
};

Make sure you have included arm_const_structs.c in your project so that it compiles and links with your program.

Upvotes: 1

Related Questions