24 Signal Processing Essentials
fundamentals
signal-processing
ADC
filtering
sensors
24.1 Learning Objectives
By completing this chapter series, you will be able to:
- Distinguish Analog from Digital: Explain why sensors produce analog signals and why processors require digital data
- Apply Sampling Concepts: Calculate appropriate sampling rates using the Nyquist-Shannon theorem for IoT sensor signals
- Evaluate Quantization Trade-offs: Calculate ADC resolution, step size, and their impact on measurement accuracy and power consumption
- Diagnose Aliasing Artifacts: Identify when sampling rates are insufficient and design anti-aliasing strategies to prevent signal distortion
- Select Appropriate Filters: Compare low-pass, high-pass, median, and moving average filters to choose the optimal noise reduction approach
- Configure ADC Parameters: Set up analog-to-digital conversion with matched resolution and sampling rate for real IoT sensor applications
MVU: Minimum Viable Understanding
Core Concept: Signal processing converts continuous analog sensor signals to discrete digital values through sampling (time discretization) and quantization (amplitude discretization). Getting both right prevents aliasing artifacts and wasted resources.
Why It Matters: Every IoT sensor generates analog signals, but microcontrollers only understand digital numbers. Poor signal processing leads to missed events (undersampling), false readings (aliasing), or wasted power and storage (oversampling). A $2 temperature sensor with proper signal processing outperforms a $20 sensor with poor processing.
Key Takeaway: Sample at 2.5-5x the highest frequency you care about (not higher), and match ADC resolution to sensor accuracy - there’s no point having 16-bit precision if your sensor is only accurate to 1%.
For Beginners: Signal Processing
Signal processing is about turning the raw, messy electrical signals from sensors into clean, accurate digital numbers that a computer can work with. Imagine trying to have a phone conversation in a noisy room – signal processing is like the noise-cancellation technology that filters out background sounds so you hear only the voice. For IoT, it means converting a temperature sensor’s voltage into a reliable temperature reading, filtering out electrical noise, and doing it all efficiently enough to run on a tiny battery-powered device.
24.2 Overview
Signal processing bridges the continuous analog world of sensors with the discrete digital world of microcontrollers. This chapter series covers the complete journey from raw sensor signals to clean, usable digital data.
Sensor Squad: Signal Sally Explains Signal Processing!
Hey friends! I’m Signal Sally, and I help sensors talk to computers!
24.2.1 The Translation Problem
Imagine you speak only English, and your friend speaks only Spanish. You need a translator, right? That’s what signal processing does! Sensors “speak” in smooth, wiggly waves (analog), but computers only understand numbers (digital). Signal processing is the translator!
24.2.2 The Movie Trick
Here’s a fun secret: Movies aren’t really moving! They’re just pictures shown REALLY fast - 24 pictures every second! Your eyes think it’s moving because it’s so quick.
Signal processing works the same way:
- Sampling = Taking lots of “pictures” of the sensor’s wiggly signal
- Fast enough = It looks like the real thing!
- Too slow = Weird glitchy stuff happens (like a car wheel spinning backward in videos!)
24.2.3 Sammy’s Sampling Story
Temperature Terry measures the temperature in your room:
Real temperature: Goes up and down smoothly all day
~~~~~/\~~~~~/\~~~~~
Terry takes a "picture" every minute:
* * * * * * * * * *
(These dots are the samples!)
The computer sees: 22, 23, 24, 24, 23, 22, 21...
24.2.4 Why Does This Matter?
- Sample too slowly: You might miss when the room got really hot for a moment
- Sample too fast: You waste battery and memory for no reason
- Just right: You catch everything important without wasting energy!
24.2.5 The Goldilocks Rule
- Too few samples = Miss important changes (like missing your friend wave at you!)
- Too many samples = Waste energy (like taking 1000 photos when 10 would work!)
- Just right = Sample at least 2x faster than things change!
Fun Fact: When you hear music, your ear does signal processing too! It turns wiggly air vibrations into signals your brain understands. Your ear can detect sounds vibrating up to 20,000 times per second – and digital music players sample sound at 44,100 times per second (more than 2x that!) to capture everything you can hear!
Try This: Count how many times you blink in one minute. That’s like sampling your eyes! If someone waved at you between blinks, you’d miss it - just like a slow sample rate misses fast signals!
24.3 Signal Processing Pipeline
The following diagram shows how analog sensor signals become clean digital data ready for processing:
Understanding the Pipeline:
- Sensor Output (Orange): The raw analog signal - continuous voltage that varies smoothly with the physical quantity being measured
- Anti-Aliasing Filter (Teal): Removes high-frequency components that could cause aliasing artifacts during sampling
- ADC (Navy): The Analog-to-Digital Converter samples the signal at fixed intervals and quantizes each sample to a digital value
- Digital Filter (Teal): Removes remaining noise through software algorithms like moving average or low-pass filters
- Clean Data (Orange): The final processed signal ready for analysis or transmission
24.4 Key Concepts at a Glance
24.5 Quick Reference: Signal Processing Decisions
- Fast-changing signal looks wrong: you are probably aliasing. Increase the sample rate or add an anti-aliasing filter before the ADC. See ADC Fundamentals.
- Readings are too coarse: the quantization step is too large. Increase ADC resolution or reduce the reference range if the sensor allows it. See Quantization and Digital Filtering.
- Random high-frequency noise dominates the reading: use a moving average or low-pass filter when you need smoother trends more than sharp edges. See Quantization and Digital Filtering.
- Occasional spikes or outliers appear: use a median filter instead of averaging, because averages smear spikes into nearby samples. See Quantization and Digital Filtering.
- Sensor output is non-linear: add calibration logic such as lookup tables, piecewise linear sections, or polynomial fitting. See Linearization and Practice.
- Audio or wideband sensor data is too large to transmit: reduce bandwidth with compression only after you confirm the application can tolerate information loss. See Voice Compression.
Common Pitfall: Oversampling Wastes Resources
The Misconception: “Sampling faster is always better - more data means better accuracy!”
The Reality: Sampling faster than ~5x the signal bandwidth wastes: - Power: ADC conversions consume energy (especially at high speeds) - Storage: More samples = more memory/flash usage - Processing: More data to filter and analyze - Bandwidth: More data to transmit over the network
Real-World Example - Smart Agriculture Soil Moisture:
- Over-engineered plan:
1 Hzsampling, about4,320 mW/day, around345 KB/day, and only99.2%accuracy. - Optimized plan:
0.001 Hzsampling, about0.43 mW/day, around0.4 KB/day, and still98.8%accuracy.
The optimized approach uses 10,000x less power with only 0.4% accuracy reduction! Soil moisture doesn’t change in seconds - sampling every 15 minutes captures all meaningful variation.
Rule of Thumb: Match sample rate to the actual rate of change of your measured phenomenon, not your ADC’s maximum capability.
Interactive: ADC Resolution Calculator
Experiment with different ADC resolutions and reference voltages to see how they affect measurement precision:
Example Context: A soil moisture sensor outputs 0-3.3V. You need to detect 1% changes in moisture (50 mV resolution). Try different ADC resolutions above to see which works!
24.5.1 Check Your Understanding: ADC Resolution
24.6 Interactive: Nyquist Sampling Calculator
Use this calculator to determine the minimum and recommended sampling rates for your signal:
24.7 Knowledge Check: Signal Processing Basics
24.8 Choosing the Right Filter
Different filtering approaches suit different situations:
- Moving average: best when the sensor has random jitter and you care about a smooth trend. Trade-off: it delays the response and blurs sharp transitions. Implementation: average
Nsamples. - Median filter: best when the stream has isolated spikes or outliers. Trade-off: more compute because it has to rank or sort samples. Implementation: keep a small window and emit the middle value.
- Low-pass filter: best when high-frequency noise sits above the useful signal band. Trade-off: reduces available bandwidth and can hide fast events. Implementation: simple digital IIR or FIR filter.
- Notch filter: best when interference is concentrated at one known frequency, such as
50/60 Hzmains hum. Trade-off: narrower use case and more tuning effort. Implementation: band-reject filter centered on the offending frequency. - High-pass filter: best when the problem is slow baseline drift or DC offset. Trade-off: removes steady-state information along with the drift. Implementation: differentiation or a high-pass IIR stage.
24.8.1 Check Your Understanding: Aliasing
24.9 Chapter Contents
This comprehensive topic has been organized into focused chapters:
24.9.1 1. ADC Fundamentals: Sampling and Aliasing
Core concepts for analog-to-digital conversion:
- Analog vs digital signals and the continuous/discrete divide
- The Nyquist-Shannon sampling theorem
- Understanding and preventing aliasing
- Anti-aliasing filters and their role
Time: ~25 minutes | Level: Foundational to Intermediate
24.9.2 2. Quantization and Digital Filtering
Precision, resolution, and noise reduction:
- ADC resolution and quantization levels (8-bit to 16-bit)
- Step size calculations and precision trade-offs
- Moving average, median, and low-pass filters
- Choosing the right filter for your application
Time: ~20 minutes | Level: Intermediate
24.9.3 3. Voice Compression for IoT
Audio processing for bandwidth-constrained devices:
- Toll quality baseline (64 kbps)
- Companding: μ-law and A-law encoding
- Linear Predictive Coding (LPC) and source-filter models
- Codec selection for IoT applications
Time: ~15 minutes | Level: Advanced
24.9.4 4. Sensor Dynamics and Response
Understanding how sensors behave over time:
- Mass-spring-damper mechanical model
- Transfer functions and natural frequency
- Step response: underdamped, critically damped, overdamped
- Sensor bandwidth and its relationship to sampling
Time: ~15 minutes | Level: Advanced
24.9.5 5. Linearization and Practice
Handling non-linear sensors and hands-on lab:
- Taylor series linearization
- Lookup tables and piecewise approximation
- Knowledge check scenarios
- ESP32 Wokwi signal processing lab
Time: ~30 minutes | Level: Intermediate to Advanced
24.10 Prerequisites
Before diving into these chapters, you should be familiar with:
- Sensor Fundamentals and Types: Understanding different sensor types and their output characteristics
- Data Representation Fundamentals: Knowledge of binary numbers, bits, and bytes
- Basic electronics: Familiarity with voltage, current, and simple circuits
24.12 Worked Example: Choosing ADC Resolution and Sampling Rate for a Soil Moisture System
Worked Example: ADC Selection for Precision Agriculture
Scenario: A vineyard in Napa Valley deploys 200 capacitive soil moisture sensors (Decagon EC-5) across 50 hectares. The sensors output 0-3.0V proportional to volumetric water content (0-60%). The irrigation controller needs to detect 1% changes in soil moisture to trigger precision drip irrigation. Sensors are battery-powered (2x AA lithium, 3.6V, 3000 mAh target: 2-year battery life).
Given:
- Sensor output: 0-3.0V maps to 0-60% volumetric water content (VWC)
- Required resolution: 1% VWC = 50 mV at the sensor output
- Soil moisture changes slowly: maximum rate of 0.5%/hour during irrigation
- Power budget: 3000 mAh / (2 years x 8760 hours) = 0.17 mA average
- ADC reference voltage: 3.3V (from MCU regulator)
Step 1 – Determine minimum ADC resolution:
Required voltage resolution: 50 mV (to detect 1% VWC change)
- 8-bit ADC:
256levels and12.9 mVsteps. It technically detects1% VWC, but only with3.9 stepsper percent, so noise can still hide small moisture changes. - 10-bit ADC:
1,024levels and3.2 mVsteps. This comfortably detects1% VWCwith about15.6 stepsper percent and is a solid practical baseline. - 12-bit ADC:
4,096levels and0.8 mVsteps. This gives excellent margin and can resolve about0.1% VWCchanges if the rest of the sensor chain is stable enough.
Selected: 12-bit ADC (built into ESP32)
Why: The extra resolution (0.8 mV) allows software averaging to further reduce noise. With 16 samples averaged, effective resolution improves by 4x (equivalent to 14-bit). This detects subtle moisture gradients between vine rows that 10-bit would miss.
Step 2 – Determine sampling rate:
- Maximum signal change: 0.5% VWC/hour = 0.0083%/minute = 0.42 mV/minute
- Nyquist minimum: Signal changes at 1/120 Hz (one cycle per 2 hours), so minimum sampling: 1/60 Hz = 1 sample per minute
- Practical sampling: 1 sample per 10 minutes is sufficient (6x Nyquist) given the slow dynamics
- Oversampling for noise reduction: Take 16 ADC readings per sample (burst mode), average them
Step 3 – Calculate power consumption:
- Sleep mode: active for
99.97%of the schedule at only5 uA, for about0.12 mAh/day. - Wake and ADC burst:
15 msat30 mAevery10 minutes, for about0.108 mAh/day. - LoRa transmit:
80 msat120 mAevery10 minutes, for about1.38 mAh/day. - Total daily energy: about
1.61 mAh/day.
Battery life: 3000 mAh / 1.61 mAh/day = 1,863 days = 5.1 years (exceeds 2-year target by 2.5x)
Result: The 12-bit ADC with 10-minute sampling and 16-sample averaging achieves 0.2% VWC resolution (5x better than the 1% requirement) while consuming only 1.61 mAh/day. The 2.5x margin on battery life accounts for capacity degradation in outdoor temperature extremes (-5 to +45C in Napa Valley).
Key Insight: For slowly-changing environmental measurements like soil moisture, the sampling rate is often 100-1000x lower than the ADC’s maximum capability. The real power savings come from maximizing sleep time (99.97%) and using burst sampling for noise reduction rather than continuous monitoring.
24.13 Knowledge Check
Common Pitfalls
1. Aliasing by Sampling Below Nyquist Rate
Sampling a 100 Hz vibration signal at 150 Hz (below the required 200 Hz minimum) folds frequencies above 75 Hz back into the spectrum as false low-frequency components. Always sample at ≥2× the highest frequency of interest, plus margin for anti-aliasing filter roll-off.
2. Applying FFT Without Windowing to Non-Periodic Signals
Applying FFT to a finite signal segment without a window function (Hann, Hamming, Blackman) causes spectral leakage — energy from one frequency bin bleeds into adjacent bins, masking peaks. Always apply a window function before FFT for spectral analysis.
3. Confusing Filter Cutoff with Complete Attenuation
A low-pass filter with 100 Hz cutoff does not eliminate all frequencies above 100 Hz — it begins attenuating at 100 Hz with gradual roll-off (20 dB/decade for first-order, 40 dB/decade for second-order). Design filters with adequate order for the required stop-band attenuation.
24.14 What’s Next
Start with ADC Fundamentals to build your foundation in sampling theory and the Nyquist theorem, then progress through quantization, filtering, and practical applications.
- ADC Fundamentals: Sampling and Aliasing: build the core model for Nyquist, sample-rate selection, and aliasing prevention.
- Quantization and Digital Filtering: go deeper on ADC resolution, step size, moving average filters, and low-pass filtering.
- Voice Compression for IoT: learn how bandwidth constraints change the signal-processing design for audio.
- Sensor Dynamics and Response: connect bandwidth, damping, and step response to what the ADC should sample.
- Linearization and Practice: work through calibration, lookup tables, and the hands-on Wokwi lab.
- Sensor Fundamentals and Types: revisit the sensor side of the chain when you need more context on outputs and conditioning.