Module stft

Module stft 

Source
Expand description

STFT engine with WOLA (weighted overlap-add) processing.

This module provides a spectral processing framework using short-time Fourier transform with carefully designed windowing to maintain perfect reconstruction.

§Design: WOLA (Weighted Overlap-Add)

  • Window: 20 ms at 16 kHz = 320 samples, hop = 10 ms = 160 samples (50% overlap)
  • Window function: sqrt-Hann applied on BOTH analysis and synthesis
  • COLA invariant: When squared windows overlap-add at 50% offset, the sum is constant (1.0) everywhere, guaranteeing perfect reconstruction for spectral stages that do not modify phase or change the FFT size. After overlap-add and normalization, the output exactly reconstructs the input (delayed by window_len).
  • Normalization: The COLA sum of squared windows is approximately 1.0 at every sample position due to 50% overlap and sqrt-Hann windowing. A small normalization factor accounts for hop boundaries; we divide each output sample by the sum of squared window values at that position.

§Latency

The STFT introduces exactly one window length of latency. At construction, the output FIFO is primed with window_len zeros so that output length always equals input length.

§Arbitrary Input Block Sizes

The STFT accepts blocks of any length via a FIFO input buffer. It processes every complete hop (forward FFT of the last window, spectral stage, inverse FFT, overlap-add into the output accumulator), emitting exactly as many output samples as input samples arrived.

Structs§

Identity
Identity spectral stage: passes the spectrum through unchanged. Used for testing and latency measurement.
SpectralFloor
Per-bin spectral floor tracker with magnitude-domain spectral subtraction. Tracks a slow per-bin minimum-following floor estimate using EWMA with fast-down/slow-up asymmetry, then subtracts the floor from each bin.
Stft
STFT processor implementing the DspStage contract.

Traits§

SpectralStage
Trait for spectral processing stages: one call per hop, operating on the one-sided FFT spectrum (bins 0..n/2+1) with magnitude and phase.