KALMAN FILTER
E . CINTHURIYA
ME – COMMUNICATION ENGINEERING
kalman filter 1/18
Kalman Filter
•Born 1930 in Hungary
•Studied at MIT / Columbia
•Developed filter in 1960/61
kalman filter 2/18
Kalman Filters
 A Kalman Filter is a more
sophisticated smoothing algorithm that
will actually change in real time as the
performance of Various Sensors
Change and become more or less
reliable
 What we want to do is filter out noise
in our measurements and in our
sensors and Kalman Filter is one way
to do that reliably
kalman filter 3/18
Noise
This is the actual path of our
UGV(Unmanned Ground Vehicle) as
it follows unwinding road.
This is the data we got
from GPS.
Notice it has the same
shape with some random
variations plus and minus.
Ok . How about if we just
average out our GPS
reading?
That’s a bit better and smoothes out some of the
bumps but it is not useful since GPS is slow already
and averaging makes it much slower
kalman filter 4/18
Noise
 Removing Noise from Measurements by
Sensor is the purpose of Kalman Filter
 When you average the sensor signals or
readings it will slow down the system
Path of a Robot
Data We Get from SENSOR
Data after we average the Signals kalman filter 5/18
Kalman Filter-Basic Block
Diagram
 System state cannot be measured directly
 Need to estimate “optimally” from measurements
Measuring
Devices Estimator
Measurement
Error Sources
System State
(desired but not
known)
External
Controls
Observed
Measurements
Optimal
Estimate of
System State
System
Error Sources
System
Black Box
Sometimes the system state
and the measurement may be
two different things
kalman filter 6/18
Error in PS(Global Positioning
System)-HISTOGRAM
 We usually get GPS from manufacturers with
specification specifying some percentage of Accuracy
with in Some meters. For example we may get 95%
accuracy with in 2 meters If we were to plot
just the error of
GPS on graph, we
would see a plot
like this
Erro
r
As a review,
Histogram gets
taller the more
measurements
are at a particular
value
Most of the time GPS is
inside this error range.
Notice that this makes a
particular distribution of
values that fall in certain
range. Let's say that as
4 meters
4m
So the Noise is
this random bits
of stuff here at
the bottom
So we could make a filter
that would get rid of this
noise.BUT we can’t
measure our own error
while we are moving
kalman filter 7/18
Moving Robot – Estimating Error
Path followed by robot
according to law of motion
Sensor
Readings
Sensor Readings doesn’t follow
the Law of Physics or
Equilibrium of Motion which is
Y=x + vt + 1/2at2
Here’s the real path of
UGV over the ground
with boxes showing
1second interval
Now here’s the
GPS reading we
received at 1 Hz
So what if we used the
physical motion of the
vehicle to estimate where
the next measurement
should be and use that for
the error?
kalman filter 8/18
Moving Robot – Estimating Error
Equilibrium of Motion which is
Y=x + vt + 1/2at2
X=position
V=velocity(meters per second)
a= acceleration(meters per
second squared
T=time interval
We also Know if we commanded
the vehicle to change course of
Speed- a steering input or
throttle change
With this sort of straight line motion
the state estimate can be very
accurate as the UGV is moving in a
constant direction and at constant
speed.
So we might see something like this
out of a continuously updated
estimation function
20
mph
20
mph
20
mph
kalman filter 9/18
Kalman Filter Concept
 We can’t directly measure where the UGV(Unmanned Ground
Vehicle Robot) is- We have to use various Sensors to make
estimates.
 Each of those Sensors has a Certain amount of Accuracy and a
Certain amount of NOISE.
 We can use Equation of Motion to provide estimates on where
UGV may have moved and then see if Sensor Readings makes
sense given that estimate.
 Then we can Update our Estimates with new Sensor information
and whole cycle starts over again.
 Kalman filter is all done with matrix math
kalman filter 10/18
The Kalman Filter
Prior Knowledge
of State
Pk-1|k-1
x̌ k-1|k-1
Prediction Step
Based on
Example Physical
Model
Pk|k-1
x̌ k|k-1
Update Step
Compare
Prediction to
Measurements
Measurement
s
yk
Pk|k
x̌ k|k
Next Time
step
k=k+1
Output Estimate
of State
kalman filter 11/18
Set of Kalman filter Equations in
Detail
Prediction(Time Update)
1) Project the STATE
ahead
ŷk
-=Ayk-1+Buk
2) Project the Error
Covariance ahead
P-
k≡APk-1AT+Q
Correction (Measurement
Update)
1) Compute the KALMAN
GAIN
K=P-
kHT(HP-
kHT+R)-1
2) Update the estimate with
measurement zk
ŷk=ŷk
- + K (zk-H ŷk
- )
3) Update the Error Covariance
Pk=(I-KH)P-
k
kalman filter 12/18
Kalman Filter
1. Project the STATE ahead
ŷk
-=Ayk-1+Buk
 Ŷk is the predicted state of Vehicle at time k
 A is the model(equations of motion) that predict the
