14
$\begingroup$

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.

$\endgroup$
  • 2
    $\begingroup$ Similar question: What is the difference between Kalman filter and moving average?. $\endgroup$ – RioRaider Sep 16 '12 at 14:42
  • $\begingroup$ 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. $\endgroup$ – dvreed77 Sep 16 '12 at 14:46
  • $\begingroup$ 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. $\endgroup$ – Ali Sep 16 '12 at 14:54
  • $\begingroup$ 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. $\endgroup$ – dvreed77 Sep 16 '12 at 15:18
  • $\begingroup$ and if it makes a difference, when I say outerperform, I mean the MSE is smaller using the moving average. $\endgroup$ – dvreed77 Sep 16 '12 at 15:24
4
$\begingroup$

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

$\endgroup$
2
$\begingroup$

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.

$\endgroup$
  • 1
    $\begingroup$ 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. $\endgroup$ – EngrStudent - Reinstate Monica Jul 4 '17 at 14:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.