开发者

What is the Hamming window for?

I'm working with some code that does a Fourier transform (to calculate the cepstrum of an audio sample). Before it computes the Fourier transform, it applies a Hamming window to the sample:

for(int i = 0; i < SEGMENTATION_LENGTH开发者_Go百科;i++){
    timeDomain[i] = (float) (( 0.53836 - ( 0.46164 * Math.cos( TWOPI * (double)i  / (double)( SEGMENTATION_LENGTH - 1 ) ) ) ) * frameBuffer[i]);
}

Why is it doing this? I can't find any reason for it to do this in the code, or online.


This is an old question, but I thought the answer could be improved.

Imagine the signal you want to fourier transform is a pure sine wave. In the frequency domain, you would expect it to have a sharp spike only at the frequency of the sine. However if you took the fourier transform, your nice sharp spike would be replaced by something like this:

What is the Hamming window for?

Why is that? Real sine waves extend to infinity in both directions. Computers can't do computations with an infinite number of data points, so all signals are "cut off" at either end. This causes the ripple on either side of the peak that you see. The hamming window reduces this ripple, giving you a more accurate idea of the original signal's frequency spectrum.

More theory, for the interested: when you cut your signal off at either end, you are implicitly multiplying your signal by a square window. The fourier transform of a square window is the image above, known as a sinc function. Whenever you do a fourier transform on a computer, like it or not, you're always choosing some window. The square window is the implicit default, but not a very good choice. There are a variety of windows that people have come up with, depending on certain characteristics you want to optimize. The hamming window is one of the standard ones.


Whenever you do a finite Fourier transform, you're implicitly applying it to an infinitely repeating signal. So, for instance, if the start and end of your finite sample don't match then that will look just like a discontinuity in the signal, and show up as lots of high-frequency nonsense in the Fourier transform, which you don't really want. And if your sample happens to be a beautiful sinusoid but an integer number of periods don't happen to fit exactly into the finite sample, your FT will show appreciable energy in all sorts of places nowhere near the real frequency. You don't want any of that.

Windowing the data makes sure that the ends match up while keeping everything reasonably smooth; this greatly reduces the sort of "spectral leakage" described in the previous paragraph.


With what I know about sound and quick research, it appears that Hamming Window is here to minimize the signal side lobe (unwanted radiation). Thus improving the quality or harmonics of the sound. I also understand this type of window function fits good with DTFT.

You will find some good technical explanation on a stanford researcher page or wikipedia and also in a paper of Harris if you are ready for maths :D.


The FT of a finite length segment of sinusoid convolves the Fourier transform of the window against the sinusoid's frequency peak, since a property of the FFT is that vector multiplication in one domain is convolution in the other. The FT of a rectangular window (which is what any unmodified finite length of samples in an FFT implies) is the messy looking Sinc function which splatters any signal that is not exactly periodic in the window over the entire frequency spectrum.

The FT of a Hamming shaped window concentrates this "splatter" much nearer to the frequency peak after the convolution (than a Sinc function), resulting in a fatter but smoother frequency peak, but a lot less splatter across frequencies far from the frequency peak. This results in not only a cleaner looking spectrum, but also less interference from far away frequencies on any signal of interest.

This interpretation (as opposed to the "infinitely repeating" interpretation) makes it more clear why differently shaped windows than Hamming may give you better results with even less "leakage". In particular, a Hamming window will reduce the size of the first Sinc side lobe of "leakage" right next to the frequency peak in exchange for actually more "leakage" (or convolution splatter) far from the frequency of interest. Other windows may be more appropriate if you wish a different trade-off. The Harris paper (pdf here) linked in another answer above gives several examples of these different windows.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