Chapters

16 IoT Mathematics: Fusion and Sampling Decisions

capstone
mathematical
foundations

16.1 Start With the Decision

GPS drifts slowly while an accelerometer reacts fast. A filter must blend both and still respect the sample limit.

16.2 Route Overview

This is part 2 of 2. Review IoT Mathematics: Linear Algebra and Probability for the preceding evidence.

16.3 Learning Objectives

  • Work through a Kalman filter for GPS and motion data.
  • Choose a sample rate with the Nyquist rule.

16.4 Chapter Roadmap

  • Worked Example: Designing a Kalman Filter for GPS-Accelerometer Fusion
  • Decision Framework: Choosing Sampling Rates Using Nyquist Theorem
  • Common Mistake: Misapplying dB Calculations to Voltage vs. Power
  • Knowledge Check
  • Auto-Gradable Quick Check
  • Try It Yourself
  • Hands-On Exercise: Calculate Battery Life with Real Power Measurements
  • Concept Relationships
  • How Math Concepts Connect in IoT Systems
  • See Also
  • Related Resources
  • Interactive Quiz: Match Mathematical Foundations Concepts
  • Interactive Quiz: Sequence the Steps
  • What’s Next
  • Navigation

You’re building a fleet tracking system using GPS (+/-10m accuracy) and an accelerometer-based dead reckoning system. Here’s how to apply the mathematical foundations to implement sensor fusion.

Step 1: Model the System State

From Section C.2 (Matrices), define state vector as position and velocity:

x=[pxpyvxvy]\vec{x} = \begin{bmatrix} p_x \\ p_y \\ v_x \\ v_y \end{bmatrix}

Where:

  • px,pyp_x, p_y = position (meters)
  • vx,vyv_x, v_y = velocity (meters/second)

Step 2: State Transition (Prediction)

From Section A.1 (Derivatives) and A.2 (Integrals), position changes via velocity integration:

pnew=pold+vΔtp_{new} = p_{old} + v \cdot \Delta t

In matrix form (Section C.3):

xk+1=Fxk+wk\vec{x}_{k+1} = F \cdot \vec{x}_k + \vec{w}_k

F=[10Δt0010Δt00100001]F = \begin{bmatrix} 1 & 0 & \Delta t & 0 \\ 0 & 1 & 0 & \Delta t \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix}

Example: Current state is position (100m, 200m), velocity (15 m/s, 0 m/s), Δt=0.1s\Delta t = 0.1s

[pxpyvxvy]new=[100.100100.100100001][100200150]=[101.5200150]\begin{bmatrix} p_x \\ p_y \\ v_x \\ v_y \end{bmatrix}_{new} = \begin{bmatrix} 1 & 0 & 0.1 & 0 \\ 0 & 1 & 0 & 0.1 \\ 0 & 0 & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 100 \\ 200 \\ 15 \\ 0 \end{bmatrix} = \begin{bmatrix} 101.5 \\ 200 \\ 15 \\ 0 \end{bmatrix}

Predicted position: (101.5m, 200m) after 0.1 seconds.

Step 3: Measurement Update (GPS Reading)

GPS reports position (103m, 201m) with sigma = 10m uncertainty.

From Section D.2 (Gaussian Distribution), GPS measurement has:

  • Mean: mu = (103, 201)
  • Covariance: σ2=100\sigma^2 = 100 (since sigma = 10m)

From Section D.3 (Sensor Fusion), combine prediction with measurement:

pfused=σGPS2ppred+σpred2pGPSσpred2+σGPS2p_{fused} = \frac{\sigma_{GPS}^2 \cdot p_{pred} + \sigma_{pred}^2 \cdot p_{GPS}}{\sigma_{pred}^2 + \sigma_{GPS}^2}

Assume prediction uncertainty σpred=5m\sigma_{pred} = 5m (accelerometer integration), GPS uncertainty σGPS=10m\sigma_{GPS} = 10m:

X-coordinate: px=100101.5+2510325+100=10150+2575125=12725125=101.8mp_x = \frac{100 \cdot 101.5 + 25 \cdot 103}{25 + 100} = \frac{10150 + 2575}{125} = \frac{12725}{125} = 101.8m

Y-coordinate: py=100200+25201125=20000+5025125=200.2mp_y = \frac{100 \cdot 200 + 25 \cdot 201}{125} = \frac{20000 + 5025}{125} = 200.2m

Fused estimate: (101.8m, 200.2m)

