NIWeek99 Annual International Conference, National Instruments, Austin, TX, 1999.
NIWeek99 Conference Proceedings CD: (c) 1999 by National Instruments.
The Art of Signal Sampling and Aliasing:
Simulation with a LabVIEW Virtual Instrument
"What we see is not what it is!"
|By Professor M. Kostic |
Northern Illinois University
www.kostic.niu.edu or www.ceet.niu.edu/faculty/kostic
Products Used:LabVIEW, LabPC+ DAQ board, Demo-box with function generator
An interactive LabVIEW virtual instrument is developed to qualitatively and quantitatively simulate sampling of an arbitrary frequency signal while changing sampling frequency. The effect of sampling frequency on the measured signal is observed graphically and interactively. Sampled signal distortion is effectively demonstrated, including peculiar interference phenomena, like "beat" wave, aliasing, and others.
If we measure (sample) real dynamic signal (s) using a measurement system, like data acquisition system or an oscilloscope, what we get (sampled signal, ss) may not be what it is (s). Distorted signal shape, "beat" wave, or aliasing (distorted frequency) may occur. It all depends on characteristics of the measurement system, like its sampling frequency (fs), frequency response and other properties. On Figure 1, a real measurement with LabPC+ DAQ board of a simple sine wave, generated by a National Instruments' Demo-box, resulted in a peculiar "beat" wave shape, due to interference of signal and sampling frequencies. This phenomenon will be simulated on Figure 2, when the sampling to signal frequency ratio is close to 2. It is known that the "beat" wave's "envelope" frequency equals to the difference between the sampling and double wave frequencies.
Figure 1: Real measurement of a simple periodic sine wave with sampling frequency close to the double wave frequency, see below (click on Figure to enlarge it).
Virtual Instrument and Results
To interactively evaluate and plot sampled/measured signal (ss) versus sampling time (t), the appropriate simulation procedure is developed as a LabVIEW virtual instrument, to sample a "real" signal (s) of frequency (f) with any sampling frequency (fs), or the corresponding sampling to signal frequency ratio (mfs=fs/f).
Arbitrary "real" signal frequency (f), and its number of periods (np), are given as input to define and plot the "real" signal (s) in time (t).
Calculated output values are: sampling frequency if the sampling to signal frequency ratio is given, the Nyquist frequency, the frequency ratio if the sampling frequency is given, aliasing to signal frequency ratio, the aliasing frequency, total number of sampled points, and number of sampled points per signal period or cycle; the latter should be equal to the sampling to signal frequency ratio. The input and output values and plot are clearly presented in the front panel of the developed virtual instrument, see Figures 2.
The sampled/measured signal (ss) with the corresponding "real" signal (s) with frequency (f) are plotted together in time (t). The larger the frequency ratio mfs (>5 or >10) the more realistic sampled signal shape is, see Figure 3 (mfs=8). The sampled signal (ss) will differ from "real" signal (s) if the sampling frequency (fs), i.e. its ratio (mfs=fs/f) is small. For example, if mfs<2, we even can not get the signal's (s) real frequency, but the aliasing will occur (remember Nyquist rule: fs>2f), see Figure 4.
Several characteristic examples are presented on Figures 2, 3, and 4. As seen on these Figures, the same signal "measured" with different sampling frequencies, appears quite differently in form, shape, and frequency. This paper's theme phrase, "What we see is not what it is!" is compellingly self-evident. Using the developed virtual instrument one may interactively (very clearly and vividly) experiment with different frequency ratios (mfs) and other values, and qualitatively and quantitatively demonstrate influence of sampling frequency on measurement of periodic signals. Note that the frequency ratio (mfs) is equal to the number of sampled points per signal's period or cycle!
(click on Figure to enlarge it).
Figure 2: If the sampling to signal frequency ratio is close to 2 (i.e. 2.10), the sampled simple periodic signal will appear as a very peculiar, so called "beat" wave shape, similar to one on Figure 1 obtained in real measurement in the lab
(click on Figure to enlarge it).
Figure 3: If the sampling frequency changes, everything else being the same, the sampled (measured) signal may appear somewhat or quite differently. If the frequency ratio, mfs=8 (i.e. fs=8f, for example), the signal will be pretty realistic
(click on Figure to enlarge it).
Figure 4: If the sampling frequency changes again (fs=500Hz), everything else being the same (f=1200 Hz), the sampling (measured) signal (fa=200 Hz) may appear quite differently from the real signal, see also the "folding diagram" below on Figure 5
Discussion and Conclusion
As explained above, the fal =fa=mfa*f, is the aliasing frequency of the signal with frequency f, also expressed as aliasing frequency ratio, mfa=fa/f. The Nyquist frequency, fN=fs/2 is the maximum frequency which could be measured for a given sampling frequency, fs. Any signal with higher than fN frequency will appear (or "fold back") as smaller aliasing signal frequency, according to the frequency "folding" diagram, see Figure 5. It will appear as if the signal frequency is much smaller. To avoid this misrepresentation, we have to filter the signal harmonics with higher than the Nyquist frequency or to sample at different sampling frequencies, thus different Nyquist frequencies (fN=fs/2). The real signal components, with smaller than Nyquist frequency, will not depend on sampling frequency, while the aliasing components will change/float with the changing Nyquist frequency (changing "folding").
Figure 5: The "folding" diagram, representing the aliasing frequencies of the two signals with real frequencies higher than the Nyquist frequency (click on Figure to enlarge it).
The concept of sampling is very well demonstrated by measuring angular speed of a rotating wheel in a dark room with a stroboscope. A reflective mark on a rotating wheel, for example, will be sampled (seen) when the strobe light fires. If the strobe firing (or blinking) frequency is the same as the wheel's rotational frequency, the reflective wheel's mark will be seen at exactly the same position, and it will appear that the wheel is stationary, does not rotate at all. The same will appear if the wheel rotates at any integer multiple of the strobe light frequency, since the reflective mark will be caught at the same position after that integer multiple of revolutions. These cases correspond to the zero aliasing frequency (i.e. they correspond to the left end of the "folding" diagram, like f2). If the wheel rotates somewhat faster or slower, it will appear that the wheel rotates very slowly in forward or backward direction, respectively, which is clearly indicative on the folding diagram. To see the "full" wheel's rotation, the sampling or strobe frequency has to be much bigger than the wheel's rotational frequency. Increasing the strobe frequency will fill up the dark room with continuous-like light and the real signal (wheel's rotation) will be "visible." A signal sampling is like probing the position of the rotating wheel in the dark with a strobe's intermittent light. If the "sampling" strobe frequency is slow, we may miss a lot of wheel's rotation "in the dark," and may wrongly conclude that the wheel rotates much slower or even in the wrong direction, due to aliasing.
Note that the sampling phenomena depend on the relative sampling and signal frequency ratio (fs/f=mfs, called for short here, the frequency ratio), so that the increase of the signal (or wheel) frequency has the same effect as the corresponding decrease of sampling (or strobe) frequency, or vice versa. Usually, for analysis of the phenomena it is more convenient to vary the strobe frequency than the wheel's rotation. However, in our virtual instrument either way is equally convenient. This paper gives a brief and "static" overview of the developed virtual instrument, which provide "live," what-if interactive simulation, essential for full understanding and appreciation of the art of signal sampling and aliasing.
Author Biography:M. Kostic is a professor in the Department of Mechanical Engineering at Northern Illinois University. He received his Ph.D. in 1984 from the University of Illinois, and then worked in industry for some time. Professor Kostic's teaching and research interests are Thermodynamics, Fluid Mechanics, Heat Transfer and related Fluid/Thermal/Energy sciences; with emphases on new technologies, experimental methods, creativity, design, and computer applications.
Contact Information:Prof. M. Kostic, Ph.D., P.E.