kalman

Kalman filter design, Kalman estimator

Syntax

[kest,L,P] = kalman(sys,Qn,Rn,Nn)
[kest,L,P] = kalman(sys,Qn,Rn,Nn,sensors,known)
[kest,L,P,M,Z] = kalman(sys,Qn,Rn,...,type)

Description

kalman designs a Kalman filter or Kalman state estimator given a state-space model of the plant and the process and measurement noise covariance data. The Kalman estimator provides the optimal solution to the following continuous or discrete estimation problems.

Continuous-Time Estimation

Given the continuous plant

x˙=Ax+Bu+Gw(stateequation)y=Cx+Du+Hw+v(measurementequation)

with known inputs u, white process noise w, and white measurement noise v satisfying

E(w)=E(v)=0,E(wwT)=Q,E(vvT)=R,E(wvT)=N

construct a state estimate x^(t) that minimizes the steady-state error covariance
    P=limtE({xx^}{xx^}T)

The optimal solution is the Kalman filter with equations

x^˙=Ax^+Bu+L(yCx^Du)[y^x^]=[CI]x^+[D0]u

The filter gain L is determined by solving an algebraic Riccati equation to be

L=(PCT+N¯)R¯1

where

R¯=R+HN+NTHT+HQHTN¯=G(QHT+N)

and P solves the corresponding algebraic Riccati equation.

The estimator uses the known inputs u and the measurements y to generate the output and state estimates y^ and x^. Note that y^ estimates the true plant output

y=Cx+Du+Hw+v

Discrete-Time Estimation

Given the discrete plant

x[n+1]=Ax[n]+Bu[n]+Gw[n]y[n]=Cx[n]+Du[n]+Hw[n]+v[n]

and the noise covariance data

E(w[n]w[n]T)=Q,E(v[n]v[n]T)=R,E(w[n]v[n]T)=N

The estimator has the following state equation:

x^[n+1|n]=Ax^[n|n1]+Bu[n]+L(y[n]Cx^[n|n1]Du[n])

The gain matrix L is derived by solving a discrete Riccati equation to be

L=(APCT+N¯)(CPCT+R¯)1

where

R¯=R+HN+NTHT+HQHTN¯=G(QHT+N)

There are two variants of discrete-time Kalman estimators:

  • The current estimator generates output estimates y^[n|n] and state estimates x^[n|n] using all available measurements up to y[n]. This estimator has the output equation

    [y^[n|n]x^[n|n]]=[(IMy)CIMxC]x^[n|n1]+[(IMy)DMyMxDMx][u[n]y[n]],

    where the innovation gains Mx and My are defined as:

    Mx=PCT(CPCT+R¯)1,My=(CPCT+HQHT+HN)(CPCT+R¯)1.

    Mx updates the prediction x^[n|n1] using the new measurement y[n].

    x^[n|n]=x^[n|n1]+Mx(y[n]Cx^[n|n1]Du[n])innovation.

    When H = 0, My=CMx and y[n|n]=Cx[n|n]+Du[n].

  • The delayed estimator generates output estimates y^[n|n1] and state estimates x^[n|n1] using measurements only up to yv[n–1]. This estimator is easier to implement inside control loops and has the output equation

    [y^[n|n1]x^[n|n1]]=[CI]x^[n|n1]+[D000][u[n]y[n]]

[kest,L,P] = kalman(sys,Qn,Rn,Nn) creates a state-space model kest of the Kalman estimator given the plant model sys and the noise covariance data Qn, Rn, Nn (matrices Q, R, N described in Description). sys must be a state-space model with matrices A,[BG],C,[DH].

The resulting estimator kest has inputs [u;y] and outputs [y^;x^] (or their discrete-time counterparts). You can omit the last input argument Nn when N = 0.

The function kalman handles both continuous and discrete problems and produces a continuous estimator when sys is continuous and a discrete estimator otherwise. In continuous time, kalman also returns the Kalman gain L and the steady-state error covariance matrix P. P solves the associated Riccati equation.

[kest,L,P] = kalman(sys,Qn,Rn,Nn,sensors,known) handles the more general situation when

  • Not all outputs of sys are measured.

  • The disturbance inputs w are not the last inputs of sys.

The index vectors sensors and known specify which outputs y of sys are measured and which inputs u are known (deterministic). All other inputs of sys are assumed stochastic.

[kest,L,P,M,Z] = kalman(sys,Qn,Rn,...,type) specifies the estimator type for discrete-time plants sys. The type argument is either 'current' (default) or 'delayed'. For discrete-time plants, kalman returns the estimator and innovation gains L and M and the steady-state error covariances

P=limnE(e[n|n1]e[n|n1]T),e[n|n1]=x[n]x[n|n1]Z=limnE(e[n|n]e[n|n]T),e[n|n]=x[n]x[n|n]

Examples

See LQG Design for the x-Axis and Kalman Filtering for examples that use the kalman function.

Limitations

The plant and noise data must satisfy:

  • (C,A) detectable

  • R¯>0 and Q¯N¯R¯1N¯T0

  • (AN¯R¯1C,Q¯N¯R¯1N¯T) has no uncontrollable mode on the imaginary axis (or unit circle in discrete time) with the notation

    Q¯=GQGTR¯=R+HN+NTHT+HQHTN¯=G(QHT+N)

References

[1] Franklin, G.F., J.D. Powell, and M.L. Workman, Digital Control of Dynamic Systems, Second Edition, Addison-Wesley, 1990.

[2] Lewis, F., Optimal Estimation, John Wiley & Sons, Inc, 1986.

[3] Deshpande, A.S., "Bridging a Gap in Applied Kalman Filtering: Estimating Outputs When Measurements Are Correlated with the Process Noise." IEEE Control Systems Magazine, Vol. 37, Number 3, 2017, pp. 87–93.

Introduced before R2006a