Notice the fused position is closer to the prediction (101.5, 200) than the GPS (103, 201) because prediction is 2x more accurate (σ=5\sigma=5 vs σ=10\sigma=10).

Step 4: Uncertainty Reduction

From Section D.3, combined variance:

σfused2=σpred2σGPS2σpred2+σGPS2=2510025+100=2500125=20\sigma_{fused}^2 = \frac{\sigma_{pred}^2 \cdot \sigma_{GPS}^2}{\sigma_{pred}^2 + \sigma_{GPS}^2} = \frac{25 \cdot 100}{25 + 100} = \frac{2500}{125} = 20

σfused=20=4.47m\sigma_{fused} = \sqrt{20} = 4.47m

Interpretation: Fusing 5m-accurate prediction with 10m-accurate GPS yields 4.47m accuracy - better than either sensor alone!

Step 5: Real-World Performance Calculation

For a delivery truck moving at 60 km/h (16.67 m/s):

  • GPS update rate: 1 Hz (once per second)
  • Dead reckoning uncertainty growth: 2% per second (from accelerometer bias)

Between GPS updates (1 second):

  • Distance traveled: 16.67 meters
  • Dead reckoning error: 16.67 x 0.02 = 0.33m (grows linearly)
  • Fused uncertainty after 1 sec: σ=4.472+0.332=4.48m\sigma = \sqrt{4.47^2 + 0.33^2} = 4.48m

After GPS update:

  • Pre-update: sigma = 4.48m
  • Post-fusion: sigma = 4.47m (Kalman correction brings accuracy back)

Key Insight: Kalman filter prevents dead reckoning drift by periodically re-anchoring position with GPS, while smoothing GPS noise with prediction.

Implementation Pseudocode:

# Initialize state
state = [position_x, position_y, velocity_x, velocity_y]
P = [[25, 0, 0, 0],    # Position covariance matrix (5m uncertainty)
     [0, 25, 0, 0],
     [0, 0, 4, 0],     # Velocity covariance (2 m/s uncertainty)
     [0, 0, 0, 4]]

# Prediction step (every 0.1 seconds)
state_predicted = F @ state  # Matrix multiplication from Section C.3
P_predicted = F @ P @ F.T + Q  # Add process noise Q

# Measurement step (GPS reading every 1 second)
innovation = gps_reading - H @ state_predicted  # H extracts position
S = H @ P_predicted @ H.T + R  # Innovation covariance (R = GPS noise)
K = P_predicted @ H.T @ inv(S)  # Kalman gain (optimal weighting)
state = state_predicted + K @ innovation  # Update state
P = (I - K @ H) @ P_predicted  # Update covariance

Math concepts used: Vectors (C.1), matrices (C.2), matrix multiplication (C.3), Gaussian distribution (D.2), sensor fusion (D.3), integrals (A.2).

Use this framework to determine the minimum ADC sampling rate for your sensor based on signal frequency content.

16.4.1 The Nyquist Rule (Section A.1 + Quick Reference)

fsample2×fmaxf_{sample} \geq 2 \times f_{max}

Where fmaxf_{max} is the highest frequency component in your signal. But how do you find fmaxf_{max}?

16.4.2 Step-by-Step Decision Process

Signal TypeFrequency Estimation MethodExample CalculationRecommended Sampling Rate
Temperature (slow)Physical time constantThermocouple: tau = 1s -> fmax=1/(2πτ)=0.16f_{max} = 1/(2\pi\tau) = 0.16 Hz0.5 Hz (2 samples/sec)
VibrationMechanical resonanceMotor bearing: fmaxf_{max} = 120 Hz (2x rotation speed)250 Hz (Nyquist) + anti-alias filter
AudioHuman hearing rangeSpeech: 20 Hz - 8 kHz16 kHz (telephone quality)
AccelerometerExpected motionHand gesture: 0-10 Hz25 Hz (2.5x Nyquist for margin)
Voltage ripplePower supply frequencyAC mains: 60 Hz + harmonics -> 300 Hz1 kHz (capture up to 5th harmonic)

16.4.3 Worked Example: Vibration Monitoring on Industrial Motor

Background: 1800 RPM motor (30 Hz rotation), 4-blade fan

Step 1: Identify Frequency Components

From Section B.1 (Exponential Functions) and mechanical theory:

  • Fundamental: Motor rotation = 30 Hz
  • Blade pass frequency: 4 blades x 30 Hz = 120 Hz
  • Harmonics: Up to 3x fundamental for imbalance detection = 120 x 3 = 360 Hz

