25  Lab: Signal Processing

Run Evidence-First Sampling, Filtering, and Validation Exercises

fundamentals
signal
processing

25.1 In 60 Seconds

Signal-processing labs should prove that a sampled signal still represents the physical event. Capture a raw trace first, then vary one decision at a time: sample rate, ADC range, bit depth, filter type, frequency analysis, and downsampling. The output of each lab is a short evidence record that names what changed, what was preserved, what was removed, and what must be validated before the pipeline is reused.

Phoebe the physics guide

Phoebe’s Why

Exercise 5 in this lab asks you to confirm “the record length gives enough frequency resolution for the question” – a separate check from Exercise 2’s sample-rate review. They are separate because they answer different physical questions. Sample rate sets the highest frequency you can see without aliasing (that is Nyquist, covered in the sampling-rate chapter). Record length sets how finely you can tell two nearby frequencies apart, because you are only ever watching the signal for a finite window of time, and a short window simply has not run long enough to distinguish two tones that are close together. Doubling the sample rate does nothing for that problem; only watching longer does.

The Derivation

Capturing \(N\) samples at rate \(f_s\) covers a record length:

\[T = \frac{N}{f_s}\]

A spectrum computed from that record can only report frequency in discrete steps spaced by:

\[\Delta f = \frac{f_s}{N} = \frac{1}{T}\]

A finite-length rectangular capture is equivalent to multiplying an infinite signal by a rectangular window, which convolves each true frequency component with a sinc function of main-lobe width \(\sim 1/T\) in the spectrum – so two tones closer together than about \(1/T\) smear into one peak no matter how fast they were sampled.

Worked Numbers: Sizing A Capture For This Lab’s Own Exercise 5

  • A catalog-typical 1 kHz sample rate (\(f_s\)) with a 1-second capture (\(N=1{,}000\) samples) gives \(T=1{,}000/1{,}000=1.00\) s, so \(\Delta f = 1/T = 1.00\) Hz. That is fine for separating a 50 Hz motor tone from a 53 Hz misalignment tone, 3 Hz apart.
  • The same 1-second capture cannot separate two tones only 0.5 Hz apart, because \(0.5\ \mathrm{Hz} < \Delta f\) – the two peaks smear together in the spectrum regardless of how clean the 1 kHz sampling is.
  • Fixing that requires a longer window, not a faster one: resolving 0.5 Hz needs \(T \geq 1/0.5 = 2.00\) s, i.e. doubling the capture length to \(N=2{,}000\) samples at the same 1 kHz rate.
  • This is why Exercise 5’s record-length check and Exercise 2’s sample-rate check both belong in the lab record: raising \(f_s\) without raising \(N\) only pushes the aliasing boundary higher, while raising \(T\) without checking \(f_s\) can still let a fast component fold back and masquerade as one of your closely spaced “resolved” peaks.

25.2 Start With the Story

Start with a physical signal that is noisy, delayed, sampled, quantized, calibrated, filtered, packed, and finally sent as a number someone will trust. The core idea in Lab: Signal Processing is simple: signal processing is the bridge between the physical world and digital evidence, so every sampling, ADC, filter, and calibration choice changes the value that leaves the device. This page focuses that idea on Platform-neutral signal-processing lab for capturing raw traces, testing sample-rate and ADC-resolution choices, comparing filters. In everyday IoT, temperature drift, vibration spikes, audio snippets, and lab traces all become decisions only after their limits and uncertainty are made visible. Start simple: trace one measurement through the chain, keep the raw-to-processed evidence, and move advanced math into the deeper review only when the simple chain no longer explains the result.

25.3 Learning Objectives

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

  • Capture a raw sensor trace and preserve enough metadata to repeat the test.
  • Compare sample-rate choices without confusing aliasing with real behavior.
  • Fit ADC resolution to useful signal span, noise, and reference range.
  • Compare median, moving-average, low-pass, notch, and high-pass filters by failure pattern.
  • Use frequency-domain evidence carefully, with sample-rate and window choices recorded.
  • Build a multi-stage pipeline and document what each stage removes or delays.

