18  Nyquist Sampling Theory

In 60 Seconds

The Nyquist-Shannon sampling theorem states that you must sample an analog signal at least twice its highest frequency component (f_sample >= 2 x f_max) to accurately reconstruct it digitally. Sampling too slowly causes aliasing – high frequencies masquerade as lower ones, corrupting your data. In practice, IoT engineers oversample at 2.5-5x and add hardware anti-aliasing filters to ensure reliable sensor readings.

Key Concepts
  • 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

18.1 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.

18.2 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

18.3 Nyquist-Shannon Sampling Theorem

To accurately digitize an analog signal, you must sample at least TWICE the highest frequency component.

\[f_{sample} \geq 2 \times f_{max}\]

For audio sampling human voice (max frequency \(f_{max} = 3400\) Hz), Nyquist requires \(f_{sample} \geq 2 \times 3400 = 6800\) Hz minimum. Telephony uses 8 kHz (17% margin). For music (\(f_{max} = 20\) kHz), CD audio samples at \(44.1\) kHz = \(2.205 \times f_{max}\), 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 \(|1000 - 1500| = 500\) 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).

Diagram of the Nyquist-Shannon sampling theorem showing that a continuous signal must be sampled at a rate of at least twice its highest frequency component to be accurately reconstructed from discrete samples
Figure 18.1: Nyquist-Shannon sampling theorem

The theorem has direct implications for how we choose sampling rates in practice, as shown below.

Detailed explanation of the Nyquist theorem illustrating the relationship between signal bandwidth, sampling frequency, and the conditions required for perfect signal reconstruction without information loss
Figure 18.2: Nyquist theorem explanation and implications

When the sampling rate meets or exceeds the Nyquist rate, the original signal can be perfectly reconstructed. When it falls below, the reconstructed waveform is distorted.

Graph comparing a properly sampled signal where the sampling rate exceeds twice the signal frequency against an undersampled signal where aliasing distorts the reconstructed waveform into a lower-frequency artifact
Figure 18.3: Nyquist theorem graphical representation

18.3.1 Why This Matters

Undersampling (too slow) causes aliasing - high frequencies appear as low frequencies!

Nyquist sampling theorem diagram showing proper sampling versus aliasing when sample rate is too low
Figure 18.4: Nyquist Sampling Theorem: Proper Sampling vs Aliasing

18.4 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:

  • Maximum sample rate: ~9,600 Hz (9.6 kHz)
  • Practical rate: ~1-5 kHz for stable readings

ESP32 ADC:

  • Maximum sample rate: ~83 kHz
  • Practical audio sampling: 16-48 kHz


18.5 Understanding Aliasing

Real-World Scenario:

You’re designing a predictive maintenance system for a manufacturing plant. The system monitors motor vibrations to detect bearing failures before catastrophic breakdown. Motors typically vibrate at: - Normal operation: 0-200 Hz (fundamental frequency + harmonics) - Bearing defect signature: 500 Hz peak - Critical failure precursor: High-frequency components up to 1 kHz

Your ESP32-based vibration sensor uses an accelerometer with analog output. You need to decide the ADC sampling rate.

Customer Requirements:

  1. Detect 500 Hz bearing defect signals reliably
  2. Minimize false alarms from aliasing artifacts
  3. Battery-powered operation (sampling consumes power)
  4. Real-time processing on ESP32 (limited RAM for buffering)

Engineering proposes three options: - Option A: Sample at 500 Hz (same as defect frequency) - Option B: Sample at 1000 Hz (2x defect frequency, Nyquist minimum) - Option C: Sample at 2500 Hz (5x defect frequency, oversampling)

Analysis:

Nyquist Sampling Trade-Offs for Vibration Monitoring

Option A: 500 Hz Sampling (FAILS)

  • Nyquist minimum for 500 Hz signal: 2 x 500 Hz = 1000 Hz
  • Sampling at 500 Hz = exactly at signal frequency → aliasing occurs!
  • Aliasing: Nyquist frequency is only 250 Hz, so the 500 Hz component folds back to |500 - 500| = 0 Hz (DC) or nearby low frequencies depending on phase
  • Result: Cannot detect bearing defects reliably → UNACCEPTABLE for safety-critical application

Option B: 1000 Hz Sampling (RISKY)

  • Meets Nyquist minimum (1000 Hz >= 2 x 500 Hz)
  • But: Real motors have frequency components >500 Hz (harmonics, noise)
  • If motor has 800 Hz component (unfiltered), aliasing occurs:
    • Aliased frequency = |800 Hz - 1000 Hz| = 200 Hz (false low-frequency artifact)
    • Appears as normal vibration, masking actual bearing defect
  • Problem: No margin for real-world signal complexity

