Loading header...

Sampling, Quantization, and Aliasing

An ADC does not record a continuous waveform. It takes snapshots at specific times and rounds each snapshot to the nearest available code. Sampling and quantization are powerful, but they also introduce limits that firmware cannot fix after the data is captured.

Learning Objectives

By the end of this lesson, you should be able to:

  • calculate ADC code size from reference voltage and resolution;
  • explain sampling rate and the Nyquist limit;
  • identify aliasing and why it is dangerous;
  • choose a practical anti-alias filter target;
  • separate resolution, accuracy, and noise-free performance.

Sampling in Time

Sampling rate f_s is the number of samples per second. Sampling period is:

$$
T_s=\frac{1}{f_s}
$$

A 10 kS/s ADC takes one sample every:

$$
T_s=\frac{1}{10000}=100\ \mu s
$$

title "Sampling a changing signal"
time start=0 end=10 unit=ms divisions=5

IN: sine label="analog input" amplitude=1 cycles=2 unit=norm color=#2563eb
CLK: square label="sample clock" low=0 high=1 duty=10 cycles=10 unit=mark color=#dc2626

The clock trace marks sampling instants, not a measured ADC output.

Nyquist Limit

For an ideal band-limited signal, the sampling rate must be more than twice the highest signal frequency:

$$
f_s>2f_\text{max}
$$

The frequency f_s/2 is called the Nyquist frequency. In real embedded systems, sampling only a little above Nyquist is rarely enough because filters are not ideal and signals contain noise, harmonics, and interference.

A practical rule is to sample at least 5x to 10x faster than the highest frequency you need to analyze, then filter anything above the useful band.

Aliasing

Aliasing happens when high-frequency content appears as a false lower-frequency signal after sampling.

$$
f_\text{alias}=|f_\text{in}-Nf_s|
$$

where N is the nearest integer that folds the input into the 0 to f_s/2 band.

Example: sampling a 7 kHz interference signal at 10 kS/s produces an alias at:

$$
f_\text{alias}=|7000-1\times10000|=3000\ \text{Hz}
$$

Firmware sees a fake 3 kHz signal unless the analog front end removes the original 7 kHz before sampling.

Quantization

An N-bit ADC has 2^N output codes. The ideal code width, often called one LSB, is approximately:

$$
\text{LSB}=\frac{V_\text{REF}}{2^N}
$$

For a 12-bit ADC with 3.3 V reference:

$$
\text{LSB}=\frac{3.3}{4096}=0.000805\ \text{V}=0.805\ \text{mV}
$$

Ideal code from input voltage is approximately:

$$
\text{code}=\left\lfloor\frac{V_\text{IN}}{V_\text{REF}}(2^N-1)\right\rfloor
$$

Quantization Noise

Quantization rounds the input to the nearest code. The error is ideally within about +/-0.5 LSB. For a full-scale sine wave, ideal signal-to-quantization-noise ratio is approximately:

$$
\text{SNR}_\text{ideal}=6.02N+1.76\ \text{dB}
$$

A 12-bit converter has an ideal SNR near 74 dB, but real circuits often deliver less because of reference noise, input noise, clock jitter, distortion, and layout.

Anti-Alias Filtering

An anti-alias filter is an analog low-pass filter placed before the ADC. Its job is to attenuate frequencies that would fold into the measurement band.

flowchart LR SENSOR["Sensor"] --> LPF["Analog low-pass filter"] LPF --> ADC["ADC sampler"] ADC --> DSP["Firmware processing"]

If a temperature loop only needs changes below 10 Hz, a low-pass filter before a 100 S/s ADC can reject mains hum and switching noise. If vibration analysis needs 2 kHz, the sampling and filter requirements are much stricter.

Common Mistakes

  • Sampling at exactly 2x the signal frequency and expecting clean data.
  • Assuming digital averaging removes aliased signals.
  • Confusing resolution with accuracy.
  • Forgetting that ADC input noise can be larger than one LSB.
  • Calculating LSB with volts but reporting millivolts incorrectly.

Summary

Sampling converts a continuous-time signal into measurements at intervals. Quantization converts each measurement into a finite code. Use f_s > 2 f_max as a minimum theorem, then add practical margin and an anti-alias filter. Use LSB = V_REF / 2^N to estimate code size, but remember that real accuracy also depends on reference, noise, offset, gain, timing, and layout.

Further Reading

Mind Map

mindmap root((Sampling)) Time Sampling rate fs Period Ts equals 1 over fs Nyquist fs over 2 Use margin Quantization N bits Codes equal 2 power N LSB equals Vref over 2 power N Error about half LSB SNR ideal equals 6.02N plus 1.76 dB Aliasing High frequency folds low Digital filters cannot undo Need analog low pass Check interference sources Applications Sensor logging Audio capture Motor current Vibration Common mistakes Exact 2x sampling No anti alias filter Resolution equals accuracy Wrong LSB units