Quick Check: Lab

25.4 How It Works: Run a Signal Lab Without Hiding Evidence

The labs follow a repeatable evidence loop.

  1. Capture raw data first. Save units, timestamps, sample interval, sensor setup, and expected event timing before changing the stream.
  2. Change one decision. Adjust only sample rate, ADC range, bit depth, or filter choice so the result has a traceable cause.
  3. Compare against the requirement. Decide whether the changed stream still preserves the event, threshold, or trend the product needs.
  4. Write the release note. Record what the pipeline removes, what it delays, and what should trigger a retest.

25.5 Incremental Examples

Beginner Example: Compare raw and moving-average temperature data. The average may reduce jitter, but the lab record must note the delay it introduces.

Intermediate Example: Test two sample rates for a vibration trace. If the apparent pattern changes, keep the raw traces and review aliasing before choosing a filter.

Advanced Example: Build a staged pipeline for an acoustic event: anti-alias filter, sample-rate choice, windowed frequency review, and a validation check against missed events.

25.6 Concept Check: One Variable

Why should the lab avoid changing sample rate and filter type at the same time?

Answer: changing both hides the cause. A cleaner output could come from better sampling, stronger smoothing, or accidental loss of useful evidence.

25.7 Concept Check: Raw Trace Value

What should you do before accepting a processed trace as release evidence?

Answer: compare it with the raw trace and the original requirement, then record what was preserved, removed, or delayed.

25.8 Try It Yourself

Design a five-row lab table with columns for raw evidence, one changed decision, before/after observation, risk introduced, and release decision. Fill it for a sensor or dataset you can inspect.

25.9 See Also

25.10 Lab Workflow

Run the labs as small experiments. Do not change the sensor, sample rate, reference range, and filter all at once.

Signal-processing lab workflow showing raw capture, one-variable experiment, comparison, pipeline decision, and validation record.
Signal-processing lab workflow keeps raw evidence, one-variable changes, comparison, pipeline decisions, and validation records separate.

25.10.1 Start With Raw Evidence

Save an unfiltered trace with timestamp spacing, units, expected event timing, reference range, and any known environmental conditions.

25.10.2 Change One Decision

Vary only sample rate, bit depth, reference range, or filter choice. A lab that changes multiple decisions cannot explain the result.

25.10.3 Compare Before and After

Keep the raw trace beside the processed trace. Record latency, missed events, rejected spikes, and any information the processing could hide.

25.10.4 Validate the Pipeline

Test with a known event or reference trace before treating the processed stream as trustworthy.

25.11 Lab Sequence

Use the following sequence as a workbook. Each exercise has a decision, an observation, and a record.

Signal-processing lab matrix listing sample-rate, ADC-fit, filter, spectrum, and pipeline experiments.
The lab matrix separates raw traces, sample-rate tests, ADC-fit checks, filter tests, spectrum checks, and pipeline records.
Exercise
Run
Observe
Record
Raw trace
Capture the sensor stream before smoothing, averaging, clipping, or downsampling.
Range, noise, spikes, drift, event length, and timestamp spacing.
Units, reference range, sample interval, and raw file or trace identifier.
Sample rate
Repeat a known event at two or three sample rates while keeping the analog path unchanged.
Whether event timing, amplitude, or apparent frequency changes with rate.
Highest useful bandwidth, selected rate, and anti-alias boundary.
ADC fit
Compare code step against useful span, noise, and required physical change.
Whether extra bits reveal information or only record analog noise.
Reference range, bit depth, code step, noise estimate, and margin.
Filter test
Apply one filter type at a time to the same raw trace.
Spike rejection, smoothing, lag, ringing, drift removal, or lost events.
Filter type, window or cutoff, visible benefit, and visible cost.
Pipeline
Combine only the stages that passed individual tests.
End-to-end timing, retained event shape, data reduction, and review triggers.
Stage order, validation evidence, and conditions that require rework.

