# Kalman filtering application

Show 40 post(s) from this thread on one page
Page 1 of 4 1234 Last
• February 20th 2009, 01:21 AM
atlove
Kalman filtering application
Dear all

I am doing a project which is about energy comsumption estimation.
First, I need to read all parameters available in different time instant, i.e. x1(ti), x2(ti), x3(ti),... x6(ti) etc. ti means time at the ith interval. Suppose x6 represents power consumption at that instant while i believes that x6 is the dependent variable while x1, x2, .... x5 are all independent variables.

Then, i can formulate a linear equation, like x6 = a x1 + b x2 +c x3 + d x4 + e x5. Since i can get data for a series of time, say i = 1 to 100. Then, i can have 100 linear equations. Kalam filter is used to estimate a, b, c, d and e. Once their values are know, i can preduct x6(t101) based on x1(t101), x2(t101), ....x5(t101).

Then, i can compare such x6 at t101 with the real x6 from the simulator. Since it is a linear approximation, a, b, c, d and e will keep on changing. So, i need to write a program to keep track of these five constants and do predict. Then plot the graph of predicted x6 with the real x6 to finish my work.

Since i am new to Kalman filter, i have no idea how can i start my job with the filter. Can you guys give me some guidance how to start? I have read many materials about kalman filter, but i don't know which aspects of kalman filter is applicable to my project.....

Thank you
• February 20th 2009, 02:15 AM
CaptainBlack
Quote:

Originally Posted by atlove
Dear all

I am doing a project which is about energy comsumption estimation.
First, I need to read all parameters available in different time instant, i.e. x1(ti), x2(ti), x3(ti),... x6(ti) etc. ti means time at the ith interval. Suppose x6 represents power consumption at that instant while i believes that x6 is the dependent variable while x1, x2, .... x5 are all independent variables.

Then, i can formulate a linear equation, like x6 = a x1 + b x2 +c x3 + d x4 + e x5. Since i can get data for a series of time, say i = 1 to 100. Then, i can have 100 linear equations. Kalam filter is used to estimate a, b, c, d and e. Once their values are know, i can preduct x6(t101) based on x1(t101), x2(t101), ....x5(t101).

Then, i can compare such x6 at t101 with the real x6 from the simulator. Since it is a linear approximation, a, b, c, d and e will keep on changing. So, i need to write a program to keep track of these five constants and do predict. Then plot the graph of predicted x6 with the real x6 to finish my work.

Since i am new to Kalman filter, i have no idea how can i start my job with the filter. Can you guys give me some guidance how to start? I have read many materials about kalman filter, but i don't know which aspects of kalman filter is applicable to my project.....

Thank you

Identify the state vector, the measurement matrix, the measurement (co)variance and if possible any prior knowlege of the state (so we can initialise the state and its covarianve matrix).

Also you may have to identify the state kinematics (looks like your have a stationary state so we already have that).

Then you just use the equations from the book (assuming we can treat the plant noise as non-existant).

CB
• February 21st 2009, 02:48 AM
atlove
Do you mind to give me some information about how to determine state vector, the measurement matrix, the measurement (co)variance and state kinematics?
I have found some of them but don't really know what that means....
• February 21st 2009, 03:16 AM
CaptainBlack
Quote:

Originally Posted by atlove
Do you mind to give me some information about how to determine state vector, the measurement matrix, the measurement (co)variance and state kinematics?
I have found some of them but don't really know what that means....

Your state vector is a column vector containing all the information needed to describe the system, here that is ${\bf{X}} = [a,b,c,d,e]^T$, the measurement matrix is the matrix $\bf{H}$ such that:

$z={\bf{HX}}+w$

where $z$ is what is measured in this case $x_6$ and $w$ is the measurement error/noise. So for this problem it is the row vector: ${\bf{H}}=[x_1,x_2,x_3,x_4]$.

In your case as the state is just a vector of constants there is no kinematics, and so if you use the eqaations form a text the state propagation matrix is:

$
{\bf{\Phi}}={\bf{I}}_{5,5}
$

CB
• February 21st 2009, 03:23 AM
atlove
how to work out the w?
Is the $z={\bf{HX}}+w$ the process equation ? Is it necessary to find the measurement equation? $Y(K)=H(K) X(K) + V(K)$ where k is time variable, y-noise measurement of x, H-measurement matrix, v-noise. If it do, how to determine it? thank you
• February 21st 2009, 03:32 AM
CaptainBlack
Quote:

Originally Posted by atlove
how to work out the w?
Is the $z={\bf{HX}}+w$ the process equation ? Is it necessary to find the measurement equation? $Y(K)=H(K) X(K) + V(K)$ where k is time variable, y-noise measurement of x, H-measurement matrix, v-noise. If it do, how to determine it? thank you

There will be a lot of confusion as there are a large number of conventions on the notation. Your Y(K) is my z. I also drop the K from my notation, as this is a sequantial process, and the update always always referes to the current measurement the prior estimate of the state and generates a posterior mesurement of the state.

The measurement error/noise my z and your V should be known processes and so the variance should be known.

CB
• February 21st 2009, 05:48 PM
atlove
it'seems that the idea of kalman filtering you proposed has some difference with mine.

do you mind to read the following website to get what 's my idea?
KALMAN FILTERS

This website showed one equation (the dynamic equation) to estimate the measurement of posterior with prior estimation of state , another equation(y(k)=Mx(t1)+w(1)) is the measurement of noise in estimating X. Do the idea proposed in this website applicable to my project?

can you give me an example of measurement noise?

thank you
• February 22nd 2009, 12:20 AM
CaptainBlack
Quote:

