DSP Sampling
DSP Sampling
DSP Sampling
NOTES:
6-1
Sampling
Nyquist Limit
NOTES:
6-2
Sampling
Sampling Theory
Sampled signals behave differently than continuous signals. In order to create or analyze sampled signals correctly, we need to apply proper sampling theory. In this chapter we explain the basics of sampling theory and coherent sampling, and introduce the student to potential problems and issues when dealing with sampled waveforms.
Sampling Requirements
Consider a continuous time signal that must be digitized and stored as a sequence of digital numbers. Sampling must occur at specific intervals, referred to as the sample time, and be converted to a digital number. These digital numbers are stored as sample points that describe the waveform. If the samples are taken correctly, an infinite-valued signal can be completely represented by a set of finite sample points. Sample time is the inverse of the sample frequency Fs.
Figure 6.1: Sampling a Continuous Waveform. In this example, 31 samples were taken over one cycle of the waveform. The samples are equally spaced in time. Sample 32 occurs at the beginning of the second cycle.
NOTES:
6-3
Sampling
Periodicity
Sampling theory applies to signals that are considered by the mathematics to be periodic even if they are not. Therefore, errors are introduced if a signal is sampled that is not periodic.
Sample Sets
A sample set is an array of digital information that represents a sampled analog signal. A sample set can be created using a Waveform Digitizer, or it can be mathematically created from an algorithm. A sample set contains no information about time or frequency in the numbers. It is important to understand the relationship between sample time and signal frequency and how they relate to the index of each sample value in a set. In general, more samples are better from the perspective of digitizing or generating signals. In this chapter, the discussion of sampling applies to both digitizing and generating signals. NOTES:
6-4
Sampling
0-1MHz
1-2MHz
2-3MHz
3-4MHz
.
Figure 6.2: How a Spectrum Analyzer Computes Frequency Data. An input is passed through several filters simultaneously, and the resulting RMS voltage is plotted on a display.
Each filter extracts the sinusoidal components in its bandpass range and sets the amplitude to be plotted for that band. The first benchtop spectrum analysis instruments worked this way, and some purely continuous spectrum analyzers still work this way. However, because DSP-based spectral analysis offers many advantages over traditional techniques, this type of spectral analysis is fast becoming obsolete, .
NOTES:
6-5
Sampling
The section, Fourier Series on page 2-23, describes how a complex waveform can be analyzed as a sum of pure sinusoids and discusses the mathematics required for the analysis. A set of discrete samples taken from a time waveform can also be analyzed and mathematically converted into a discrete set of frequency data that represents the sinusoidal frequency components of the waveform. The conversion of time to frequency data is performed with an algorithm known as the Discrete Fourier Transform.
n=0
(6.1)
where n = one of N samples, N = total number of samples, b = one of B frequency bins where each bin represents a frequency range of Fs/N and j is the imaginary operator. The DFT algorithm uses each sample point in the summation from 0 to N - 1 for each analyzed frequency. Note that all N sample points contain information about all B frequencies, thus each of the B frequencies for which information is desired requires a summation of N time sample products. Processing a DFT is slow, because N2 calculations are necessary. For example, a 2000 point DFT requires 4 million calculations, often floating point calculations, that are slower than integer calculations.
NOTES:
6-6
Sampling
For a 2048 point data set, an FFT requires 11,264 calculations; using a DFT requires over 4 million!
NOTES:
6-7
Sampling
time
amplitude
Replica
Signal
Replica
Replica
Replica
Figure 6.3: Ambiguity Inherent in Sampled Data. The sample points could represent any one of an infinite number of sinusoids.
Spectral Replication
Using DSP techniques, a set of amplitude samples over time can be converted into a set of samples in the frequency domain. The frequency information returned from a DSP operation such as an FFT can be ambiguous regarding frequency, because more than one sinusoid can fit the sample points. NOTES:
6-8
Sampling
A sample set contains the original test signal frequency (Ft), replicated at frequencies every k times the sample frequency in both the positive and negative directions. Figure 6.3 on page 6-8 illustrates this phenomenon; mathematically, the frequency components in the test signal are replicated to other frequencies as: F replica = k F s F t , k = integer Notice how the sampled waveform has identical components at additional frequencies; these replicas extend to infinity. The information returned by a DFT/FFT can be analyzed using the low pass data, that is, the band of frequencies out to Fs/2, ignoring the replicas. Note that the replicas extend to infinity in both directions. A sampled signal with a component higher than those in the band of interest, but lower than the sample frequency Fs can end up aliased into the frequency band of interest. This can be a problemif the input signal being sampled contains signal components greater than Fs/2, those signal components are folded into the frequency data for the original signal, distorting the spectral information. In fact, the spectrum from Fs/2 to Fs is not a replica per se - it is a mirror image. So is the spectrum from 3Fs/2 to 2Fs, and each even numbered spectrum. The odd numbered spectra are replicas.
Fs - F t
Ft Fs/2
F s - Ft Fs
Fs + F t
2Fs - Ft 3Fs/2
Frequency
Figure 6.4: Spectral Replicas and Mirror Images. A set of discrete time domain samples results in a continuous frequency domain representation.
NOTES:
6-9
Sampling
Aliasing
Although replication and aliasing can mean the same thing, we prefer to define aliasing as the distortion of frequency results due to signal components that are folded into the frequency band of interest from outside the Nyquist band.
2nd Harmonic
3 Harmonic
rd
4 Harmonic
th
5 Harmonic
th
6 Harmonic
th
7 Harmonic
th
Bin Freq
N/2 Fs/2
Figure 6.5: Effects of Aliased Signal on the Nyquist Band.
N Fs
An alias adds nonharmonically related frequency components to the sampled signal which cannot be distinguished nor removed from the signal of interest. In other words, a frequency component that is aliased into the frequency band of interest destroys the integrity of the information returned by the Fourier Transform. Notice in Figure 6.5 that the spectral band of interest is from 0 to Fs/2. Unless removed, replicas from other areas in the spectrum will be aliased into the low pass band of interest, corrupting the frequency data.
NOTES:
6-10
Sampling
An Aliasing Example
A common set of test parameters for a telecom device uses a test frequency of 1020Hz, sampled at 8KHz. The fourth harmonic and any higher frequencies will cause aliases to appear in the frequency spectrum.
Nyquist Band
1020Hz
4KHz
8KHz
Figure 6.6: Aliasing Example. The fourth harmonic appears at the wrong frequency. Instead of appearing at 4080Hz, it wraps back to 3920Hz.
NOTES:
6-11
Sampling
AntiAliasing filter
Figure 6.7: Use of an Anti-Aliasing Filter. The filter removes frequencies above the Nyquist Limit prior to digitizing.
NOTES:
6-12
Sampling
Spectral Leakage
Recall that Fourier transform algorithms assume that time data passed to them is periodic. Because the DFT/FFT returns a discrete set of amplitude points in the frequency domain, its results contain information only about frequencies that are integer multiples of the fundamental frequency Fs/N. The result of this and the assumption of periodicity is that frequency components contained in the sample set which are not integer multiples of Fs/N leak into the frequency points which are returned by the DFT/FFT.
Same sample points appended time Incomplete set of sample points Generates high frequency components
Figure 6.8: Sample Set with Spectral Leakage. Too many samples were taken, causing the non-overlapping effect.
NOTES:
6-13
Sampling
Figure 6.9: Spectral Leakage in the Frequency Domain. The leakage will interfere with signal-to-noise ratio testing.
NOTES:
6-14
Sampling
The primary tradeoff when using windowing functions is the width of the main lobe versus the height of the side lobes.3 To prevent windowing functions from dominating the spectral information generated from the time samples, the main lobe must surround the test signal fundamental frequency and the amplitude of the side lobes must be less than the test signals noise and harmonics amplitudes.
NOTES:
6-15
Sampling
The windowing functions available in a mixed signal ATE system will accept a time sample array and return a windowed sample set array automatically.
NOTES:
6-16
Sampling
Figure 6.10: Windowing in the Frequency Domain. A Blackman-Harris window has been applied to the spectrum shown in Figure 6.9.
Figure 6.11: Windowing in the Time Domain. Note the reduction in amplitude at the end points, as well as in the middle of the waveform.
NOTES:
6-17
Sampling
time Wp=0
time
Wp
Figure 6.12: Sin(x) / x Amplitude Error from a DAC. The DAC provides a zero order hold function on the set of impulses. This time domain convolution results in frequency domain multiplication.
NOTES:
6-18
Sampling
When the frequency conversion math is performed for this series of rectangles, the frequency spectrum of a sine wave is multiplied by the spectrum of a rectangle, that has a sin(x) / x characteristic. The magnitude spectrum of a rectangle is shown at the top of Figure 6.13. The amplitude error versus frequency for the generated sine wave can be seen in the lower diagram. The error can be compensated with a filter or precompensated by modifying the data going to the waveform generator.
Magnitude of sin(x) / x
1 2 3 __ __ __ Wp Wp Wp
Less error results from higher sample frequency
Fs/2
Fs
2Fs
True Signal Spectrum Figure 6.13: Sin(x) / x Amplitude Error. The top figure shows the FFT of a rectangular pulse. The bottom figure shows the results of multiplying pulses of various widths by a frequency spectrum of interest.
NOTES:
6-19
Sampling
Notice that the pulse width in Figure 6.12 on page 6-18 is equal to the sample period or 1/Fs, causing the frequency characteristic of the sin(x)/x curve to be zero at integer multiples of Fs. In a test situation, all frequencies of interest will be between DC and Fs/2. The error is an amplitude multiplication factor with bounds of zero and one, which is related to the ratio of the signal and sample frequencies. The higher the ratio Fs/Ft the less amplitude error as seen in the large diagram in Figure 6.13. The multiplication factor is given by the sin(x)/x equation as related to Fs and Ft: F t sin -------- Fs Multiplier = --------------------F t -------Fs
(6.2)
For any frequency component equal to the Nyquist frequency, the ratio of Fs/Ft will be two, and the multiplier value will be 0.6366 or (-3.9dB). The multiplier will be one at DC and zero for any frequency that is an integer multiple of Fs. Figure 6.13 shows that higher sample frequencies yield less amplitude error. The effect is more clear in the time domain, when the samples are closer together; the stepped DAC output more closely approximates a true sinusoid. As Fs goes to infinity, the slope of the frequency domain sin(x)/x curve in Figure 6.13 near the frequencies of interest goes to horizontal, and the amplitude error goes to zero.
Truncation error
Digitizers do not have infinite resolution. If data is stored in a 16-bit word, it allows integer storage of quantities from 0 to 65535 (216). To calculate signal power, it is necessary to square the voltage, which will require more bits than the original value. When stored back into a 16-bit word, all bits that extend past the end of the 16-bit register are truncated. Although this is a simplified example of truncation error, it exists in any digitized signal. Digitized values are often represented using floating point values, which reduces truncation errors but does not eliminate them. Truncation errors are minimized by using double length variables and registers.
NOTES:
6-20
Sampling
Quantization Error
Waveform digitizers, and ADCs in general, may be used to digitize signals. This process consists of two pieces: sampling and quantization.
Q U A N T I Z A T I O N
SAMPLING
Figure 6.14: Digitization Process
The power of two to which an ADC can resolve a signal is the resolution of the digitizer, while the minimum value to which it resolves is one LSB. For example, an ADC which converts an analog signal to a 12-bit wide data word resolves that signal into one of 4096 values. A 12-bit ADC, with a 5V full scale input range, has an LSB size of 10V/212, or 2.44mV. This digitizer could not be used to directly measure an offset voltage of 100V because it cannot resolve any voltage smaller than 2.44mV. In this example, any analog signal change less than 2.44mV cannot be stored, or quantized, no matter how good the ADC. This results in an error known as quantization error, or Q. Q is bounded by 1/2 LSB. It is equally likely to be any value between 1/2 LSB.
1
-1/2 LSB
+1/2 LSB
NOTES:
6-21
Sampling
The maximum signal to noise ratio of an ADC depends directly on the quantization error:4 V in 6.02 bits + 4.77 + 20 log -------- dB = SNR V FS
(6.3)
where Vin and VFS are the ADC input signal and full scale input range as RMS values. If a sine wave analog input signal has a peak value equal to the ADC full scale input range, then the maximum (ideal) SNR of the digitizer is: SNR = ( 6.02 bits + 1.76 ) dB
(6.4)
Thus you can expect to measure an incoming analog signals SNR to no better than this ideal value for the digitizer. This also means that, to see the best test results, you must condition your analog signal such that it matches the full scale range of the ADC in the digitizer. The concept of quantization error and the derivation of Equation 6.4 are continued in Chapter 8.
NOTES:
6-22
Sampling
Jitter Error
When digitized information is examined with a Fourier transform, the DFT/FFT algorithm assumes that the data was sampled at precise intervals with no time jitter. Any time deviation in the digitizer clock from its expected value causes an error. Jitter in the clock will distort the data the same way as if the signal had jittered. When a signal is digitized, only its amplitude information is preserved. The data in the time sample array appears to the math algorithm as amplitude error, distorting the time waveform. Time jitter in a sampler distorts the frequency analysis results, which may appear as noise. Suppose the sample timing is perfect and the input sine wave has no amplitude distortion, but jitters in time; the result is the same. In other words, jitter in either the sample timing or the analog signal timing can result in frequency distortion. If there is sample and signal jitter that is statistically independent, the problem is compounded even further. If there is sample and signal jitter that always moves exactly the same, the problem is hidden; this occurs when both the analog signal and the sample timing are created via a master clock.
NOTES:
6-23
Sampling
Coherent sampling
Coherent sampling defines a way to guarantee that a sample set has a fixed, well defined relationship between the sample frequency Fs, the number of samples N, the test signal frequency Ft and the number of test signal periods sampled M. Coherent sampling restricts the timing relationships that exist between the test signal period and the sample period, making the timing setup for testing a particular device somewhat more difficult than with noncoherent sampling. It also requires a known waveform type, usually sinusoidal, as the input to a digitizer (ADC or WD) and the output of a generator (DAC or WG). If certain constraints are met, coherency also guarantees that the maximum amount of information about a particular waveform exists in the sample set (i.e. there are no duplicate samples).
Frequency Bins
A FFT operation on a set of coherent samples taken in the time domain produces frequency amplitudes in the spectrum being tested; and puts all relevant information about the fundamental, its harmonics, and noise into specific, well defined frequency ranges of equal width. These frequency ranges are called bins. The width of a bin is determined by the relationship of the sample frequency to the number of samples taken. It is also related to the relationship of the test signal frequency and the number of test frequency cycles. This subject will be covered in greater detail later on in this chapter.
NOTES:
6-24
Sampling
Referring to Equation (6.5), note that N samples may be taken from a waveform over M test signal periods. If M = 1, all samples are taken in a single test signal period. If M > 1, the samples are spread over more than one test signal period. The total time required to take all samples is called the Unit Test Period (UTP) and requires M cycles of the test signal, which has frequency Ft.
NOTES:
6-25
Sampling
Fourier Frequency
The resolution of the spectrum (the width of each frequency bin) is determined by the UTP of the sample set and is called the Fourier frequency (FF) or frequency resolution (Fres): Fs Ft 1 FF = F res = ----------- = ---- = ---N M UTP
(6.7)
Frequency Bins
Since the total number of frequency bins used for spectral analysis is N/2 and the resolution of the frequency bins is the Fourier frequency, we can state that the maximum frequency in the spectral data is Ftmax= Fres*(N/2). With Fres = Ft/M, the fundamental test frequency Ft will appear in the Mth frequency bin.
6-26
Sampling
The sample placement on the time domain waveform looks funny. This is because there are only about 8 samples per cycle of the waveform. This does, however, meet the Nyquist criteria for sampling. Is this a good set of sampling parameters? For capture, it has one major drawback - the number of samples N is not a power of two. For waveform creation, this is not required, since an FFT is not executed.
NOTES:
6-27
Sampling
In the frequency domain, the spectral components are spaced equally at intervals of FF.
1020Hz Bin 51
You can see that the fundamental of 1020Hz is in the Mth bin. Since the FF is 20Hz, this is correct (51 * 20 = 1020Hz). Each frequency component represents the energy across a small bandwidth of 20Hz. If greater resolution is required, the number of bins can be increased, thereby decreasing FF.
NOTES:
6-28
Sampling
Spectral Parameters
DFT and FFT Transforms
Figure 6.18 graphically displays a Fourier transform performed on a coherent sample set that will produce N + 1 spectral components called frequency bins. The first half of the spectrum contains N/2 + 1 points. A mirror duplicate of the first N/2 points was created in the second half of the spectrum, but it was discarded. Only the first N/2 + 1 bins are used. The first bin (Bin 0) is the DC component, which is not used in spectral analysis.
0.0
-20.0
-80.0
N/2 Fs 2
Figure 6.18: Frequency Axis Data from FFT. This figure shows a generic frequency spectrum, and how the Fourier Frequency (FF) is derived.
NOTES:
6-29
Sampling
Digitizing samples
Sampling is not a complicated process. Only four things must be determined: 1.How many samples of a waveform are required (N) 2.How often the samples should be taken (1 / Fs) 3.Over how many cycles of the test waveform they should be taken (M) 4.Tester timing resolution With these decisions made, put the signal into the digitizer, take the samples and store them.
NOTES:
6-30
Sampling
NOTES:
6-31
Sampling
Fast test.
Fast test Easy to create filter input signal using Inverse FFT
As noted in the last column of the last row in Table 6.2, it is easy to create a tone containing multiple frequency components using an Inverse FFT. Fill an array with frequency data having very small values (e.g. -160dB) for the frequency points with no amplitude, and large values (e.g. 0dB) for frequency points at the tone components.
NOTES:
6-32
Sampling
NOTES:
6-33
Sampling
NOTES:
6-34
Sampling
References
1. C. E. Shannon, Communication in the Presence of Noise, Proceedings of the Institute of Radio Engineers, Vol. 37, 1949, pp 10. 2. Matthew Mahoney, DSP Based Testing of Analog and Mixed Signal Circuits, IEEE Computer Society Press, 1987, pp 37. 3. Understanding Digital Signal Processing, Richard G. Lyons, Addison Wesley Longman, Inc., 1997, pp 86. 4. Ibid, pp 362.
NOTES:
6-35
Sampling
NOTES:
6-36