Option C: 2500 Hz Sampling (RECOMMENDED)

  • 5x oversampling provides safety margin
  • Allows for anti-aliasing filter with gradual roll-off
  • Captures harmonics up to 1.25 kHz
  • Power Cost: 2.5x higher than Option B (ESP32: ~3mA @ 1 kHz → ~4.5mA @ 2.5 kHz)
  • Benefit: Reliable defect detection, worth the power trade-off for predictive maintenance

Aliasing Example - Why Undersampling Fails:

Sampling 2 kHz signal at 3 kHz (below Nyquist 4 kHz): - Nyquist minimum: 2 x 2 kHz = 4 kHz - Actual sampling: 3 kHz < 4 kHz → aliasing! - Aliased frequency: |2 kHz - 3 kHz| = 1 kHz - Critical failure: 2 kHz bearing defect appears as harmless 1 kHz vibration - Maintenance team ignores “false” 1 kHz signal → bearing fails → $500K production downtime


18.6 Sampling Rate vs Power Consumption

Tradeoff: Sampling Rate vs. Power Consumption

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!

18.7 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:

  1. Add hardware filter with f_cutoff = f_sample / 4
  2. Sample at 2.5-5x desired f_max
  3. 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 (\(f_{sample}/2\)). In practice, set the filter cutoff below Nyquist to allow for the filter’s gradual roll-off:

\[f_{cutoff} \leq \frac{f_{sample}}{2}\]

A common practical guideline is \(f_{cutoff} = f_{sample}/4\), which provides sufficient transition bandwidth for the filter to reach adequate attenuation by \(f_{sample}/2\).

Why? If high-frequency noise (>f_sample/2) reaches the ADC, it aliases to lower frequencies, corrupting data.

Design a passive RC low-pass filter for anti-aliasing. Enter the desired cutoff frequency or component values to calculate the filter response.

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

18.8 Interactive: ADC Sampling and Aliasing Demo

Experiment with ADC sampling concepts: adjust signal frequency, sampling rate, and ADC resolution to see how they affect signal reconstruction and observe aliasing when the Nyquist criterion is violated.

How to Use This Demo:

  1. Start with defaults (10 Hz signal, 100 Hz sampling) - observe clean sampling
  2. Increase signal frequency past 50 Hz (half of sampling rate) to see aliasing occur
  3. Watch the aliased frequency - a 60 Hz signal sampled at 100 Hz appears as 40 Hz!
  4. Increase sampling rate to eliminate aliasing
  5. Change ADC resolution to see how quantization levels affect the sampled values

Key Observations:

  • Nyquist Rule: When signal frequency > sampling rate / 2, aliasing occurs
  • Aliased Frequency: The signal “folds back” into the [0, fs/2] range
  • Quantization: Higher bit resolution = more voltage levels = finer measurements
  • Status Indicators: The dashboard above turns red when the Nyquist criterion is violated

Try These Experiments:

Experiment Settings What to Observe
Nyquist Limit f=49 Hz, fs=100 Hz Just under limit - OK
Aliasing f=60 Hz, fs=100 Hz 60 Hz appears as 40 Hz
Severe Aliasing f=90 Hz, fs=100 Hz 90 Hz appears as 10 Hz
More Samples f=20 Hz, fs=200 Hz Clean reconstruction
Low Resolution Any, 8-bit Visible quantization steps
High Resolution Any, 12-bit Smoother quantization

18.9 Sampling Rate Design Calculator

Use this calculator to determine the required sampling rate, storage needs, and estimated power draw for your IoT sensor design. Enter your signal parameters and the calculator will apply the Nyquist theorem with practical engineering margins.

How to use: Enter your signal’s highest frequency component, pick an oversampling factor appropriate for your application (2.5x for general IoT, 5x for industrial/safety, 10x for medical), then set your ADC resolution, recording duration, and channel count. The calculator outputs the Nyquist minimum, practical recommended rate, required anti-aliasing filter cutoff, storage budget, data throughput rate, and estimated ESP32 ADC current draw.


Sampling is like taking photos of a moving object – take photos too slowly and you miss the action!

18.9.1 The Sensor Squad Adventure: The Speed Camera

Sammy the Sensor was watching a spinning wheel. “I can see it spinning smoothly, going round and round!”

Max the Microcontroller said, “I cannot watch continuously like you, Sammy. I can only take snapshots – like photographs. Tell me what you see at each snapshot!”

So Max took a photo every second. But the wheel was spinning 10 times per second! In Max’s photos, the wheel looked like it was barely moving – or even going backwards!

