Chapters

15 IoT Mathematics: Linear Algebra and Probability

capstone
mathematical
foundations

15.1 Start With the Decision

Several sensor values form a vector, while noise makes each value unsure. Matrices and probability keep those facts visible.

15.2 Route Overview

This is part 1 of 2. Continue with IoT Mathematics: Fusion and Sampling Decisions.

15.3 Part Objectives

  • Use vectors and matrices to combine sensor state.
  • Represent sensor uncertainty with probability and variance.

15.4 Start With the Situation

A single formula can bound change, accumulation, or signal scale, but many IoT decisions combine several measurements and uncertain events. The team now needs vectors, matrices, and probability to fuse evidence without hiding assumptions.

15.5 Overview

This route builds linear-algebra and probability tools, then applies them to cryptography, radio links, sensors, power, and capstone calculations.

This is part 2 of 2. Review IoT Mathematics: Calculus, Exponents, and Logs when you need the first route.

15.6 Learning Objectives

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

  • use vectors and matrices to represent multi-sensor systems
  • apply probability and statistics to uncertain IoT evidence
  • build bounded RF, sensor, cryptography, and battery calculations

15.7 Chapter Roadmap

  • Start With the Situation
  • Overview
  • C. Linear Algebra Basics
  • The Core Idea
  • Interactive Calculator: 3D Vector Magnitude
  • The Core Idea
  • Quick Rule
  • D. Probability and Statistics
  • The Core Idea
  • The Core Idea
  • Interactive Calculator: Sensor Fusion
  • Try It: Write a Sensor Uncertainty Assumption Check
  • Checkpoint: State and Uncertainty
  • E. Modular Arithmetic for Cryptography
  • The Core Idea
  • F. Complex Numbers for Signal Processing
  • The Core Idea
  • G. Information Theory Basics
  • The Core Idea
  • Checkpoint: Security and Signals
  • H. Quick Reference Card
  • Visual Reference Gallery
  • Kalman Filter Visualization
  • Signal Processing Pipeline
  • Common Pitfalls
  • 1. Skipping the units when applying IoT formulas
  • 2. Confusing linear and logarithmic scales for signal measurements
  • 3. Applying normal distribution assumptions to real IoT sensor noise
  • Label the Diagram
  • Code Challenge
  • Summary

15.8 C. Linear Algebra Basics

15.8.1 C.1 Vectors

The Core Idea

A vector is an ordered list of numbers representing multiple related quantities. In IoT, sensors often produce vector outputs (e.g., 3-axis accelerometer gives [x, y, z]).

Notation: v=[xyz]\vec{v} = \begin{bmatrix} x \\ y \\ z \end{bmatrix} or simply [x,y,z][x, y, z]

IoT Applications:

Data TypeVector Representation
3-axis accelerometer[ax,ay,az][a_x, a_y, a_z] in g-force
GPS position[latitude,longitude,altitude][latitude, longitude, altitude]
RGB color[red,green,blue][red, green, blue] values 0-255
IMU (9-axis)[ax,ay,az,gx,gy,gz,mx,my,mz][a_x, a_y, a_z, g_x, g_y, g_z, m_x, m_y, m_z]

Vector Operations:

Magnitude (Length): How “big” is the vector? v=x2+y2+z2|\vec{v}| = \sqrt{x^2 + y^2 + z^2}

Example: Accelerometer reads [0.5,0.3,0.8]g[0.5, 0.3, 0.8]g a=0.52+0.32+0.82=0.980.99g|\vec{a}| = \sqrt{0.5^2 + 0.3^2 + 0.8^2} = \sqrt{0.98} \approx 0.99g

This tells us the total acceleration magnitude (useful for fall detection).

15.8.2 C.2 Matrices

The Core Idea

A matrix is a 2D array of numbers. Matrices transform vectors - rotate them, scale them, or combine multiple measurements.

Notation: M=[abcd]M = \begin{bmatrix} a & b \\ c & d \end{bmatrix}

IoT Applications:

1. Coordinate Transformation:

Rotating sensor data to align with a reference frame:

x=xcosθysinθy=xsinθ+ycosθ\begin{aligned} x' &= x\cos\theta - y\sin\theta \\ y' &= x\sin\theta + y\cos\theta \end{aligned}

2. Kalman Filter State:

