4.47059

4.5 | 17 ratings Rate this file 465 downloads (last 30 days) File Size: 2.1 KB File ID: #18189

Learning the Extended Kalman Filter

by Yi Cao

 

02 Jan 2008 (Updated 23 Jan 2008)

Code covered by BSD License  

An implementation of Extended Kalman Filter for nonlinear state estimation.

Download Now | Watch this File

File Information
Description

This is a tutorial on nonlinear extended Kalman filter (EKF). It uses the standard EKF fomulation to achieve nonlinear state estimation. Inside, it uses the complex step Jacobian to linearize the nonlinear dynamic system. The linearized matrices are then used in the Kalman filter calculation.

The complex step differentiation seems improving the EKF performance particularly in accuracy such that the optimization and NN training through the EKF are better than through the UKF (unscented Kalman filter, http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=18217&objectType=FILE). Other complex step differentiation tools include the CSD Hessian available at http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=18177&objectType=FILE.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Learning the Kalman Filter
This submission has inspired the following:
Unconstrained Optimization using the Extended Kalman Filter, Neural Network training using the Extended Kalman Filter, Learning the Unscented Kalman Filter

MATLAB release MATLAB 7.4 (R2007a)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (26)
17 Jan 2008 sayed mohammad mousavi gazafrudi  
23 Jan 2008 edwin de Vries

??? Error: File: ekf.m Line: 19 Column: 10
Expression or statement is incomplete or incorrect.

??? Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space can
crash MATLAB and/or your computer.

Error in ==> ekf>create@(x)[x(2);x(3);0.05*x(1)*(x(2)+x(3))] at 25
 f=@(x)[x(2);x(3);0.05*x(1)*(x(2)+x(3))]; % nonlinear state equations

23 Jan 2008 Yi Cao

Dear Edwin,

As I expected, this error is due to your way to run the example because the error message shows that the error occures at line 19, which is a commented line to begin the example.

To correctly run the example, you can follow the following steps:

1. select the example lines correctly
2. press control-t to uncomment the selection
3. right-click to run the selection
4. click un-do to recover the file. (DO NOT click the save button.)

For you and other users' convenient, I updated the file with block-comment lines for the example. Now, you just need to select and right-click to run the example without change the file. The update will appear a few hours later.

Hope this help.

24 Jan 2008 Taher DERBEL  
14 Apr 2008 Reza Baghaei  
16 Apr 2008 meng jun

very well.

24 Apr 2008 feng yu  
03 May 2008 hu aijun  
06 May 2008 Dmitry Sh

Nicely made, and very intuitive if one has an idea how a linear Kalman Filter works. However I found that numerically solving the Jacobian is not always the best form of linerisation, especially for simpler cases when an analytic Jacobian can be computed by hand.
In my experiments (with simple non-linear models) an analytic Jacobian usually gave a significant improvement of fit when compared to its numeric counterpart. Maybe you could add an option on how it should be solved

11 Jun 2008 Neric Lau

Very helpful for learning Kalman Filter Implementation.

16 Jun 2008 Saroj Pandey

it is very good and helpful in my project.

21 Jul 2008 Tim Davis

Excellent! Nice use of CHOL instead of INV (as can be seen in two other Kalman-filter codes on the File Exchange). Nice to see good numerics at work.

I see that "K=P12*inv(...)" is commented out; that's perfect. It gives the math behind what the CHOL and backslashes are doing.

29 Jul 2008 Lihong Wang

Nice code. But if there is load disturbance on the state, why the estimate from the EKF almost ignores the load disturbance?

04 Oct 2008 maureen clerc

Beware: function ekf changes the value of the measurement covariance matrix R. It shouldn't be the case. Otherwise the code is nice and efficient.

17 Feb 2009 Zhongjie Chen

Hi, I still get the error

??? Maximum recursion limit of 500 reached. Use set(0,'RecursionLimit',N)
to change the limit. Be aware that exceeding your available stack space
can
crash MATLAB and/or your computer.

