Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 36 ยท Instrument Control and DAQ

Sampling, Nyquist and Aliasing

Choose a sampling rate for data acquisition: Nyquist theorem, aliasing, anti-alias filters, resolution and quantization, and basic LabVIEW signal analysis such as RMS and FFT.

When you set a rate in DAQmx Timing, you are deciding what the computer can know about the signal. Sample too slowly and you do not just lose detail: you can see a signal that is not there. This lesson explains how to pick rates and ranges and which LabVIEW functions analyse the result. LabVIEW is not available on this site, so the experiments use Python stand-ins that implement the same mathematics.

The Nyquist limit

A signal can be reconstructed from samples only if it contains no frequency at or above half the sampling rate. That half is the Nyquist frequency: f_N = fs / 2. With fs = 1000 S/s, frequencies up to 500 Hz are representable.

In practice you want a margin. For waveform shape you want 5 to 10 samples per period of the highest frequency of interest; for frequency measurement alone, about 2.5 times is a practical minimum.

Aliasing

A frequency above Nyquist folds back to a false lower one. The alias is |f - k * fs| for the integer k that lands in [0, fs/2]. A 900 Hz tone sampled at 1000 S/s appears as 100 Hz, and nothing in the data says it is fake.

Python Find the alias frequency

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The cure is not processing after the fact; once aliased, the information is gone. Instead:

  • Sample faster than twice the highest frequency present (including noise).
  • Use an anti-alias low-pass filter before the ADC. Many DAQ cards include one; delta-sigma cards oversample internally and filter digitally, so they avoid most aliasing automatically.
  • Use a sensor with a limited bandwidth.

Seeing it: sampling a sine wave

Python Sample a 900 Hz sine at 1000 S/s

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

The two sets of samples are the same, which is exactly why an alias cannot be distinguished from a real signal.

Resolution and quantization

An ADC with N bits splits its range into 2^N steps. The step (one least significant bit, LSB) is range / 2^N. A 16-bit card on a +/-10 V range has 20 / 65536, about 0.31 mV per count. On a +/-1 V range the same card resolves 30 microvolts, which is why you set the channel min and max to what you expect.

The ideal quantization error is up to half an LSB, and real cards add noise, so the effective number of bits is lower than the nominal.

Python Quantization step for different ranges

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Analysing the data in LabVIEW

The Signal Processing palette (Waveform Measurements, Signal Generation, Filters, Spectral) covers common needs:

  • Basic Averaged DC-RMS or Amplitude and Level Measurements for DC value and RMS.
  • Spectral Measurements Express VI or FFT Power Spectrum and PSD: spectrum from a waveform. Use a window (Hanning is a good default) to limit leakage when the signal is not periodic in the record.
  • Filter Express VI or the Filters palette (Butterworth, Chebyshev, FIR): remove noise or isolate a band. Filters need a sample rate input to place cut-offs correctly.
  • Waveform data type: DAQmx can return waveforms that carry t0, dt and the Y array, so graphs and analysis VIs know the time base automatically.

The FFT resolves frequencies in steps of fs / N where N is the number of samples: 1000 S/s and 1000 samples gives 1 Hz bins.

Python RMS and a simple DFT peak finder

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Practical guidelines

  1. Identify the highest frequency that matters, then sample at least ten times faster for waveform work.
  2. Filter before the ADC if there is noise above Nyquist.
  3. Choose the smallest input range that never clips.
  4. Use hardware timing for anything that needs even spacing; software timing in a Windows loop jitters by milliseconds.
  5. Acquire a whole number of periods or apply a window before an FFT.

Oversampling and averaging reduce random noise by about the square root of the number of samples, but they do not fix aliasing that already happened.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. What is the Nyquist frequency for a sampling rate of 2000 S/s?

    Nyquist is half the sampling rate.
  2. 2. A 700 Hz tone is sampled at 1000 S/s. At what frequency does it appear?

    700 is above 500, so it folds to |700 - 1000| = 300 Hz.
  3. 3. Where must an anti-alias filter be placed?

    Aliasing happens at sampling, so unwanted high frequencies must be removed before conversion.
  4. 4. What is the LSB of a 16-bit ADC on a -10 V to +10 V range?

    20 V divided by 65536 counts is roughly 0.305 mV.

Summary

  • Nyquist: you can only represent frequencies below half the sampling rate.
  • Higher frequencies alias to false lower ones and cannot be removed later.
  • Filter before sampling and pick enough rate and the tightest safe range.
  • LabVIEW's Signal Processing palette provides RMS, FFT, filters and waveform types.

Next: Designing State Machines