25.12 Exercise 1: Raw Trace and Timing Record

Capture a short trace from the sensor or signal source before applying any digital processing.

Minimum record:

  • physical quantity and units
  • expected range and useful signal span
  • sample interval and timestamp source
  • reference range or gain setting
  • known event timing or stimulus
  • raw trace storage location
Do Not Start With a Filter

If the raw trace is not saved, there is no way to prove that a later filter preserved the event instead of hiding it. Raw evidence is the baseline for every later lab.

25.13 Exercise 2: Sample-Rate Review

Use a known event or controlled signal and repeat the capture at several sample rates. The goal is not to find the fastest setting; the goal is to find the lowest rate that preserves the needed timing evidence with margin.

Review prompts:

  • Does the apparent frequency change when the sample rate changes?
  • Does a short event disappear at a lower rate?
  • Is the analog front end limiting content before the ADC?
  • Is the selected rate justified by useful bandwidth rather than convenience?

When a pattern moves with sample rate, suspect aliasing and return to ADC Sampling Fundamentals before choosing a filter.

25.14 Exercise 3: ADC Resolution Fit

Measure whether the chosen reference range and bit depth are meaningful for the useful signal span. More bits help only if the analog evidence supports them.

Run it: Put your numbers into the formula calculator below before you judge the fit. Enter the reference range and bit depth to get the ADC code step, then compare that step against your required change size and noise estimate. Sweep the bit depth and watch where extra bits stop shrinking the code step below your noise floor – that is the point the practical fit rule warns about – and record whether the resolution is too coarse, useful, or overspecified.

Use this record:

  • reference range
  • expected useful signal span
  • required physical change size
  • code step
  • noise estimate in codes or physical units
  • decision: too coarse, useful, or overspecified
Practical Fit Rule

The code step should be smaller than the required change size, but extra bit depth stops helping when analog noise, reference drift, or sensor uncertainty is larger than the code step.

25.15 Exercise 4: Filter Comparison

Run every candidate filter against the same raw trace. A filter should be chosen because it matches the observed failure pattern.

Run it: Run all four filters against one signal in the workbench below instead of arguing about them on paper. Load a sampled trace with spikes, jitter, and a drift or tone, then switch between median, moving average, low-pass, and notch and watch each one help one failure pattern while damaging another – staircasing, smeared spikes, missed fast events, or removed signal. Match the filter to the failure pattern you actually see, and note the window delay or lag it costs.

25.15.1 Median

Best for isolated spikes. Watch for staircase behavior and window delay.

25.15.2 Moving Average

Best for random jitter when lag is acceptable. Watch for smeared spikes and delayed edges.

25.15.3 Low-Pass

Best when useful content is slower than unwanted noise. Watch for missed fast events.

25.15.4 Notch or High-Pass

Best for a known interference tone or slow baseline drift. Watch for removed legitimate signal content.

25.16 Exercise 5: Frequency Evidence

Frequency analysis is useful only when sample rate, record length, and windowing choices are part of the record.

Frequency evidence check showing time trace, sample plan, spectrum peaks, and alias review before accepting a frequency result.
Frequency evidence is only useful when the time trace, sample plan, spectrum peak, and alias check agree.

Before accepting a spectral peak:

  1. Confirm the sample rate is above the useful frequency range with room for the analog filter boundary.
  2. Confirm the record length gives enough frequency resolution for the question.
  3. Compare the peak with known physical events or a reference capture.
  4. Change the sample rate as a diagnostic test if the peak seems suspicious.
  5. Record the windowing or binning method if spectral leakage matters.

25.17 Exercise 6: Pipeline Review

Build the pipeline only after the individual stages have evidence. A common order is analog boundary, sampling, spike rejection, smoothing, downsampling, and validation.

Signal-processing pipeline record showing stage order, purpose, input evidence, output evidence, and review trigger.
A pipeline record names each stage, its purpose, its input and output evidence, and the trigger for rework.

