Daqarta for DOS Contents
FFT function treats the N samples that it receives as though they formed the basic unit of a repetitive waveform: It assumes that if we took more samples they would repeat exactly, with the (N + 1) sample being identical to the first sample, and so on. In other words, we should be able to reproduce that repetitive input by playing back our N samples, looping from the last sample back to the first, over and over continuously. In reality, this is only true if the input is a repeating waveform and its basic frequency is an exact multiple of the sample rate divided by N.
Real signals are rarely that cooperative. The usual case is that if our N samples start at one point in a cycle, they end at some other point, so that if we really did play these back in a loop we would get a discontinuity or "glitch" between the last sample and the first. If the original signal was a pure sine wave, our replica would have a buzz added to it, and the bigger the discontinuity, the louder the buzz would sound. The buzz would have a frequency of the sample rate divided by N, which would not be a harmonic of the input wave and would thus sound very bad.
And this is exactly what the FFT spectrum shows. Try this with the Virtual Source: Set a sine wave to show an exact integer number of cycles on the waveform display, and flip to the FFT display. You will see a single line at the sine wave frequency if you tuned things just right. Flip to Y-log to get a better view of the lower levels.
Now adjust the frequency slowly and watch the leakage "skirts" of the peak broaden as you move farther from the optimum value, then drop back down again as you get nearer to the next integer number of cycles... which you can verify by flipping back to see the waveform. Set the frequency so that the waveform ends on a positive or negative peak, and when you flip to the FFT you will find the broad skirts again, indicating lots of energy at frequencies other than the one we set.
The FFT shows us something besides an increase in bogus "skirt" signal when we don't have an integer number of cycles: We have also lost some of the true signal energy from the peak. How can we get an accurate reading of our signal? The obvious and best way is to adjust the sample rate (or the signal itself, if that is an option) to get integer alignment. But with a changing signal, or one that contains more than one component frequency, that may not be possible.
The problem comes from that glitch where the end of the trace should wrap back to the start. Hmmmm... what if we could somehow taper both ends of the set of samples down to zero, so they always lined up perfectly if we looped them? What would that do to the spectrum?
Consider what would happen if the signal was amplitude modulated (AM) with a sinusoid whose period exactly matched our N-points sampling interval. The signal would smoothly go from zero to full-strength and back to zero, once per cycle. Those already familiar with AM may recall that the spectrum has two sidebands, one above and one below the carrier frequency, separated from it by the modulating frequency. This tells us what to expect from our tapered-samples spectrum:
In our case, the modulating frequency is one cycle per N points, which is the line spacing of the FFT output. So instead of just the spectral line at our desired "carrier" frequency, we will see that one, plus one on each side of it. Our ability to resolve the true frequency is thus reduced, but if we can get rid of the large leakage skirts without needing to fiddle with the sample frequency, this might be a bargain.
Let's use the Virtual Source to see what happens: Set Wave to Sine and Level to half of full scale. With an X-axis sampling frequency of 20 kHz and N = 512, one cycle per N samples is 20000 / 512 or 39.0625 Hz. Set AM Hz to 39 and AM Pct to 100. The waveform should look very bouncy, since it is still being triggered on the "carrier", and the AM wave is not synchronized to it.
Go to the Trigger control menu and set Source to AM. You'll see a flat-nosed whale whose nose starts at half of full scale, back rises to full scale and swoops down to zero, and tail rises back to half-scale... we are triggering on the modulator, and modulator zero is the original half-scale signal level. Instead, set the trigger Level to minus full scale: The negative modulator peak is where the output goes to zero, so now our trace starts at zero, and yes, ends at zero as well... just what we wanted.
Now flip FFT on and look at the spectrum: A slightly fatter peak with skirts almost as low as when we had the sine wave set for exact integer cycles. Change the frequency and the peak moves to match, changing only slightly in level with nothing much happening to the skirts. Problem solved!
The formal name for this process is "windowing", and the "window function" is the shape that we multiply the data by. In our AM case this is a sinusoid, and with our trigger arrangement it is really a cosine wave raised up so the negative peaks are at zero. For true AM, the positive peaks are at twice the carrier level, but this would force us to always limit our input level to half of full scale. Instead, we can make our raised cosine half as large, so the positive peak goes only to unity. Now when we multiply our data samples by this window, we will never need to worry about overloading anything, and we can just multiply the final spectrum magnitudes by two to correct for this.
This raised cosine is called a Hanning window, but there are many more shapes in use. Most are based on variants of this, usually with an additional cosine component at twice the frequency. Which one is the best?
As it turns out, none of the other windows is really all that much better than our first try, the Hanning window. There are tradeoffs, however, and for critical work it could make a difference. Ideally, we would like to have no leakage skirts at all, but the best we can do is control their shape.
The Hamming window (not to be confused with Hanning!) gives a narrower spectral peak than the Hanning at higher levels, in exchange for flaring skirts farther down. The Blackman, and its derivatives Blackman Exact and Blackman-Harris, give a wider peak than the Hanning but with even lower skirts. A Flat Top gives the widest peak, with skirts about like Hamming, but the top of the peak is flattest for the most accurate level readings with changing frequencies.
To familiarize yourself with these different windows, use the Virtual Source with AM Pct set to zero. (Set the trigger source back to Main and the trigger level to zero if they are still set from the above AM experiment.) Set Freq to give the widest spectral skirts in Y-log FFT mode, then activate the window (Windo) with the W-key. Use CTRL-W to bring up the Window control menu, and select each different window type in turn as you watch the shape of the spectrum. Change the frequency around and toggle Windo off and on, and try toggling Trig off and on as well to get the big picture.
You can see the actual shape of the window function itself by flipping to the waveform display while the window menu is active. The shape will be shown superimposed over the waveform. Note that the signal waveform is shown unwindowed unless you specifically activate Windo in the waveform mode... even if it was previously active in FFT mode. Daqarta keeps these states separate between modes.
OK, so now that we see how wonderful windows are, we can just pick a decent window type and always leave it on in FFT mode, right? WRONG! There are other aspects to windowing that we have not considered: The effect on transient signals, and on broadband signals like noise.
512 point FFT. Even though we see the output as a single narrow line, each filter actually accepts frequencies over a finite bandwidth that overlaps with adjacent filters. For a broadband noise signal, with equal energy at all frequencies, adjacent filters exactly complement each other's responses ("Nice looking skirt!" "Thanks, yours too!") so that the output of each is correct for total power when no window is used.
Unfortunately, the use of a window function has the effect of widening each filter so that it sees too much adjacent energy. Its output for broadband inputs is thus larger than it should be. In the case of the Hanning window, for example, the noise bandwidth of each filter is 50% wider than normal, so its power output is 1.5 times larger, or 1.76 dB greater.
For this reason it is necessary to use a special bandwidth correction factor when measuring broadband responses with a window. Of course, if the signal is only broadband, then there is no need for a window in the first place, because there are no regular waveforms to be off-integer.
skirts which may completely swamp any low level background noise. But even with windowing active the window itself may have skirt energy in the noise area.
The best way to handle this situation is to adjust the source frequency and/or sample rate to get an integer relation. If this is not possible, you must make certain that the window skirts are not obscuring the noise you want to measure.
Be sure to turn off the bandwidth correction factor when you make readings of the spectral peaks, and turn it back on when you read the broadband areas.
FFT modes, so you can apply the window while viewing the spectrum, but it won't be applied to the waveform display if you flip back to that. However, you can apply the window to the waveform if you want to see the same data that a windowed FFT would get as its input. This can be useful not only to get a feel for how windows work, but also to check that no important aspect near the beginning or end of of a waveform is being overly suppressed by the window.
The spectrum is unaffected by whether or not Windo is active in the waveform mode... it never gets "applied twice" when set in both modes.
When Windo is inactive, the title line above the trace will show Rect to indicate that a Rectangular window is applied to the data... the effective window function is unity for all data points, so the raw data just passes right through. When Windo is active, the title line will show the window type, such as Hann or Hamm, which was previously selected by the Window control menu.
Hanning (Hann):Good resolution of spectral peaks and good rejection of sidelobe leakage "skirts" at low levels for input signals that don't have an integer number of cycles in the N-points data set. A good choice for most uses.
One application for a Flat-Top window is where you are trying to measure the frequency response of a system using Peak mode spectral averaging with a frequency sweep. Because the input frequency is constantly changing, the poor amplitude accuracy of other window types causes a jagged or rippled frequency response: Some frequencies fall near a spectral line and give accurate, narrow peaks; others fall midway between lines and give lower, broader peaks. The Flat-Top has broad peaks for all inputs, and little variation in amplitude.
bandwidth overlap of each FFT line when a window is active. Use this only when you want to find the total energy or power with broadband sources such as noise or closely-packed harmonics. The peak amplitudes will be in error, but the energy or power will be correct. You will probably only need this when measuring the broadband portions of mixed narrow and broadband signals, since if the overall signal is broadband, you don't need any window at all.
printing or to reduce clutter in busy traces.
Questions? Comments? Contact us!We respond to ALL inquiries, typically within 24 hrs.
25 Years of Innovative Instrumentation
© Copyright 1999 - 2006 by Interstellar Research