# When will a Kalman filter give better results than a simple moving average?

I recently implemented a Kalman filter on the simple example of measuring a particles position with a random velocity and acceleration. I found that Kalman filter worked well, but I then asked myself what's the difference between this and just doing a moving average? I found that if I used a window of about 10 samples that the moving average outperformed the Kalman filter and I'm trying to find an example of when using a Kalman filter has an advantage to just using the moving average.

I feel like a moving average is far more intuitive than the Kalman filter and you can apply it blindly to the signal without worrying about the state-space mechanism. I feel like I am missing something fundamental here, and would appreciate any help someone could offer.

• Similar question: What is the difference between Kalman filter and moving average?. Commented Sep 16, 2012 at 14:42
• I saw this post, but my question is asking for an example of when a Kalman filter will give me better results than a moving average. Commented Sep 16, 2012 at 14:46
• If the moving average is sufficient in your application then use it, you don't need the Kalman filter (KF). Under certain assumptions, the KF provides the best possible estimate. Either these assumptions doesn't hold in your application or your KF implementation should be checked.
– Ali
Commented Sep 16, 2012 at 14:54
• What are these assumptions? Gaussian noise? If so that's what my simulation is adding. My code is a slightly modified version of code given to me from a signal processing class, and I've checked it against several other sources and my update and prediction equations should be correct. I am wondering if the reason the moving average performs better is because it is using the past 10 samples instead of just the last sample that the KF is using. Though I think the error covariance is getting tighter with each additional sample, and so I am confused with how the MA is doing better. Commented Sep 16, 2012 at 15:18
• and if it makes a difference, when I say outerperform, I mean the MSE is smaller using the moving average. Commented Sep 16, 2012 at 15:24

The estimate given by a moving average will lag behind the true state.

Say you want to measure the altitude of a plane rising at a constant velocity and you have noisy (Gaussian) altitude measurements. An average over a time interval of noisy altitude measurements is likely to give you a good estimate of where the plane was in the middle of that time interval.

If you use a larger time interval for your moving average, the average will be more accurate but it will estimate the plane's altitude at an earlier time. If you use a smaller time interval for your moving average, the average will be less accurate but it will estimate the plane's altitude at a more recent time.

That said, the lag of a moving average may not pose a problem in some applications.

edit: this post asks the same question and has more responses and resources

I found that using the original parameters that I used to setup the problem, the moving average was performing better, but when I started playing with the parameters that defined my dynamic model I found the Kalman Filter was performing much better. Now that I have something setup to see the effects the parameters play I think I will gain a better intuition on what exactly is happening. Thank you to those who replied and sorry if my question was/is vague.

• It might be helpful to others engaging the question if you put reproducible toy code in your answer, to allow them to "see it in action". Personally, my answers that others have rated most highly tend to have reproducible content. Commented Jul 4, 2017 at 14:15