%%{init: {'theme':'base', 'themeVariables': {'primaryColor':'#2C3E50','primaryTextColor':'#fff','primaryBorderColor':'#16A085','lineColor':'#16A085','secondaryColor':'#E67E22','tertiaryColor':'#ECF0F1','fontSize':'12px'}}}%%
flowchart LR
subgraph Sensors
GPS[GPS<br/>5m accuracy]
WiFi[WiFi RSSI<br/>3-5m accuracy]
Baro[Barometer<br/>0.3m altitude]
IMU[IMU<br/>Accelerometer+Gyro]
end
subgraph Fusion["Kalman Filter"]
Predict[Predict<br/>State Update]
Correct[Correct<br/>Measurement Update]
end
subgraph Output
Pos[Position<br/>1-2m accuracy]
end
GPS --> Correct
WiFi --> Correct
Baro --> Correct
IMU --> Predict
Predict --> Correct
Correct --> Pos
Pos --> Predict
style Fusion fill:#e3f2fd
532 Advanced Sensor Topics
Learning Objectives
After completing this chapter, you will be able to:
- Understand 1/f noise and its impact on sensor measurements
- Implement multi-sensor fusion for improved accuracy
- Apply Kalman filtering for state estimation
- Design robust sensing systems for production deployment
532.1 Prerequisites
- Signal Processing: Filtering and noise
- Calibration Techniques: Error correction
532.2 Advanced Sensor Topics and Technical Details
This section covers advanced topics for engineers building production-quality sensor systems.
532.3 The 1/f Noise Problem for Sensor Measurements
What is 1/f Noise?
Also called “pink noise” or “flicker noise,” 1/f noise has power spectral density that increases at lower frequencies. Unlike white noise (constant across frequencies), 1/f noise gets worse the longer you average.
Impact on Sensors: - Short-term averaging reduces noise (as expected) - Long-term averaging eventually stops helping - Drift appears as slow baseline wandering - Affects all sensors to varying degrees
Quantified Example: - White noise: 10 readings -> 3.16x improvement (sqrt(10)) - 1/f noise: 10 readings -> only 2x improvement (if strong 1/f component)
Mitigation Strategies: 1. Chopping/Modulation: Periodically reverse sensor polarity to move signal above 1/f corner 2. Correlated Double Sampling: Measure twice with different conditions, subtract 3. High-pass filtering: Remove DC and very-low-frequency components 4. Shorter integration time: Stop averaging before 1/f dominates
1/f Corner Frequency: The frequency where 1/f noise equals white noise floor. Below this, averaging becomes less effective.
| Sensor Type | Typical 1/f Corner | Implication |
|---|---|---|
| MEMS accelerometer | 1-10 Hz | Avoid averaging below 1 Hz |
| Thermistor | 0.1-1 Hz | 10-second averages optimal |
| Photodiode | 100-1000 Hz | Fast acquisition reduces 1/f |
| Gas sensor | 0.01 Hz | Long-term drift expected |
532.4 Multi-Sensor Fusion for Indoor Positioning
The Problem: Single sensors have limitations: - GPS: Doesn’t work indoors - Wi-Fi RSSI: +/-5m accuracy - Barometer: Only altitude - Accelerometer: Drifts over time
The Solution: Sensor Fusion
Combine multiple sensors to get better accuracy than any single sensor:
Position Estimate = f(GPS, WiFi, Barometer, Accelerometer, Gyroscope, Magnetometer)
Fusion Architecture:
532.5 Kalman Filter for Sensor Fusion
The Core Idea: Kalman filter optimally combines: 1. Prediction: Where we expect to be based on motion model 2. Measurement: What sensors actually see
Simple 1D Example (Temperature Smoothing):
class SimpleKalman:
def __init__(self, q=0.1, r=1.0):
self.q = q # Process noise (how much we trust prediction)
self.r = r # Measurement noise (how much we trust sensor)
self.x = 0 # State estimate
self.p = 1 # Estimate uncertainty
def update(self, measurement):
# Prediction step (for static value, prediction = previous)
self.p = self.p + self.q
# Update step
k = self.p / (self.p + self.r) # Kalman gain
self.x = self.x + k * (measurement - self.x) # Update estimate
self.p = (1 - k) * self.p # Update uncertainty
return self.x
# Usage
kf = SimpleKalman(q=0.01, r=0.5) # Trust prediction more than measurement
for reading in sensor_readings:
smoothed = kf.update(reading)Tuning Parameters: - Q (Process noise): Larger = trust prediction less, respond faster to changes - R (Measurement noise): Larger = trust sensor less, smoother output
| Application | Q | R | Behavior |
|---|---|---|---|
| Fast tracking | 0.5 | 0.1 | Responsive, noisy |
| Slow averaging | 0.01 | 1.0 | Smooth, slow response |
| Balanced | 0.1 | 0.5 | Good compromise |
532.6 Sensor Fusion Example: Dead Reckoning + GPS
class PositionFusion:
def __init__(self):
self.x = 0 # Position X
self.y = 0 # Position Y
self.p_x = 100 # Position uncertainty
self.p_y = 100
def predict_with_imu(self, accel_x, accel_y, dt):
"""Dead reckoning using accelerometer"""
# Simple integration (real systems use velocity too)
self.x += accel_x * dt * dt / 2
self.y += accel_y * dt * dt / 2
# Increase uncertainty (drift accumulates)
self.p_x += 0.5 * dt # Position uncertainty grows
self.p_y += 0.5 * dt
def update_with_gps(self, gps_x, gps_y, gps_accuracy):
"""Correct with GPS measurement"""
r = gps_accuracy ** 2 # Measurement variance
# Kalman gain for X
k_x = self.p_x / (self.p_x + r)
self.x = self.x + k_x * (gps_x - self.x)
self.p_x = (1 - k_x) * self.p_x
# Kalman gain for Y
k_y = self.p_y / (self.p_y + r)
self.y = self.y + k_y * (gps_y - self.y)
self.p_y = (1 - k_y) * self.p_y
return self.x, self.y532.7 Production-Quality Sensor System Design
Reliability Checklist:
| Aspect | Requirement | Implementation |
|---|---|---|
| Power supply | Filtered, stable | LDO regulator + decoupling caps |
| Communication | Error detection | CRC on sensor data |
| Redundancy | Backup sensors | Dual sensors for critical measurements |
| Calibration | Traceable | NIST-traceable reference, documented |
| Logging | Fault tracking | Store raw + processed data |
| Watchdog | Recovery | Hardware watchdog, auto-reset |
| Updates | Field upgradeable | OTA firmware updates |
Error Handling Best Practices:
class RobustSensor:
def __init__(self, sensor, max_retries=3):
self.sensor = sensor
self.max_retries = max_retries
self.last_good_reading = None
self.consecutive_failures = 0
def read(self):
for attempt in range(self.max_retries):
try:
value = self.sensor.read()
# Validate reading
if not self._validate(value):
continue
# Success
self.last_good_reading = value
self.consecutive_failures = 0
return value
except Exception as e:
self.consecutive_failures += 1
log_error(f"Sensor read failed: {e}")
# All retries failed
if self.consecutive_failures > 10:
trigger_alert("Sensor failure detected")
return self.last_good_reading # Return last known good
def _validate(self, value):
if value is None or math.isnan(value):
return False
if value < self.sensor.min_range or value > self.sensor.max_range:
return False
return True532.8 Summary
Key advanced sensor takeaways:
- 1/f noise limits long-term averaging - Know the corner frequency
- Sensor fusion beats single sensors - Combine complementary measurements
- Kalman filter optimally combines - Prediction + measurement
- Production systems need robustness - Error handling, redundancy, watchdogs
- Always validate data - Range checks, NaN detection, rate limiting
532.9 What’s Next
Now that you understand advanced topics:
- To test knowledge: Quiz and Exercises - Self-assessment
- To return to index: Sensor Fundamentals - Chapter overview
- To explore related topics: Sensor Interfacing - Connection techniques