new state
 yk-1 is the state of Vehicle at previous time k-1
 B is the model that predicts what changes based on
commands to the vehicle – increase in throttle or
steering
 Uk is the commanded inputs at time k
kalman filter 13/18
Kalman Filter
2. Project the Error Covariance ahead
 We want to predict how much noise will be in our
measurements
P-
k≡APk-1AT+Q
 A, same as first equation,Model of Motion
 P,the previous error value at time k-1
 AT,the model Transposed
 Q,the covariance of Error noise – describes the
distribution of noise
kalman filter 14/18
Kalman Filter
1. Computing the KALMAN GAIN
K=P-
kHT(HP-
kHT+R)-1
 K, the Kalman gain(How much to trust this sensor)
 P-
k, as before, the Predicted Error Covariance
 H,the model of how Sensor readings reflect the
vehicle state – a function to go from Sensor
Reading to STATE VECTOR
 R describes the noise in Sensor Measurement
kalman filter 15/18
Kalman Filter
 Update the Error Covariance
Pk=(I-KH)P-
k
 Pk is our new Error Covariance(description of the error
noise Gaussian Curve)
 I is the Identity Matrix
 K is the Kalman Gain
 H is the measurement Model
 P-
k was the previous estimate of error noise
kalman filter 16/18
Problems with Kalman Filters
 It is very difficult to compute the covariance matrix
of noise of various sensors and systems
 It is possible to do some trial and error fitting of
error matrix to the problem to “tune” the filter for
performance
 The filter needs to process several samples in
order to get enough iterations to produce
meaningful results – You need to discard the first
20 iterations or so when the filter first starts.
kalman filter 17/18
What is a Kalman Filter?-
Another Interpretation
 P(H|D)=P(H) * P(D|H)
 P(H)=Probability of Hypothesis
 P(D)=Probability of Data
 Kalman Filter is based on
 P(Ht|Ht-1,Dt) => P(Ht|Ht-1,At,Dt) Where At =Action State
