Spectra
An analyzer cannot observe forever, and that truncation has consequences: a pure tone appears smeared out. Windows correct it at the cost of resolution, and choosing one is choosing what you give up.
01What is plotted when you plot a spectrum
The transform returns one complex number for each frequency, so two plots are needed to show it in full: the magnitude plot and the phase plot.
In practice you almost always look at the magnitude plot, and for one reason: the ear and most detectors are insensitive to phase. But the phase is there, and it is what holds the information about when: two signals with identical magnitude spectra can be completely different in time if their phases differ.
| Type of signal | Its spectrum | Units |
|---|---|---|
| Periodic | Lines at \( k\omega_0 \) | Volts: it is an amplitude |
| Isolated, finite energy | Continuous | V/Hz: it is a density |
| Noise, random signal | Power spectral density | V²/Hz |
The difference between amplitude and density matters more than it seems. The spectrum of an isolated signal is not measured in volts but in volts per hertz, and its value at a point means nothing by itself: what makes sense is the integral over a band. That is why the noise of an amplifier is specified in nV/√Hz, and you have to multiply it by the square root of the bandwidth to obtain volts.
02Two-sided and one-sided
The transform gives positive and negative frequencies. For a real signal, the Hermitian symmetry means that the negative half is determined by the positive half, so instruments show only one half. This calls for an adjustment:
This is the origin of a classic mistake: computing the complex coefficients, keeping those with \( n \ge 1 \) and forgetting the factor 2. The result is half of what the analyzer shows.
03What the analyzer does with a finite window
A real spectrum analyzer cannot observe the signal from \( -\infty \) to \( +\infty \): it takes a piece of finite duration. And taking a piece is multiplying by a rectangular pulse, which by the multiplication property is equivalent to convolving the spectrum with a sinc.
The consequence is called spectral leakage: a pure tone, which should give a single line, appears smeared over the neighboring frequencies. Unless the window contains an integer number of cycles, in which case the zeros of the sinc fall exactly on the other lines and nothing odd shows up.
A tone observed over a finite window. Move the frequency and watch what happens when an integer number of cycles no longer fits; then try the windows and compare them.
04Choosing the window is choosing what you lose
All windows do the same thing: instead of cutting the signal off abruptly, they fade it out smoothly at the edges. That reduces leakage, but it widens the main lobe, which is the same as saying that it worsens the frequency resolution. There is no good window: there are windows suited to each purpose.
| Window | Sidelobes | Main lobe width | What it is for |
|---|---|---|---|
| Rectangular | −13 dB | The narrowest | Separating two similar, strong tones |
| Hann | −31 dB | Double | General use, it is the default |
| Hamming | −43 dB | Double | When the first sidelobes are a nuisance |
| Blackman | −58 dB | Triple | Seeing a weak signal next to a strong one |
| Flat-top | −90 dB | Very wide | Measuring amplitudes: its level error is minimal |
The last row deserves an explanation. When a frequency falls between two lines of the analysis, the measured amplitude ends up below the real one: with a rectangular window the error reaches 3.9 dB, and with Hann 1.4 dB. The flat-top is designed so that this error is a few hundredths of a dB, at the cost of terrible resolution. That is why, on an analyzer, you use flat-top to measure the level of a tone, and another window to separate nearby tones.
Two tones can be told apart only if they are separated by more than \( 1/T \), where \( T \) is the duration of the window. To resolve 1 Hz you have to observe for 1 second, and no window or algorithm can avoid that: it is the same trade-off between duration and bandwidth as always. When you lower the resolution bandwidth on an analyzer, what you are actually doing is observing for a longer time, and that is why the sweep becomes slow.
05In the lab
Using the FFT of an oscilloscope, capture a sinusoid whose frequency is an exact multiple of the resolution and then shift it by half a line. Compare the two spectra and measure how many decibels appear at the sides.
Generate two tones 50 Hz apart with equal amplitudes, and then with one 40 dB lower than the other. Find which window lets you see both in each case and explain why it is not the same one.
Measure the amplitude of a tone with a rectangular window, Hann and flat-top, for a frequency that falls between two lines. Compare the three values with the one shown by the true-RMS voltmeter.
06Common mistakes
- Forgetting the factor 2 when going to one-sided. It gives half of the real amplitude.
- Reading a spectral density as if it were an amplitude. V/Hz are not volts; you have to integrate over the band.
- Blaming the instrument for leakage. It is a consequence of observing for a finite time, not a defect.
- Using the default window to measure amplitudes. That is what the flat-top is for.
- Expecting more resolution than the observation time allows. The limit is \( 1/T \).
07Self-assessment
Why are two plots needed for a spectrum?
Because the transform is complex: one for the magnitude and one for the phase.
What causes spectral leakage?
Observing for a finite time, which is equivalent to multiplying by a pulse and convolving the spectrum with a sinc.
When is there no leakage with a rectangular window?
When an integer number of cycles fits in the window: the zeros of the sinc fall on the other lines.
What do you gain and what do you lose with a window?
You gain low sidelobes and lose resolution: the main lobe widens.
Which window is best for measuring the level of a tone?
The flat-top: its amplitude error is minimal, even though its resolution is poor.
How long do you have to observe to resolve 1 Hz?
One second. The resolution is \( 1/T \), and there is no way around it.
08Further reading
- Alan V. Oppenheim and Ronald W. Schafer. Discrete-Time Signal Processing. 3rd ed. (Spanish edition, “Tratamiento de señales en tiempo discreto”), Prentice Hall, 2010. The chapter on spectral analysis with windows, with the figures for each one.
- Fredric J. Harris. On the Use of Windows for Harmonic Analysis with the DFT. Proceedings of the IEEE, vol. 66, no. 1, 1978. The reference paper on windows. All the tables that are still in use come from here.
- Keysight Technologies. Spectrum Analysis Basics · Application Note 150. Keysight, current edition. How a real analyzer works: resolution bandwidth, sweep time and detectors.