Originally Posted by atlove
it'seems that the idea of kalman filtering you proposed has some difference with mine.

do you mind to read the following website to get what 's my idea?
KALMAN FILTERS

This website showed one equation (the dynamic equation) to estimate the measurement of posterior with prior estimation of state , another equation(y(k)=Mx(t1)+w(1)) is the measurement of noise in estimating X. Do the idea proposed in this website applicable to my project?

can you give me an example of measurement noise?

You have no dynamic, that site's F is my $\bf{\Phi}$ and as there is no dynamic in this case if we insist on using it it is the identity transfoem. Also as far as I am aware you have no plant noise (u(k) in that sites notation, which represents the (unknown and modelled as random) divergence of the true state from the state that the dynamic predicts).

That site's M is my $\bf{H}$ which I beleive is the more common notation, and we agree on w.

Note that the site you quote is only presenting a 1-D KF, you need the multi-dimensional case.

Quote:

can you give me an example of measurement noise?
I want to measure the height of one of my children so we mark their height on the door post and measure that height with a extending steel rule. So if their true height is $h_t$ and I measure height $h_m$ we have:

$h_m=h_t+w$

where $w$ represents the error in this measurement process. This error is composed of multiple terms, lets say the accuracy of making the mark, and that of reading the height on the rule. What is important is the distribution of this error, we would hope it has zero mean, and has a standard deviation we can estimate. After thinking about how the mark is made we may conclude that the standard deviation of that is $\approx 1 \text{cm}$ and that the standard deviation of reading the rule is $\approx 0.25 \text{cm}$, so the SD of $w$ is $\approx 1.03 \text{cm}$. For convienience we also assume that $w$ is normally distributed so we have assumed: $w \sim N(0,1.03^2)$.

I would suggest that you try to find a copy of Applied Optimal Estimation by Gelb et al. which in my opinion contains the very best presentation of the practical (as well as theoretical) aspects of Kalman filtering.

CB
• February 22nd 2009, 12:50 AM
atlove
ThX for the book, i found the book in my campus library fortunately(Happy)

I will read this book first.

Thank you
• February 22nd 2009, 01:45 AM
atlove
CaptainBlack
do you have some example about the application of kalman filtering which somehow similar to my project?

i have read many material , i want some example to further my understanding.

if you don't have , just leave it, doesn't matter,

thank you very much
• February 22nd 2009, 02:09 AM
CaptainBlack
Quote:

Originally Posted by atlove
CaptainBlack
do you have some example about the application of kalman filtering which somehow similar to my project?

i have read many material , i want some example to further my understanding.

if you don't have , just leave it, doesn't matter,

thank you very much

No, all the applications I have used are to target tracking and bearings only analysis.

CB
• February 22nd 2009, 04:30 AM
CaptainBlack
Quote:

Originally Posted by atlove
CaptainBlack
do you have some example about the application of kalman filtering which somehow similar to my project?

i have read many material , i want some example to further my understanding.

if you don't have , just leave it, doesn't matter,

thank you very much

I have implemented a 2-D verion of your problem in Matlab, the code follows:

Code:

function rv=DataGen x=rand(1,2).*20; y=sum(x)+randn(1,1); rv=[x,y];
This generates a data set such that the third element is the sum of the first two plus a normally distributed random number of unit variance.

(the model is $d_3=d_1+d_2+w$, I use d here as x is usually reserved for the state )

Code:

function [X,P]=KalmanInov(Data,R,X,P) % % Kalman Filter Inovation Processing % % %   H=[Data(1),Data(2)];  %extract the H matrix or vector from the data   z=Data(3);                %extract the measurement from the data   % Below is the standard Kalman inovation equations in matrix form     S=H*P*H'+R; %note this is a scalar   K=P*H'*inv(S);   X=X+K*(z-H*X);   P=(diag([1,1])-K*H)*P;
The above is the Kalman innovation process straight from the book X on input is the old state estimate, and on exit the new state estimate, and P on input is the prior state covariance matrix and on exit is the posterior state estimate.

Code:

function rv=KalmanSim   P=[100,0;0,100]; %initial covariance of state estimate   X=[0;0];            %initial state estimate   R=1;                %measurement variance   rv=X   for idx=1:10     D=DataGen;    % generate some data     [X,P]=KalmanInov(D,R,X,P);     rv=[rv,X];        %accumulate the state estimate   end
The above loops over 10 sets of data, plotting the rows of the returned matrix will show the evolution of the state estimate, which tend to [1,1]'

Note there is no need for a dynamic with this model.

The attached figure shows the evolution of the components of the state estimate.

CB
• February 22nd 2009, 06:28 PM
atlove
CaptainBlack, thx for spending time on making such a simulation.

I need to read some matlab material to check what the code actually doing.

Is your code use many built-in functions from matlab? since i didn't see any calculation within the code.
• February 22nd 2009, 08:08 PM
CaptainBlack
Quote:

Originally Posted by atlove
CaptainBlack, thx for spending time on making such a simulation.

I need to read some matlab material to check what the code actually doing.

Is your code use many built-in functions from matlab? since i didn't see any calculation within the code.

No, but it does use the built in matrix arithmetic operators and random number generators.

CB
• February 23rd 2009, 02:39 AM
CaptainBlack
Quote:

Originally Posted by atlove
CaptainBlack, thx for spending time on making such a simulation.

I need to read some matlab material to check what the code actually doing.

Is your code use many built-in functions from matlab? since i didn't see any calculation within the code.

What language were you intending to program this in?

(by the way I now have a version of the filter in Matlab and the simulation which operates with the full model of you original post)

CB
Show 40 post(s) from this thread on one page
Page 1 of 4 1234 Last