69  Sensor Dynamics and Linearization

69.1 Learning Objectives

By the end of this chapter, you will be able to:

  • Understand Sensor Dynamics: Explain why sensors don’t respond instantly using mass-spring-damper models
  • Analyze Step Response: Interpret sensor behavior using rise time, settling time, and overshoot
  • Match Sampling to Bandwidth: Choose appropriate sampling rates based on sensor response characteristics
  • Apply Linearization: Use Taylor series, lookup tables, and piecewise methods for non-linear sensors

Fundamentals: - Signal Processing Overview - Sampling basics - Aliasing and ADC - Quantization and filtering - Voice Compression - Previous chapter - Signal Processing Labs - Hands-on experiments

Sensing: - Sensor Fundamentals - Sensor types - Sensor Circuits - Signal conditioning

69.2 Prerequisites

  • Signal Processing Overview: Sampling rate concepts
  • Basic physics: Understanding of mass, spring, and damping
  • Basic calculus: Understanding derivatives for linearization

69.3 Sensor Dynamics: Why Sensors Don’t Respond Instantly

⏱️ ~15 min | ⭐⭐⭐ Advanced | 📋 P02.C05.U07

The Hidden Problem: You might think sensors measure instantly—apply heat to a thermistor and it reads the new temperature immediately. But in reality, every sensor takes time to respond. Understanding how sensors respond dynamically is crucial for designing accurate IoT systems.

Intuitive Explanation: Think about a bathroom scale. When you step on it:

  1. The dial doesn’t jump instantly to your weight—it bounces around first
  2. It overshoots (shows more than your weight briefly)
  3. It oscillates back and forth, getting closer each swing
  4. Finally settles at your actual weight after 1-2 seconds

This happens because the scale has mass (the platform moves), springiness (the spring stores energy), and friction (damping that slows oscillations).

Every sensor behaves similarly: - Temperature sensors have thermal mass—they take time to heat up or cool down - Pressure sensors have mechanical elements that deflect and settle - Accelerometers have tiny proof masses that oscillate before settling

Why This Matters for IoT: - If you sample too fast, you might read the sensor while it’s still bouncing - If you need fast response, you must choose sensors designed for it - Understanding sensor dynamics helps you filter data correctly

The Bottom Line: Sensors don’t give instant readings—they have dynamics governed by physical properties. Understanding these dynamics helps you design better sampling strategies and filters.

69.3.1 The Mass-Spring-Damper Model

Almost every sensor can be modeled as a second-order mechanical system consisting of three elements:

  1. Mass (m): Inertia that resists change
  2. Spring (k): Restoring force proportional to displacement
  3. Damper (c): Friction that dissipates energy

The differential equation:

\[m\frac{d^2x}{dt^2} + c\frac{dx}{dt} + kx = F(t)\]

Where: - \(x\) = displacement (sensor reading) - \(F(t)\) = input force (physical quantity being measured) - \(m, c, k\) = mass, damping, spring constant

Key Parameters:

  • Natural frequency: \(\omega_n = \sqrt{k/m}\) (how fast it oscillates)
  • Damping ratio: \(\zeta = \frac{c}{2\sqrt{mk}}\) (how quickly oscillations decay)

Damping Regimes:

Damping Ratio (ζ) Behavior Example
\(\zeta < 1\) Underdamped: Oscillates before settling Cheap pressure sensor
\(\zeta = 1\) Critically damped: Fastest settling without overshoot Well-designed accelerometer
\(\zeta > 1\) Overdamped: Slow, sluggish response Thermal sensor with heavy mass

69.3.2 Step Response Characteristics

When you apply a sudden change (step input), sensors exhibit characteristic response curves:

Key Metrics:

  1. Rise Time (tr): Time to reach 90% of final value
  2. Settling Time (ts): Time to stay within ±2% of final value
  3. Overshoot: Maximum percentage above final value
  4. Bandwidth: Frequency at which response drops to 70.7% (-3dB)
NoteReal-World Example: MEMS Accelerometer

ADXL345 Accelerometer Specifications: - Bandwidth: 1600 Hz (user-configurable: 25 Hz to 1600 Hz) - Rise time: ~0.6 ms (for 1600 Hz bandwidth) - Settling time: ~2 ms (for step input at 1600 Hz) - Damping: Near-critical (ζ ≈ 0.7)

Design Implications: - Sampling rate: Must be >3200 Hz to capture 1600 Hz bandwidth (Nyquist × 2) - Practical choice: 3200-5000 Hz sampling - Don’t oversample: 10 kHz wastes power without benefit—sensor can’t respond faster than 1600 Hz

Key Lesson: Sensor bandwidth limits useful sampling rate. Sampling faster than 2× sensor bandwidth captures only noise, not signal.

TipImportant Design Rule: Match Sampling to Sensor Bandwidth

The Rule: Sample at 2-5× the sensor’s bandwidth, not its measurement range.

Example: Temperature Sensor (NTC Thermistor) - Thermal time constant: 10 seconds (τ = 10s) - Bandwidth: 1/(2πτ) ≈ 0.016 Hz - Nyquist requirement: >0.032 Hz - Practical sampling: 0.1 Hz (once every 10 seconds) - Don’t do: 1 kHz sampling—thermistor can’t respond faster than 0.016 Hz!

