%%{init: {'theme': 'base', 'themeVariables': {'primaryColor':'#2C3E50','primaryTextColor':'#fff','primaryBorderColor':'#16A085','lineColor':'#16A085','secondaryColor':'#E67E22','tertiaryColor':'#7F8C8D','clusterBkg':'#ECF0F1','clusterBorder':'#16A085','edgeLabelBackground':'#ECF0F1'}}}%%
flowchart LR
A["Analog Signal<br/>(Continuous)"] --> B["Anti-Aliasing<br/>Filter<br/>(Low-Pass)"]
B --> C["Sample & Hold<br/>Circuit"]
C --> D["ADC<br/>(Analog-to-Digital<br/>Converter)"]
D --> E["Digital Value<br/>(Discrete)"]
style A fill:#E67E22,stroke:#2C3E50,stroke-width:3px,color:#fff
style B fill:#16A085,stroke:#2C3E50,stroke-width:2px,color:#fff
style C fill:#16A085,stroke:#2C3E50,stroke-width:2px,color:#fff
style D fill:#2C3E50,stroke:#16A085,stroke-width:3px,color:#fff
style E fill:#E67E22,stroke:#2C3E50,stroke-width:3px,color:#fff
62 ADC Fundamentals: Sampling and Aliasing
62.1 Learning Objectives
By the end of this chapter, you will be able to:
- Distinguish Analog from Digital: Understand why sensors produce analog signals and why processors need digital data
- Apply Sampling Concepts: Explain the Nyquist theorem and calculate appropriate sampling rates
- Recognize Aliasing: Identify when sampling is too slow and how to prevent signal distortion
- Design Anti-Aliasing Solutions: Choose appropriate filters to prevent sampling artifacts
The Problem: Sensors measure the real world (temperature, light, pressure), which is continuous and smooth. But microcontrollers and computers only understand discrete numbers (0s and 1s).
The Solution: Signal processing bridges this gap by converting continuous analog signals into discrete digital values that computers can process.
Real-World Analogy: Imagine watching a movie. The real world moves smoothly, but a movie is actually 24 still pictures per second. Your brain fills in the gaps, so it looks smooth. Signal processing does the same thing - it takes “snapshots” of sensor values fast enough that we capture all the important information.
Key Terms:
| Term | Simple Definition |
|---|---|
| Analog Signal | Continuous value that can be anything (like temperature: 23.456789…C) |
| Digital Signal | Discrete value limited to specific numbers (like 23, 24, 25C) |
| Sampling | Taking snapshots of an analog signal at regular intervals |
| Sampling Rate | How many snapshots per second (measured in Hz) |
| Aliasing | Distortion when sampling too slowly (makes fast signals look slow) |
The Bottom Line: Sample fast enough (at least 2x the fastest change you care about) to capture what matters without wasting resources.
A wearable ECG sensor demonstrates the complete signal processing pipeline:
Raw Signal Characteristics: - Cardiac signal: 0.5-40 Hz frequency range (heart rate + waveform shape) - Powerline noise: 50/60 Hz interference from electrical environment - Muscle artifacts: High-frequency noise from arm movement - DC drift: Baseline wander from electrode contact variation
Processing Chain:
- High-pass filter (0.5 Hz cutoff): Removes DC drift and baseline wander
- Notch filter (50/60 Hz): Eliminates powerline interference
- Low-pass filter (40 Hz cutoff): Removes muscle artifacts and high-frequency noise
- Anti-aliasing filter (100 Hz): Prevents sampling distortion
- ADC sampling (250 Hz): Nyquist requires 2x the max frequency = 200 Hz minimum; 250 Hz provides 25% safety margin above Nyquist
- R-peak detection: Pan-Tompkins algorithm identifies heartbeat peaks
- Heart rate calculation: 72 BPM from R-R interval measurement (833 ms between peaks)
System Performance: - ADC resolution: 12-bit (0.8 mV precision for 3.3V range) - Power consumption: 1.2 mW continuous operation - Battery life: 8 hours on 50 mAh battery - Accuracy: +/-2 BPM compared to medical-grade ECG - Latency: <100 ms from heartbeat to BPM update
Key Lesson: Signal processing isn’t just about converting analog to digital - it’s about intelligently filtering noise, choosing appropriate sample rates, and balancing accuracy with power consumption.
62.2 Analog vs Digital Signals
62.2.1 The Continuous World
Physical phenomena are inherently continuous - temperature changes smoothly, light intensity varies gradually, and sound waves oscillate continuously.
Example: A thermometer might show 23.456789…C at one instant and 23.458123…C a moment later. There are infinite possible values between any two measurements.
62.2.2 The Digital Constraint
Microcontrollers and computers work with discrete digital values: - 8-bit number: Can only represent 256 different values (0-255) - 12-bit number: 4,096 different values (0-4095) - 16-bit number: 65,536 different values (0-65535)
This creates two challenges:
- Sampling: How often do we measure the signal? (temporal discretization)
- Quantization: How precisely do we measure each sample? (amplitude discretization)
ADC Pipeline: The complete analog-to-digital conversion process. Anti-aliasing filter removes high frequencies before sampling to prevent distortion. Sample & hold captures instantaneous voltage. ADC quantizes to nearest digital level. {fig-alt=“Flowchart showing analog-to-digital conversion pipeline: analog signal flows through anti-aliasing filter, sample-and-hold circuit, ADC, and outputs digital value. Components colored orange (input/output), teal (preprocessing), and navy (ADC core).”}
This variant shows the same ADC pipeline with concrete values from a real temperature sensor - making abstract concepts tangible:
%% fig-alt: "ADC pipeline with concrete temperature sensor example showing actual values at each stage. Analog Signal shows NTC thermistor outputting 1.234V for 23.5C room temperature. Anti-Aliasing Filter with 10Hz cutoff removes HVAC cycling noise, output unchanged at 1.234V. Sample & Hold captures voltage 1000 times per second, holds 1.234V during conversion. 12-bit ADC converts 1.234V to digital value 1534 (range 0-4095 for 0-3.3V). Finally, microcontroller maps 1534 back to 23.5C temperature reading. This concrete example shows what happens to real sensor data at each pipeline stage."
%%{init: {'theme': 'base', 'themeVariables': {'primaryColor':'#2C3E50','primaryTextColor':'#fff','primaryBorderColor':'#16A085','lineColor':'#16A085','secondaryColor':'#E67E22','tertiaryColor':'#7F8C8D','fontSize':'11px'}}}%%
flowchart TD
subgraph analog["1. ANALOG SIGNAL"]
A1["NTC Thermistor<br/>outputs 1.234V"]
A2["(23.5C room temp)"]
end
subgraph filter["2. ANTI-ALIASING FILTER"]
F1["10Hz Low-Pass<br/>removes HVAC noise"]
F2["Output: 1.234V<br/>(noise removed)"]
end
subgraph sample["3. SAMPLE & HOLD"]
S1["Captures voltage<br/>1000x per second"]
S2["Holds 1.234V<br/>during conversion"]
end
subgraph adc["4. ADC CONVERSION"]
D1["12-bit ADC"]
D2["1.234V -> 1534<br/>(0-4095 range)"]
end
subgraph digital["5. DIGITAL OUTPUT"]
O1["Microcontroller<br/>reads: 1534"]
O2["Maps back:<br/>23.5C"]
end
analog --> filter --> sample --> adc --> digital
style analog fill:#E67E22,stroke:#2C3E50,color:#fff
style filter fill:#16A085,stroke:#2C3E50,color:#fff
style sample fill:#16A085,stroke:#2C3E50,color:#fff
style adc fill:#2C3E50,stroke:#16A085,color:#fff
style digital fill:#E67E22,stroke:#2C3E50,color:#fff
Why this variant helps: The original shows abstract component names. This variant shows actual values flowing through a real temperature sensor - you can trace 23.5C from voltage (1.234V) through digital value (1534) and back. Understanding what happens to real data at each stage makes the pipeline tangible.
62.3 The Nyquist Theorem: How Fast to Sample?
The fundamental question: How many times per second must we sample to accurately capture a changing signal?
Nyquist-Shannon Sampling Theorem: > To accurately capture a signal, you must sample at more than twice the highest frequency component.
Minimum Sampling Rate = 2 x Maximum Signal Frequency
%%{init: {'theme': 'base', 'themeVariables': {'primaryColor':'#2C3E50','primaryTextColor':'#fff','primaryBorderColor':'#16A085','lineColor':'#16A085','secondaryColor':'#E67E22','tertiaryColor':'#7F8C8D','clusterBkg':'#ECF0F1','clusterBorder':'#16A085','edgeLabelBackground':'#ECF0F1'}}}%%
graph TB
subgraph under["Undersampling (< 2f)"]
U1["Sampling Rate: 0.8f<br/>(Too Slow)"]
U2["Result: Aliasing<br/>Signal appears distorted<br/>Fast signal looks slow"]
end
subgraph nyquist["Nyquist Minimum (= 2f)"]
N1["Sampling Rate: 2f<br/>(Barely Adequate)"]
N2["Result: Reconstructible<br/>Theoretically correct<br/>No margin for error"]
end
subgraph over["Oversampling (> 2f)"]
O1["Sampling Rate: 5-10f<br/>(Practical Choice)"]
O2["Result: Accurate<br/>Clean reconstruction<br/>Safety margin"]
end
U1 --> U2
N1 --> N2
O1 --> O2
style under fill:#E67E22,stroke:#2C3E50,stroke-width:3px,color:#000
style nyquist fill:#7F8C8D,stroke:#2C3E50,stroke-width:3px,color:#fff
style over fill:#16A085,stroke:#2C3E50,stroke-width:3px,color:#fff
style U1 fill:#ECF0F1,stroke:#E67E22,stroke-width:2px,color:#000
style U2 fill:#ECF0F1,stroke:#E67E22,stroke-width:2px,color:#000
style N1 fill:#ECF0F1,stroke:#7F8C8D,stroke-width:2px,color:#000
style N2 fill:#ECF0F1,stroke:#7F8C8D,stroke-width:2px,color:#000
style O1 fill:#ECF0F1,stroke:#16A085,stroke-width:2px,color:#000
style O2 fill:#ECF0F1,stroke:#16A085,stroke-width:2px,color:#000
Nyquist Sampling Comparison: Undersampling causes aliasing distortion. Sampling exactly at 2f is theoretically sufficient but risky. Practical systems oversample at 5-10x the signal frequency for reliability. {fig-alt=“Three-column comparison showing undersampling (red, causes aliasing), Nyquist minimum (gray, barely adequate), and oversampling (teal, practical choice with safety margin). Each shows sampling rate and resulting signal quality.”}
This variant uses a movie filming analogy to make sampling rate intuitive:
%% fig-alt: "Analogy comparing Nyquist sampling to movie frame rates. A spinning wheel at 30 rotations per second (like a car wheel at highway speed) is filmed at different frame rates. At 24 fps (too slow, below Nyquist), wheels appear to spin backward - this is aliasing, the same effect as undersampling. At 60 fps (exactly 2x, Nyquist minimum), wheels appear frozen - technically correct but no margin for faster motion. At 120 fps (4x, oversampled), wheels spin correctly with smooth motion - this is the practical choice like sampling at 5-10x signal frequency. Key insight: just as movies need enough frames to capture motion, IoT sensors need enough samples to capture signal changes."
%%{init: {'theme': 'base', 'themeVariables': {'primaryColor': '#2C3E50', 'primaryTextColor': '#fff', 'primaryBorderColor': '#16A085', 'lineColor': '#16A085', 'secondaryColor': '#E67E22', 'tertiaryColor': '#7F8C8D'}}}%%
graph TB
subgraph MOTION["Spinning Wheel: 30 rotations/sec"]
WHEEL["Like a car wheel<br/>at highway speed"]
end
subgraph SLOW["24 fps: TOO SLOW"]
S1["Below Nyquist (< 2x30)"]
S2["Wheel appears to<br/>spin BACKWARD"]
S3["This is ALIASING!"]
end
subgraph EXACT["60 fps: EXACTLY 2x"]
E1["At Nyquist limit"]
E2["Wheel appears<br/>FROZEN in place"]
E3["No margin for error"]
end
subgraph FAST["120 fps: OVERSAMPLED"]
F1["4x frequency (safe)"]
F2["Wheel spins smoothly<br/>FORWARD correctly"]
F3["Practical choice!"]
end
MOTION --> SLOW
MOTION --> EXACT
MOTION --> FAST
style WHEEL fill:#2C3E50,stroke:#16A085,stroke-width:2px,color:#fff
style S1 fill:#E67E22,stroke:#2C3E50,stroke-width:1px,color:#fff
style S2 fill:#E67E22,stroke:#2C3E50,stroke-width:1px,color:#fff
style S3 fill:#E67E22,stroke:#2C3E50,stroke-width:2px,color:#fff
style E1 fill:#7F8C8D,stroke:#2C3E50,stroke-width:1px,color:#fff
style E2 fill:#7F8C8D,stroke:#2C3E50,stroke-width:1px,color:#fff
style E3 fill:#7F8C8D,stroke:#2C3E50,stroke-width:1px,color:#fff
style F1 fill:#16A085,stroke:#2C3E50,stroke-width:1px,color:#fff
style F2 fill:#16A085,stroke:#2C3E50,stroke-width:1px,color:#fff
style F3 fill:#16A085,stroke:#2C3E50,stroke-width:2px,color:#fff
Why this variant helps: The original shows abstract frequency ratios (2f, 0.8f). Everyone has seen the “wagon wheel effect” in movies where car wheels appear to spin backward. This directly connects Nyquist undersampling to a visible, memorable phenomenon that students can visualize.
62.3.1 Practical Examples
Example 1: Temperature Sensor - Building HVAC changes slowly: ~0.01 Hz (1 cycle per 100 seconds) - Nyquist requirement: Sample > 0.02 Hz - Practical choice: 0.1 Hz (once every 10 seconds) provides 5x margin
Example 2: Heart Rate Monitor - Heart rate: 0.5-3 Hz (30-180 bpm) - Nyquist requirement: Sample > 6 Hz - Practical choice: 100-500 Hz to capture waveform shape, not just frequency
Example 3: Accelerometer for Vibration - Machine vibration: 0-1000 Hz - Nyquist requirement: Sample > 2000 Hz - Practical choice: 5000-10000 Hz for safety margin
The Myth: “I should sample as fast as possible to get the best data quality.”
Why It’s Wrong: Higher sampling rates don’t improve signal quality beyond Nyquist requirements - they just waste resources.
The Reality:
Misconception #1: “1000 Hz is better than 100 Hz for all sensors” - Reality: Temperature changes at 0.01 Hz. Sampling at 1000 Hz captures the same 0.01 Hz signal 100,000 times without gaining new information. - Cost: 10x higher sampling rate = 10x more power, 10x more data storage, 10x more bandwidth - Better approach: Match sampling rate to signal bandwidth (5-10x Nyquist, not 1000x)
Misconception #2: “16-bit ADC is always better than 12-bit” - Reality: If your sensor accuracy is +/-1% (e.g., thermistor), 12-bit resolution (0.025%) already exceeds sensor precision by 40x. Using 16-bit (0.0015%) provides 667x more precision than the sensor can deliver! - Cost: 16-bit ADCs typically consume 3-5x more power than 12-bit - Better approach: Match ADC resolution to sensor precision, not maximum available bits
Real-World Example: - Inefficient design: Soil moisture sensor sampled at 1 kHz, 16-bit ADC, no filtering - Soil moisture changes over hours (0.0003 Hz) - Power consumption: 5 mA continuous - Battery life: 20 hours
- Optimized design: Same sensor sampled at 0.01 Hz (once per 100 seconds), 10-bit ADC, median filter
- Captures all relevant changes (30x Nyquist margin)
- Power consumption: 50 uA average (100x reduction!)
- Battery life: 2000 hours (83 days)
- Data quality: Identical for the application
Key Lesson: “Good enough” signal processing saves 100x power without sacrificing data quality. Over-specification wastes resources on precision you can’t use.
Rule of Thumb: 1. Identify maximum signal frequency (fmax) 2. Sample at 5-10x fmax (not 100x or 1000x) 3. Match ADC resolution to sensor accuracy +/-20% margin 4. Filter intelligently to remove noise, not signal
Your Challenge: You’re designing a predictive maintenance system for industrial machinery. Your accelerometer detects vibrations indicating bearing wear.
Scenario Details: - Bearing frequency: Healthy bearings vibrate at 200 Hz (shaft rotation rate) - Wear signature: Damaged bearings show harmonics up to 500 Hz (2.5x fundamental) - Your accelerometer: ADXL345 digital accelerometer - Available sample rates: 25 Hz, 50 Hz, 100 Hz, 200 Hz, 400 Hz, 800 Hz, 1600 Hz, 3200 Hz - Power consumption scales with sample rate: 40 uA @ 100 Hz, 140 uA @ 3200 Hz - Power budget: Battery-powered sensor node, need 1-year battery life
Your Task: What sample rate should you choose? Show your reasoning.
Solution: Step-by-Step Analysis
Step 1: Identify Maximum Signal Frequency - Bearing fundamental: 200 Hz - Wear harmonics: up to 500 Hz - Maximum frequency to detect: 500 Hz (fmax)
Step 2: Apply Nyquist Theorem - Nyquist minimum: Sample rate > 2 x fmax = 2 x 500 Hz = 1000 Hz - Practical target: 5-10x margin -> 1250-1500 Hz minimum
Step 3: Evaluate Available Options
| Sample Rate | Nyquist Margin | Power (uA) | Meets Requirements? |
|---|---|---|---|
| 400 Hz | 0.8x (too slow!) | ~60 | No - Aliasing risk |
| 800 Hz | 1.6x (barely) | ~85 | Marginal |
| 1600 Hz | 3.2x (good) | ~115 | Yes - Adequate |
| 3200 Hz | 6.4x (excellent) | ~140 | Yes - Overkill? |
Step 4: Power Budget Analysis - Battery capacity: 1000 mAh (typical AA battery) - Target lifetime: 1 year = 8760 hours - Allowed current: 1000 mAh / 8760 h = 114 uA average
Power consumption breakdown: - Accelerometer @ 1600 Hz: 115 uA - Microcontroller sleep mode: 20 uA - Wireless transmission (1% duty): 5 uA average - Total: ~140 uA (exceeds budget by 26 uA!)
Step 5: Optimization Strategy
Option B: Duty-cycle the accelerometer - Sample at 1600 Hz for 1 second every 10 seconds (10% duty cycle) - Accelerometer power: 115 uA x 10% = 11.5 uA average - Total: 11.5 + 20 + 5 = 36.5 uA - Battery life: 1000 mAh / 0.0365 mA = 27,400 hours = 3.1 years
Best Choice: 1600 Hz with 10% duty cycle
Why This Works: - Nyquist-compliant: 1600 Hz > 1000 Hz requirement (3.2x margin) - Catches transient events: 1-second bursts at 1600 Hz = 1600 samples per measurement window - Power-efficient: 10% duty cycle saves 90% accelerometer power - Exceeds 1-year target: 3+ years battery life - Practical: Bearings don’t wear instantly - sampling every 10 seconds catches degradation trends
Key Lessons: 1. Nyquist is non-negotiable: 400 Hz would alias 500 Hz signals to 100 Hz (false readings!) 2. Oversampling has costs: 3200 Hz provides no benefit over 1600 Hz for this application 3. Duty cycling saves power: 10% duty cycle = 10x battery life extension 4. Match sampling to physics: Bearing wear develops over days/weeks, not milliseconds
62.4 Aliasing: When Sampling is Too Slow
What happens if you sample too slowly?
Fast signals masquerade as slow signals - this is called aliasing.
Visual Example: Imagine a wheel spinning at 60 RPM (1 revolution/second = 1 Hz). If you sample at 1.5 Hz (every 0.67 seconds), the wheel appears to spin slowly backward instead of forward!
IoT Example: - True signal: 50 Hz vibration (motor spinning at 3000 RPM) - Sampling rate: 40 Hz (too slow! Violates Nyquist) - Observed signal: Appears as 10 Hz vibration (completely wrong!)
Solution: Use anti-aliasing filter (low-pass) before ADC to remove frequencies above Nyquist limit.
%%{init: {'theme': 'base', 'themeVariables': {'primaryColor':'#2C3E50','primaryTextColor':'#fff','primaryBorderColor':'#16A085','lineColor':'#16A085','secondaryColor':'#E67E22','tertiaryColor':'#7F8C8D','clusterBkg':'#ECF0F1','clusterBorder':'#16A085','edgeLabelBackground':'#ECF0F1'}}}%%
flowchart TD
A["True Signal<br/>50 Hz Vibration<br/>(Motor @ 3000 RPM)"] --> B{"Sampling Rate?"}
B -->|"100+ Hz<br/>(Correct)"| C["Sampled Signal<br/>Accurate 50 Hz<br/>No Aliasing"]
B -->|"40 Hz<br/>(Too Slow)"| D["Sampled Signal<br/>Appears as 10 Hz<br/>ALIASED"]
B -->|"20 Hz<br/>(Way Too Slow)"| E["Sampled Signal<br/>Appears as 10 Hz<br/>SEVERELY ALIASED"]
D --> F["Problem: Fast signal<br/>masquerades as<br/>slow signal"]
E --> F
F --> G["Solution:<br/>Anti-Aliasing Filter<br/>(Low-Pass before ADC)"]
style A fill:#2C3E50,stroke:#16A085,stroke-width:3px,color:#fff
style B fill:#7F8C8D,stroke:#2C3E50,stroke-width:2px,color:#fff
style C fill:#16A085,stroke:#2C3E50,stroke-width:3px,color:#fff
style D fill:#E67E22,stroke:#2C3E50,stroke-width:3px,color:#fff
style E fill:#E67E22,stroke:#2C3E50,stroke-width:3px,color:#000
style F fill:#ECF0F1,stroke:#E67E22,stroke-width:2px,color:#000
style G fill:#16A085,stroke:#2C3E50,stroke-width:3px,color:#fff
Aliasing Effect: When sampling rate is below Nyquist (2x signal frequency), high-frequency signals incorrectly appear as low-frequency signals. A 50 Hz vibration sampled at 40 Hz masquerades as 10 Hz. Anti-aliasing filters prevent this by removing high frequencies before sampling. {fig-alt=“Flowchart showing aliasing effect: 50 Hz true signal with three sampling scenarios. 100+ Hz sampling (teal) is correct. 40 Hz and 20 Hz sampling (orange) cause aliasing, making signal appear as 10 Hz. Solution is anti-aliasing low-pass filter before ADC.”}
62.4.1 Calculating Aliased Frequencies
When a frequency f_signal is sampled at rate f_sample (where f_signal > f_sample/2), the aliased frequency is:
f_aliased = |f_sample - f_signal|
Example: - Signal: 60 Hz HVAC vibration - Sampling: 100 Hz - Nyquist limit: 50 Hz (100/2) - Since 60 Hz > 50 Hz, aliasing occurs - Aliased frequency: |100 - 60| = 40 Hz
The 60 Hz vibration appears as 40 Hz in your data!
62.5 Summary
Key concepts from this chapter:
- Analog vs Digital: Continuous sensor signals must be discretized for digital processing
- Nyquist Theorem: Sample at >2x the highest frequency you care about
- Practical sampling: Use 5-10x oversampling for safety margin
- Aliasing: Sampling too slowly makes fast signals appear slow
- Anti-aliasing filters: Low-pass filter before ADC prevents aliasing artifacts
- Resource optimization: Don’t over-sample - it wastes power, storage, and bandwidth
%%{init: {'theme': 'base', 'themeVariables': {'primaryColor':'#2C3E50','primaryTextColor':'#fff','primaryBorderColor':'#16A085','lineColor':'#16A085','secondaryColor':'#E67E22','tertiaryColor':'#7F8C8D'}}}%%
flowchart LR
A["Analog<br/>Signal"] --> B["Anti-Alias<br/>Filter"]
B --> C["Sample<br/>(>2x fmax)"]
C --> D["Quantize<br/>(ADC)"]
D --> E["Digital<br/>Value"]
style A fill:#E67E22,stroke:#2C3E50,stroke-width:2px,color:#fff
style B fill:#16A085,stroke:#2C3E50,stroke-width:2px,color:#fff
style C fill:#16A085,stroke:#2C3E50,stroke-width:2px,color:#fff
style D fill:#2C3E50,stroke:#16A085,stroke-width:2px,color:#fff
style E fill:#E67E22,stroke:#2C3E50,stroke-width:2px,color:#fff
62.6 What’s Next
Now that you understand sampling and aliasing, proceed to Quantization and Digital Filtering to learn about ADC resolution, precision trade-offs, and noise reduction techniques.