递归滤波器:SMA、EMA、低通滤波器及微型卡尔曼滤波器
Recursive Filters: SMA, EMA, Low‑Pass, and a Tiny Kalman

原始链接: https://www.staszewski.xyz/blog/recursive-filters/

本文探讨了在嵌入式系统和实时流处理等资源受限环境中,用于平滑噪声数据的递归滤波器。这些滤波器因其 $O(1)$ 的内存和计算需求而备受青睐,能够实现即时状态更新,无需大型缓冲区。 作者重点介绍了三种主要技术: * **简单移动平均 (SMA):** 一种直观的方法,对最近的 $k$ 个样本进行平均。虽然在降低噪声方面有效,但它需要缓冲区并会引入滞后。 * **指数移动平均 (EMA) / 一阶低通滤波器:** 一种“泄漏积分器”,通过平滑因子 ($\alpha$) 来平衡响应速度与噪声抑制。它是大多数流数据处理的首选方案。 * **一维卡尔曼滤波器 (1D Kalman Filter):** 一种更复杂的方法,它根据预定义的传感器噪声 ($R$) 和过程噪声 ($Q$),动态调整对先前状态与新测量值之间的信任度。 本指南强调,虽然 SMA 和 EMA 足以应对基础的平滑需求,但一维卡尔曼滤波器为处理自适应、不稳定的数据提供了原则性的方法。这些方法为任何需要低延迟、计算高效信号处理的开发者提供了一套实用的工具箱。

```Hacker News新帖 | 往期 | 评论 | 提问 | 展示 | 招聘 | 提交登录递归滤波器:SMA、EMA、低通滤波器和微型卡尔曼滤波 (staszewski.xyz)7 分,作者 kamilstaszewski,1 小时前 | 隐藏 | 往期 | 收藏 | 讨论 帮助 考虑申请 YC 2026 年秋季批次!申请截止日期为 7 月 27 日。 指南 | 常见问题 | 列表 | API | 安全 | 法律 | 申请 YC | 联系 搜索:```
相关文章

原文

/ 4 min read

While exploring optimizers I fell down the rabbit hole of recursive filters. This post is a compact, practical tour of smoothers you can use when measurements are noisy but latency and compute are tight. We’ll keep the math minimal, the intuition high, and focus on when and why to use SMA, EMA/low‑pass, and a tiny 1D Kalman.

If you are here just for code, my Kaggle Notebook can be found here.

Why recursive filters

Recursive filters shine when compute and memory are scarce, or when data arrives as a stream and you must react immediately.

  • O(1) memory: you keep just the last state (and maybe a running sum) rather than a long buffer.
  • O(1) compute per sample: one or two multiply‑adds per step—perfect for microcontrollers and tight loops.
  • Online, low‑latency: produce an updated estimate as soon as a sample arrives; no need to wait for a full window.
  • Simple, robust implementations: easy to port, vectorize, or run in reduced precision.
  • Graceful with irregular sampling: updates are incremental and don’t assume batch availability.

Intuition note

Recursive filters that we’ll use, all use constant‑size state. That’s why they’re common in embedded systems, robotics control loops, mobile sensor smoothing and telemetry.

Notation

  • xtx_t
  • sts_t
  • kk: window size (for moving averages).
  • α[0,1]\alpha\in[0,1]

Recursive Average Filter (also known as EMA)

The one‑liner you’ll use most:

st=αst1+(1α)xt.s_t = \alpha\, s_{t-1} + (1-\alpha)\, x_t.
联系我们 contact @ memedata.com