MTBuilder AcademyLearn it. Test it. Build it.
Feedback & motionLesson 36 of 48
Practice60 minutes2 project connections

Filtering and state estimation

Reduce measurement noise without hiding motion, delay, or faults, and quantify what an estimate can support.

After this lesson, you can
  • Implement and analyze a moving-average or exponential low-pass filter.
  • Separate measurement, estimate, residual, and true-but-unknown state in a diagnostic record.
Print / Save PDF
ReadPracticedBench demonstrated
Related study — optional context
01

Understand

The working idea

Sensors do not reveal truth directly. A camera-derived position jitters, an ADC includes quantization and electrical noise, and a distance sensor may occasionally return an outlier. Filtering combines measurements over time to make a more useful estimate. The cost is usually delay or reduced ability to follow rapid change.

An N-sample moving average is ȳ_k = (1/N)Σx_{k-i}. For independent zero-mean noise with standard deviation σ, its standard deviation falls ideally to σ/√N, but the window delays changing signals. An exponential filter uses ŷ_k = αx_k + (1-α)ŷ_{k-1}, with 0 < α ≤ 1. Smaller α smooths more and responds more slowly. A state estimator goes further by combining a process model and measurement uncertainty; even a simple “predict, compare residual, correct” loop makes its assumptions explicit.

The residual r_k = measurement - predicted measurement is diagnostically valuable. Random residuals near zero may support the model; persistent bias suggests calibration error or an unmodelled force; abrupt large residuals may signal dropout or impact. Do not silently discard inconvenient readings. Record raw data, estimate, filter parameters, timestamp, saturation, and rejection decisions. For a camera mount, the build decision could be a modest filter that reduces pixel jitter while preserving enough bandwidth to track intentional pan motion.

A common misconception is that a smoother plot is more accurate. Heavy filtering can produce a clean but late estimate and hide a loose connector. Another is treating a filter's output as a physical measurement; it is a computed estimate based on assumptions. Averaging correlated drift does not remove the drift as σ/√N predicts. Choose filter bandwidth relative to system dynamics, examine residuals, and test known changes. If control stability worsens after filtering, added delay may outweigh reduced noise.

02

Follow the reasoning

Worked example

A distance sensor reports 100, 104, 98, and 102 mm. Compute the four-sample mean and the ideal standard-deviation reduction factor for independent noise.

  1. 1

    Sum readings: 100 + 104 + 98 + 102 = 404 mm.

  2. 2

    Mean is 404 mm ÷ 4 = 101 mm.

  3. 3

    For independent zero-mean noise, standard deviation of the mean is σ/√4 = σ/2.

Result

The estimate is 101 mm, with an ideal random-noise standard deviation half that of one reading.

Sanity checkThe mean lies within the observed 98–104 mm range; the uncertainty claim does not cover bias or correlated drift.

03

Try it yourself

Independent check

A larger moving-average window makes a stationary trace smoother but causes a robot to react late to obstacles. What explains both effects?
04

Move to the bench

Compare raw, filtered, and residual signals during stationary and moving tests.

Gather
  • Low-voltage distance or light sensor
  • Microcontroller
  • Serial logger
  • Movable target
  • Ruler

Experiment

  1. Log raw readings from a fixed target and predict how windows N = 1, 4, and 16 will affect scatter and response time.
  2. Move the target by a measured amount at a marked time; compute each moving average without deleting raw samples.
  3. Compare actual scatter, time to cross 90% of the change, and residuals for each window.
  4. Deliberate fault: briefly cover or disconnect the sensor within its safe interface; diagnose the outlier/dropout from raw data and residual rather than masking it with a long average.

Observe

  • Expected: longer windows reduce stationary scatter but delay the measured step.
  • Measure: actual raw range, filtered crossing time, residuals, and dropout code; identify assumptions behind any uncertainty estimate.
Transfer it

Choose and justify a filter for a desk robot that must ignore millimetre jitter yet detect a hand approaching within 0.3 s.

Limits and cautions
  • Use only sensor-safe low-voltage wiring and disconnect power before changing connections.
05

Keep evidence

Bench note

Record what you expected, what you actually measured or observed, and one difference worth investigating. This is self-reported evidence, not a certification.

0 / 5,000A bench demonstration needs a concrete note of at least 20 characters.
Terms in this lessonBrowse the advanced glossary

Sources and further reading

  1. Control Tutorials for MATLAB and Simulink
  2. Modern Robotics