Say you wanted to run a X point FFT on the last X audio samples that were played. The problem being, using a normal hann window function would place emphasis on the "middle" of the audio sample. However, the most current audio samples played (the audio samples toward the end) are of the greater importance for algorithms such as real-time beat detection. The question is, which window function best emphasizes the frequencies at the end of the waveform?

  • 2
    $\begingroup$ There is no such thing as an optimal window function unless you define some criteria to optimize. There is an inherent tradeoff when designing a window between sidelobe height and mainlobe width. The best course of action is dependent upon what you're trying to do. You might not even need to window the signal (or stated differently, you could just use the rectangular window). $\endgroup$
    – Jason R
    Commented Nov 4, 2011 at 20:43
  • $\begingroup$ What you probably need to do is use overlapping segments (again, depends on what exactly you're doing). Nearly all window functions taper to zero at the end of the segment. By using sufficient overlaps, you account for the frequencies at the ends of the segments. $\endgroup$ Commented Nov 4, 2011 at 22:22
  • $\begingroup$ Yes i have an 80% overlap. I run the FFT every 20ms on the last 180ms of captured audio. I was wondering if there were any proven ways to attenuate the frequencies played in the last 20ms. Though, it seems like favoring the last 1000 samples or so would just add noise. @yoda $\endgroup$ Commented Nov 4, 2011 at 23:16
  • $\begingroup$ Are you actually doing beat detection, or something else? $\endgroup$
    – datageist
    Commented Nov 4, 2011 at 23:45
  • 1
    $\begingroup$ The kick drum gives a spectral spike of 40Hz - 150hz, then resonates around 50Hz. Its the initial spectral spike i wish to detect, since it is unique solely to a kick drum. The kick is usually quite distinguishable from the bassline. Example $\endgroup$ Commented Nov 5, 2011 at 14:29

2 Answers 2


A full-width rectangular window (a.k.a no window) would best emphasize spectral content near the edges of an FFT aperture, at the cost of artifacts caused by convolution of the spectum with a Sinc function, also called "spectral leakage". If you can ignore or compensate for these spectral artifacts then there's little reason to window.

But you might be asking the wrong question. If you want the fastest possible response to some specific frequency band, you should be using a minimum phase filter (or a bank of them, as needed) or a close approximation to such, not a faster block DFT. Then you can update with each new sample instead of waiting to process a block, and tune the time-frequency response of the filter(s) for each specific band of interest.


I think the glitch in your question comes out at the very end: there are no "frequencies at the end" of the windowed signal. When performing the Fourier transform, the frequency bins don't have localized time; they describe the entire signal. But you knew that, that's why you are doing the STFT.

If you are doing beat detection, you could work in the time domain to get the absolute lowest latency. But if you are doing beat detection that also detects some transient in the frequency domain, where a sine tone shifting from 440 to 880 hz counts as an onset -- I'd suggest there's more of a fundamental limit to your latency, dependent on the pitch period; and in that case your best bet is to reduce the window size to, say, capture 4 periods of the lowest frequency you are interested in. If you are "weighting" the last bunch of samples coming in, you might as well shrink the window and get a predictable frequency response out of it. Another thought is to run parallel FFTs, one with a short window, and one with a long window...

  • $\begingroup$ Yeah, i agree favoring the latest samples won't help much. I had not thought of parallel FFTs though. If I could detect frequencies in the short window FFT that aren't present in the longer window, that could be a indicator of a beat. $\endgroup$ Commented Nov 5, 2011 at 0:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.