File Exchange

image thumbnail

Learning the Kalman Filter in Simulink v2.1

version 1.3 (82 KB) by

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

15 Ratings



View License

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.

Comments and Ratings (26)

b b

b b (view profile)

i m working on interacting multiple model with kalman estimators, how can i start my work ?

it too useful,but i have some request if it is possible.Can u please show us off the code of kalman Filter and the linear random process in Matlab, in the case that we want just to call the Simulink as sim('Name of the Simulink')

Thank you a lot Yi Cao

Ying Jie Jin

thank you so much!

what is the role of the random process bloc ??


thanks a lot!

W. Chong

thanks a lot~ very helpful

W. Chong

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.

Thank you a lot. It's useful for me


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.


thank you for all your interest in answering my questions


Yi Cao

Yi Cao (view profile)

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


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].

Yi Cao

Yi Cao (view profile)

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


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.

V. Poor

Imtiaz Hussain

Imtiaz Hussain (view profile)

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

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
cell: 210 906 5110

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.

These files have been added now.

YH Zhang

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

Gabrie Tejeda

Excelent, very usefull.

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.

Scheffe held

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



update simulink model


update descriptions


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

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

MATLAB Release
MATLAB 7.0.1 (R14SP1)

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video