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

digital filterdspfftspeech

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.

Best Answer

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.