Why This Matters: - Sampling too fast wastes power and generates redundant data - Sampling too slow misses transient events - Match sample rate to sensor physics, not ADC capabilities


69.4 Linearization: Handling Non-Linear Sensors

⏱️ ~12 min | ⭐⭐⭐ Advanced | 📋 P02.C05.U08

The Problem: Many sensors are non-linear—their output doesn’t scale linearly with the measured quantity.

Common Non-Linear Sensors: - NTC Thermistor: Resistance vs. temperature (exponential) - Photoresistor (LDR): Resistance vs. light (logarithmic) - Hall Effect: Voltage vs. magnetic field (polynomial) - Load Cell: Voltage vs. force (polynomial, hysteresis)

69.4.1 Method 1: Lookup Table

Simplest approach: Pre-compute a table of (ADC value → physical quantity) pairs.

Example: NTC Thermistor Lookup Table

const float tempTable[256] = {
    -40.0,  // ADC value 0
    -39.8,  // ADC value 1
    -39.6,  // ADC value 2
    // ... 253 more entries
    125.0   // ADC value 255
};

float getTemperature(uint8_t adc_reading) {
    return tempTable[adc_reading];
}

Pros: Fast, simple Cons: Uses memory (256 floats = 1024 bytes), limited precision

69.4.2 Method 2: Piecewise Linear Approximation

Better approach: Divide non-linear curve into linear segments.

float getTemperature(uint16_t adc) {
    if (adc < 500) {
        // Segment 1: -40°C to 0°C
        return -40.0 + (adc / 500.0) * 40.0;
    } else if (adc < 3000) {
        // Segment 2: 0°C to 50°C
        return 0.0 + ((adc - 500) / 2500.0) * 50.0;
    } else {
        // Segment 3: 50°C to 125°C
        return 50.0 + ((adc - 3000) / 1096.0) * 75.0;
    }
}

Pros: Memory-efficient (only stores breakpoints), good accuracy Cons: Slightly more complex

69.4.3 Method 3: Polynomial Fit (Steinhart-Hart for Thermistors)

For high accuracy: Use polynomial approximation.

Steinhart-Hart Equation (for NTC thermistors):

\[\frac{1}{T} = A + B\ln(R) + C(\ln(R))^3\]

Where: - \(T\) = temperature in Kelvin - \(R\) = resistance in ohms - \(A, B, C\) = calibration constants (from datasheet)

Example Implementation:

float getTemperature(uint16_t adc) {
    // Convert ADC to resistance
    float R = 10000.0 * (4096.0 / adc - 1.0);

    // Steinhart-Hart coefficients (example)
    float A = 0.001129148;
    float B = 0.000234125;
    float C = 0.0000000876741;

    float logR = log(R);
    float T_kelvin = 1.0 / (A + B*logR + C*logR*logR*logR);

    return T_kelvin - 273.15;  // Convert to Celsius
}

Pros: High accuracy across full range Cons: Requires floating-point math, slower

69.4.4 Method 4: Taylor Series Linearization

For small deviations: Linearize around operating point.

Taylor Series Expansion:

\[f(x) \approx f(x_0) + f'(x_0)(x - x_0)\]

Example: Linearize NTC thermistor around room temperature (25°C).

// Operating point: T0 = 25°C, R0 = 10kΩ
// Sensitivity: dR/dT ≈ -400 Ω/°C at 25°C

float getTemperature(uint16_t adc) {
    float R = 10000.0 * (4096.0 / adc - 1.0);
    float dR = R - 10000.0;  // Deviation from R0
    return 25.0 + (dR / -400.0);  // Linear approximation
}

Pros: Very fast, simple Cons: Only accurate near operating point (±10°C for NTC)

69.4.5 Choosing a Linearization Method

Method Accuracy Speed Memory Use Case
Lookup Table Good Fast High (1-4 KB) Fixed ADC resolution, limited range
Piecewise Linear Good Fast Low (< 100 bytes) General purpose, good balance
Polynomial Excellent Medium Low High accuracy needed, full range
Taylor Series Fair Very Fast Minimal Small deviations from operating point

Recommendation: Start with piecewise linear (2-5 segments). Upgrade to polynomial if accuracy demands it.


69.5 Summary

This chapter covered advanced signal processing topics:

Sensor Dynamics: - All sensors have mass, spring, and damping—they don’t respond instantly - Key parameters: rise time, settling time, bandwidth - Critical rule: Sample at 2-5× sensor bandwidth, not faster

Linearization: - Many sensors are non-linear (thermistors, LDRs, Hall effect) - Four methods: lookup table, piecewise linear, polynomial, Taylor series - Best choice: Piecewise linear for most IoT applications

Design Guidelines: 1. Check sensor datasheet for bandwidth/time constant 2. Match sampling rate to sensor bandwidth (not ADC max rate!) 3. For non-linear sensors, use piecewise linear approximation 4. Don’t oversample—it wastes power without improving accuracy

What’s Next: - Signal Processing Labs - Hands-on ESP32 experiments with ADC, filters, and FFT