# Effect of Hanning Window on phase of FFT

I'm calculating the beat of song through the frequency domain. I have 60 seconds of audio sampled at 48000Hz, multiplied by a Hanning window in the time domain. This gives me a resolution in the frequency domain of 1BPM, and I'm interested in frequencies from ~10 BPM to ~300BPM, which is only the first 300 bins of the 48000*60 bin length FFT. How does the Hanning window affect the phase of the song's beat? Using no window (really a rectangular window) results in a different phase than the Hanning window does.

• Phase on its own is irrelevant. It only makes sense if you were to reconstruct the signal using an inverse transform (you don't), or you were comparing the signal to some other signal. Are you? – Reinstate Monica Jun 23 '14 at 20:37
• Not really working on this anymore, but I was comparing the phases of multiple audio files and trying to align them. It worked okay. – ablatner Jun 24 '14 at 20:54

It't really more of a question of what the rectangular window is doing to your phase relationships, because it doesn't deemphasize the "edge effects" that occur at the beginning and end of your block of samples, which is the whole point of using a non-rectangular window.

Try this experiment: Do a number of FFTs with lengths ranging from 59*48000 samples to 60*48000 samples, using both window types. You'll find that the Hanning window gives much more consistent results than the rectangular window does. The two results will agree best when the length is close to an integer number of beats.

• Thanks. Because changing the length affects the resolution and changes the frequencies, I did a linear interpolation of the phase using the bins just below and above 130 (which is the known BPM for this song), and I got this nice plot of frequency vs phase. With the Hanning window, they all overlap pretty well. puu.sh/6zozE.png – ablatner Jan 26 '14 at 23:28
• Just out of curiosity, are you analyzing the audio signal directly, or the envelope of the audio signal? – Dave Tweed Jan 27 '14 at 0:44
• I'm analyzing it directly. Would finding the envelope and analyzing that give more precise calculations? This is my first time analyzing real audio, but I think it should get rid of most of the high frequency components and leave the range that I'm actually interested in. Is that right? – ablatner Jan 27 '14 at 9:03
• In terms of the audio, there's actually very little energy at 2.17 Hz, and the microphone and recording system aren't really designed to capture energy at such low frequencies. Musically, what we think of as "beat" is a pulsation in the overall energy level of the sound, and this is best extracted from the envelope data. – Dave Tweed Jan 27 '14 at 12:13
• Then I'll also try analyzing the envelope, thanks. – ablatner Jan 28 '14 at 2:47

Recall that windowing in the time domain is the equivalent of convolution in the frequency domain. Multiplying a signal in the time domain with a Hanning window is the equivalent of convolving the frequency domain signal with the kernel [-1 2 -1]/4.

Thus, if $H(f)$ represents the (non-windowed) frequency response, a corresponding windowed frequency response would be: $$H_w(f) = -0.25H(f-\Delta f) + 0.5H(f) -0.25H(f+\Delta f)$$ where $\Delta f$ is the frequency resolution - else you could write this (with $n$ being a frequency index) as:

$$H_w[n] = -0.25H[n-1] + 0.5H[n] -0.25H[n+1]$$

( windowed frequency response in terms of 'non-windowed' frequency response )

So the phase difference you are looking for is:

delta_phase = angle(Hw(n)) - angle(H(n))

Hope this helps