Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;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.

like image 664
fredley Avatar asked Mar 24 '11 12:03

fredley


People also ask

What is Hamming window used for?

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.

What does Hamming window do in Matlab?

hamming( Length ) returns a symmetric Hamming window object with length Length . Length must be a positive integer. Entering a positive noninteger value for Length rounds the length to the nearest integer.

What is Hamming and Hanning window?

Hamming and HanningThe Hamming window stops just shy of zero, meaning that the signal will still have a slight discontinuity. Hamming and Hanning Windows. Both of these windows result in a wide peak, but nice low side lobes: DFT of Hamming and Hanning Windowed Signals.

Why do we use windowing technique?

You can minimize the effects of performing an FFT over a noninteger number of cycles by using a technique called windowing. Windowing reduces the amplitude of the discontinuities at the boundaries of each finite sequence acquired by the digitizer.


3 Answers

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:

Sinc function

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.

like image 167
David Avatar answered Oct 21 '22 05:10

David


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.

like image 45
Gareth McCaughan Avatar answered Oct 21 '22 03:10

Gareth McCaughan


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.

like image 11
M'vy Avatar answered Oct 21 '22 05:10

M'vy