Sensors & Measurement · Study deck

Sensor Processing: Sampling and Signals

A clean chart can hide aliasing, clipping, or lost detail.

Physics Phoebe is your guide for this deck.

sensordataprocessing
Physics Phoebe, the module guide, in a scene from this chapter.
iotclass.org

After studying this chapter

Learning objectives

You will be able to:

  • Implement and compare moving average, Kalman, and median filters to reduce sensor noise
  • Execute two-point calibration procedures to correct sensor offset and gain errors
  • Design data validation pipelines that detect anomalies and reject outliers
  • Select and justify appropriate filtering strategies based on signal characteristics and resource constraints
iotclass.org

Major section

Start With the Measurement Story

Bandwidth is the range of change a signal or link can carry.

  • Smoothing may hide the jump, but it may also hide a real door-open event.
  • No filter can recover facts that were never measured.
  • A reading becomes information only after noise, drift, outliers, scaling, and timing are handled.

Why it matters

They show which fault each method can reduce and which limit must remain visible.

iotclass.org

Major section

Phoebe's Field Notes: Where Vibration Nyquist Meets the Sensor's Own Step Size

The mathematical gist: The chapter's 100 Hz ADXL345 stream has a 50 Hz Nyquist ceiling: higher vibration components fold to false lower frequencies before a median or moving-average filter can see them.

  • Choosing the right filter depends on your signal characteristics and noise type.

Key terms

Higher Q/R ratio
Higher Q/R ratio means the filter trusts measurements more; lower ratio means it trusts its own predictions more.
Sensor data processing pipeline showing stages from raw ADC input through outlier rejection, smoothing, calibration, to clean output in engineering units
Sensor data processing pipeline from raw readings to calibrated output
iotclass.org

Major section

Phoebe's Field Notes: Where Vibration Nyquist Meets the Sensor's Own Step Size (continued)

For most beginner IoT projects, do not start with Kalman.

  • The order shows why noise reduction cannot repair bias and why calibrated values still require invalid-sample handling.
  • The moving average filter is the simplest and most common approach.
  • ESP32's floating-point unit makes Kalman practical.
iotclass.org

Major section

Phoebe's Field Notes: Where Vibration Nyquist Meets the Sensor's Own Step Size (continued)

When sensor data has occasional spike errors (outliers), a median filter is more effective than averaging.

  • For a beginner, the behavior matters more than the implementation: a larger window gives a smoother line but reacts more slowly.
  • The Kalman filter provides optimal noise reduction for linear systems with Gaussian noise by modeling the system dynamics.
  • The median instead rejects an isolated outlier while preserving the surrounding level.
Filter comparison showing response to noisy input with spike
Filter comparison showing response to noisy input with spike
iotclass.org

Major section

Phoebe's Field Notes: Where Vibration Nyquist Meets the Sensor's Own Step Size (continued)

It adapts based on measurement uncertainty and process noise. (For non-linear sensors such as thermistors or pH electrodes, Extended or Unscented Kalman Filters are needed instead.).

  • A single bad spike is ignored instead of being averaged into future readings.
  • Kalman filter response varies based on Q and R parameters and is explored in the interactive calculator below.
  • The moving average spreads a spike across its window, so several later samples remain displaced after the raw event has passed.
  • Kalman requires knowing process noise (Q) and measurement noise (R) -- wrong values degrade performance.
iotclass.org

Major section

Phoebe's Field Notes: Where Vibration Nyquist Meets the Sensor's Own Step Size (continued)

That difference connects the expected noise shape to filter choice: use averaging for distributed random variation, but prefer a median when occasional impulses would contaminate a windowed mean.

  • The EMA is the most memory-efficient filter -- it requires only a single float (4 bytes) of state.
  • Unlike a moving average that weights all N samples equally, the EMA gives exponentially decreasing weight to older samples.
  • The smoothing factor alpha (0 to 1) controls responsiveness: lower alpha means smoother output but slower response.
iotclass.org

Major section

Phoebe's Field Notes: Where Vibration Nyquist Meets the Sensor's Own Step Size (continued)

Option B: Kalman Filter (1D): A compact state estimate with adaptive gain and Q/R tuning; memory, CPU time, delay, and noise reduction depend on the implementation and signal.

  • Decision Factors: For stationary signals with Gaussian noise (temperature averaging), moving average is simpler and nearly as effective.
  • For tracking changing signals (position, velocity, acceleration) where latency matters, Kalman filters provide faster response with better noise rejection.
  • For resource-constrained 8-bit MCUs (ATmega328), moving average's integer-only math saves flash and runs faster.
iotclass.org

Deck summary

Key takeaways

Bandwidth is the range of change a signal or link can carry.

  • The mathematical gist: The chapter's 100 Hz ADXL345 stream has a 50 Hz Nyquist ceiling: higher vibration components fold to false lower frequencies before a median or moving-average filter can see them.
  • For most beginner IoT projects, do not start with Kalman.
  • When sensor data has occasional spike errors (outliers), a median filter is more effective than averaging.
  • It adapts based on measurement uncertainty and process noise. (For non-linear sensors such as thermistors or pH electrodes, Extended or Unscented Kalman Filters are needed instead.).
iotclass.org

Retrieval practice

Recall check 1 of 3

Physics Phoebe says: answer from memory, then check your reasoning.

Q1A sensor stream has rare impossible spikes and ordinary jitter. Which pipeline keeps a spike from tainting later decisions?

AAverage raw samples before checking spikes, spreading one bad reading.
BReject impossible samples, smooth valid values and retain fault evidence.
CDelete raw readings after a smooth chart appears, hiding invalid samples.
DUse calibration alone as if it removed random impossible spikes.
Show answer

Answer: B Correct: validation before smoothing prevents a bad value spreading through the window.

iotclass.org

Retrieval practice

Recall check 2 of 3

Physics Phoebe says: answer from memory, then check your reasoning.

Q2A sensor is calibrated in the lab, then loses power in the field. What should firmware do at startup?

AAssume the old values remain in working memory
BUse raw readings until the next manual calibration
CRead valid stored gain and offset before using the readings
DAverage more samples instead of loading coefficients
Show answer

Answer: C Correct: persistent coefficients let the corrected measurement survive a restart.

iotclass.org

Retrieval practice

Recall check 3 of 3

Physics Phoebe says: answer from memory, then check your reasoning.

Q3What is the main purpose of sensor data processing before data is used for decisions?

AApply processing that preserves the measurement's meaning.
BSmooth readings solely to make the display look steady.
CArchive raw values because retaining every reading preserves the decision evidence automatically.
DProcess readings while discarding measurement limits and assumptions.
Show answer

Answer: A Processing should improve interpretability for a use case while keeping measurement assumptions visible.

iotclass.org

Print reference

Answers

Answer key.

  1. B · Correct: validation before smoothing prevents a bad value spreading through the window.
  2. C · Correct: persistent coefficients let the corrected measurement survive a restart.
  3. A · Processing should improve interpretability for a use case while keeping measurement assumptions visible.
iotclass.org