Inferensys

Glossary

Short-Time Fourier Transform (STFT)

The Short-Time Fourier Transform (STFT) is a Fourier-related transform used to determine the sinusoidal frequency and phase content of local sections of a signal as it changes over time, producing a spectrogram.
Stylish WeWork-like workspace with hot desks and document wall, professional searching through enterprise knowledge base on a mounted ultrawide display, warm industrial pendants overhead.
SIGNAL PROCESSING

What is Short-Time Fourier Transform (STFT)?

A core technique for analyzing how the frequency content of a signal, like audio or vibration, changes over time, essential for real-time sensor data processing on edge devices.

The Short-Time Fourier Transform (STFT) is a Fourier-related transform that computes the sinusoidal frequency and phase content of local, short-duration segments of a signal as it evolves, producing a time-frequency representation called a spectrogram. It works by applying a sliding window to the time-domain signal and computing the Discrete Fourier Transform (DFT)—typically via the Fast Fourier Transform (FFT)—on each windowed segment. This reveals how spectral components, such as specific tones in audio or vibration frequencies, appear and disappear over time, which is critical for analyzing non-stationary signals from sensors.

For TinyML deployment on microcontrollers, STFT implementation requires careful optimization of the window function (e.g., Hann, Hamming), window length, and hop size to balance time-frequency resolution with computational cost. The resulting spectrogram serves as a foundational feature extraction step for downstream machine learning tasks like Acoustic Event Detection (AED), voice activity detection, and anomaly detection in vibration monitoring. Efficient computation, often using fixed-point arithmetic and optimized FFT libraries, is paramount for real-time analysis under severe memory and power constraints.

SENSOR DATA PROCESSING

Key STFT Parameters & Trade-offs

The Short-Time Fourier Transform (STFT) is defined by a set of interdependent parameters that create a fundamental trade-off between time and frequency resolution. Configuring these parameters is critical for optimizing performance in resource-constrained TinyML applications.

01

Window Function & Spectral Leakage

The window function (e.g., Hann, Hamming, Blackman) is multiplied with each segment of the signal before the FFT to reduce spectral leakage, a distortion where energy from one frequency spreads into neighboring bins. The choice of window involves a direct trade-off:

  • Main lobe width: Determines frequency resolution; wider lobes smear nearby frequencies together.
  • Side lobe attenuation: Determines how well the window suppresses leakage from distant frequencies.
  • TinyML Implication: Simpler windows (like Hann) offer a good balance and are computationally cheaper to apply on a microcontroller than more complex ones.
02

Window Length (N) & Frequency Resolution

The window length (N) is the number of samples in each analysis segment. It directly defines the frequency resolution (Δf) of the resulting spectrogram: Δf = Fs / N, where Fs is the sampling rate.

  • Longer Windows: Provide finer frequency resolution (smaller Δf), better for distinguishing close tones.
  • Shorter Windows: Provide coarser frequency resolution, but better time localization for transient events.
  • TinyML Constraint: Longer windows require larger FFTs, increasing memory usage and compute time quadratically (O(N log N)). On an MCU, N is often severely limited by RAM.
03

Hop Size (H) & Temporal Resolution

The hop size (H) is the number of samples the window advances between successive STFT frames. It determines the temporal resolution (or overlap) of the spectrogram.

  • Smaller Hop (High Overlap): Produces a smoother, more detailed spectrogram in time but increases the total number of frames to compute.
  • Larger Hop (Low/No Overlap): Reduces computational load and output data rate but can cause temporal aliasing, missing short-duration events.
  • TinyML Optimization: A hop size of N/2 (50% overlap) is common, but for ultra-low-power applications, H = N (no overlap) may be necessary to minimize compute.
04

The Time-Frequency Uncertainty Principle