Lila the LED was confused. “That is like when car wheels look like they spin backwards in movies!”

“Exactly!” said ADC Andy. “That is called ALIASING. Max is not taking photos fast enough, so the fast spinning LOOKS like slow spinning.”

Bella the Battery asked, “How fast does Max need to take photos?”

Andy did some math. “The wheel spins 10 times per second. Max needs to take at LEAST 20 photos per second – that is the Nyquist Rule: at least TWICE as fast as the thing is changing!”

Max tried again at 25 photos per second. Now the wheel looked perfect in his snapshots!

“Even better,” Andy added, “take 50 photos per second for extra safety. We call that oversampling!”

18.9.2 Key Words for Kids

Word What It Means
Sampling Taking snapshots of something that changes continuously
Nyquist Rule You need at least 2x as many snapshots as the speed of change
Aliasing When too few snapshots make fast things look slow (or wrong)
Oversampling Taking extra snapshots for safety (2.5-5x is common)
Anti-aliasing A filter that removes changes too fast for your snapshot speed

18.9.3 Try This at Home!

The Spinning Wheel Experiment!

  1. Ask someone to wave their hand back and forth quickly
  2. Blink your eyes slowly (once per second) – can you track their hand? (No! Aliasing!)
  3. Now keep your eyes open normally – you see smooth movement (high sample rate!)
  4. Try blinking faster and faster until you can track the hand again

What you learned: Your normal vision is like a high sample rate camera (about 60 frames per second). Blinking slowly is like undersampling – you miss what is really happening!

Scenario: You’re designing a smart doorbell that records 5-second audio clips when the button is pressed. The microphone outputs analog audio (20 Hz - 8 kHz human voice range). You need to select the ADC sampling rate for the ESP32 and calculate storage requirements.

Given:

  • Audio range: 20 Hz - 8 kHz (human voice with harmonics)
  • Clip duration: 5 seconds
  • ADC resolution: 12-bit (ESP32)
  • Available flash: 4 MB
  • Target: Store 100 clips

Step 1: Calculate Minimum Sampling Rate (Nyquist)

\[f_{sample} \geq 2 \times f_{max} = 2 \times 8000\text{ Hz} = 16,000\text{ Hz}\]

Step 2: Choose Practical Sampling Rate

Nyquist minimum is 16 kHz, but practical audio uses oversampling: - Standard rates: 8 kHz (telephone), 16 kHz (wideband), 44.1 kHz (CD quality) - Select 16 kHz (matches Nyquist minimum, adequate for doorbell voice)

Step 3: Calculate Storage Per Clip

Samples per clip: 16,000 samples/sec × 5 sec = 80,000 samples

Bytes per sample: 12-bit ADC → 2 bytes/sample (stored as 16-bit)

Storage per clip: 80,000 samples × 2 bytes = 160 KB/clip

Step 4: Verify Storage Budget

100 clips × 160 KB = 16 MB

Available: 4 MB → Insufficient!

Step 5: Optimization Options

Option A: Reduce sampling rate to 8 kHz (below Nyquist for 8 kHz signal) - Problem: Aliasing! 8 kHz components fold to 0 Hz (DC) - Result: Muffled, distorted audio

Option B: Reduce clip duration to 2 seconds - Storage: 16,000 × 2 × 2 = 64 KB/clip - 100 clips × 64 KB = 6.4 MB → Still too much

Option C: Compress audio (recommended) - Use 8-bit μ-law compression (telephone standard): 50% size reduction - 160 KB → 80 KB/clip - 100 clips × 80 KB = 8 MB → Still over budget

Option D: Hybrid solution (BEST) - Reduce sampling to 12 kHz (still above Nyquist for 6 kHz bandwidth) - Add 6 kHz anti-aliasing filter (removes >6 kHz before ADC) - Use 8-bit encoding - Storage: 12,000 × 5 × 1 byte = 60 KB/clip - 100 clips × 60 KB = 6 MB → Need to reduce to 66 clips OR add external flash

Final Design:

  • Sampling rate: 12 kHz
  • Anti-aliasing filter: 6 kHz cutoff (hardware RC filter)
  • Encoding: 8-bit μ-law compression
  • Storage: 60 KB/clip
  • Clips stored: 66 clips (fits in 4 MB with margin)

Key Lesson: Sampling rate directly impacts storage. Always verify the full system budget (sample rate × duration × resolution × quantity) before finalizing the design. Hardware filters enable lower sampling rates without aliasing.

18.10 Incremental Example Set: Sampling Rate Selection

Scenario: You’re reading a DS18B20 temperature sensor for a home automation system. Room temperature changes slowly over minutes/hours.

