Notes / Sensors & Signal Processing
Seeing frequencies with the FFT
Convert a time-domain signal into its frequency components to see which frequencies the vibration and noise are concentrated in. How to use an FFT on an MCU.
What the FFT gives you
Put in N samples and you get the magnitude and phase of N/2 frequency bins from 0 to fs/2.
- Frequency resolution = fs / N
- Example: fs = 1 kHz, N = 1024 → one bin is about 1 Hz
Uses in embedded work
- Vibration diagnosis: a bad motor bearing or imbalance shows up as a peak at a particular frequency
- Finding the cause of noise: tell whether noise in the ADC values is the PWM frequency or supply ripple
- Control tuning: find the resonant frequency and design a notch filter
- Audio: pitch detection, spectrum display
Implementation
arm_rfft_fast_instance_f32 S;
arm_rfft_fast_init_f32(&S, 1024);
arm_rfft_fast_f32(&S, in, out, 0);
arm_cmplx_mag_f32(out, mag, 512);
With CMSIS-DSP a 1024-point FFT takes around 1 ms on a Cortex-M4.
RoadmapSee where this note sits in Sensors & Signal Processing→Window functions
If the start and end of the sampled section do not join up, the frequencies appear smeared (leakage). Multiply by a window function such as Hann before the FFT.
On the PC first
Collect the data as a log and run an FFT in Python (numpy), and you quickly learn what to look at. Then decide whether real-time processing on the MCU is needed.