The pipeline record should answer:

  • Which stage prevents aliasing before sampling?
  • Which stage removes isolated bad samples?
  • Which stage smooths random jitter?
  • Which stage reduces data volume?
  • What is the latency added by each stage?
  • What event or signal change would force a new review?

25.18 Check Your Understanding

Lab Workflow Label Check

Lab Decision Matching

Lab Order

Knowledge Check

25.19 Common Pitfalls

If sample rate, bit depth, reference range, and filter type change together, the lab cannot explain which decision caused the improvement or failure.

Digital smoothing can hide aliasing, clipping, or missed short events. Check the analog boundary and sample plan first.

A processed stream should be tested with a known event. A trace that looks calm may simply be removing the information the system needs.

25.20 Capture Limits Software Cannot Repair

A signal-processing lab is not a search for the smoothest chart. It is a controlled experiment that proves whether a processing decision still preserves the physical event the IoT product needs. The baseline is always a raw trace with units, timestamps, expected event timing, reference range, sensor setup, and analog-front-end settings recorded before any smoothing, clipping, downsampling, or frequency analysis.

For sampling, define the highest useful signal frequency, the shortest event duration, and the analog bandwidth before choosing a sample rate. Nyquist gives the lower bound: to capture frequencies up to f, the stream must be sampled above 2f. In practice, leave margin above that bound because analog filters need transition room and real events rarely arrive as perfect sinusoids.

For conversion, record the ADC reference range, bit depth, noise estimate, and smallest meaningful physical change. An N-bit ADC divides its reference into 2^N codes, so one code step is approximately Vref / 2^N. Extra nominal bits do not help when sensor noise, reference drift, or analog-front-end error is larger than the code step.

ADC bits Levels Step at Vref = 3.3 V
8-bit 256 about 12.9 mV
12-bit 4096 about 0.81 mV
16-bit 65536 about 0.050 mV

A vibration lab that expects useful energy up to 1 kHz and meaningful amplitude changes around 1 mV needs both timing and amplitude evidence. Nyquist demands more than 2 kHz, but a lab might test 3.2 kHz and 4 kHz to leave margin for the analog filter and short events. At a 3.3 V reference, an 8-bit ADC cannot resolve a 1 mV change; a 12-bit ADC can, provided analog noise is not larger. The final record should name both the sample-rate margin and the ADC-fit evidence.

25.20.1 Irreversible Failures

Two lab failures are irreversible after capture: aliasing and clipping. Aliasing occurs when energy above half the sample rate folds into the measured band. Once that folding has happened, the sampled data cannot tell whether a low-frequency pattern was real or created by undersampling. A proper lab therefore records the analog anti-alias boundary, not just the digital sample rate. The low-pass filter must act before the ADC, with cutoff and rolloff chosen so unwanted energy is reduced before it can fold down.

Clipping is equally destructive. If the sensor, amplifier, or ADC reference range saturates, the missing waveform shape cannot be reconstructed by a later smoothing filter. The raw-trace exercise should mark full-scale hits, baseline drift, and gain settings before any filter makes the trace look acceptable. The ADC-fit exercise then decides whether to change gain, reference range, bit depth, or sensor placement.

Frequency evidence has its own bookkeeping. An FFT bin spacing of fs / N depends on sample rate and record length, so a spectral peak is only meaningful when those values and the windowing method are recorded. Window choice affects leakage; downsampling requires a low-pass stage before decimation; and filter phase or group delay can move event timing even when amplitude looks improved.

A release-ready pipeline records the analog boundary, ADC fit, filter cost, spectral assumptions, decimation rule, and validation trigger. Without those records, a clean trace is only a presentation artifact.

25.21 Summary

The strongest signal-processing lab is repeatable. Capture raw evidence, vary one decision, compare before and after, choose filters by observed failure pattern, and validate the final pipeline with a known event. The lab record should make the engineering decision easy to audit later.

25.22 What’s Next

25.23 Key Takeaway

Signal-processing labs should compare expected transformations with measured data. The goal is to understand noise, delay, quantization, calibration, and error before deploying the algorithm.