Given:

  • Temperature range: 20-30°C
  • Typical change rate: 0.5°C per hour
  • Sensor accuracy: ±0.5°C

Solution:

  • Maximum meaningful frequency: ~0.001 Hz (one change per 1000 seconds)
  • Nyquist minimum: 2 × 0.001 Hz = 0.002 Hz (one sample per 500 seconds)
  • Practical choice: 0.1 Hz (one sample every 10 seconds) = 100× oversampling
  • Power consumption: Minimal (0.005 mW with ESP32 deep sleep between samples)

Result: 0.1 Hz sampling captures all temperature variations while maximizing battery life.

Scenario: Design a wearable ECG monitor for arrhythmia detection. The QRS complex (the sharp peak in a heartbeat) contains clinically significant features up to 150 Hz, though most energy is below 40 Hz.

Given:

  • Clinically relevant bandwidth: 0.05-150 Hz (AHA/ACC diagnostic standard)
  • ADC: ESP32 12-bit @ max 83 kHz
  • Power: 250 mAh LiPo battery, target 24-hour continuous recording

Solution:

  • Maximum frequency: 150 Hz
  • Nyquist minimum: 2 x 150 Hz = 300 Hz
  • Practical choice: 500 Hz (3.3x oversampling)
    • Standard clinical ECG rate (AHA recommendation)
    • Captures QRS morphology detail needed for arrhythmia classification
    • Allows anti-aliasing filter with gradual roll-off above 150 Hz
  • Anti-aliasing filter: 2nd-order Butterworth, cutoff = 200 Hz (before 500 Hz sampling)
  • Storage: 500 samples/s x 2 bytes x 86,400 s = 86.4 MB/day (fits on 1 GB flash with margin)

Result: 500 Hz sampling meets clinical diagnostic requirements while keeping power draw under 5 mA for 24+ hour battery life.

Scenario: Design a wildlife audio recorder with 4 microphone channels. Different animals vocalize at different frequencies. The system must optimize storage/power by adapting sampling rates.

Given:

  • Channel 1: Infrasound (elephants, 5-20 Hz)
  • Channel 2: Birdsong (2-8 kHz)
  • Channel 3: Ultrasound (bats, 20-80 kHz)
  • Channel 4: Ambient (full spectrum, 20 Hz - 20 kHz)
  • Storage: 256 GB SD card, 30-day deployment
  • Power: Solar + 10,000 mAh battery

Solution:

Step 1: Calculate Nyquist minimums per channel

  • Ch1 (infrasound): 2 × 20 Hz = 40 Hz
  • Ch2 (birdsong): 2 × 8 kHz = 16 kHz
  • Ch3 (ultrasound): 2 × 80 kHz = 160 kHz
  • Ch4 (ambient): 2 × 20 kHz = 40 kHz

Step 2: Select practical rates (2.5× oversampling)

  • Ch1: 100 Hz
  • Ch2: 40 kHz
  • Ch3: 200 kHz (ESP32 limit = 83 kHz → requires external ADC)
  • Ch4: 100 kHz (requires external ADC)

Step 3: Calculate storage budget

  • Ch1: 100 samples/s × 2 bytes × 86,400 s/day = 17.3 MB/day
  • Ch2: 40,000 × 2 × 86,400 = 6.9 GB/day
  • Ch3: 200,000 × 2 × 86,400 = 34.6 GB/day (exceeds 30-day budget!)
  • Ch4: 100,000 × 2 × 86,400 = 17.3 GB/day

Step 4: Optimization strategies

  • Triggered recording: Only record when sound detected (reduces duty cycle 90%)
  • Compression: Use 8-bit μ-law (50% reduction) for Ch2/Ch4
  • Variable rate: Ch3 records only at night (bats), Ch2 only at dawn/dusk (birds)
  • Anti-aliasing filters: Per-channel analog filters (Ch1: 40 Hz, Ch2: 16 kHz, Ch3: 80 kHz, Ch4: 40 kHz)

Final Design:

  • Ch1: 100 Hz, continuous, 8-bit → 8.6 MB/day
  • Ch2: 40 kHz, 2 hours/day (dawn/dusk), 8-bit → 576 MB/day
  • Ch3: 200 kHz, 8 hours/day (night), 16-bit → 11.5 GB/day
  • Ch4: 48 kHz (CD-quality), event-triggered (10% duty cycle), 16-bit → 1.7 GB/day
  • Total: ~13.8 GB/day × 30 days = 414 GB → Still over budget!

Final optimization: Use lossless compression (FLAC) achieving 40% size reduction → 248 GB fits with margin on 256 GB SD card.

