Library 62- Fast Fourier Transform (FFT) for STM32F4xx

Here is an example of Fast Fourier Transform on STM32F4xx devices. Today, I was looking something on ARM DSP documentation and I saw that some functions for FFT used in my example are deprecated and will be removed in future.

That was the main reason I decided to make a library for FFT on STM32F4xx.

To use this library, some third-party libraries are also required. All these required files can be found in STM32F4xx Standard peripheral drivers and DSP instructions provided from from their website. Now is version 1.5.1 of these drivers and also .lib file is included for ARM MATH for Cortex-M4 Little-Endian with Floating point instructions.

Point of this library is that user don’t actually need to know how FFT works in real life. You just have to know, that calculated FFT is always half of size in length than data, which are used for calculation, because ARM DSP library uses real and imaginary part in input array, so input array is twice of size of output array.



  • Calculate FFT result with float 32 type of variable
  • Calculate max value of your FFT result
  • Works with highly optimized ARM DSP library
  • Support for variable FFT size
  • Allows 16, 32, 64, 128, 256, 512, 1024, 2048 or 4096 samples for FFT size


    • STM32F4xx
  • TM
    • defines.h
    • arm_const_structs.c, available in “CMSIS\DSP_Lib\Source\CommonTables”
    • arm_cortexM4lf_math.lib for ARM compiler, available in “CMSIS\Lib\ARM”

CMSIS folder can be found if you download these libraries directly from or if you download Standard Perihperal Drivers for STM32F4xx from site.


ARM MATH is a library provided from ARM and is the same for all Cortex families, except that you have to provide some informations to library.

In your global compiler defines, you should add these 2 lines:

FFT Samples count

ARM FFT library allows you to use specific number of samples for data calculation.

These values can be every number which is power of 2 from 2^4 and 2^12. So, 9 different FFT length options. These number are passed into function when you initialize FFT with my library.

FFT input/output buffers

FFT works in a way that you first fill input buffer with samples and then you process them and you got samples in output buffer. Complex (CFFT) Fast Fourier Transform, which is also used behind the scenes in my library so uses real and imaginary part in input buffer and only real part is calculated to output buffer.

For this reason, input buffer HAVE TO be 2 * FFT_Size in length and output buffer HAVE TO be FFT_Size in length where FFT_Size is the same as FFT_Samples count explained above.

Library is able to use malloc() to allocate memory for you. You just need to enable this feature when you initialize FFT module and everything will be done for you. You just have to make sure that you have enough HEAP memory available for malloc, otherwise malloc will fail and you will not get anything.

For example, if you have 512 length FFT size, then input buffer must be 2 * 512 = 1024 samples of float 32 and output buffer is 512 samples of float 32. In common, this is 1536 samples of float32 which is 4-bytes long in memory. So, together this would be 6144 Bytes of HEAP memory.

Functions and enumerations


The example works the same as my first FFT example provided on link at the beginning of post. Only library is here and everything looks more nicer.

Project is available on Github, download library below.


Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...