Daqarta
Data AcQuisition And Real-Time Analysis
Scope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!

Gut-Level Fourier Transforms - Part 5:

Dumping Spectral Leakage Out a Window


Previous Next

Spectral leakage can cause problems with digital spectrum analysis whenever the input data set doesn't hold an exact integer number of cycles of the signal. That's the usual situation with real-time analysis, since there is normally no synchrony between the input signal and the analyzer's sample rate.

The problem is that the DFT or FFT treats the data set as a complete cycle of an infinitely-repeating waveform. If that data set ends abruptly while the input is actually mid-cycle, it creates an apparent discontinuity at the splice point in the assumed infinite wave, as shown in Figure 1:


Fig. 1: Repeating a Non-Integer Period

It's the spectrum of this spliced waveform, not the true input waveform, that is actually computed by the DFT or FFT. As we saw last time, it contains lots of "leakage" energy at frequencies other than the desired one. How can we reduce that leakage?

One idea is to adjust the length of the data set to exactly match the input period. This can be done by adjusting the number of samples used by a DFT, but the DFT is notoriously inefficient. The FFT is much more efficient, but its requirement for power-of-2 sample sets obviously precludes fine adjustments. Alternatively, in a real-time system it might be possible to adjust the sample rate, and hence the duration of a fixed-size sample set, to get a perfect match. But either of these "adjustment" methods would be cumbersome at best, and neither would be feasible for signals containing multiple uncorrelated waves.

Look again at that problem signal in Figure 1. Suppose we taper it smoothly to zero at both ends of the data set, so that it splices cleanly no matter what the actual frequency or waveform. If we provide the taper by multiplying the input by an envelope or "window" having a sinusoidal shape (actually a raised inverted cosine in this case), we get a waveform that is normally associated with 100% amplitude modulation. The raw and windowed waveforms are shown in Figure 2:


Fig. 2: Raw and Windowed Waveforms

Those familiar with AM may recall that the spectrum of such a signal has an added sideband on each side of the carrier, separated from it by the modulating frequency. If the carrier (input) is at frequency A and the raised cosine modulator (window) is at frequency B, we have:

sin(A) × (1 - cos(B) = sin (A) - 1/2 × sin(A-B) - 1/2 × sin(A+B)

In our case, the modulation frequency is once per N-sample data set duration, which translates to one spectral line above and below the carrier. If the input sine falls exactly on a spectral line, then the spectrum of the windowed input will show the carrier line flanked by two half-amplitude sideband lines. The window thus gives an erroneous view for input frequencies that happen to be aligned properly, but that error is one we can usually live with, if it confers benefits elsewhere.

The more important issue is what happens to misaligned input frequencies. Can adding two extra sidebands actually help reduce the normal leakage sidebands? The answer is "yes!" However, to understand how this comes about, we need to go back to the leakage spectrum for a single misaligned input.

A spectrum analyzer normally shows only magnitudes, but internally it performs computations on signed values. For an input frequency that falls midway between two spectral lines, the analyzer shows a trace like that at the top of Figure 3. The true signed spectrum is shown below it.


Fig. 3: Magnitude and Signed Leakage Spectra

Note that all the components above the input frequency show positive amplitudes, while those below it are negative. That's because these leakage components result from multiplying the input by the various spectral line reference frequencies, and each product includes a difference-frequency term. For reference frequencies above the input frequency, that difference is positive. For those below, it is negative. Recall that a negative-frequency sine moves backward in time, going through the same values as a positive-frequency sine that has a negative amplitude.

(The above-mentioned products also include sum-frequency terms, but as discussed last time they contribute much less to each leakage component and don't affect its sign.)

The windowed spectrum is the sum of this input spectrum, plus similar spectra for the two half-amplitude sidebands shifted one line higher and lower. Note that from the modulation formula these sidebands are inverted in sign relative to the input carrier. The situation is shown in Figure 4, with the input on top, then the lower and upper sidebands, and the signed sum of all these on the bottom trace.


Fig. 4: Summing Windowed Leakage Spectra

This shows how the leakage components of the inverted sidebands partially cancel the leakage components of the carrier. (They don't really go completely to zero, just below the resolution of the figure. Spectrum analyzers typically provide a logarithmic display mode to allow viewing the low-level parts of a spectrum, but a linear scale was used here to show the summation.)

Just as important as reducing leakage, the inverted sidebands add to the two main sidelobes to make them closer to the true value. Last time, we computed the main sidelobes to be about 0.6366 of the true value, but here the window has brought them up to about 0.8488. Essentially, some of the leakage has been squeezed back into these main lobes.

Can we do better still? This simple raised cosine is called a Hanning window, but there are many others. They all use the same idea of tapering the input data near the ends to reduce the splice that causes spectral leakage. They differ in the shape of the envelope, which means differences in the spectrum of the amplitude modulator. For example, many common windows add a second harmonic to the modulator.

However, all windows must make trade-offs in the width of the passband versus the steepness of its slopes and the depth of the ultimate floor. Some are better at specific tasks than others, but the simple Hanning window is still the most popular and probably the best all-around compromise.

Next time, we'll discuss the characteristics of some of these other windows and show comparison spectra. We'll also cover caveats in windows use, including transient signals and broadband noise. Until then you can experiment with window behavior using the author's Daqarta for Windows software that turns your Windows sound card into a full-fledged spectrum analyzer... and much more.

All Daqarta features are free to use for 30 days or 30 sessions, after which it becomes a freeware signal generator... with full analysis capabilities. (Only the sound card inputs are ignored.)


Previous Next

Features:

Oscilloscope

Spectrum Analyzer

8-Channel
Signal Generator

(Absolutely FREE!)

Spectrogram

Pitch Tracker

Pitch-to-MIDI

DaqMusiq Generator
(Free Music... Forever!)

Engine Simulator

LCR Meter

Remote Operation

DC Measurements

True RMS Voltmeter

Sound Level Meter

Frequency Counter
    Period
    Event
    Spectral Event

    Temperature
    Pressure
    MHz Frequencies

Data Logger

Waveform Averager

Histogram

Post-Stimulus Time
Histogram (PSTH)

THD Meter

IMD Meter

Precision Phase Meter

Pulse Meter

Macro System

Multi-Trace Arrays

Trigger Controls

Auto-Calibration

Spectral Peak Track

Spectrum Limit Testing

Direct-to-Disk Recording

Accessibility

Applications:

Frequency response

Distortion measurement

Speech and music

Microphone calibration

Loudspeaker test

Auditory phenomena

Musical instrument tuning

Animal sound

Evoked potentials

Rotating machinery

Automotive

Product test

Contact us about
your application!

Questions? Comments? Contact us!

We respond to ALL inquiries, typically within 24 hrs.
INTERSTELLAR RESEARCH:
Over 35 Years of Innovative Instrumentation
© Copyright 2007 - 2023 by Interstellar Research
All rights reserved