# What are the origins of the window functions in DSP? Why not just use a rectangular window?

As far as I know, in DSP we wish to remove or reduce the effect of some undesired signals by separating its frequency spectrum from the spectrum of the whole signal (our main signal and the noise). This process is done by using a window of rectangular shape, right? I thought that the window function is something in the frequency domain that is multiplied by the frequency spectrum of our main signal that is being filtered. I thought we took an FFT of the main signal, multiply it with the filter rectangle window which looks like a rectangle in the frequency domain (each sample of window multiplies with corresponding sample of the FFT of the main signal) and then did an inverse FFT to get the filtered main signal back. I think this will not work very well since our main signal is not periodic (like speech) and we do not have ALL samples of it when we do the FFT, so perhaps the filtered main signal would not be good.

My confusion is arising from coming to know that the window function has its origins in the time domain and not the frequency domain and the window function is convolved in time with our main signal to filter it! (For the window function in the frequency domain we get all this mess with lobes that look weird, which is another thing I do not understand). Why don't we filter in the frequency domain by taking FFT and multiplying it with a window and than doing an inverse FFT?

Apparently a rectangular window is bad since its side lobes are not small enough and there is something called "power leakage" in the spectrum so we do not use a rectangular window. It's all confusing me.

Your real confusion seems to be a fundamental misunderstanding of what DSPs do. DSPs are optimized to perform convolutions. Since a coeficient has to be stored and a multiply-accumulate performed for each point of the convolution, the number of points is limited by memory and available processor time. The convolutions therefore by necessity must be some finite width, so these types of filters are often referred to as finite impulse response, or FIR.

Other than the restriction on the width of the convolution, nothing in the DSP hardware says what you can do with that convolution, or more specifically, what coeficients you can use. All the coeficients together form the function you are convolving a input signal with. They are sometimes collectively called the filter kernel.

There are many possible uses for this basic capability provided by DSPs. Sometimes the desire is to eliminate all content past some frequency while not altering content below that frequency, but that is only one of many useful things a wide digital convolution can do.

However, even when a DSP is used in this way, it is not done with a "window of rectangular shape". There will always be a window of some finite size (that's the basis of a FIR filter), but the shape of that window is rarely rectangular. Using DSP hardware to implement a rectangular filter is rather a waste. Since all coeficients are equal, you can implement this specific case of convolution with a circular buffer, two multiplies, and two adds per sample, regardless of how wide the buffer is. This is sometimes called a "moving average" filter, or "box" filter. For most purposes these don't have very good characteristics. They seem to be used a lot for two reasons: They are the knee jerk reaction of those that didn't pay attention in signal processing class, and they are conceptually easy to implement.

The specific case of a sharp cutoff low pass filter requires the filter kernel to be a sinc function. A sinc in the time domain maps to a rectangle in the frequency domain, and vice versa.

You also seem to be confused in that a FFT is somehow envolved. A fourier transform or lots of other analisys tools may be used to determine what the filter kernel should be, but once the kernel coeficients are determined it's all just a convolution at run time. If you start out knowing what you want to do to a signal in terms of a frequency domain multiplication, then it takes a fourier transform to find the filter kernel that will realize that operation in the time domain as a convolution. However, there are many possible criteria for manipulating a signal, and not all of those may be expressed in the frequency domain. Some may come at you directly in the time domain, in which case no fourier analisys may be needed to determine the filter kernel.

My confusion is arising from coming to know that the window function has its origins in the time domain

This is correct. Normally when we talk about a window function we're talking about something that's applied in the time domain.

and not the frequency domain and the window function is convolved in time with our main signal to filter it!

This is incorrect. The window function is not convolved with the input signal, it is multiplied by it.

Convolving the window with the input would be equivalent to multiplying after doing the FFT (of both the window and the input sigal). This would be equivalent to what you describe in your first paragraph. But calculating it as a convolution in the time domain would require potentially much more computational effort than doing multiplication in the frequency domain.

I thought that the window function is something in the frequency domain that is multiplied by the frequency spectrum of our main signal that is being filtered.

If we multiply in the frequency domain, we don't usually call that a window function. We call it a filter.

Why don't we do filtering in the frequency domain by taking FFT and multiplying it with a window and than doing inverse FFT?

We often do do filtering this way. But windowing is not the same as filtering. Filtering is equivalent to convolution in the time domain.

But when we do windowing, we actually want multiplication in the time domain.

I think this will not work very well since our main signal is not periodic (like speach) and we do not have ALL samples of it when we do the FFT

This is exactly why we use window functions. When we do a discrete Fourier transform (DFT), we assume we have sampled one or more periods of a periodic function. But, like you say, this is often a very poor assumption.

The result is that our periodic-extended signal has large jumps where the last sample wraps around to the first sample. When we do the DFT, that big jump can be the dominant feature whose effects we see in the spectrum. But it's not at all what we want to study.

Typically our window function is "large" in the middle and "small" at the edges. This enhances the features we want to see in our samples and minimizes the effect of the jump between the last and the first sample.

Of course we can also look at its effect in the frequency domain in terms of side lobes and so on, but as you say that is a bit hairy to get your head around.

• hmm that is wierd, I have always thought of filters in the frequency domain e.g we have a frequency response of 1 until a cut-off frequency = low pass filter. Now take the frequency spectrum of the main signal and multiply with this filter's frequency spectrum. This is so easy to understand since the time domain gets all messed up with convolutions (hmm how does convolution = filtering???) but in frequency domain it all makes sense. So windowing is not = filtering? – quantum231 Apr 22 '13 at 16:10
• @quantum231, multiplication in the frequency domain is equivalent to convolution in the time domain. So a filter that's defined by a spectral response that you multiply in the frequency domain could be equivalently defined by an impulse response that you would convolve in the time domain. – The Photon Apr 22 '13 at 16:12
• where can I find how this idea of using windows in time was conceived? We are not doing convolution here at all, it is simple multiplication. I am very surprised. – quantum231 Apr 22 '13 at 18:46
• For this topic I highly recommend Hamming, R. W., Digital Filters, available from Dover. It has a very readable coverage of windowing. Note the very commonly used "hamming window" is named for the author. – The Photon Apr 22 '13 at 18:53
• @quantum231, Windows and filters are different things with different purposes. That is why they function differently. – The Photon Apr 23 '13 at 14:35

Filtering with a rectangular window in the frequency domain is the equivalent of convolving with a sinc function (sin(pi*x)/(pi*x)) in the time domain. If you were using a filter of infinite width, things would work out just fine. Real implementations, however, are rarely infinite, and the application of a filter window (like Hamming, Hanning (really von Hann), cosine, etc) can minimize some of the nastier effects of the truncated side lobes of the sinc function.

Taking the fft, multiplying by the rectangular window in the frequency domain, and then taking the inverse fft is equivalent to convolution with the sinc function in the time domain, and shares its shortcomings