Some Notes on Windows in Spectral Analysis
Please cite this document as
Jens Ahrens, “Some Notes on Windows in Spectral Analysis,” Tech. Report, Chalmers Univeristy of Technology, 2020.
Abstract
The following plots show the (unwindowed) singlesided Discrete Fourier Transform (DFT) amplitude spectra of two sine waves of amplitude . (Refer to this article if you are unsure about what a singlesided amplitude spectrum is.)
Fig. 1: Singlesided DFT amplitude spectra of two sine waves of amplitude and frequency (left) and . The horizontal axis was converted from bin index to frequency in as explained here.
Both sines were sampled at Hz, and the length of the DFT was in both cases. So, the only difference is the frequencies. Yet, the spectra suggest that the sines differ in amplitude by more than . This article clarifies why this is and how this apparent difference can be avoided using flat top windows.
Main Lobes and Side Lobes of Windows Revisited
Let’s look at the singlesided amplitude spectra of two sine waves with a DFT length of . See this MATLAB script.
Fig. 2: Singlesided amplitude spectra of two sines with a frequency that is equivalent to bin index (left) and (right).
These plots were obtained by connecting all spectral magnitudes that occur at integer with straight lines. This is how magnitude spectra are usually plotted. Note that on the left hand side, the magnitude is at all values of other than , which is the frequency of the sine. As you may know, all windows including the rectangular window that is implied here, exhibit a main lobe and side lobes which cause smearing of the spectrum. Why can’t we see any of this in the left hand plot in Fig. 2?
The short answer is: The left hand plot in Fig. 2 is a special case where the frequency of the sine whose spectrum we are looking at corresponds to one of the basis functions of the DFT (some may call this “It is exactly in the center of a bin .”).
Recall the definition of the DFT:
It happens so that if the frequency of a sine is exactly in the center of a bin of the DFT \eqref{eq:dft}, there will be a complex exponential that will oscillate at the exact same frequency like the sine. In other words, we need only this single basis function (plus the one at ) of the DFT to represent the sine. The spectral coefficients will be zero for all other .
Ok, so far so good. How can we bring the lobes into the game? Usually, the DFT \eqref{eq:dft} is only computed for integer because this covers all of the information. You can actually also evaluate \eqref{eq:dft} for fractional as the spectrum of a timediscrete signal is continuous^{1}. There is nothing that prevents us from doing this. See this MATLAB script, which produces the following Fig. 3, which is identical to Fig. 2 but with the DFT \eqref{eq:dft} evaluated also for fractional (gray line).
Fig. 3: Same like Fig. 2 but with the DFT evaluated also at fractional .
The black circles mark the spectral points at integer . That’s the same data points that Fig. 2 comprises, and that’s the ones that we usually look at. You can now actually discern the window lobes in the gray lines! It just happens so that for this particular case, the DFT “samples” the window only at the maximum of the main lobe and exactly at the zeros between the lobes. Note that the circumstance that the integer bins sample the window exactly at the zeros between lobes is a particularity of the reactangular window. You will always see traces of the side lobes for any other window.
The story changes if we look at sines with arbitrary frequency, for example equivalent to . See the right hand plot in Fig. 3 , which is a variant of Fig. 2 (right) and also plots fractional . The DFT does indeed sample the window lobes outside of the zeros between the lobes so that we notice them. It happens so that the main lobe is not sampled at its maximum so that the sine amplitude that we read from the amplitude spectrum is misleading. This is where flat top windows come into play.
Flat Top Windows
The following figure plots a flat top window [1] in the domain of the original signal (some call this the time domain). See this MATLAB script.
Fig. 4: The standard flat top window that MATLAB uses for
Fig. 5 depicts the amplitude spectra of the same scenario like in Fig. 2 and 3 (sine waves with frequencies equivalent to and ) but with a Hann window^{2} and a flat top window applied before the DFT^{3}. See this MATLAB script. We chose the Hann window for completeness. The story is very similiar like for the rectangular window discussed above.
Fig. 5: Same like Fig. 3 but with a Hann window (dotted line) and a flat top window (solid line) applied.
The main lobe of the Hann window is pointy so that it is not guaranteed that the DFT samples its maximum (cf. Fig. 5 (right)). The main lobe of the flat top window has a flat top (surprise!) with ripples of less than and that is a least one bin wide. It is therefore guaranteed that that DFT samples the main lobe around its maximum (green circle in Fig. 5 (right)) so that we obtain approximately the same magnitude independent of the frequency of the sine.
The price that we pay is that the width of the main lobe obscures the precise frequency of the sine that we analyse even more than it occurs for other windows. We know the sine’s amplitude more precisely but lose precision of its frequency. Greetings from Heisenberg!
In order to determine both frequency and magnitude with precision requires either a DFT with integer , which is not commonly applied because of the computational cost, or interpolation of the DFT magnitude spectrum as proposed, for example, in [2]. Either way, you have to hope that the frequency of the sine that you analyse is constant during the length of the DFT. More greetings from Heisenberg.
Note that it happens so that the side lobes of both the Hann window and the flat top window are so low in magnitude that they are not visible in Fig. 5 (left) because the magnitude is plotted on a linear scale. Feel free to play around with the MATLAB script and switch the plotting to logarithmic see the side lobes even at integer .
To close the loop, we’re getting back to the example from Fig. 1 in the Abstract but apply a flat top window (see this MATLAB script):
Fig. 6: Same like Fig. 1 but with a flat top window applied
No matter what the frequency of the sine is, we can deduce that its amplitude is dB or equivalently . Recall that we are looking at singlesided amplitude spectra.
Conclusions
Use a flat top window to determine the amplitudes of stationary oscillations in a signal. Do not use it if you need to deduce the frequencies of the oscillations.
References

G. Heinzel, A. Rüdiger, R. Schilling. Spectrum and spectral density estimation by the Discrete Fourier transform (DFT), including a comprehensive list of window functions and some new flattop windows. Tech. Rep. http://hdl.handle.net/11858/00001M00000013557A5, 2002.

J. Smith and X. Serra, “PARSHL: An analysis/synthesis program for nonharmonic sounds based on a sinusoidal representation,” in Proc. of the Int. Computer Music Conf. (ICMC), Champaign/Urbana, Illinois, USA, Aug. 1987.