Skip to content
BoKSA

Sampling and A/D Conversion

Sampling and A/D Conversion

Introduction

The physical world is continuous; computers are discrete. Sampling measures a signal at intervals; A/D conversion quantizes each sample to a digital code; D/A conversion reconstructs analog output. Wrong sample rate causes aliasing; wrong reference voltage causes wrong readings — common embedded debugging traps.

This article covers Nyquist, sample-and-hold, ADC/DAC types, and digital filtering basics (FIR/IIR) as in Van Moergestel's signal-processing chapter.


Sampling

Sampling records the signal at times t = n · T_s, where T_s is the sample period and f_s = 1/T_s is the sample rate.

Parameter Symbol Unit
Sample period T_s seconds
Sample rate f_s Hz (samples per second)

Example: audio CD uses f_s = 44.1 kHz — one sample every ~22.7 µs.


Nyquist theorem

To reconstruct a signal with maximum frequency f_max, you need:

1
f_s > 2 · f_max   (Nyquist rate)

Practical rule: f_s ≥ 2.5–10 × f_max depending on filter quality and application.

If f_s is too low, aliasing folds high frequencies into the band you care about — irreversible without analog anti-alias filtering.

flowchart LR subgraph good [Adequate sampling] A[True signal] --> B[Correct digital representation] end subgraph bad [Undersampling] C[High freq masquerades as low freq] end

Anti-aliasing filter

Analog low-pass filter before ADC removes energy above f_s/2. On MCUs, oversample + digital filter can help, but you still need reasonable front-end bandwidth control for serious measurement.


Quantization

ADC maps continuous voltage to integer codes:

1
2
Resolution (bits) → 2^n levels
3.3 V reference, 12-bit ADC → 4096 levels → ~0.8 mV per LSB
Error type Cause
Quantization noise Finite steps
Offset/gain error Reference, calibration
DNL/INL Non-linear steps (datasheet specs)

ADC architectures

Type Speed Resolution Typical use
Flash Very fast Low (6–8 bit) Oscilloscope front-end
SAR (Successive Approximation) Medium 8–16 bit General MCU ADC
Delta-Sigma (ΣΔ) Slower High (16–24 bit) Audio, precision sensing
Dual-slope Slow High Multimeters

MCU built-in ADC is usually SAR — check acquisition time vs source impedance in datasheet.

Sample-and-hold

Input is held at a fixed voltage during conversion — required when input changes faster than conversion time.


DAC architectures

Type Notes
Resistor ladder (R-2R) Common, medium speed
PWM + filter Cheap "DAC" for motors, LEDs, low-fi audio
Sigma-delta DAC Audio codecs

PWM DAC: filter high-frequency switching to analog — resolution depends on timer bits and filter cutoff.


Digital filters (overview)

After digitizing, software can filter noise:

FIR IIR
Structure Sum of weighted past inputs Feedback + feedforward
Phase Can be linear phase Often non-linear
Stability Always stable Must check poles
MCU cost More taps for sharp cutoff Fewer coefficients

Moving average is a simple FIR — common for smoothing sensor readings.

IIR biquad sections appear in audio EQ — need floating point or fixed-point care.


Practical embedded workflow

  1. Choose f_s from fastest frequency of interest + Nyquist margin.
  2. Design analog front-end (gain, anti-alias).
  3. Configure ADC (reference, channel, DMA for streaming).
  4. Apply calibration (offset/gain from known references).
  5. Optional digital filter in firmware.

See also Basics of electronics for op-amp conditioning.


Relevant topics


Starting points

  1. Calculate minimum f_s for a 500 Hz vibration signal — add 4× margin.
  2. Read one ADC channel with known voltage — compare to multimeter.
  3. Implement 8-sample moving average — plot raw vs filtered.
  4. Generate sine wave via DAC or PWM + RC filter — measure THD with scope.

Focus points

  • Aliasing is not fixable in software after the fact — filter before ADC.
  • Reference voltage must be stable — noise on VDDA becomes noise in codes.
  • Acquisition time vs source impedance — datasheet formula matters.
  • Float vs fixed-point for filters on MCUs without FPU.

Key points

  • Sampling discretizes time; ADC/DAC discretize amplitude.
  • Nyquist: sample faster than twice the highest frequency of interest.
  • SAR and ΣΔ dominate MCU and precision applications respectively.
  • FIR/IIR filters process digital samples to reduce noise or shape frequency response.