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 | |
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.
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 | |
| 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
- Choose f_s from fastest frequency of interest + Nyquist margin.
- Design analog front-end (gain, anti-alias).
- Configure ADC (reference, channel, DMA for streaming).
- Apply calibration (offset/gain from known references).
- Optional digital filter in firmware.
See also Basics of electronics for op-amp conditioning.
Relevant topics
- Introduction to computer systems
- Data representation
- Input/output and DMA
- Nyquist–Shannon theorem
- Analog-to-digital converter
Starting points
- Calculate minimum f_s for a 500 Hz vibration signal — add 4× margin.
- Read one ADC channel with known voltage — compare to multimeter.
- Implement 8-sample moving average — plot raw vs filtered.
- 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.