Β· Hankyu Kim Β· Filter  Β· 3 min read

Moving Average Filter

The moving average filter reduces noise while preserving the dynamic behavior of time-varying signals by averaging only a recent window of measurements.

The moving average filter reduces noise while preserving the dynamic behavior of time-varying signals by averaging only a recent window of measurements.

Introduction

This post introduces the Moving Average Filter, an extension of the basic average filter designed to handle time-varying signals.

As shown in the previous post, taking an average is highly effective at removing noise.
However, when the underlying signal changes over time, a simple average filter becomes inadequate.


Limitation of the Average Filter

The standard average filter computes the mean of all past measurements.

This works well when the true value is constant, but fails when the signal evolves.

Consider a signal that increases linearly:

xk=1,2,3,4,5,…x_k = 1, 2, 3, 4, 5, \dots

Applying a cumulative average produces:

1β†’1.5β†’2β†’2.5β†’31 \rightarrow 1.5 \rightarrow 2 \rightarrow 2.5 \rightarrow 3

Instead of following the signal, the filter outputs a smoothed but lagging estimate.

As the sequence grows longer, this accumulated lag becomes more severe.


Why Moving Average?

Most real-world signals are dynamic.

We want a filter that:

  • Suppresses noise
  • Responds to recent changes
  • Does not accumulate long-term bias

This motivation leads to the Moving Average Filter.


Core Idea

Instead of averaging all past data, the moving average computes the mean over a fixed window of recent samples.

At time kk, only the most recent nn samples are used:

xΛ‰k=1nβˆ‘i=kβˆ’n+1kxi\bar{x}_k = \frac{1}{n} \sum_{i=k-n+1}^{k} x_i

Old data is discarded, allowing the estimate to track changes in the signal.


Simple Example

Assume the input sequence:

[1,2,3,4,5][1, 2, 3, 4, 5]

Using a window size of n=2n=2:

1β†’1.5β†’2.5β†’3.5β†’4.51 \rightarrow 1.5 \rightarrow 2.5 \rightarrow 3.5 \rightarrow 4.5

Comparison:

Measured12345
Average Filter11.522.53
Moving Average11.52.53.54.5

Even in this simple case, the moving average tracks the signal far more accurately.


Dynamic Signal Example

Consider a signal defined as

y=x+1+noisey = x + 1 + \text{noise}

Super wide

  • The average filter increasingly lags behind the true signal

Super wide

  • The moving average filter continues to track the trend

Using a window of the most recent 5 samples, the moving average maintains stability while responding to changes.

The performance difference becomes more pronounced as:

  • The signal duration increases
  • The signal variation becomes larger

Efficient Recursive Update

The moving average can be updated efficiently without recomputing the full sum.

Let:

  • xΛ‰kβˆ’1\bar{x}_{k-1} be the previous moving average
  • xkx_k be the new sample
  • xkβˆ’nx_{k-n} be the oldest sample leaving the window

Then:

xΛ‰k=xΛ‰kβˆ’1+xkβˆ’xkβˆ’nn\bar{x}_k = \bar{x}_{k-1} + \frac{x_k - x_{k-n}}{n}

This update rule highlights the sliding window nature of the filter.


Key Insight

  • Only the newest and oldest samples affect the update
  • Middle samples remain unchanged
  • The filter adapts quickly to signal changes

This structure provides a balance between noise reduction and responsiveness.


Why This Matters

  • Average filters fail for time-varying signals
  • Moving average filters preserve dynamics
  • Window size controls the noise–responsiveness tradeoff

The moving average filter is a practical stepping stone toward more advanced adaptive filters.


Summary

  • Moving average filters use a fixed window of recent data
  • They remove noise without excessive lag
  • They outperform cumulative averages on dynamic signals
  • They are widely used in signal processing and control

Simple modification, significantly better behavior.

Back to Blog

Related Posts

View All Posts Β»
Low Pass Filter (LPF)

Low Pass Filter (LPF)

A low pass filter reduces noise while emphasizing recent measurements, overcoming the limitations of uniform averaging in moving average filters.

Average Filter

Average Filter

The average filter is the simplest form of recursive estimation. Despite its simplicity, it provides strong noise reduction and forms the foundation of more advanced filters such as the Kalman filter.

Kalman Filter (Part 1)

Kalman Filter (Part 1)

The Kalman filter is an optimal recursive estimator for linear systems, combining system models and noisy measurements through simple matrix operations.

Extended Kalman Filter (EKF)

Extended Kalman Filter (EKF)

The Extended Kalman Filter applies the Kalman filter to nonlinear systems by locally linearizing system and measurement models using Jacobians.