Spark Logic

Benchmark a 1024-point complex Q15 FFT on STM32

Set up a fixed-point CMSIS-DSP complex FFT and measure its transform time separately from ADC and serial transfers.

Prepare the CMSIS-DSP input

Reserve 2048 q15_t values for 1024 complex samples. Store real and imaginary components in consecutive positions. For real-only samples passed to the complex FFT, set every imaginary component to zero. Normalize arbitrary int16_t input to the Q15 range with enough headroom for windowing and preprocessing.

Call the 1024-point Q15 CFFT for the chosen CMSIS-DSP build, with the forward transform and bit reversal enabled if you need natural bin order. The transform works in place. Follow the version-specific output scaling before comparing bin magnitudes, and map bin k to k × sample_rate / 1024.

#include <arm_math.h>
#include <arm_const_structs.h>

static q15_t samples[2 * 1024];

void transform(void) {
  arm_cfft_q15(&arm_cfft_sR_q15_len1024, samples, 0, 1);
}

Measure the transform

Time transform() using DWT CYCCNT on a supported core or a hardware timer. Report the exact MCU, CPU frequency, compiler flags and CMSIS-DSP version. Exclude windowing, ADC acquisition and logging unless you intend to measure the entire pipeline.

Two milliseconds correspond to 144,000 cycles at 72 MHz or 336,000 at 168 MHz. Treat those as budgets to measure on your build. Fill the buffer again before each run because the FFT overwrites the samples.

The indexed STM32F103C discussion reported testing several C implementations before moving to assembly. The CMSIS-DSP example here gives a reproducible baseline for timing. The indexed excerpt does not preserve the full assembly implementation.

References