File Exchange Pick of the Week

Our best user submissions

Learning the (Linear) Kalman Filter

Brett's Pick this week is "Learning the Kalman Filter", by Michael Kleder.

If one were to sort the entries of the File Exchange by the number of downloads in the past 30 days, an interesting trend would become apparent: a handful of files have been downloaded far more times than the vast majority of the rest of the files on the Exchange. Of those, one file in particular has been dowloaded 43% more times than the next most popular file.

The popularity of Michael's "Learning the Kalman Filter" mini tutorial (as of this writing, it has been downloaded 2803 times in the past 30 days--even though the file has been up for 6 years!), along with the great feedback it has garnered (73 comments and 67 ratings, averaging 4.5 out of 5 stars), initially caught my eye.

Michael wrote in the preamble to his tutorial:

%%%%%%%%%%%%%%%%%%%

Many people have heard of Kalman filtering, but regard the topic as mysterious. While it's true that deriving the Kalman filter and proving mathematically that it is "optimal" under a variety of circumstances can be rather intense, applying the filter to a basic linear system is actually very easy. This Matlab file is intended to demonstrate that.

%%%%%%%%%%%%%%%%%%%

In his in-file example, Michael then steps through a Kalman filter example in which a voltmeter is used to measure the output of a 12-volt automobile battery. The model simulates both randomness in the output of the battery, and error in the voltmeter readings. Then, even without defining an initial state for the true battery voltage, Michael demonstrates that with only 5 lines of code, the Kalman filter can be implemented to predict the true output based on (not-necessarily-accurate) uniformly spaced, measurements:

This is a simple but powerful example that shows the utility and potential of Kalman filters. It's sure to help those who are trepid about delving into the world of Kalman filtering.

A couple notes on Michael's implementation... First, note that the return statement at the end of his function is extraneous. But perhaps this code was culled from a larger file in which that command served some purpose? Also, as one commenter noted, and as the MLINT Code Analyzer points out, inv(A)*B is better written as A\B. There's a similar suggested substitution for A*Inv(B), both of which can be rendered faster and more accurate using the backslash (matrix left division) operator.

Comments?.




Published with MATLAB® 7.11

|
  • print

Comments

To leave a comment, please click here to sign in to your MathWorks Account or create a new one.