Trash
WALL-E
GPS
Robot
Trash
Robot Picks
up Trash
kalman filter 18
What is a Kalman Filter?
-0.5
0
0.5
1
1.5
2
2.5
3
3.5
0 0.5 1 1.5 2 2.5 3 3.5 4
Position
Time
Probability Where
Robot Is
Position Where
Robot is Sent
Where GPS
THINKS Robot is
Combination Where
Robot Actually is
Xt
µ-Motor Command
Xt-1
kalman filter 19
What is a Kalman Filter?
STATE PREDICTION:
Xt=Axt-1+Bµt+€t
Where €t is Gaussian Error. It is a Linear Function
Based on Rule of Physics.
SENSOR PREDICTION:
Zt=Cxt +€t
Xest =Xt+K(Zt-Žt) WHERE
•Xt=Prediction
•K=Kalman Gain
•Zt =Actual Measurement
•Žt =Predicted Measurement
kalman filter 20
What is a Kalman Filter?
STATE PREDICTION MODEL:
Xt=Axt-1+Bµt+€t
Where €t is Gaussian Error. It is a Linear Function
Based on Rule of Physics.
Pt=Pt-1+Vt-1.t+1/2 att2
Vt=Vt-1+att 






)(
)(
VVelocity
PPosition
x
kt
T
t
t
t
t
t a
Tv
pt
v
p
x 





























2
2
10
1
1
1
kalman filter 21
What is a Kalman Filter?
STATE PREDICTION MODEL:
Pt=Pt-1+Vt-1.t+1/2 att2
Vt=Vt-1+att
Measurement Prediction:
Zt=Cxt +€t
k
tTav
p
v
p
x
t
t
t
t
t 



















1
t1-t1
0
Ta1/2.TV 2
    t
t
t
t
V
P
P 








1
1
01
kalman filter 22
kalman filter
23/
18

Kalmanfilter

  • 1.
    KALMAN FILTER E .CINTHURIYA ME – COMMUNICATION ENGINEERING kalman filter 1/18
  • 2.
    Kalman Filter •Born 1930in Hungary •Studied at MIT / Columbia •Developed filter in 1960/61 kalman filter 2/18
  • 3.
    Kalman Filters  AKalman Filter is a more sophisticated smoothing algorithm that will actually change in real time as the performance of Various Sensors Change and become more or less reliable  What we want to do is filter out noise in our measurements and in our sensors and Kalman Filter is one way to do that reliably kalman filter 3/18
  • 4.
    Noise This is theactual path of our UGV(Unmanned Ground Vehicle) as it follows unwinding road. This is the data we got from GPS. Notice it has the same shape with some random variations plus and minus. Ok . How about if we just average out our GPS reading? That’s a bit better and smoothes out some of the bumps but it is not useful since GPS is slow already and averaging makes it much slower kalman filter 4/18
  • 5.
    Noise  Removing Noisefrom Measurements by Sensor is the purpose of Kalman Filter  When you average the sensor signals or readings it will slow down the system Path of a Robot Data We Get from SENSOR Data after we average the Signals kalman filter 5/18
  • 6.
    Kalman Filter-Basic Block Diagram System state cannot be measured directly  Need to estimate “optimally” from measurements Measuring Devices Estimator Measurement Error Sources System State (desired but not known) External Controls Observed Measurements Optimal Estimate of System State System Error Sources System Black Box Sometimes the system state and the measurement may be two different things kalman filter 6/18
  • 7.
    Error in PS(GlobalPositioning System)-HISTOGRAM  We usually get GPS from manufacturers with specification specifying some percentage of Accuracy with in Some meters. For example we may get 95% accuracy with in 2 meters If we were to plot just the error of GPS on graph, we would see a plot like this Erro r As a review, Histogram gets taller the more measurements are at a particular value Most of the time GPS is inside this error range. Notice that this makes a particular distribution of values that fall in certain range. Let's say that as 4 meters 4m So the Noise is this random bits of stuff here at the bottom So we could make a filter that would get rid of this noise.BUT we can’t measure our own error while we are moving kalman filter 7/18
  • 8.
    Moving Robot –Estimating Error Path followed by robot according to law of motion Sensor Readings Sensor Readings doesn’t follow the Law of Physics or Equilibrium of Motion which is Y=x + vt + 1/2at2 Here’s the real path of UGV over the ground with boxes showing 1second interval Now here’s the GPS reading we received at 1 Hz So what if we used the physical motion of the vehicle to estimate where the next measurement should be and use that for the error? kalman filter 8/18
  • 9.
    Moving Robot –Estimating Error Equilibrium of Motion which is Y=x + vt + 1/2at2 X=position V=velocity(meters per second) a= acceleration(meters per second squared T=time interval We also Know if we commanded the vehicle to change course of Speed- a steering input or throttle change With this sort of straight line motion the state estimate can be very accurate as the UGV is moving in a constant direction and at constant speed. So we might see something like this out of a continuously updated estimation function 20 mph 20 mph 20 mph kalman filter 9/18
  • 10.
    Kalman Filter Concept We can’t directly measure where the UGV(Unmanned Ground Vehicle Robot) is- We have to use various Sensors to make estimates.  Each of those Sensors has a Certain amount of Accuracy and a Certain amount of NOISE.  We can use Equation of Motion to provide estimates on where UGV may have moved and then see if Sensor Readings makes sense given that estimate.  Then we can Update our Estimates with new Sensor information and whole cycle starts over again.  Kalman filter is all done with matrix math kalman filter 10/18
  • 11.
    The Kalman Filter PriorKnowledge of State Pk-1|k-1 x̌ k-1|k-1 Prediction Step Based on Example Physical Model Pk|k-1 x̌ k|k-1 Update Step Compare Prediction to Measurements Measurement s yk Pk|k x̌ k|k Next Time step k=k+1 Output Estimate of State kalman filter 11/18
  • 12.
    Set of Kalmanfilter Equations in Detail Prediction(Time Update) 1) Project the STATE ahead ŷk -=Ayk-1+Buk 2) Project the Error Covariance ahead P- k≡APk-1AT+Q Correction (Measurement Update) 1) Compute the KALMAN GAIN K=P- kHT(HP- kHT+R)-1 2) Update the estimate with measurement zk ŷk=ŷk - + K (zk-H ŷk - ) 3) Update the Error Covariance Pk=(I-KH)P- k kalman filter 12/18
  • 13.
    Kalman Filter 1. Projectthe STATE ahead ŷk -=Ayk-1+Buk  Ŷk is the predicted state of Vehicle at time k  A is the model(equations of motion) that predict the new state  yk-1 is the state of Vehicle at previous time k-1  B is the model that predicts what changes based on commands to the vehicle – increase in throttle or steering  Uk is the commanded inputs at time k kalman filter 13/18
  • 14.
    Kalman Filter 2. Projectthe Error Covariance ahead  We want to predict how much noise will be in our measurements P- k≡APk-1AT+Q  A, same as first equation,Model of Motion  P,the previous error value at time k-1  AT,the model Transposed  Q,the covariance of Error noise – describes the distribution of noise kalman filter 14/18
  • 15.
    Kalman Filter 1. Computingthe KALMAN GAIN K=P- kHT(HP- kHT+R)-1  K, the Kalman gain(How much to trust this sensor)  P- k, as before, the Predicted Error Covariance  H,the model of how Sensor readings reflect the vehicle state – a function to go from Sensor Reading to STATE VECTOR  R describes the noise in Sensor Measurement kalman filter 15/18
  • 16.
    Kalman Filter  Updatethe Error Covariance Pk=(I-KH)P- k  Pk is our new Error Covariance(description of the error noise Gaussian Curve)  I is the Identity Matrix  K is the Kalman Gain  H is the measurement Model  P- k was the previous estimate of error noise kalman filter 16/18
  • 17.
    Problems with KalmanFilters  It is very difficult to compute the covariance matrix of noise of various sensors and systems  It is possible to do some trial and error fitting of error matrix to the problem to “tune” the filter for performance  The filter needs to process several samples in order to get enough iterations to produce meaningful results – You need to discard the first 20 iterations or so when the filter first starts. kalman filter 17/18
  • 18.
    What is aKalman Filter?- Another Interpretation  P(H|D)=P(H) * P(D|H)  P(H)=Probability of Hypothesis  P(D)=Probability of Data  Kalman Filter is based on  P(Ht|Ht-1,Dt) => P(Ht|Ht-1,At,Dt) Where At =Action State Trash WALL-E GPS Robot Trash Robot Picks up Trash kalman filter 18
  • 19.
    What is aKalman Filter? -0.5 0 0.5 1 1.5 2 2.5 3 3.5 0 0.5 1 1.5 2 2.5 3 3.5 4 Position Time Probability Where Robot Is Position Where Robot is Sent Where GPS THINKS Robot is Combination Where Robot Actually is Xt µ-Motor Command Xt-1 kalman filter 19
  • 20.
    What is aKalman Filter? STATE PREDICTION: Xt=Axt-1+Bµt+€t Where €t is Gaussian Error. It is a Linear Function Based on Rule of Physics. SENSOR PREDICTION: Zt=Cxt +€t Xest =Xt+K(Zt-Žt) WHERE •Xt=Prediction •K=Kalman Gain •Zt =Actual Measurement •Žt =Predicted Measurement kalman filter 20
  • 21.
    What is aKalman Filter? STATE PREDICTION MODEL: Xt=Axt-1+Bµt+€t Where €t is Gaussian Error. It is a Linear Function Based on Rule of Physics. Pt=Pt-1+Vt-1.t+1/2 att2 Vt=Vt-1+att        )( )( VVelocity PPosition x kt T t t t t t a Tv pt v p x                               2 2 10 1 1 1 kalman filter 21
  • 22.
    What is aKalman Filter? STATE PREDICTION MODEL: Pt=Pt-1+Vt-1.t+1/2 att2 Vt=Vt-1+att Measurement Prediction: Zt=Cxt +€t k tTav p v p x t t t t t                     1 t1-t1 0 Ta1/2.TV 2     t t t t V P P          1 1 01 kalman filter 22
  • 23.