Step 2: Apply Nyquist Theorem

fsample2×360=720 Hzf_{sample} \geq 2 \times 360 = 720 \text{ Hz}

Step 3: Add Safety Margin

Industry standard: 2.5x Nyquist to account for filter roll-off

fsample=2.5×720=1800 Hzf_{sample} = 2.5 \times 720 = 1800 \text{ Hz}

Step 4: Select Standard ADC Rate

Common options: 1 kHz, 2 kHz, 5 kHz, 10 kHz

Decision: 2 kHz (exceeds requirement, standard IC availability)

16.4.4 Anti-Aliasing Filter Design

From Section A.2 (RC Time Constant):

Goal: Attenuate frequencies above 360 Hz before sampling at 2 kHz

Filter cutoff frequency: fc=400f_c = 400 Hz (between signal and Nyquist/2)

fc=12πRCf_c = \frac{1}{2\pi RC}

RC=12π×400=398μsRC = \frac{1}{2\pi \times 400} = 398 \mu s

Choose: R=10kΩR = 10k\Omega, then C=398μs/10kΩ=39.8nFC = 398 \mu s / 10k\Omega = 39.8 nF -> Use standard 39 nF capacitor

16.4.5 Real-World Tradeoffs

Sampling RateData Rate (16-bit samples)ProsCons
720 Hz (minimum Nyquist)11,520 bits/secLow power, minimal storageNo margin, aliasing risk
2 kHz (recommended)32,000 bits/secSafe margin, standard ADCs2.8x data volume
10 kHz (over-sampled)160,000 bits/secDigital filtering, noise averaging14x data volume, unnecessary

Energy Impact (from Section A.2, Energy Budget):

ADC power: 5 mW active, conversion time: 10 us

720 Hz: Duty cycle = 720 x 10 us = 0.72%, average power = 5 mW x 0.0072 = 36 uW 2 kHz: Duty cycle = 2000 x 10 us = 2%, average power = 100 uW 10 kHz: Duty cycle = 10%, average power = 500 uW

Battery life impact (2000 mAh at 3.3V):

2 kHz: 100 uW -> 30 uA -> 2000/0.03 = 66,667 hours = 7.6 years 10 kHz: 500 uW -> 150 uA -> 13,333 hours = 1.5 years

Decision: 2 kHz sampling provides a 2.8x margin over the Nyquist minimum while preserving 7+ year battery life. 10 kHz over-sampling wastes 80% of battery life with no signal quality benefit.

16.4.6 Common Mistake: Under-Sampling

Example: Student samples 60 Hz mains voltage at 100 Hz

fsample=100 Hz,fsignal=60 Hzf_{sample} = 100 \text{ Hz}, \quad f_{signal} = 60 \text{ Hz}

Nyquist requires fsample>120f_{sample} > 120 Hz, so 100 Hz causes aliasing.

What happens: 60 Hz signal appears as 40 Hz after aliasing (10060=40|100 - 60| = 40 Hz)

Fix: Sample at >=150 Hz (2.5x Nyquist) -> use 250 Hz for standard ADC compatibility

Common Mistake: Misapplying dB Calculations to Voltage vs. Power

The Problem: Students often use the power formula dB=10log10(P2/P1)dB = 10\log_{10}(P_2/P_1) when comparing voltages, leading to 6 dB errors.

Real Example from Student Report:

“Our amplifier increased signal voltage from 0.1V to 1.0V, a gain of 10 dB.”

What’s wrong?

From Section B.2 (Logarithms), dB formulas differ for power vs. voltage:

QuantityFormulaCorrect Calculation
Power ratiodB=10log10(P2/P1)dB = 10\log_{10}(P_2/P_1)10x power = 10 dB
Voltage ratiodB=20log10(V2/V1)dB = 20\log_{10}(V_2/V_1)10x voltage = 20 dB

Why the factor of 20 for voltage?

From basic electronics (Section A.2, Power formula):

P=V2RP = \frac{V^2}{R}

If voltage doubles, power quadruples (voltage squared relationship).

dB=10log10(P2P1)=10log10(V22/RV12/R)=10log10(V22V12)dB = 10\log_{10}\left(\frac{P_2}{P_1}\right) = 10\log_{10}\left(\frac{V_2^2/R}{V_1^2/R}\right) = 10\log_{10}\left(\frac{V_2^2}{V_1^2}\right)