The Heisenberg-Gabor limit (or uncertainty principle) imposes a fundamental constraint: one cannot simultaneously achieve arbitrarily high resolution in both time and frequency. This is the core trade-off governing STFT parameter selection.

  • Fine Frequency Resolution requires a long time window, which blurs the timing of rapid changes.
  • Fine Time Resolution requires a short window, which spreads out frequency information.
  • Engineering Implication: Parameters must be chosen based on the signal's characteristics. Analyzing a steady hum requires high frequency resolution; detecting a brief click requires high time resolution.
05

FFT Size & Zero-Padding

The FFT size (M) is often larger than the window length (N). The difference is filled with zero-padding, which appends zeros to the windowed segment before the FFT.

  • Purpose: Zero-padding interpolates the frequency spectrum, providing a smoother visual representation and allowing frequency bins to be centered on specific frequencies of interest.
  • Critical Note: It does not improve true frequency resolution (which is fixed by N). It only provides interpolated bins.
  • TinyML Cost: Increasing M increases FFT computation time. Efficient libraries use M as a power of two. The choice is a balance between spectral smoothness and MCU cycle count.
06

Computational Complexity & MCU Optimization

The STFT's computational load on a microcontroller is dominated by the window multiply and the FFT for each frame.

  • Operations per Frame: ~N (window multiply) + O(M log₂ M) (FFT).
  • Frames per Second: Fs / H.
  • Total Load: Scales with (Fs / H) * (N + M log₂ M).
  • Optimization Strategies for TinyML:
    • Use fixed-point arithmetic instead of floating-point.
    • Pre-compute and store the window function in ROM.
    • Use a highly optimized, power-of-two FFT library (e.g., CMSIS-DSP for ARM Cortex-M).
    • Carefully select N, M, and H to stay within real-time deadlines and memory limits.
COMPARATIVE ANALYSIS

STFT vs. Other Time-Frequency Analysis Methods

A technical comparison of the Short-Time Fourier Transform (STFT) against other common time-frequency analysis techniques, focusing on characteristics critical for sensor data processing on resource-constrained devices.

Feature / MetricShort-Time Fourier Transform (STFT)Wavelet Transform (CWT/DWT)Wigner-Ville Distribution (WVD)

Time-Frequency Resolution

Fixed (Uniform tiling)

Variable (Multi-resolution tiling)

Theoretically optimal (No windowing)

Computational Complexity (for N samples)

O(N log N) via FFT

Continuous (CWT): O(N^2), Discrete (DWT): O(N)

O(N^2)

Memory Footprint (Typical)

Low (One window at a time)

Low to Moderate (Depends on decomposition)

High (Full quadratic matrix)

Suitability for Non-Stationary Signals

Moderate (Assumes local stationarity)

High (Designed for transients)

High (No stationarity assumption)

Cross-Term Interference

Real-Time Streaming Feasibility (MCU)

DWT: true, CWT: false

Common Output Representation

Spectrogram (2D matrix)

Scalogram (CWT) / Coefficient Tree (DWT)

Wigner-Ville Distribution (2D matrix)

Primary Use Case in TinyML

General-purpose spectral analysis (audio, vibration)

Transient detection, signal compression, denoising

Theoretical analysis; rarely deployed on MCUs

SHORT-TIME FOURIER TRANSFORM (STFT)

Frequently Asked Questions

Essential questions about the Short-Time Fourier Transform (STFT), a core technique for analyzing how the frequency content of a signal, such as audio or vibration data, changes over time.

The Short-Time Fourier Transform (STFT) is a signal processing technique that computes the Fourier Transform of sequential, overlapping windowed segments of a time-domain signal to produce a time-frequency representation called a spectrogram. It works by:

  1. Windowing: A sliding window function (e.g., Hamming, Hann) isolates a short segment of the signal.
  2. Transformation: The Fast Fourier Transform (FFT) is applied to each windowed segment.
  3. Shifting: The window is shifted forward by a hop length, and the process repeats. The output is a complex-valued matrix where one axis represents time (window center), the other represents frequency bins, and the magnitude reveals the signal's spectral power over time.
Prasad Kumkar

About the author

Prasad Kumkar

CEO & MD, Inference Systems

Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.

His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.