Spectral analysis is concerned with determining the frequency content of an arbitrary signal using digital computers. Obtaining a suitable discrete-frequency representation of a discrete-time signal requires two steps:
In the first step, a finite segment of the discrete-time signal is extracted using a discrete-time window. This window simply selects part of the signal; depending on the window shape, it may scale portions of the selected segment. The result of this first step is a finite-length, discrete-time signal. In theory, we can compute the frequency content of such a signal by applying the DTFT equation. However, since that equation requires integration, this computation is not practical for arbitrary signals and digital computers. Even though we will not compute this integral, it is helpful to our understanding of spectral analysis to refer to the DTFT of the windowed segment, or the underlying DTFT.
The second step is to actually compute the DFT of the windowed segment. The DFT produces a discrete-frequency representation directly from a discrete-time signal by computing a finite weighted sum. This is in contrast to the DTFT, which requires integration and produces a continuous-frequency representation. The DFT's discrete-frequency representation constitutes samples of the underlying DTFT. The DFT length determines the spacing of these frequency samples, but not the frequency resolution of the spectral analysis, which is determined by the window length and shape. These specific effects of the DFT are described in detail elsewhere in this tutorial.
The spectral analysis demo that accompanies this tutorial allows you to select the input signal, window length, window shape, and DFT length. It produces three frequency-domain plots: the DTFT of the window, the (underlying) DTFT of the windowed segment, and the DFT of the windowed segment. When discussing frequency resolution, it is often helpful to compare the DTFTs, although it is important to note that only the DFT of the windowed segment is actually calculated for spectral analysis and the two DTFT's are only provided to assist our understanding of the process.
The frequency-domain representation of a window deviates from an impulse in two main ways. First, the mainlobe has non-zero width, compared to an impulse with zero width. Second, the sidelobes are nonzero outside the mainlobe, compared to an impulse which is zero ''everywhere else''. As a result, applying a window affects the spectral content of the signal, by spreading each single frequency component with a pattern that matches the magnitude of the window's frequency-domain representation.
Computing an N-point DFT produces X[k] for k=0,...,N-1. These N values correspond to uniformly-spaced frequency samples of the DTFT, X(f) at values of f=k/N. If the discrete-time signal was obtained by sampling a continuous-time signal at sampling frequency Fs, then the original continuous-time frequencies are related by F=fFs=kFs/N.
In order to resolve neighboring frequencies, we require that the window's mainlobe width be less than or equal to the desired frequency resolution. In this case the underlying DTFT will show separate peaks for neighboring frequency components separated by the width of the window's mainlobe as measured between first zero crossings. (The mainlobe width of a rectangular window is 2/M, where M is the window length.)
When we know that the original signal is a sum of two cosines, then each peak in the windowed signal's DTFT has the same width, because it is formed by convolving the window's mainlobe with the underlying impulse in frequency. In this case we are confident that a peak in the windowed signal's DTFT is due to a single frequency component at the center frequency of the peak. Arbitrary signals, on the other hand, do not have DTFT's consisting only of impulses. Therefore, for arbitrary signals, the width of features in the windowed signal's DTFT result from both the mainlobe width of the window and the shape of those features in the original signal. Even so, the above description of frequency resolution applies to arbitrary signals as well, quantifying our ability to attribute features in the windowed signal's DTFT to a particular range of frequencies in the original signal.
We can improve the frequency resolution and reduce spectral smearing by using a window with a narrower mainlobe. One way to get a narrower mainlobe is to use a longer window. (Try using a 64-point window in the above example and compare the results for two window lengths with f1=0.12. Then repeat the exercise with shorter and longer windows and different frequency spacings.)
Another way to get a narrower mainlobe (to improve the frequency resolution) is to change the window shape. (For the above example with f1=0.12, compare 100-point rectangular and Hamming windows. Then experiment with different window shapes, window lengths, and frequency spacings.)
We can improve the amplitude resolution by using a window with lower sidelobes. The easiest way to get lower sidelobes is to change the window shape. (Try using a Hamming window in the above example the above example and compare the results with the rectangular window for A1=0.05.)
The two characteristics that define a window in the time domain are the window length and shape. The two most relevant window characteristics in the frequency domain are the mainlobe width and the sidelobe height. The relationships between window length, mainlobe width, and sidelobe height are summarized in the following table for a number of commonly used window shapes.
Window Shape | Relative peak | Approx. mainlobe width |
sidelobe magnitude | (in frequency) | |
Rectangular/boxcar | -13 dB | 2/M |
Bartlett (triangle) | -26 dB | 4/M |
Hanning (raised cosine) | -31 dB | 4/M |
Hamming (rasied cosine on pedestal | -42 dB | 4/M |
Blackman | -58 dB | 6/M |
Window shapes in frequency domain (linear and dB)