=10log10[(V2V1)2]=10×2×log10(V2V1)=20log10(V2V1)= 10\log_{10}\left[\left(\frac{V_2}{V_1}\right)^2\right] = 10 \times 2 \times \log_{10}\left(\frac{V_2}{V_1}\right) = 20\log_{10}\left(\frac{V_2}{V_1}\right)

Corrected Calculation:

Voltage gain from 0.1V -> 1.0V:

dB=20log10(1.00.1)=20log10(10)=20×1=20 dBdB = 20\log_{10}\left(\frac{1.0}{0.1}\right) = 20\log_{10}(10) = 20 \times 1 = 20 \text{ dB}

The student’s 10 dB answer is off by 6 dB (a factor of 2x in linear terms).

16.4.7 Decision Matrix: Power vs. Voltage dB

Measurement TypeUse This FormulaExample
Transmit power (mW)dBm=10log10(PmW)dBm = 10\log_{10}(P_{mW})100 mW -> 20 dBm
Antenna gain (power ratio)dB=10log10(Pout/Pin)dB = 10\log_{10}(P_{out}/P_{in})2x power -> 3 dB
Signal voltage (ADC reading)dBV=20log10(V)dBV = 20\log_{10}(V)1.0 V -> 0 dBV
Path loss (power reduction)dB=10log10(Prx/Ptx)dB = 10\log_{10}(P_{rx}/P_{tx})0.01x power -> -20 dB
Amplifier gain (voltage)dB=20log10(Vout/Vin)dB = 20\log_{10}(V_{out}/V_{in})10x voltage -> 20 dB
SNR (power ratio)dB=10log10(S/N)dB = 10\log_{10}(S/N)100:1 -> 20 dB SNR

16.4.8 Quick Lookup Table (Section B.2)

Linear RatioPower dB (10 log)Voltage dB (20 log)
0.5x (half)-3 dB-6 dB
2x (double)+3 dB+6 dB
10x+10 dB+20 dB
100x+20 dB+40 dB
1000x+30 dB+60 dB

Memory trick: Voltage uses 20 log because power depends on voltage SQUARED (the 2 becomes a multiplier in the log).

16.4.10 Rule Summary

Step 1 — Power quantities (W, mW, dBm): Use 10log1010\log_{10} Step 2 — Voltage quantities (V, dBV): Use 20log1020\log_{10} Step 3 — Always label units (dBm, dBV, dB relative to reference) Step 4 — Never mix voltage dB with power dB in same calculation

When in doubt: Check if your measurement is voltage (from ADC, oscilloscope) -> 20 log. If it’s power (from spectrum analyzer, RF meter) -> 10 log.

16.5 Knowledge Check

Auto-Gradable Quick Check

16.6 Try It Yourself

Objective: Apply integrals (energy budgeting) and exponentials (battery discharge curves) to estimate how long an ESP32 sensor will run on two AA batteries.

Given Data:

  • Battery capacity: two AA alkaline = 2,000 mAh at 3V (6,000 mWh total energy)
  • ESP32 power states:
    • Active (Wi-Fi transmit): 160 mA for 2 seconds
    • Light sleep: 0.8 mA for 58 seconds
    • Measurement interval: Every 60 seconds

Step 1: Calculate Average Current (from Section A.2, Integrals)

Using the duty cycle formula from Quick Reference:

Iavg=(Iactive×Dactive)+(Isleep×Dsleep)I_{avg} = (I_{active} \times D_{active}) + (I_{sleep} \times D_{sleep})

Where D = duty cycle (fraction of time):

  • Dactive=2s/60s=0.0333D_{active} = 2s / 60s = 0.0333 (3.3% of time)
  • Dsleep=58s/60s=0.9667D_{sleep} = 58s / 60s = 0.9667 (96.7% of time)

Iavg=(160mA×0.0333)+(0.8mA×0.9667)I_{avg} = (160mA \times 0.0333) + (0.8mA \times 0.9667) Iavg=5.33mA+0.77mA=6.1mAI_{avg} = 5.33mA + 0.77mA = 6.1mA

Step 2: Calculate Battery Life

Hours=Battery Capacity (mAh)Average Current (mA)=2000mAh6.1mA=328 hoursHours = \frac{Battery\ Capacity\ (mAh)}{Average\ Current\ (mA)} = \frac{2000mAh}{6.1mA} = 328\ hours

Days=328÷24=13.7 daysDays = 328 \div 24 = 13.7\ days

Step 3: Account for Battery Discharge Curve (Section B.1, Exponentials)