Error in ==> ekf>create@(x)[x(2);x(3);0.05*x(1)*(x(2)+x(3))]

after following your instructions. How do I correctly run the code?

17 Feb 2009 Yi Cao

This error occurs because you run the example incorrectly so that ekf calls itself more than 500 times. To run the example, you need copy contents between "%{" and "%}" then past it on matlab command window to execute the example.

It also could be because your MATLAB version is too old to support block comments. If that is the case, you can comment out all line by adding "%" at the begining of each line between "%{" and "%}" to solve the problem.

05 Apr 2009 V. Poor  
20 Apr 2009 Dapat Chawah

This code is working good for N<=150
but when N exceeds this limit, a nonsense happens
Is there any improvement to the code considering this error?

20 Apr 2009 Dapat Chawah

Sorry, this comment is meant to be in the unscented kalman filter file discussion

28 Apr 2009 Rohit Hippalgaonkar

Hi I am looking for an example where the EKF is applied to a continuous-time non-linear system with non-zero inputs (say measurements are taken at regular time samples through a non-linear (even linear would do) measurement process. I have looked around for this kind of example in the standard texts but haven't found any. Also a good source showing the implementation of the EKF wherein we linearize about a single operating point (as against linearizing about the predicted state every time) would be really helpful! Thanks in advance! Rohit

28 Apr 2009 Yi Cao

For continuous-time EKF, please look at http://www.mathworks.com/matlabcentral/fileexchange/18485

23 May 2009 Chao  
26 May 2009 tim Heights

if in EKF i have to add state noise compensation, any good example or guidance here. how can i add to the example given by Yi Cao.
secondly, any one who could also recommend some book about it.

08 Jun 2009 tim

i wrote a very simple compound pendulum code, and some how this ekf algorithm does not work for that. only change that i had to do to that example file was change the states to 2 and rest
f=@(x)[x(2);-(g/l)*sin(x(1))];
this should give me sinusoidal waveform but it does not.
can you point out to me what could be wrong.

20 Jul 2009 maheswaran Rathinasamy  
11 Aug 2009 iasri icar

hi yi, would like to know if its appropriate to use EKF for forecasting of agricultural yields like fish ,rice etc. i am planning to use EXPAR with EKF for the problem stated above and would you kindly be able to give some of your ideas regarding the same.thankyou, with regards bishal.

Please login to add a comment or rating.
Updates
09 Jan 2008

Improve efficiency in inverse calculation

16 Jan 2008

update description

23 Jan 2008

Update example with block-comment lines

Tag Activity for this File
Tag Applied By Date/Time
filter design Yi Cao 22 Oct 2008 09:41:24
filter analysis Yi Cao 22 Oct 2008 09:41:24
state estimate Yi Cao 22 Oct 2008 09:41:24
kalman filter Yi Cao 22 Oct 2008 09:41:24
extended kalman filter Yi Cao 22 Oct 2008 09:41:24
extended kalman filter Franc Dimc 25 Nov 2008 14:10:19
extended kalman filter Zhongjie Chen 17 Feb 2009 08:06:41
extended kalman filter Jesus Garcia 21 Apr 2009 09:19:14
extended kalman filter ciobanu emilian 24 Jun 2009 04:13:30
extended kalman filter david lee 12 Sep 2009 20:24:47
 

MATLAB Central Terms of Use

NOTICE: Any content you submit to MATLAB Central, including personal information, is not subject to the protections which may be afforded information collected under other sections of The MathWorks, Inc. Web site. You are entirely responsible for all content that you upload, post, e-mail, transmit or otherwise make available via MATLAB Central. The MathWorks does not control the content posted by visitors to MATLAB Central and, does not guarantee the accuracy, integrity, or quality of such content. Under no circumstances will The MathWorks be liable in any way for any content not authored by The MathWorks, or any loss or damage of any kind incurred as a result of the use of any content posted, e-mailed, transmitted or otherwise made available via MATLAB Central. Read the complete Terms prior to use.

Contact us at files@mathworks.com