28 Sampling and Aliasing: Nyquist and Filters
28.1 Start With the Decision
A sensor can report a slow false wave when it samples a fast real signal. Sampling rate and filtering must protect the measurement before analysis begins.
28.2 Route Overview
This is part 1 of 3. Continue with Sampling Design: Product Scenarios.
28.3 Part Objectives
- Apply the Nyquist condition to a bounded sensor signal.
- Explain how aliasing and anti-alias filters change sampled evidence.
28.4 Start Simple
Prove a Fast Signal Does Not Become a Slow Lie
Picture a vibration monitor that reports a gentle wobble while the machine is shaking much faster. The stored trace may be neat and still be false.
Sampling rate means how many measurements are taken each second. State the fastest signal of interest and what the input filter removes before choosing that rate.
Apply a known slow tone, a near-limit tone, and one above the limit. Keep the source frequency, filter, sampling rate, raw samples, spectrum, and false component so another person can repeat the check.
This check covers chosen tones and one signal path, not every transient. The deeper sections develop aliasing, limits, filtering, oversampling, and reconstruction.
Imagine measuring vibration but sampling so slowly that a fast wobble appears as a slow false pattern. Nyquist sampling is the rule that prevents a changing signal from pretending to be something else. Start with the highest frequency you need to trust, then choose sample rate and filtering before collecting data.
- Nyquist-Shannon Sampling Theorem: A continuous signal can be perfectly reconstructed from its samples if the sampling rate fs is at least 2x the highest frequency component fmax in the signal; fs >= 2 x fmax is the Nyquist criterion
- Aliasing: The distortion that occurs when a signal is sampled below the Nyquist rate; high-frequency components above fs/2 fold back into the spectrum and appear as false low-frequency components that do not exist in the original signal
- Nyquist Frequency: The maximum frequency that can be represented without aliasing at a given sampling rate; equal to fs/2; signals at exactly the Nyquist frequency are ambiguously represented and may appear at any frequency from 0 to fs/2
- Anti-Aliasing Filter: A low-pass filter applied before the ADC to attenuate signal components above the Nyquist frequency before sampling; prevents aliased components from entering the digital data; cutoff frequency is typically set to 0.4 x fs or below
- Oversampling: Sampling at a rate significantly above the Nyquist minimum; spreads quantization noise over a wider frequency band, allowing it to be filtered out; oversampling by 4x and decimating effectively adds 1 bit of resolution
- Sample-and-Hold Circuit: The analog input circuit that captures (samples) the input voltage at a precise instant and holds it stable during the ADC conversion period; settling time of the S/H circuit limits the maximum usable sampling rate
- Quantization Noise: The error introduced by representing a continuous voltage as one of 2^N discrete levels; quantization noise is approximately white noise with amplitude +-0.5 LSB; SNR improvement = 6.02 dB per additional bit of resolution
- Signal Reconstruction: Recovering the original continuous signal from discrete samples using an ideal reconstruction (sinc interpolation) or practical low-pass filter; the reconstructed signal is an accurate replica of the original only if the Nyquist criterion was satisfied during sampling
28.5 Learning Objectives
By the end of this section, you will be able to:
- Apply Nyquist Theorem: Calculate minimum sampling rates for different signals
- Diagnose Aliasing: Explain why undersampling causes incorrect frequency representation and predict aliased frequencies
- Design Anti-Aliasing Filters: Specify hardware low-pass filter parameters to prevent high-frequency contamination before ADC
- Evaluate Sampling-Power Trade-offs: Select optimal sampling rates that satisfy Nyquist while minimizing energy consumption in battery-powered IoT devices
- Implement Oversampling: Use extra samples to improve effective resolution and reduce anti-aliasing filter complexity
Imagine trying to draw a smooth wave by only placing a dot every few seconds — if you place dots too infrequently, you get a distorted picture that looks nothing like the original wave. Sampling theory tells us exactly how often we need to measure a changing signal to capture it faithfully. The key rule is simple: sample at least twice as fast as the signal changes. This concept applies every time a sensor reads the physical world.
28.6 Prerequisites
Before diving into this chapter, you should be familiar with:
- ADC Fundamentals: Understanding how ADCs convert analog to digital
- Binary Fundamentals: Understanding of resolution and bit depth
- Basic Signal Concepts: Understanding of frequency (Hz) and waveforms
28.7 Why This Chapter Matters
Follow these connections in order: Sampling theory sounds mathematical, but it answers a brutally practical question: how often do I need to read a sensor so the data still represents reality. In real IoT systems, bad sampling choices create fake signals, missed events, wasted battery, and misleading analytics. The device may still produce numbers, but the numbers no longer describe the real world. This chapter gives students a way to choose sampling rates intentionally instead of guessing.
28.8 How To Use This Chapter
- Start with the Nyquist rule and the aliasing examples. Those are the ideas you must keep.
- Read the tables with real signal types slowly and compare them to devices you already know: temperature sensors, microphones, ECG signals, accelerometers, and vibration monitors.
- When you finish a section, ask yourself what would happen in a real product if the sampling rate were cut in half.
- Start Simple
- In 60 Seconds
- Key Concepts
- For Beginners: Sampling Theory
- Prerequisites
- Why This Chapter Matters
- How To Use This Chapter
- Nyquist-Shannon Sampling Theorem
- Phoebe’s Field Notes: Why Aliases Fold Back
- Deep dive: Putting Numbers to It
- Practical Sampling Rate Examples
- Checkpoint: Rate Selection
- Understanding Aliasing
- Vibration Monitor Check
- Sampling Tradeoffs for Vibration
- Sampling Rate vs Power Consumption
- Sampling Rate vs Power
- Checkpoint: Aliasing and Power
- Anti-Aliasing Filters
- Anti-Aliasing Filter Strategies
- RC Anti-Aliasing Calculator
- ADC Sampling and Aliasing Demo
- Sampling Rate Design Calculator
- Nyquist Rate Calculator
- Checkpoint: Filters and Calculators
28.9 Nyquist-Shannon Sampling Theorem
The first design question is simple: what is the fastest part of the signal you must preserve. Nyquist turns that question into the minimum sampling rate.
To accurately digitize an analog signal, you must sample at least TWICE the highest frequency component.
For audio sampling human voice (max frequency Hz), Nyquist requires Hz minimum. Telephony uses 8 kHz (18% margin). For music ( kHz), CD audio samples at kHz = , providing a 10% guard band for the anti-aliasing filter’s roll-off. If you undersample a 1 kHz tone at 1.5 kHz (below Nyquist 2 kHz), it aliases to Hz — you hear the wrong pitch. Power cost: sampling at 10 kHz vs 1 kHz increases ADC energy significantly (ESP32: ~2mA base + ~0.001mA per sample/s).
Inspect Figure 28.1 at this point because its depiction of nyquist-Shannon sampling theorem summary supplies the physical context for the prose.
Figure 28.1 gives separate roles to Nyquist-Shannon Sampling Theorem, pn = period of the “fastest” sine wave, and fn = frequency of the “fastest” sine wave. Following those roles reveals nyquist-Shannon sampling theorem summary. That reading provides the evidence needed for the section’s next calculation, comparison, or field check.
For verification, record the fastest sine-wave period pn, derive fn = 1/pn, and compare the sampling interval with half that period.
The theorem has direct implications for how we choose sampling rates in practice. Bare Nyquist is the mathematical minimum, but real devices usually need extra margin for noise, timing uncertainty, and anti-aliasing filter roll-off.
Trace Figure 28.2 before continuing. It turns how sample rate changes the reconstructed signal from a verbal claim into labelled evidence.
Figure 28.2 gives separate roles to How Sample Rate Changes, Teal is the true signal, dots are the samples,, and 1. Undersampling. Following those roles reveals how sample rate changes the reconstructed signal. That reading provides the evidence needed for the section’s next calculation, comparison, or field check.
28.9.1 Why This Matters
Undersampling (too slow) causes aliasing - high frequencies appear as low frequencies!
Inspect Figure 28.3 before why this matters; its labelled elements make aliasing in a real sampling scenario concrete enough to test against the circuit narrative.
Anchor Figure 28.3 on True waveform: period = 20 ms, which corresponds to the stated Shaft speed = 3000 RPM. Under Signal Aliasing and Sampling, compare that real motion with the more slowly changing sample sequence. The mismatch shows how sparse observations can imply a false shaft speed or direction, connecting the sampling theorem to a concrete monitoring failure rather than an abstract waveform exercise.
28.10 Practical Sampling Rate Examples
| Signal Type | Frequency | Minimum Sample Rate | Typical Rate | Reason |
|---|---|---|---|---|
| Temperature | ~0.01 Hz (slow) | 0.02 Hz | 1 Hz | Changes very slowly |
| Audio (human voice) | 300-3,400 Hz | 6,800 Hz | 8,000 Hz | Phone quality |
| Audio (music) | 20-20,000 Hz | 40,000 Hz | 44,100 Hz | CD quality |
| ECG (heart) | 0.5-100 Hz | 200 Hz | 250-500 Hz | Medical-grade clarity |
| Vibration | 10-1,000 Hz | 2,000 Hz | 5,000-10,000 Hz | Safety margin for harmonics |
| Accelerometer (gesture) | 50 Hz | 100 Hz | 200 Hz | Oversampling for noise |
Arduino Uno ADC:
Compare the examples by moving from the stated input to the resulting electrical behavior: Maximum sample rate: ~9,600 Hz (9.6 kHz). Practical rate: ~1-5 kHz for stable readings.
ESP32 ADC:
Compare the examples by moving from the stated input to the resulting electrical behavior: Maximum sample rate: ~83 kHz. Practical audio sampling: 16-48 kHz.
Checkpoint: Rate Selection
You now know:
- A 500 Hz signal needs at least 1000 Hz sampling.
- A 500 Hz vibration design usually uses 1250-2500 Hz instead of the bare minimum.
- A 3400 Hz voice band needs at least 6800 Hz; telephony uses 8 kHz.
28.11 Understanding Aliasing
Meeting the minimum is only half the story. Out-of-band frequencies can still make sampled data look clean but wrong.
28.12 Sampling Rate vs Power Consumption
Once the signal is sampled honestly, every extra sample must justify its current, storage, and transmission cost.
Option A: High-frequency sampling (1000 Hz): Captures fast transients, supports 500 Hz signal bandwidth, power draw ~5mW continuous (ESP32 ADC at 1kHz), generates 86.4 million samples/day, requires 345 MB/day storage at 32-bit
Option B: Low-frequency sampling (1 Hz): Adequate for slow environmental signals (temperature, humidity), power draw ~0.005mW with sleep between samples, generates 86,400 samples/day, requires 345 kB/day storage
Decision Factors: For battery-powered environmental sensors where signals change over minutes/hours, 1 Hz sampling extends battery life 1000x while capturing all meaningful variation. For vibration analysis, motor monitoring, or audio capture, 1000+ Hz is mandatory to avoid aliasing. A smart approach uses adaptive sampling: high rate during detected events, low rate during quiet periods.
Power vs Sampling Rate:
- ESP32 ADC power: ~2mA base + 0.001mA per sample/sec
- @ 100 Hz: 2.1mA
- @ 1 kHz: 3mA
- @ 10 kHz: 12mA
- For battery-powered devices: Sample only as fast as needed!
Checkpoint: Aliasing and Power
You now know:
- Sampling 500 Hz at 500 Hz fails: the Nyquist frequency is only 250 Hz, and the defect can fold to 0 Hz.
- A 1000 Hz design has no margin for an 800 Hz harmonic, which can appear as 200 Hz.
- Cost scales quickly: 1 Hz creates 86,400 samples/day and about 345 kB/day; 1000 Hz creates 86.4 million samples/day and about 345 MB/day.
28.13 Anti-Aliasing Filters
Problem: Real-world signals have infinite frequency components (noise, harmonics). How to ensure f_max before ADC?
Solution: Hardware Anti-Aliasing Filter
-
Passive RC low-pass filter:
- R = 10k ohm, C = 1uF → f_cutoff = 15.9 Hz
- Blocks frequencies >50 Hz before ADC sampling at 100 Hz
- Cost: $0.15 (resistor + capacitor)
-
Active Sallen-Key filter:
- Op-amp based, sharp roll-off
- 4th-order Butterworth: -80 dB/decade above cutoff
- Cost: $1-2 (op-amp + passives)
Best Practice:
- Add hardware filter with f_cutoff = f_sample / 4
- Sample at 2.5-5x desired f_max
- Apply digital low-pass filter in software for extra margin
Example: 500 Hz vibration monitoring
- Hardware filter: f_cutoff = 600 Hz (Sallen-Key 4th-order)
- ADC sampling: 2500 Hz (5x oversampling)
- Digital filter: 500 Hz FIR low-pass
- Result: Aliasing risk <0.01%, reliable defect detection
Anti-Aliasing Filter Design Rule:
Before the ADC, use a low-pass filter to attenuate frequencies above the Nyquist frequency (). In practice, set the filter cutoff below Nyquist to allow for the filter’s gradual roll-off:
A common practical guideline is , which provides sufficient transition bandwidth for the filter to reach adequate attenuation by .
Why? If high-frequency noise (>f_sample/2) reaches the ADC, it aliases to lower frequencies, corrupting data.
Example: 1 kHz accelerometer sampling without anti-aliasing filter
- Motor emits 1.2 kHz vibration harmonic
- Nyquist frequency: 1000 Hz / 2 = 500 Hz
- 1.2 kHz signal aliases to: |1200 Hz - 1000 Hz| = 200 Hz
- False reading: 200 Hz vibration appears in data (doesn’t exist!)
- Solution: Add RC low-pass filter with f_c = 400 Hz before ADC
28.14 ADC Sampling and Aliasing Demo
28.15 Sampling Rate Design Calculator
Checkpoint: Filters and Calculators
You now know:
- At 1 kHz sampling, a 1.2 kHz vibration harmonic can fold into a false 200 Hz reading.
- A 500 Hz vibration monitor can sample at 2500 Hz, use a 600 Hz hardware filter, and apply a 500 Hz digital filter.
- A first-order RC filter rolls off at -20 dB/decade; a 2nd-order Sallen-Key filter gives -40 dB/decade.
28.16 Continue to the Next Part
Carry this evidence into Sampling Design: Product Scenarios, which begins with For Kids: Meet the Sensor Squad!.
