Moving average low-pass filter - klinke.studio

Moving average low-pass filter

browse sections

Moving average low-pass filter

A moving average smooths noisy sensor data by averaging the last NN samples. It is a simple low‑pass filter with a tunable window size.

y[n]=1Ni=0N1x[ni]y[n] = \frac{1}{N} \sum_{i=0}^{N-1} x[n-i]
Moving average filter
Moving average filter

Python example

from collections import deque

buffer = deque(maxlen=5)

buffer.append(value)
filtered_value = sum(buffer) / len(buffer)

Notes

  • Increasing NN reduces noise but adds latency.
  • For lower latency with adaptive smoothing, the 1‑Euro filter is a strong alternative (Casiez et al., 2012).
Casiez, G., Roussel, N., & Vogel, D. (2012). 1€ filter: A simple speed-based low-pass filter for noisy input in interactive systems. Proceedings of the SIGCHI Conference on Human Factors in Computing Systems, 2527–2530. https://doi.org/10.1145/2207676.2208639
  • Casiez, Gèry et al. (2012). 1€ filter: A simple speed-based low-pass filter for noisy input in interactive systems. Proceedings of the SIGCHI conference on human factors in computing systems. casiez2012aa