Alkaline batteries don’t provide constant voltage — they follow exponential decay. Usable capacity is ~80% at 1.1V cutoff:

Daysactual=13.7×0.80=11 daysDays_{actual} = 13.7 \times 0.80 = 11\ days

Challenge Extension:

  • What if you reduce transmit time to 1 second (faster Wi-Fi)? Recalculate IavgI_{avg}.
  • What if you switch to lithium AA (2,500 mAh, flatter discharge curve = 90% usable)? New battery life?
  • Use Section B.1 RC time constant: If ESP32 has 100uF decoupling cap, how long to charge from sleep voltage?

Answer: With 1s transmit, IavgI_{avg} drops to 3.44 mA -> 19.3 days (alkaline) or 27 days (lithium).

Why This Matters: Battery life estimation is the #1 requirement for field-deployed IoT. This exercise applies integrals (averaging), exponentials (discharge curves), and real-world engineering judgment (efficiency factors).

16.7 Concept Relationships

How Math Concepts Connect in IoT Systems

Calculus -> Signal Processing:

Derivatives detect rapid changes (anomaly detection: sudden temperature spike) Integrals smooth noisy data (moving average filter = discrete integral) Fourier Transform (Section F.2) decomposes signals into frequency components for filtering

Exponentials + Logarithms -> Wireless Communication:

Exponential decay models signal attenuation: P=P0eαdP = P_0 e^{-\alpha d} Logarithms (dB scale) compress 100,000:1 power ranges into manageable numbers Shannon Capacity links SNR (exponential in linear scale) to data rate via logarithm

Linear Algebra -> Sensor Fusion:

Vectors represent multi-axis sensor data (accelerometer: [ax,ay,az][a_x, a_y, a_z]) Matrices transform coordinate frames (rotate sensor orientation) Kalman Filter (Section C.2) uses matrix multiplication to fuse GPS + IMU

Probability -> Reliability & Quality:

Gaussian distribution models sensor noise (Section D.2) Expected value predicts component failure rates Sensor fusion weights measurements by inverse variance (trust precise sensors more)

Modular Arithmetic -> Security:

Diffie-Hellman key exchange (Section E.3) uses “easy forward, hard reverse” property Public-key cryptography relies on discrete logarithm difficulty Hash functions (checksums, message authentication) use modular arithmetic

The Integration: A GPS-IMU tracker uses ALL these: calculus (integrate acceleration -> velocity -> position), logarithms (dB for signal strength), linear algebra (Kalman filter matrices), probability (sensor noise models), and modular arithmetic (encrypted data transmission).

16.8 See Also

Related Resources

Within This Module:

Glossary A-F - Definitions for technical terms (dB, Shannon Capacity, Kalman Filter) Reference Appendix - Visual conventions and quick-reference material for mathematical diagrams

Applied Mathematics (Cross-Module):

Signal Processing Essentials - Fourier transforms, filtering, Nyquist theorem in practice Kalman Filtering for Sensor Fusion - Step-by-step implementation of matrix-based sensor fusion Cryptography Fundamentals - Modular arithmetic in RSA, Diffie-Hellman, elliptic curves Energy-Aware Design - Battery life calculations using integrals and exponentials

Interactive Tools:

Power Budget Calculator - Interactive tool applying the integral-based battery life formulas from this chapter dB Conversion Tool - Practice logarithmic conversions between mW and dBm Kalman Filter Visualizer - See matrix operations in real-time sensor fusion

Reference Materials:

Quick Reference Card (Section H) - Copy-paste formulas for IoT calculations Worked Example: Kalman Filter (Section D.3) - Full GPS-accelerometer fusion walkthrough Decision Framework: Sampling Rates (Section A.1) - Nyquist theorem application guide

Interactive Quiz: Match Mathematical Foundations Concepts
Interactive Quiz: Sequence the Steps

16.9 What’s Next

If you want to…Read this
Apply calculus concepts to PID control system designProcess Control and PID
Use probability theory in sensor fusion and Kalman filteringSensor Fusion Fundamentals
Apply logarithms (dB) to wireless signal budget calculationsWireless Sensor Network Fundamentals
Apply statistical analysis to time-series IoT dataTime-Series Queries
Access reference materials and supplementary contentAppendix

16.11 Continue Your Route

This final part closes the route from Worked Example: Designing a Kalman Filter for GPS-Accelerometer Fusion through Navigation. Return to IoT Mathematics: Linear Algebra and Probability or continue from the capstone module index.