Data AcQuisition And Real-Time AnalysisScope - Spectrum - Spectrogram - Signal Generator
Software for Windows
Science with your Sound Card!
Gut-Level Fourier Transforms - Part 2:
A Clean Sweep
Last time, we saw how a conceptual spectrum analyzer can be made from a couple of multipliers and lowpass filters. It uses an adjustable reference oscillator with sine and cosine outputs to set the analysis frequency, which can be moved throughout a band of interest to measure the spectrum.
Fig. 3: Conceptual Spectrum Analyzer
The outputs of the multipliers will contain only components at frequencies that are the sum and difference of the reference frequency A and the input signal frequency B:
cos(A) × cos(B) = 1/2 × cos(A-B) + 1/2 × cos(A+B)
When any input signal component matches the reference frequency, the "difference" terms will be at zero frequency (DC), with an amplitude proportional to the input component. The lowpass filters remove all the non-zero frequencies, essentially finding an average value; since any sinusoid has an average value of zero, it doesn't contribute to the output.
The filters/averagers are the key to the frequency resolution of this device, and also to its response time. With sharp lowpass filters that cut off everything above 5 Hz, for instance, only input components that are within +/- 5 Hz of the reference will be passed, giving a frequency resolution of 10 Hz.
If the reference is 1000 Hz, signals from 1000 to 1005 Hz will produce 0 to 5 Hz difference signals from the multiplier, which will pass through the filters. Inputs from 995 to 1000 Hz will produce difference signals with negative frequencies, which will pass just as well. (A negative frequency means that the wave is moving backwards in time, so it goes through the identical values in reverse order. This is just another sine wave, but with negative polarity... it's heading up-slope when the normal sine is headed down.)
But we want to measure an entire spectrum, not just a single 10 Hz-wide slice. We can easily arrange for the reference oscillator to be swept in frequency to cover any range we wish. We would like to do this fast enough to produce a real-time display from the output, say in a tenth of a second or so, but there is a problem:
It turns out that any filter needs to be exposed to an input signal for a time that is at least as long as the reciprocal of its bandwidth, in order to give a meaningful output. This makes sense if you consider that sine waves of frequencies above the cutoff will need at least one full cycle to average to zero.
If we think of the sweep as a bunch of separate steps in the reference frequency, we would need to hold it at each step for the reciprocal of the filter bandwidth. That would mean about 0.1 second for each 10 Hz step; a 20 kHz audio spectrum would take 2000 seconds... more than 33 minutes!
Swept-spectrum analyzers actually work quite well for radio frequencies, because the required resolution is much coarser. That helps two ways: Continuing with the step analogy, the minimum time per step is shorter and it takes less of these bigger steps to cover a given range. The sweep time is thus the reciprocal of the square of the filter bandwidth, so with 10 kHz steps, for example, each would requires only 1 msec, and in 0.1 second we could cover a 1 MHz range.
But what about the audio range where 10 Hz is a reasonable resolution? Early real-time analyzers used a "time compression" technique, where a snippet of input signal was recorded, then repeatedly played back many times faster into a swept-spectrum analyzer. With a 50x speed-up, the effective frequency range would be widened by a factor of 50, allowing a 500 Hz resolution instead of 10 Hz for the same relative results. Since a 50x wider filter bandwidth allowed a 2500x faster sweep, a full 25 kHz spectrum could be displayed in 0.1 second.
Since complex hardware was required for time compression, on top of all the other spectrum analysis and sweep circuits, these were finicky beasts that are now totally extinct. Instead, as in so many other areas, purely digital methods have prevailed.
Digital Spectrum Analysis:
Conceptually, we can start with the exact same block diagram and theory. The only difference is that the input data will be sampled at some constant rate, yielding a series of digital numbers corresponding to the analog input voltages at the instant each sample was taken.
The sine and cosine reference frequencies must be likewise supplied in digital form, and the sets of input and reference values can then be digitally multiplied together, sample by sample.
The sine values can be read from a circular table that is pre-computed and stored in memory. For each successive input sample, the next sine value is just read from the table, rolling around as needed to create a continuous stream of reference values. Cosine values can be read from the same table simply by starting at the 90 degree location.
The lowpass filters can be implemented via digital equivalents, but that's usually only done for specialized single-frequency applications. Instead, there is a simpler method that lends itself to the multiple-frequency operation needed for spectrum analysis: Ordinary arithmetic averages are taken of a succession of samples as they come from each multiplier.
As with the filter approach, the average must include enough time samples to equal the reciprocal of the desired resolution bandwidth. At a sample rate Fs and desired resolution BW, the number of samples N needed is:
There are some serious shortcomings to using this fixed-length average instead of a lowpass filter, which we will deal with later, but they are compensated by the ease of computation. That's important, since what we really want is to compute an entire spectrum as quickly as possible.
To see how this can be done, let's first make a few assumptions:
Let's say we are using N = 1024 samples. The circular sine/cosine table will likewise have 1024 steps around one cycle, so if we multiply each of these by the input samples in sequence, we will be multiplying by a reference frequency of one cycle per 1024 samples, which is the same as 1/1024 of the Fs sample rate.
For the next band, the reference must be 2/1024 of Fs. We can easily accomplish this with the same table, just by taking steps that are twice as big, skipping every other value but going twice around the table. For 3/1024 we step by threes and make three cycles, and so on through all the bands up to N/2.
After all the bands have been computed using one set of input samples, the results are displayed and the whole process is repeated with another N input samples. The speed to do all this is limited only by computation time, so in theory we can create a real-time spectrum analyzer at audio frequencies or below.
The method just described is known as the Discrete Fourier Transform (DFT). It requires a lot of multiplications, which are typically one of the slower operations on most computers. All N samples must be multiplied by sine and cosine values, which takes 2N multiplications, and this must be repeated for all N/2 frequencies, for N² total multiplications... over a million if N = 1024.
Fortunately, back in the '60s a couple of talented guys named Cooley and Tukey at Bell Laboratories noticed that there were many redundancies in the DFT that could be eliminated, yet still give the identical results. Their method is called the Fast Fourier Transform, and is used nearly universally in place of the DFT. Next time, we'll look at some details of how it works, along with a few caveats.
In the meantime, you can experiment with the author's Daqarta for Windows software, which 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.)
Or just read more about Fourier Transform Theory from the Web version of the Daqarta Help system.
Contact us about
Questions? Comments? Contact us!We respond to ALL inquiries, typically within 24 hrs.
Over 30 Years of Innovative Instrumentation
© Copyright 2007 - 2017 by Interstellar Research
All rights reserved