State vector might be [position,velocity,acceleration][position, velocity, acceleration]: x=[pva]\vec{x} = \begin{bmatrix} p \\ v \\ a \end{bmatrix}

State transition predicts next state: xk+1=Fxk\vec{x}_{k+1} = F \cdot \vec{x}_k

3. Covariance Matrix:

Describes uncertainty in measurements: P=[σx2σxyσxyσy2]P = \begin{bmatrix} \sigma_x^2 & \sigma_{xy} \\ \sigma_{xy} & \sigma_y^2 \end{bmatrix}

Diagonal elements: Variance (uncertainty) in each variable Off-diagonal: How variables correlate (change together)

15.8.3 C.3 Matrix Multiplication

Quick Rule

To multiply matrix A (m by n) by matrix B (n by p), the inner dimensions must match. Result is m by p.

Example: Transforming a 3D point [200020002][123]=[246]\begin{bmatrix} 2 & 0 & 0 \\ 0 & 2 & 0 \\ 0 & 0 & 2 \end{bmatrix} \begin{bmatrix} 1 \\ 2 \\ 3 \end{bmatrix} = \begin{bmatrix} 2 \\ 4 \\ 6 \end{bmatrix}

This scales the vector by 2 in all directions.


15.9 D. Probability and Statistics

15.9.1 D.1 Basic Probability

The Core Idea

Probability quantifies uncertainty. In IoT, sensor readings are never perfect - probability helps us reason about noise, errors, and reliability.

Key Concepts:

TermDefinitionIoT Example
Probability P(A)Chance of event A (0 to 1)P(packet loss) = 0.02
Expected Value E[X]Average outcomeAverage sensor reading
Variance Var(X)Spread around averageNoise level
Standard Deviation sigmasqrt(variance)+/- 1 sigma covers 68% of readings

Practical Example - Sensor Reliability:

If a sensor has 99.9% uptime:

  • P(working) = 0.999
  • P(failure) = 0.001

For 100 sensors, expected failures = 100 x 0.001 = 0.1 per unit time

15.9.2 D.2 Gaussian (Normal) Distribution

The Core Idea

The Gaussian distribution (bell curve) describes random noise in most physical systems. It’s characterized by mean (mu) and standard deviation (sigma).

p(x)=1σ2πe(xμ)22σ2p(x) = \frac{1}{\sigma\sqrt{2\pi}} e^{-\frac{(x-\mu)^2}{2\sigma^2}}

Properties:

  • 68% of values within mu +/- 1 sigma
  • 95% of values within mu +/- 2 sigma
  • 99.7% of values within mu +/- 3 sigma

IoT Application - Sensor Noise:

A temperature sensor with:

  • Mean reading: mu = 25.0 C
  • Noise: sigma = 0.5 C

95% of readings will be between 24.0 C and 26.0 C.

15.9.3 D.3 Sensor Fusion: Combining Measurements

When you have two noisy measurements of the same thing, the optimal combination is:

xcombined=σ22x1+σ12x2σ12+σ22x_{combined} = \frac{\sigma_2^2 \cdot x_1 + \sigma_1^2 \cdot x_2}{\sigma_1^2 + \sigma_2^2}

Intuition: Weight each measurement inversely by its uncertainty. Trust the more precise sensor more.

Example:

  • GPS says position is 100m (sigma = 10m)
  • Accelerometer integration says 95m (sigma = 5m)

xcombined=25×100+100×95100+25=2500+9500125=96mx_{combined} = \frac{25 \times 100 + 100 \times 95}{100 + 25} = \frac{2500 + 9500}{125} = 96m

The combined estimate is closer to the accelerometer (more precise).

Try It: Write a Sensor Uncertainty Assumption Check

Before using a fused sensor estimate in a capstone decision, write one short assumption check:

Decision: what action will use the estimate, such as triggering an alert, logging a location, or changing actuator output. Inputs: each sensor value, its stated or measured σ\sigma, and the time window used to collect samples. Assumption: why a Gaussian model is reasonable here, or which evidence shows that outliers, drift, or saturation need a different model. Rule: the numeric threshold that separates accept, warn, and reject states, including units. Recalculation condition: the condition that forces a new estimate, such as a new enclosure, different sample rate, firmware filter change, or field noise pattern.

Accept the estimate only when the decision, units, uncertainty source, and recalculation condition are all explicit.

