← Gallery FFT & STFT — known-tone spectrogram

FFT & STFT — known-tone spectrogram

scripts/xa-fft.js

Feed a pure 440 Hz tone into the analyzer and the spectrogram below should show exactly one bright horizontal line — at 440 Hz and nowhere else. Because the tone's frequency is known in advance, every number the FFT and STFT report can be checked against the truth. Technically: at sr=8192 with N=8192, bin index equals Hz exactly, so the fft() peak bin must be 440 with zero tolerance; ifft(fft([1,2,3,4])) must return 1,2,3,4 exactly; the stft(1024/256) magnitude spectrogram must show one horizontal line at bin 55 (440 Hz at 8 Hz/bin); and istft() must reconstruct the interior of the signal to maxErr < 1e-4. Same asserts run headless in examples/node/xa-fft.mjs.