Key lesson: Multi-channel systems with diverse sampling rates require careful storage/power budgeting. Anti-aliasing filters are mandatory for each channel. Adaptive/triggered recording is essential for battery-powered deployments.

Key Takeaway

The Nyquist theorem is the single most important rule for digitizing analog signals: always sample at least twice the highest frequency present. Violating this rule causes aliasing, where high-frequency content masquerades as lower frequencies, producing silently corrupted data that looks plausible but is wrong. In battery-powered IoT devices, balancing sampling rate against power consumption is a critical design decision.

18.11 Summary

This chapter covered the Nyquist-Shannon Sampling Theorem - the fundamental rule for digitizing analog signals:

  • Nyquist Theorem: Sample at least 2x the highest frequency component (f_sample >= 2 x f_max)
  • Aliasing: Undersampling causes high frequencies to appear as lower frequencies
  • Aliased Frequency: f_alias = |f_signal - n * f_sample| (where n is the nearest integer) when Nyquist is violated; for signals between f_s/2 and f_s this simplifies to |f_signal - f_sample|
  • Anti-Aliasing Filters: Hardware low-pass filters remove high frequencies before ADC
  • Oversampling: Sampling at 2.5-5x f_max provides margin for filter roll-off
  • Power Trade-offs: Higher sampling rates consume more power; sample only as fast as needed

Understanding Nyquist is essential for avoiding aliasing artifacts in IoT sensor data.

18.12 Concept Relationships: Nyquist Sampling

Concept Relates To Relationship
Nyquist Rate Signal Bandwidth Nyquist rate = 2 × highest frequency component; 20 kHz audio requires ≥ 40 kSPS
Aliasing Under-sampling Occurs when f_s < 2f_max; 50 Hz signal sampled at 80 Hz appears as 30 Hz (80 - 50)
Anti-Aliasing Filter Nyquist Frequency Low-pass filter cutoff <= f_s/2 (practically f_max or f_s/4); attenuates frequencies above Nyquist to prevent aliasing
Oversampling SNR Improvement Each 2× increase in sampling rate improves SNR by ~3 dB (effectively 0.5 bits of resolution)
Oversampling Filter Complexity 4× oversampling reduces anti-aliasing filter steepness requirement from 96 dB/octave to 24 dB/octave
Decimation Data Rate After oversampling + digital filtering, downsample (decimate) to reduce storage/transmission bandwidth
Sampling Rate Power Consumption ESP32: ~2 mA base + 0.001 mA per sample/sec; 10 kHz sampling = 12 mA (6× higher than 100 Hz)

18.13 See Also

In This Series:

Related Topics:

18.14 Knowledge Check

Common Pitfalls

The Nyquist theorem requires at least 2x the highest frequency, but sampling at exactly 2x produces ambiguous results at that frequency. In practice, sample at 5-10x the highest signal frequency to leave margin for filter roll-off and timing jitter. A rule of thumb: if your highest signal frequency is 100 Hz, sample at 500-1000 Hz.

Electrical noise and interference exist at all frequencies regardless of the signal of interest. A 1 Hz temperature signal sampled at 10 Hz is contaminated by 50 Hz mains hum folded to 0 Hz DC offset if no anti-aliasing filter is present. Always filter before the ADC even if the signal of interest has very low bandwidth.

Sampling rate (samples per second) and sample acquisition time (how long each sample takes) are different concepts. The ESP32 ADC has a maximum sampling rate of approximately 100 kSps, but each conversion takes approximately 10 us. Triggering conversions faster than the ADC can complete them causes invalid readings. Always respect the minimum conversion time specified in the datasheet.

A 60 Hz (or 50 Hz) mains noise signal sampled at 100 Hz produces an alias at 40 Hz (or 50 Hz alias at 50 Hz = DC component). This adds a spurious offset to all ADC readings that looks like a sensor calibration error. When ADC readings have unexplained offsets or slow oscillations, suspect powerline noise aliasing before suspecting sensor calibration drift.

18.15 What’s Next?

Now that you understand sampling theory, explore the practical side of analog-to-digital conversion with worked examples and related topics.

Topic Link Why Read Next
ADC/DAC Worked Examples analog-digital-worked-examples.html Apply Nyquist calculations to real ADC and DAC design problems
ADC Fundamentals analog-digital-adc-fundamentals.html Deepen understanding of quantization, resolution, and conversion architectures
DAC and PWM Output analog-digital-dac-pwm.html See how digital signals are converted back to analog using DAC and PWM
Sensor Calibration ../sensors/sensor-calibration-lab.html Learn how sampling rate choices affect sensor measurement accuracy in practice