SammyCheckpoint: State and Uncertainty

You now know:

  • A vector can hold a multi-axis sensor reading such as [0.5, 0.3, 0.8]g, whose magnitude is about 0.99g.
  • A matrix can rotate, scale, or update state vectors, including Kalman filter state such as position, velocity, and acceleration.
  • Probability makes fusion reviewable: a 10m GPS estimate and a 5m accelerometer estimate should not be averaged blindly; the more precise estimate carries more weight.


15.10 E. Modular Arithmetic for Cryptography

15.10.1 E.1 The Modulo Operation

Modulo is the arithmetic mechanism behind the wraparound behavior used throughout this section. Begin with small remainders to verify the operation, then carry the same rule into modular exponentiation. The examples establish the computation; later cryptographic sections add the essential requirements for large parameters, randomness, authentication, and safe key handling.

The Core Idea

Modular arithmetic is “clock arithmetic.” After reaching a maximum value, numbers wrap around to zero.

Notation: amodna \mod n = remainder when a is divided by n

Examples:

  • 7mod5=27 \mod 5 = 2 (7 = 1x5 + 2)
  • 25mod7=425 \mod 7 = 4 (25 = 3x7 + 4)
  • 12mod12=012 \mod 12 = 0 (clock wraps at midnight)

15.10.2 E.2 Why Modular Arithmetic for Cryptography?

Key Property: Easy to compute forward, hard to reverse.

Example - Discrete Logarithm:

Given: g=5g = 5, p=23p = 23

Forward (easy): Calculate 57mod235^7 \mod 23 57=78125mod23=175^7 = 78125 \mod 23 = 17

Reverse (hard): Given 17, find x where 5xmod23=175^x \mod 23 = 17

This “trapdoor” property enables public-key cryptography.

15.10.3 E.3 Diffie-Hellman Key Exchange

Two IoT devices can agree on a shared secret over an insecure channel. First read the message sequence in Figure 15.1 from public parameters through exchanged public values to the independently derived shared result.

Two devices agree on public parameters, pick secrets, exchange computed public values and derive the same Diffie-Hellman shared secret. The worked result is 2 on both sides.
Figure 15.1: Diffie-Hellman key exchange between two IoT devices

Follow Figure 15.1 from the public parameters through the exchange. Each device keeps its private exponent, publishes only a modular result, receives the other public value, and reaches the same shared value by combining it with its own secret. Figure 15.2 now restates the one-way property visually: follow public yellow into each private mixture, across the public exchange, and into the matching final colour.

Analogy-based explanation of Diffie-Hellman using color mixing. Public shared starting color is Yellow (known to everyone including eavesdropper). Device A mixes with secret Red to get Orange, sends Orange publicly. Device B mixes with secret Blue to get Green, sends Green publicly. Device A takes Green (from B) and adds its secret Red to get Brown. Device B takes Orange (from A) and adds its secret Blue to get same Brown. Eavesdropper sees Yellow, Orange, Green but cannot unmix to find Red or Blue, so cannot compute Brown. The shared secret Brown is known only to A and B. This paint mixing analogy illustrates why DH is secure: mixing is easy, unmixing is computationally hard.
Figure 15.2: Alternative View: Paint Mixing Analogy - This diagram explains Diffie-Hellman using a color mixing analogy. Both devices start with shared public Yellow. Device A mixes with secret Red to create Orange. Device B mixes with secret Blue to create Green. They exchange Orange and Green publicly. A then adds Red to Green, B adds Blue to Orange - both get the same Brown (shared secret). The eavesdropper sees Yellow, Orange, and Green but cannot “unmix” colors to find the secrets. In math terms: mixing colors is easy (modular exponentiation), but unmixing is computationally hard (discrete logarithm). This is why Diffie-Hellman works for IoT key exchange.

Read Figure 15.2 from public yellow through the two private mixtures, across the public exchange, and into the matching final brown. The eavesdropper sees the public starting colour and both exchanged mixtures but cannot reverse them to recover either private colour. Likewise, an observer may see public values such as 8 and 19, while recovering the private exponents requires solving the discrete logarithm problem for properly chosen large parameters. The analogy explains one-way computation, not authentication; a real exchange still needs authenticated peers and safe key handling.


15.11 F. Complex Numbers for Signal Processing

15.11.1 F.1 What Are Complex Numbers?

The Core Idea

