Data Windowing

If you've been paying attention to the previous pages, and have any idea what is going on therein, you should be wondering why the spectrum of a sine signal is so jagged looking, whereas it ought to be a single pulse (or at least a narrow Gaussian, given the inaccuracies of the computer arithmetic and relative low resolution of the transform length used). Here is a repeat image of the spectrum and magnitude of the transform of a sine wave at mid-frequency:

Here the transform has been repeated, but limited to the middle 1/8th of the previous transform range to show more detail:

What is happening here is the following: The Fourier transform assumes that the signal being analyzed is infinite in length, from t = -infinity to +infinity. However, it is not possible to acquire or process such a signal in real life. In the examples used here, the signal has been limited to 256 points, from t = 0 to t = 1 sec. In effect, the whole infinite-length signal has been confined to a finite interval/duration by being multiplied by a rectangle function which is equal to 1 for the interval in question, and is equal to 0 everywhere else.

According to theory, multiplying a signal by a function is equivalent to convolving the spectrum of that signal with the spectrum of the multiplying function (see any book on signal processing for a discussion of the convolution and modulation theorems). Thus, in the case of a sine signal, the true spectrum (which should be a pulse) is convolved by the spectrum of a rectangle, yielding the jagged spectrum seen above. Since the convolution of any function by a pulse (and vice versa) is simply that function itself (possibly shifted or scaled), the resulting spectrum of a sine signal multiplied by a rectangle function is therefore the spectrum of the rectangle function.

To demonstrate this, I have created an example to show the spectra of rectangles of various widths:

As the slider is moved, the width of the rectangle function changes, and the resulting spectrum is recomputed and animated. Here is a chart of several different width rectangles and their spectra:

Note that as the rectangle is made more narrow, the resulting spectrum is wider. This is a general property of the duality of time vs. frequency data. At the limit of a rectangle which has been narrowed to a pulse, the spectrum should be everywhere flat, indicating that the Fourier transform of a Dirac function is equal to 1. Note that although the shape of the spectrum expands and contracts, in general it is the same shape found for the spectrum of the sine wave above, confirming the modulation theorem for this example.

In order to compute more accurate spectra of signals limited to a finite interval, it is desirable to find a multiplying function which distorts the resulting spectrum the least. Such functions are often called data "windowing" functions, since they can be used to scroll across a large dataset giving views into the spectra of subsets of the data. Obviously, it would be optimal to find a window function which does not distort the reulting spectrum at all, such that its own spectrum must be a pulse (so that convolving the window spectrum with the signal spectrum returns the signal spectrum). However, we already know from experience that a sine signal (having a pulse as its theoretical spectrum) does not yield such a pulse in real life. Therefore, we must look at other functions (some of which are derived from a sine signal) in order to find one with the most "pulselike" spectrum.

Rather than go into a longer discussion of this topic, I will simply present some windowing functions which are commonly used in Fourier analysis. Most windowing functions share the property that they are close to 0 at the ends of the "window", and close to 1 in the middle of it. This is a completely arbitrary constraint, although it seems like it ought to be intuitively correct (I make no such assumption, however). In each case below, I have zoomed into the center of the spectrum, using a W of -0.1 to 0.1. Note that the spectrum of a real function is Hermitian, meaning that its real component is symmetric (even) and its imaginary component is antisymmetric (odd). The spectrum of a symmetric real function can also be made completely real (with zero imaginary component), if negative time values are allowed in the equation for the DFT.

First, the default rectangle function ("default" means that this is what you get unless you explicitly use a better window):

Next, half a wave of a sine function. I think this is also called a Welch window:

Next, a full sine wave scaled into [0, 1]. I think this is also called a Hann window:

Next, a Gaussian curve scaled into [~0, 1]. I don't know if this is named after anyone or not. Note that a Gaussian might be a good choice for a window function because exp(-pi x^2) is its own Fourier transform:

There are many many more window functions, most of which are named after someone or other. Note that there appears to be a tradeoff between the narrowness of the main peak and the magnitude and distribution of the sidelobes. Actually, the rectangle window has the narrowest peak of those shown above, but it also has the worst sidelobes. In the case of the exponential function shown above, the best tradeoff between peak width and sidelobe strength is obtained when the window does not go to 0 at each end.

Note that the window function does not have to be smooth. I believe this window is called a Bartlett window:

Also note that the window function does not have to start at 0, peak at 1, and go back to 0. Most of them just tend to do this. I have no idea if the following window would be useful in practice, or if windows of radically different shapes would be worth testing:

Because there are so many possible windows to use, finding new and potentially useful data windows is usually left as an exercise for the reader, grad student, etc... Personally, I think it should be an exercise for some good automated search software.

Here is an example of multiplying a sine signal by the exponential window show above before computing the DFT:

Here is the same spectrum recomputed to zoom in on the peak. Note that while the sharpness of the peak is not so great (it would be better with a longer signal and transform), at least the jagged edges of the rectangle sidelobes have been eliminated:

Finally, note that data windowing is only one possible way to decrease the contamination of the signal spectrum by the spectrum of the window function. Another way to do this is to deconvolve the resulting spectrum by the spectrum of the windowing function as a post-processing step, rather than using multiplication as a pre-processing step. However, there are some issues concerning complex convolution and deconvolution which may make this technique impractical in some cases. The next few pages will demonstrate some examples (successful and otherwise) and properties of convolution and deconvolution.

©Copyright Sky Coyote, 2000-2002.