29 Sampling Design: Product Scenarios
More
Depth: Practitioner
Progress saves as you read. Mark sections complete as you go; your progress appears in the sidebar.
29.1 Start With the Decision
This section: Start With the Decision — A doorbell, thermometer, and ECG monitor do not need the same sample rate.
A doorbell, thermometer, and ECG monitor do not need the same sample rate. Each product must preserve its fastest useful change without wasting power or storage.
29.2 Route Overview
This section: Route Overview — This is part 2 of 3.
This is part 2 of 3. Review Sampling and Aliasing: Nyquist and Filters for the preceding evidence.
29.3 Learning Objectives
This section: Learning Objectives
- Choose sample rates for doorbell, temperature, and ECG signals.
- Adapt multi-channel sampling while preserving anti-alias margins.
29.4 Chapter Roadmap
This section: Chapter Roadmap
- For Kids: Meet the Sensor Squad!
- Doorbell Sampling Design
- Sampling Rate Examples
- Beginner: Temperature Sensor Sampling
- Intermediate: ECG Heart Monitor Sampling
- Deep dive: Adaptive Multi-Channel Sampling
- Knowledge Check: Deep dive: Adaptive Multi-Channel Sampling
- Checkpoint: Product Scenarios
- Key Takeaway
- Label the Diagram
- Code Challenge
- Aliasing Filter Contracts
This section:
A doorbell, thermometer, and ECG monitor do not need the same sample rate. ECG records electrical activity from the heart. A sample is one reading; the sample rate says how many readings are taken each second. Each product must preserve its fastest useful change without wasting power or storage. A temperature trend can be sampled slowly, while an ECG waveform needs enough samples to retain its shape. If the sampling rate is too low, different signals can produce the same apparent pattern, and later processing cannot recover the missing changes.
Sampling is like taking photos of a moving object — take photos too slowly and you miss the action!
29.4.1 Speed Camera Story
Temperature Terry was watching a spinning wheel. “I can see it spinning smoothly, going round and round!”
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!
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.”
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!”
29.4.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 |
29.4.3 Try This at Home!
The Spinning Wheel Experiment!
- Ask someone to wave their hand back and forth quickly
- Blink your eyes slowly (once per second) — can you track their hand? (No! Aliasing!)
- Now keep your eyes open normally — you see smooth movement (high sample rate!)
- 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!
Now apply the same rule to memory, flash, and filter choices.
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)
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 only after limiting the analog bandwidth below 8 kHz; an 8 kHz component lies exactly at Nyquist and cannot be reliably reconstructed from samples at 16 kHz.
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 only with a specified passband below 6 kHz and adequate stopband rejection at and above 6 kHz
- Specify analog stopband rejection above 6 kHz; a 6 kHz RC cutoff attenuates 6 kHz by only 3 dB and does not remove higher frequencies before the 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; specify a passband below 6 kHz and stopband rejection against the source spectrum
- Anti-aliasing filter: specify its transition band and stopband attenuation; a 6 kHz RC corner alone is not sufficient
- 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 can support lower sampling rates when their passband and stopband are specified against the source spectrum; a filter alone does not guarantee alias-free sampling.
29.5 Sampling Rate Examples
This section: Sampling Rate Examples
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:
- Target bandwidth: 0.05-150 Hz; applicability to clinical diagnostic standards must be established for the intended use
- 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)
- 500 Hz is a candidate sample rate; clinical requirements depend on the applicable diagnostic standard and device validation
- Captures QRS morphology detail needed for arrhythmia classification
- Allows anti-aliasing filter with gradual roll-off above 150 Hz
- Anti-aliasing filter: the proposed 2nd-order Butterworth cutoff is 200 Hz before 500 Hz sampling; verify its attenuation at and above Nyquist against the out-of-band spectrum and allowed error
- 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 supplies 500 samples/s for the stated bandwidth, but the ESP32 and analog front end need a measured power budget; an actively running ESP32 alone is specified at 20–31 mA in 80 MHz modem-sleep mode, so the stated under-5 mA continuous-recording budget is not established.
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 → 288 MB/day
- Ch3: 200 kHz, 8 hours/day (night), 16-bit → 11.5 GB/day
- Ch4: 48 kHz, event-triggered (10% duty cycle), 16-bit → 829 MB/day
- Ch4 analog anti-alias filter: pass the wanted band through 20 kHz and verify sufficient attenuation at and above 24 kHz before sampling at 48 kHz.
- Total: ~12.65 GB/day × 30 days = ~379 GB → Still over budget!
Final optimization: A verified 40% compression reduction would leave ~228 GB, within a 256 GB card’s nominal capacity.
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.
This section:
Checkpoint: Product Scenarios
You now know:
- A 5-second, 16 kHz, 12-bit doorbell clip needs 160 kB before optimization.
- A 500 Hz ECG design produces about 86.4 MB/day at 2 bytes per sample.
- A four-channel wildlife design can reach 414 GB for 30 days before compression.
This section:
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.
29.6 Aliasing Filter Contracts
This section: Aliasing Filter Contracts — The main chapter above stays focused on sampling-rate choice, Nyquist intuition, aliasing examples, power trade-offs, and practical calculators.
The main chapter above stays focused on sampling-rate choice, Nyquist intuition, aliasing examples, power trade-offs, and practical calculators. For the deeper design contract behind folded-frequency math, irreversible aliases, analog pre-ADC filtering, oversampling headroom, and reconstruction-filter boundaries, continue to Aliasing and Anti-Alias Filter Contracts.
29.7 Continue to the Next Part
This section: Continue to the Next Part — Carry this evidence into Analog-Digital Boundaries: Signal Contracts, which begins with Analog-Digital Signal Boundary Contracts.
Carry this evidence into Analog-Digital Boundaries: Signal Contracts, which begins with Analog-Digital Signal Boundary Contracts.
Find help
3 reviewed answers.
Where should I start in a module?
Open the module page from the sidebar to see its chapters in order. Use the module map to return to a topic you need.
Modules and pathsReviewed
What can I try when a project does not work?
Check the symptom, then work through the diagnostic steps. Keep the error message and the smallest example that reproduces it.
When you are stuckReviewed
How do interactive examples work?
Use the interactive guide to check how examples and simulations work before changing your project.
Interactive examples guideReviewed