Complex numbers extend real numbers to include i=1i = \sqrt{-1}. They’re essential for representing signals that have both amplitude and phase.

Form: z=a+biz = a + bi

  • aa = real part
  • bb = imaginary part

Alternative (Polar) Form: z=reiθz = r \cdot e^{i\theta}

  • rr = magnitude (amplitude)
  • θ\theta = phase angle

15.11.2 F.2 Why Complex Numbers in IoT?

1. Representing Sinusoidal Signals:

A sensor reading: v(t)=Acos(ωt+ϕ)v(t) = A \cos(\omega t + \phi)

Using Euler’s formula: eiθ=cosθ+isinθe^{i\theta} = \cos\theta + i\sin\theta

We can write: v(t)=Re[Aei(ωt+ϕ)]v(t) = \text{Re}[A \cdot e^{i(\omega t + \phi)}]

2. Fourier Transform:

Converts time-domain signals to frequency-domain: X(f)=x(t)ei2πftdtX(f) = \int_{-\infty}^{\infty} x(t) \cdot e^{-i2\pi ft} \, dt

The result is complex:

  • Magnitude X(f)|X(f)| tells you “how much” of each frequency
  • Phase X(f)\angle X(f) tells you “when” each frequency component peaks

3. I/Q Signals in Radio:

LoRa and other radios use I/Q (In-phase/Quadrature) representation:

  • I = real part of signal
  • Q = imaginary part of signal

This allows representing any modulation scheme.

15.11.3 F.3 Complex Number Operations

OperationFormulaSignal Processing Meaning
Addition(a+bi)+(c+di)=(a+c)+(b+d)i(a+bi) + (c+di) = (a+c) + (b+d)iSuperimposing signals
Magnitude$a+bi
Phase(a+bi)=arctan(b/a)\angle(a+bi) = \arctan(b/a)Signal timing
MultiplicationMagnitudes multiply, phases addMixing/modulation

15.12 G. Information Theory Basics

15.12.1 G.1 Bits and Entropy

Treat bits and entropy as measures of uncertainty, not synonyms for file size. First identify the possible outcomes and their probabilities, then calculate how much information a result conveys. The distinction connects source data, compression, cryptographic randomness, and channel capacity while keeping each claim tied to its own assumptions.

The Core Idea

Entropy measures information content or uncertainty. More unpredictable data requires more bits to represent.

Entropy formula: H=ipilog2(pi)H = -\sum_i p_i \log_2(p_i)

Where pip_i is the probability of each outcome.

Example - Sensor Alarm:

  • Alarm triggers 1% of the time
  • H=(0.01log20.01+0.99log20.99)H = -(0.01 \log_2 0.01 + 0.99 \log_2 0.99)
  • H=(0.01×6.64+0.99×0.014)=0.08H = -(0.01 \times -6.64 + 0.99 \times -0.014) = 0.08 bits

The alarm provides only 0.08 bits of information per reading (very predictable).

15.12.2 G.2 Shannon Capacity

The maximum rate at which information can be reliably transmitted:

C=Blog2(1+SNR)C = B \log_2(1 + SNR)

Practical Implications:

SNRCapacity (per Hz of bandwidth)
1 (0 dB)1 bit/s/Hz
3 (5 dB)2 bit/s/Hz
7 (8.5 dB)3 bit/s/Hz
15 (12 dB)4 bit/s/Hz
31 (15 dB)5 bit/s/Hz

Key Insight: To double capacity, you need to roughly quadruple SNR. This explains why LoRa trades data rate for range (lower SNR = lower rate but still works).

SammyCheckpoint: Security and Signals

You now know:

Modular arithmetic wraps values around a modulus, as in 7 mod 5 = 2 and 25 mod 7 = 4. That wraparound supports the forward operations used in the key-exchange example.

Diffie-Hellman relies on forward calculations such as 5^7 mod 23 = 17 being easy while the reverse problem is hard. Authentication and key handling remain separate requirements.

Complex numbers track amplitude and phase, while information theory connects entropy, SNR, bandwidth, and Shannon capacity. Together they bound what the signal chain can represent and carry.


15.13 H. Quick Reference Card

15.13.1 Essential Formulas for IoT

15.13.1.1 Signal Processing

