 Home

Daqarta for DOS Contents

Introduction

Free Registration

Daqarta for DOS
Data AcQuisition And Real-Time Analysis
Shareware for Legacy Systems

From the Daqarta for DOS Help system:

## DISCRETE SINE AND COSINE REFERENCES:

Once we have properly sampled the input signal into digital form, our spectrum analyzer needs to multiply by sine and cosine reference waves in similar digital form.

Imagine a big circular table holding sine values for all angles around a full circle, as though we had replaced the numerals and tick-marks on a round clock face with the sine of the angle of the second hand at each position. If we then step through this table and read each value in order, we will generate a sine wave.

Since the table is circular, after we read the last value we proceed to wrap around and read the first again, and so on to generate a continuous wave. We can use the same table to generate a cosine wave just by starting at the 90 degree position and proceeding around as before.

The frequency of the generated wave depends upon how many complete cycles we step around per second. But we don't actually need to do this in "real" time, since we can have a copy of the sampled input signal in memory somewhere. We can use this copy over and over for each different reference frequency, for both sine and cosine waves, and perform the necessary multiplications and averages as fast as we can. We only need to insure that each input sample is multiplied by the same value as would happen in real time. We can thus take a single set of samples and multiply it by many different frequencies "at once", or at least "pretty darn quick", before the next set of input samples.

Suppose we have collected 1024 samples of our signal, and further suppose our sine table divides the whole circle into the same number of steps. (N = 1024, in Daqarta terms.) If we multiply each sine value from the table with each signal value in order, we will in effect be multiplying by a frequency that is one cycle per 1024 samples, or 1/1024 of the sample rate that was used to acquire the signal.

To multiply by other frequencies, we can just move around the sine table with bigger steps. For example, to get 2/1024 of the sample frequency, we skip every other step in the table. Of course, we will need to make two circuits of the table while we work through our set of 1024 signal data samples. For 3/1024 of the sample rate, we take every 3rd table value and make 3 circuits per 1024 samples, and so on up through 511/1024. We don't need to bother with 512/1024 of the sample rate, since that would be the Nyquist frequency and we already know we can't believe what we get with that!

We also need to average the results of our multiplications. For each frequency, we will have 1024 multiplications as we work through the input sample set, so we just add each of these products into one total, then divide by 1024 to get the average value for that frequency. We need to do this separately for sine and cosine waves at each frequency.

We can also determine the 0 frequency (DC) component of the signal just by averaging all the input samples. This is the same as if the reference waves were generated by taking 0 steps per sample: All the sine values would stay at the initial value of 0, so we can ignore them. All the cosine values would stay at 1, so we can skip the multiplication by them and just average the input samples directly.

## DFT FREQUENCY RESOLUTION:

The frequency resolution is just the sample frequency divided by the number of samples (which is also the number of steps in the sine table). If we have a sample rate of 10240 Hz for our N = 1024 samples, for instance, we will get 10 Hz resolution.

But what happens with an input of, say, 505 Hz falling between the 500 and 510 Hz reference frequencies? The multiplier product for each of these will contain a 5 Hz difference component, but it won't average to zero since our 1024 samples represent only 0.1 second... just one half-cycle of the full 5 Hz wave. The average value for a half-cycle of a sinusoid turns out to be 2 / pi or about 0.6366, so our spectrum analyzer will report both 500 and 510 Hz components, scaled to this fraction of the true magnitude that would have appeared at 505.

What's more, the 490 and 520 Hz reference products will contain 15 Hz difference components, and they won't average to zero either because we will have 1.5 cycles of these. The full cycle portion will average out, but the remaining half cycle is one third of the total so these components will show magnitudes scaled by 0.6366 / 3 or 0.2122.

