Fix: use periodic Hann window in log-mel spectrogram - #3
Merged
Merged
Conversation
This was referenced Aug 28, 2026
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
force-pushed
the
fix/hann-window-periodic
branch
from
August 28, 2026 13:55
f03c755 to
b6120e6
Compare
monai
marked this pull request as ready for review
August 28, 2026 14:12
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
log_mel_spectrogramcallshanning(N_FFT)withoutperiodic=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=Trueby default) andtransformers(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.