FormulaExpression
Nyquist Ratefsample2×fmaxf_{sample} \geq 2 \times f_{max}
Shannon CapacityC=B×log2(1+SNR)C = B \times \log_2(1 + SNR)
dB conversiondB=10×log10(P2/P1)dB = 10 \times \log_{10}(P_2/P_1)
dBm from mWdBm=10×log10(PmW)dBm = 10 \times \log_{10}(P_{mW})

15.13.1.2 Wireless

FormulaExpression
Free Space LossFSPL=20log10(d)+20log10(f)+20log10(4π/c)FSPL = 20\log_{10}(d) + 20\log_{10}(f) + 20\log_{10}(4\pi/c)
Link BudgetPrx=Ptx+Gtx+GrxLpathP_{rx} = P_{tx} + G_{tx} + G_{rx} - L_{path}
Path Loss (approx)LdnL \propto d^n (n = 2 free space, 3-4 urban)

15.13.1.3 Electronics

FormulaExpression
Ohm’s LawV=I×RV = I \times R
PowerP=V×I=I2R=V2/RP = V \times I = I^2R = V^2/R
RC Time Constantτ=R×C\tau = R \times C
Capacitor VoltageV(t)=V0×et/τV(t) = V_0 \times e^{-t/\tau}

15.13.1.4 Battery Life

FormulaExpression
Average CurrentIavg=(Iactive×D)+(Isleep×(1D))I_{avg} = (I_{active} \times D) + (I_{sleep} \times (1-D))
Battery LifeHours=mAh/mAaverageHours = mAh / mA_{average}

15.13.1.5 Sensor Fusion

FormulaExpression
Weighted Averagex=(σ22×x1+σ12×x2)/(σ12+σ22)x = (\sigma_2^2 \times x_1 + \sigma_1^2 \times x_2) / (\sigma_1^2 + \sigma_2^2)
Combined Varianceσ2=(σ12×σ22)/(σ12+σ22)\sigma^2 = (\sigma_1^2 \times \sigma_2^2) / (\sigma_1^2 + \sigma_2^2)

15.13.1.6 Probability

FormulaExpression
Gaussian 68-95-99μ±1σ\mu \pm 1\sigma (68%), μ±2σ\mu \pm 2\sigma (95%), μ±3σ\mu \pm 3\sigma (99.7%)
Expected ValueE[X]=(x×P(x))E[X] = \sum(x \times P(x))

Common Pitfalls

Every IoT calculation has units that must be tracked: mA for current, mAh for battery capacity, dBm for signal power, Hz for frequency, seconds for time. The battery life formula puts battery capacity (mAh) in the numerator and average current (mA) in the denominator; reversing those terms or confusing mA with uA gives an answer that is wildly wrong. Always write out units in intermediate steps and verify unit cancellation before trusting a numeric result.

RF engineers universally use dB (decibels) for signal strength because path loss spans 6 orders of magnitude (0.001 mW to 1000 mW). A 3 dB increase means double the power, not a 3% increase. Students who add dB values arithmetically (10 dBm + 10 dBm = 20 dBm, assuming 20 mW) make 100x errors. Remember: add dB values for gains/losses in a chain, but convert to linear scale first when adding powers from independent sources.

The Gaussian noise model works well for electronic noise (thermal noise, quantization noise) but fails for systematic errors (calibration drift, EMI interference, sensor saturation). Before applying the 68-95-99.7 rule to your sensor’s error budget, verify that actual error samples look bell-shaped by plotting a histogram. Outlier-prone sensors need robust statistics (median, IQR) rather than mean and standard deviation.

Label the Diagram
Code Challenge

15.15 Summary

This appendix covered the mathematical foundations used throughout the IoT textbook:

TopicKey ConceptPrimary Use
CalculusRates & accumulationPID control, energy budgets
ExponentialsGrowth/decaySignal attenuation, battery life
LogarithmsCompressiondB scales, Shannon capacity
Linear AlgebraVectors, matricesSensor fusion, Kalman filter
ProbabilityUncertaintyNoise modeling, reliability
Modular ArithmeticWraparound mathCryptography
Complex NumbersAmplitude + phaseSignal processing, radio
Information TheoryBits, entropyChannel capacity, compression

15.16 Continue to the Next Part

Carry this evidence into IoT Mathematics: Fusion and Sampling Decisions, which begins with Worked Example: Designing a Kalman Filter for GPS-Accelerometer Fusion.