The same phenomenon is repeated as we move farther above and below the true frequency: At 480 and 530 Hz we have 25 Hz components of which we have 2.5 cycles, with the half cycle making up 1/5 of the total so we have components scaled by 0.6366 / 5 = 0.1273. At 470 and 540 Hz we have components scaled by 0.6366 / 7, at 460 and 550 Hz they are scaled by 0.6366 / 9, and so on, giving "skirts" in our spectrum instead of one simple line. This effect is typically called "leakage", since energy appears to have leaked from the true frequency to many other frequencies.

Use the Virtual Source to view this phenomenon. Set the sample rate to 10240 Hz in the X-axis menu. NOTE: You will need to run with NO acquisition board driver in your DQA.CFG file. The default Virtual Source sample rate "timer" can easily be set to emulate 10240 Hz, whereas most real board timers (including the DEMO driver) can't hit this exact rate. They must use a sample period that is an integer number of a master clock rate, which is usually 1, 5, or 10 MHz, giving periods that are multiples of 1, 0.2, or 0.1 µsec... not the 97.65625 µsec needed. The demo requires a power-of-2 sample rate because N values are always powers of 2 and the Virtual Source Freq control only supports integer frequencies.

Set the Virtual Source Freq to 500 for an initial comparison. View the spectrum via the F-key and you will see one single line whose magnitude is the value you set for Level. Now change Freq to 505 to see the above-mentioned leakage skirts.

If you use the trace cursors to check the magnitudes, you will see that they don't come out quite right. The prior discussion ignored the half-cycle portions of multiplier products that are the sum of frequencies, but those also contribute a small amount. For a reference at 500 Hz, the "sum" term at 1005 Hz will contribute 0.6366 / 201, while at 510 Hz the 1015 Hz term will subtract 0.6366 / 203. This is because the frequency difference term changes polarity between these two cases, from 505 - 500 = +5 to 505 - 510 = -5, while the sum term does not. (A negative sine wave is the same as a positive sine with polarity inverted, as though we were starting at the zero point and going backwards in time to the negative phase of the preceding cycle.) Since the displayed spectrum shows magnitudes, however, all values are shown as positive.

Set Freq down to 105 Hz, and watch this bias toward the low frequency skirts become more pronounced. Since the sum terms are now lower in frequency, they make fewer full cycles over the 1024 product values being averaged, giving the odd half-cycle a bigger fraction of the whole.

The bias effect depends upon the phase of the input signal, assumed in the above discussion to be a pure sine. A cosine input gives reversed skirt bias, so that the high side components are greater. To try a cosine input, go to the Trig menu and set the trigger Level to maximum. (You can just enter an impossibly large number like '1k' for Level, and Daqarta will limit it to the maximum for the input range.) You can experiment with different trigger Level and Slope settings to produce input signals of any phase.

With trigger Level back at zero, flip back to view the waveform and you will see that the 105 Hz signal has an odd half-cycle shown on the trace, which turns out to give the largest possible skirts in the spectrum. Increasing or decreasing the Freq setting will place it nearer to one of the 10 Hz reference frequencies and reduce the skirts, as it makes the number of waveform cycles nearer to the next higher or lower integer.

Another way to think about this whole situation is to consider that the spectrum is always correct, given that the input samples are treated as one unit of a repeating waveform. If the set of input samples contains an exact integer number of cycles, then additional identical sets of samples can be spliced together to make a seamless infinite wave. But if the set ends with a fraction of a cycle, the splices will cause abrupt steps every N samples:

``` |- N samples --|

o           o   o           o   o           o
o o         o o o o         o o o o         o o

o   o       o   o   o       o   o   o       o

-----o-----o---------o-----o---------o-----o----

o   o           o   o           o   o

o o             o o             o o
o               o               o
```

The spectrum of such a stepped infinite wave will have just the type of leakage skirts that we have seen.

These skirts, or "sidelobes" as they are often called, can be reduced by changing the sample rate to minimize the fractional cycles. If this is not possible, a "window" can smooth the ends of the sample set to minimize the discontinuity. See Window Theory for a full discussion.

GO: