Skip to content

Fix: use periodic Hann window in log-mel spectrogram - #3

Merged
monai merged 1 commit into
mainfrom
fix/hann-window-periodic
Aug 28, 2026
Merged

monai merged 1 commit into
mainfrom
fix/hann-window-periodic

Conversation

@monai

@monai monai commented Aug 28, 2026

Copy link
Copy Markdown
Owner

log_mel_spectrogram calls hanning(N_FFT) without periodic=True. So it uses the symmetric window, not the periodic one. This shifts edge weight on every STFT frame.

openai/whisper (torch.hann_window, periodic=True by default) and transformers (window_function(), same default) both use the periodic window. Fix: hanning(N_FFT, periodic=True).

No mlx-audio bug report exists for this, but mixing up symmetric and periodic windows is a known DSP trap: scipy/scipy#23449, librosa/librosa#6.

Found during an ASR accuracy check. This is the biggest single cause of the WER drop, together with #1 and #2.

log_mel_spectrogram built its Hann window via hanning(N_FFT), which
defaults to periodic=False and produces the symmetric window (denominator
N_FFT-1, last sample tapering to ~0). Both openai-whisper's
torch.hann_window(N_FFT) and Hugging Face transformers'
WhisperFeatureExtractor window function default to periodic=True, the
DFT-even window (denominator N_FFT, last sample near 1). The mismatched
window shape skews every STFT frame's edge weighting relative to both
reference implementations.

Pass periodic=True explicitly so the window matches the reference
implementations.
@monai
monai force-pushed the fix/hann-window-periodic branch from f03c755 to b6120e6 Compare August 28, 2026 13:55
@monai
monai marked this pull request as ready for review August 28, 2026 14:12
@monai
monai merged commit 86f6c20 into main Aug 28, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant