4.5

4.5 | 12 ratings Rate this file 173 Downloads (last 30 days) File Size: 82.01 KB File ID: #18465
image thumbnail

Learning the Kalman Filter in Simulink v2.1

by Yi Cao

 

25 Jan 2008 (Updated 22 Feb 2011)

A Simulink model to learn the Kalman filter for Gassian processes.

| Watch this File

File Information
Description

The zip file contains a Simulink model, which describes a Gassian process and the Kalman filter. A m-script is provided to show how to use this model from the command window. Two examples taken from the File Exchange are included in the m-file to explain how the Kalman filter works.

The package provides a way for beginners to learn the Kalman filter by just editting the model parameters without the need to know the details of calculation. By looking into masked subsystems, you will also be albe to learn how it can be implemented in Simulink.

The model is developed in R14SP1 (MATLAB 7.0.1, Simulink 6.1). If you require it to work with previous version, please let me know.

The new version removes a bug so that it can correctly work with non-zero D.

Acknowledgements

The author wishes to acknowledge the following in the creation of this submission:
Learning the Kalman Filter, An Intuitive Introduction to Kalman Filter
This submission has inspired the following:
Learning the Kalman-Bucy Filter in Simulink, Learning the Kalman Filter: A Feedback Perspective

Required Products Simulink
MATLAB release MATLAB 7.0.1 (R14SP1)
Tags for This File  
Everyone's Tags
Tags I've Applied
Add New Tags Please login to tag files.
Comments and Ratings (17)
27 Jan 2008 Scheffe held

i dont like it. more confusing than helping.
why sample time 1?

27 Jan 2008 Yi Cao

I am sorry you do not like the model. But, I do not understand what you refer to about sample time 1. The first example does not have sample time. The second example has the sample time 0.1 second. This is because the original problem is a continuous time problem. To use the discrete time version Kalman filter, we have to discretize the system, hence need a sample time. A continuous time Simulink model of Kalman filter (Kalman-Bucy filter) has been developed and submitted to the File Exchange. You may wish to try that one to see if you like it.

06 Feb 2008 Gabrie Tejeda

Excelent, very usefull.
Thanks

20 Mar 2008 YH Zhang

Great, but some pictures are missing in The HTML folder
such as,feedbackKF.png,KalmanLTI.png.

21 Mar 2008 Yi Cao

Dear YH Zhang,

Thanks for pointing out these missing files although this is regarding to another submission: Learning the Kalman Filter: A Feedback Perspective. http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=18628&objectType=FILE

These files have been added now.

16 Jan 2009 Todor Tchangov

Dear Yi Cao,
Knowing your good level, it’s well simplified and definitely a base to get started.

It is properly presented (for the first time in US History) as Bucy and others...
and Rudolf Kalman... who then ...moved in US... and…
Please, read the history, Colleagues:
Who was the American Engineer who made this working... and rectified the Mathematicians Problems ? That way this is the American Invention.

About the Continuous Linear Process:
I think that I have problems, but the major one is with the Process model.
 
The "A-matrix Process Dynamics- Integration" of X – output of the process, presents the Result of x-dot (or k+1). And this point is “Actuated by U input. How the “u” is presented to all different states (MISO) is presented by B matrix.

After that the Matrix C will present what is measurable and what is Observable.
And then according to “how the “A dynamics” filters the Noise Spectrum presented in point "x-dot" and + + + + will make Kalman Filter to decide “what is true signal and how to restore it”.

Now understanding only “how a (negative) feedback works” and modifies the “Transfer behavior” from Point a to point b… Check out that you made a Positive feedback from X = X+1 (???) to + summing point…!?!?!?! This model has a positive feedback…which in 1985 we had fast “overloading” and had to cold restart our 4 Mb Hard Disk Drive PCs.

But I like your work and I love you guys:
Because it is hard and…
We are big Family.

Sincerely yours,
Todor Tchangov
Sonic Works
todor@sonicworks.com
tezo.spartak@gmail.com
cell: 210 906 5110

22 Jan 2009 Imtiaz Hussain

Thanks a lot........... very useful

05 Apr 2009 V. Poor  
29 Mar 2010 Girikrishna

Hi Yi Cao thankyou for your great effort in explaining us the simulink model. I will be geratly thank full if you could solve my problem.
In your file runkalmanfilter.m file example :3 for 4 state system you have initialized
tspan=[0 1000];
u=[(0:100:1000)' rand(11,2) ] ;
which generates 11*3 matrix and gives a 1*2 matrix as input matrix for both actual system and to the kalman filter.
our state equations are
x1=Ax+Bu+Q in which
A=4*4 matrix B=4*2 matrix Q=4*4 matrix u=1*2 matrix and x=4*1matrix
in your simulink model where you actually multiplied Ax+Bu+Q how is this possible when matrix dimensions of B and u do not match for multiplication.
stunning part in this is even though matrix dimensions did not match but simulink is executing it how is this possible.
I will be very thank full if you could hell me out.

30 Mar 2010 Yi Cao

The first column of u is time. This is specified by Simulink.

01 Apr 2010 Girikrishna

even after considering 1st column as time and discarding it size of u=11*2 and size of B=4*2 how can we multiply when it is like this
B*U <==> [1*2] * [4*2].

02 Apr 2010 Yi Cao

Simulink does not treat u as 11x2 but a 2x1 vector with 11 sampling points.

08 Apr 2010 Girikrishna  
08 Apr 2010 Girikrishna

thank you for all your interest in answering my questions

08 Apr 2010 Girikrishna

can you tell me based on what equations did you decide the elements of A matrix in your 3rd example.
It would be helpful if you could explain or refer me some material which explains that.

06 Jun 2010 Examples Learn By

Thank you a lot. It's useful for me
http://learnbyexamples.org

23 Feb 2011 Marzi Azar

Thanks Yi. Can I use the code to minimize the error in the estimated data? I have one estimated data (let's call observation), and another observed data (let's say true). I want to use kalman to update observed values toward true ones.
Thanks

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

update the model to work with MIMO systems plus an MIMO example.

29 Jan 2008

update html file

01 Dec 2010

Bug remove so that it can correctly work with non-zero D matrix.

19 Feb 2011

update descriptions

22 Feb 2011

update simulink model

Tag Activity for this File
Tag Applied By Date/Time
filter design Yi Cao 22 Oct 2008 09:44:49
filter analysis Yi Cao 22 Oct 2008 09:44:49
kalman filter Yi Cao 22 Oct 2008 09:44:49
simulink Yi Cao 22 Oct 2008 09:44:49
gaussian process Yi Cao 22 Oct 2008 09:44:49
kalman filter Prasetyo Utomo 11 Nov 2008 02:38:17
state space control Todor Tchangov 16 Jan 2009 13:32:40
state observer Todor Tchangov 16 Jan 2009 13:33:07
kalman filter kuoping 29 Jun 2010 07:02:47
kalman filter Mihaela Poienar 23 Jul 2011 15:52:28
filter design waseem asif 27 Dec 2011 10:33:32
kalman filter Ly Tam Wan 21 Mar 2012 21:10:39

Contact us at files@mathworks.com