Kalman - MapleSim Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

# Online Help

###### All Products    Maple    MapleSim

ControlDesign

 Kalman
 design Kalman estimator for a given state-space system

 Calling Sequence Kalman(sys, G, H, Q, R, opts)

Parameters

 sys - System; system object G - Matrix; process noise matrix in the state equations H - Matrix: process noise matrix in the output equations Q - Matrix; process noise covariance matrix R - Matrix; measurement noise covariance matrix opts - (optional) equation(s) of the form option = value; specify options for the Kalman command

Options

 • N = Matrix or Vector
 The cross-correlation matrix between process and measurement noises. If omitted, a zero matrix with appropriate dimensions will be considered.
 • output = gain or filter
 Specifies whether the Kalman gains or the Kalman filter object must be returned. The default value is gain.
 If gain, the Kalman gains and steady state estimation error covariance matrices are returned as follows:
 – In the continuous-time domain, the gain matrix and steady state error covariance are returned as a sequence of $L,P$ where $L$ and $P$ are as defined before.
 – In the discrete-time domain, the gain matrix, the innovation gain, and the steady state error covariance matrices are returned as a sequence of $L,M,P,Z$ where $L$, $P$, and $M$ are as defined before and
 $Z=\underset{n\to \infty }{lim}E\left\{e\left[n{|}n\right]e{\left[n{|}n\right]}^{T}\right\}=\left(I-\mathrm{MC}\right)P,e\left[n{|}n\right]=x\left[n\right]-\stackrel{ˆ}{x}\left[n{|}n\right]$.
 If filter, the Kalman filter is returned as a state-space DynamicSystems object. The structure of the filter depends on the time-domain and the value of option filtertype (for the discrete Kalman filter).
 • filtertype =  current or delayed
 Specifies the type of the discrete Kalman filter. The default value is current.
 • parameters = {list, set}(name = complexcons)
 Specifies numeric values for the parameters of sys. These values override any parameters previously specified for sys. The numeric value on the right-hand side of each equation is substituted for the name on the left-hand side in the sys equations. The default is the value of sys given by DynamicSystems:-SystemOptions(parameters).

Solvability Conditions

 • The pair $\left(A,C\right)$ must be detectable.
 • The pair $\left(A-\stackrel{_}{N}{\stackrel{_}{R}}^{-1}C,\stackrel{_}{Q}-\stackrel{_}{N}{\stackrel{_}{R}}^{-1}{\stackrel{_}{N}}^{T}\right)$ must have no uncontrollable modes on the imaginary axis in continuous-time domain or on the unit circle in discrete-time domain

where $\stackrel{_}{Q}={\mathrm{GQG}}^{T}$, $\stackrel{_}{R}$, and $\stackrel{_}{N}$ are as defined before.

 • $\stackrel{_}{R}>0$ (positive definite) and $\stackrel{_}{Q}-\stackrel{_}{N}{\stackrel{_}{R}}^{-1}{\stackrel{_}{N}}^{T}\ge 0$ (positive semidefinite)

where $\stackrel{_}{Q}$, $\stackrel{_}{R}$, and $\stackrel{_}{N}$ are as defined before.

Description

 • The Kalman command designs the Kalman estimator for a given system and process and measurement noise covariance matrices.
 • The system sys is a continuous or discrete-time linear system object created using the DynamicSystems package. The system object must be in state-space (SS) form.
 • If sys contains structural uncontrollable or unobservable states, they are removed using ReduceSystem before computing the Kalman gains.  The resulting Kalman gains are then filled with zeros at positions corresponding to the removed states.

 • Continuous-Time Kalman Estimator (Filter)

Given the continuous-time system

$\stackrel{\cdot }{x}=\mathrm{Ax}+\mathrm{Bu}+\mathrm{Gw}$

$y=\mathrm{Cx}+\mathrm{Du}+\mathrm{Hw}+v$

with known (deterministic) inputs $u$, white process noise $w$, and white measurement noise $v$, satisfying

$E\left\{w\right\}=0$    (process noise has zero mean value)

$E\left\{v\right\}=0$    (measurement noise has zero mean value)

$E\left\{w{w}^{T}\right\}=Q$

$E\left\{v{v}^{T}\right\}=R$

$E\left\{w{v}^{T}\right\}=N$

where $E\left\{a\right\}$ is the mathematical expectation of $a$, the Kalman filter provides an optimal state estimation that minimizes the steady state error covariance

$P=\underset{t\to \infty }{lim}E\left\{\left(x-\stackrel{ˆ}{x}\right){\left(x-\stackrel{ˆ}{x}\right)}^{T}\right\}$.

The Kalman filter equations are given as

$\stackrel{\cdot }{\stackrel{ˆ}{x}}=A\stackrel{ˆ}{x}+\mathrm{Bu}+L\left(y-C\stackrel{ˆ}{x}-\mathrm{Du}\right)$

$\left[\begin{array}{c}\stackrel{^}{x}\\ \stackrel{^}{y}\end{array}\right]=\left[\begin{array}{c}I\\ C\end{array}\right]\stackrel{^}{x}+\left[\begin{array}{cc}0& 0\\ \mathrm{D}& 0\end{array}\right]\left[\begin{array}{c}u\\ y\end{array}\right]$.

The gain matrix $L$ is calculated as

$L=\left(P{C}^{T}+\stackrel{_}{N}\right){\stackrel{_}{R}}^{-1}$

where $P$ is the solution of the corresponding algebraic Riccati equation and

$\stackrel{_}{R}=R+\mathrm{HN}+{\left(\mathrm{HN}\right)}^{T}+\mathrm{HQ}{H}^{T}$

$\stackrel{_}{N}=G\left({\mathrm{QH}}^{T}+N\right)$.

 • Discrete-Time Kalman Estimator (Filter)

Given the discrete-time system

$x\left[n+1\right]=\mathrm{Ax}\left[n\right]+\mathrm{Bu}\left[n\right]+\mathrm{Gw}\left[n\right]$

$y\left[n\right]=\mathrm{Cx}\left[n\right]+\mathrm{Du}\left[n\right]+\mathrm{Hw}\left[n\right]+v\left[n\right]$

and the noise covariance data

$E\left\{w\left[n\right]\right\}=0$

$E\left\{v\left[n\right]\right\}=0$

$E\left\{w\left[n\right]{w\left[n\right]}^{T}\right\}=Q$

$E\left\{v\left[n\right]{v\left[n\right]}^{T}\right\}=R$

$E\left\{w\left[n\right]{v\left[n\right]}^{T}\right\}=N$

the Kalman filter provides an optimal state estimation that minimizes the steady state error covariance

$P=\underset{n\to \infty }{lim}E\left\{e\left[n{|}n-1\right]e{\left[n{|}n-1\right]}^{T}\right\},e\left[n{|}n-1\right]=x\left[n\right]-\stackrel{ˆ}{x}\left[n{|}n-1\right]$.

The discrete Kalman filter state equation is given as

$\stackrel{ˆ}{x}\left[n+1|n\right]=A\stackrel{ˆ}{x}\left[n|n-1\right]+\mathrm{Bu}\left[n\right]+L\left(y\left[n\right]-C\stackrel{ˆ}{x}\left[n|n-1\right]-\mathrm{Du}\left[n\right]\right)$

The gain matrix $L$ is calculated as

$L=\left(\mathrm{AP}{C}^{T}+\stackrel{_}{N}\right){\left(\mathrm{CP}{C}^{T}+\stackrel{_}{R}\right)}^{-1}$

where  $P$ is the solution of the corresponding algebraic Riccati equation and $\stackrel{_}{R}$ and $\stackrel{_}{N}$ are as defined before.

 – The output equation structure depends on the type of the filter specified in the option filtertype:

 – The current estimator uses all available measurements up to $y\left[n\right]$ and generates state estimates $\stackrel{ˆ}{x}\left[n|n\right]$ and output estimates $\stackrel{ˆ}{y}\left[n|n\right]$. The updated estimates are obtained from the prediction $\stackrel{ˆ}{x}\left[n|n-1\right]$ using the latest measurement $y\left[n\right]$ as

$\stackrel{ˆ}{x}\left[n|n\right]=\stackrel{ˆ}{x}\left[n|n-1\right]+M\left(y\left[n\right]-C\stackrel{ˆ}{x}\left[n|n-1\right]-\mathrm{Du}\left[n\right]\right)$.

$y\left[n\right]-C\stackrel{ˆ}{x}\left[n|n-1\right]-\mathrm{Du}\left[n\right]$ is called the innovation signal which (under Kalman optimality conditions) is white.

The innovation gain, $M$, is given as

$M=P{C}^{T}{\left(\mathrm{CP}{C}^{T}+\stackrel{_}{R}\right)}^{-1}$.

The output equation is given as

$\left[\begin{array}{c}\stackrel{^}{x}\left[n|n\right]\\ \stackrel{^}{y}\left[n|n\right]\end{array}\right]=\left[\begin{array}{c}I-\mathrm{MC}\\ \left(I-\mathrm{CM}\right)C\end{array}\right]\stackrel{^}{x}\left[n|n-1\right]+\left[\begin{array}{cc}-\mathrm{MD}& M\\ \left(I-\mathrm{CM}\right)\mathrm{D}& \mathrm{CM}\end{array}\right]\left[\begin{array}{c}u\left[n\right]\\ y\left[n\right]\end{array}\right]$.

 – The delayed estimator uses measurements up to $y\left[\mathrm{n-1}\right]$ and generates state estimates $\stackrel{ˆ}{x}\left[n|\mathrm{n-1}\right]$ and output estimates $\stackrel{ˆ}{y}\left[n|\mathrm{n-1}\right]$.

The output equation is given as

$\left[\begin{array}{c}\stackrel{^}{x}\left[n|n-1\right]\\ \stackrel{^}{y}\left[n|n-1\right]\end{array}\right]=\left[\begin{array}{c}I\\ C\end{array}\right]\stackrel{^}{x}\left[n|n-1\right]+\left[\begin{array}{cc}0& 0\\ \mathrm{D}& 0\end{array}\right]\left[\begin{array}{c}u\left[n\right]\\ y\left[n\right]\end{array}\right]$.

Examples

 > $\mathrm{with}\left(\mathrm{ControlDesign}\right):$
 > $\mathrm{with}\left(\mathrm{DynamicSystems}\right):$

Design a Kalman filter for a continuous system

 > $\mathrm{csys}≔\mathrm{NewSystem}\left(\mathrm{Matrix}\left(\left[\left[\frac{1}{s+1},\frac{s}{{s}^{2}+3s+2}\right],\left[\frac{3}{\left(s+1\right)\left(s+4\right)},\frac{s}{{s}^{2}+1}\right]\right]\right)\right):$
 > $\mathrm{sys}≔\mathrm{StateSpace}\left(\mathrm{csys}\right):$
 > $\mathrm{PrintSystem}\left(\mathrm{sys}\right)$
 $\left[\begin{array}{l}{\mathbf{State Space}}\\ {\mathrm{continuous}}\\ {\mathrm{2 output\left(s\right); 2 input\left(s\right); 6 state\left(s\right)}}\\ {\mathrm{inputvariable}}{=}\left[{\mathrm{u1}}{}\left({t}\right){,}{\mathrm{u2}}{}\left({t}\right)\right]\\ {\mathrm{outputvariable}}{=}\left[{\mathrm{y1}}{}\left({t}\right){,}{\mathrm{y2}}{}\left({t}\right)\right]\\ {\mathrm{statevariable}}{=}\left[{\mathrm{x1}}{}\left({t}\right){,}{\mathrm{x2}}{}\left({t}\right){,}{\mathrm{x3}}{}\left({t}\right){,}{\mathrm{x4}}{}\left({t}\right){,}{\mathrm{x5}}{}\left({t}\right){,}{\mathrm{x6}}{}\left({t}\right)\right]\\ {\mathrm{a}}{=}\left[\begin{array}{cccccc}{0}& {1}& {0}& {0}& {0}& {0}\\ {-4}& {-5}& {0}& {0}& {0}& {0}\\ {0}& {0}& {0}& {1}& {0}& {0}\\ {0}& {0}& {0}& {0}& {1}& {0}\\ {0}& {0}& {0}& {0}& {0}& {1}\\ {0}& {0}& {-2}& {-3}& {-3}& {-3}\end{array}\right]\\ {\mathrm{b}}{=}\left[\begin{array}{cc}{0}& {0}\\ {1}& {0}\\ {0}& {0}\\ {0}& {0}\\ {0}& {0}\\ {0}& {1}\end{array}\right]\\ {\mathrm{c}}{=}\left[\begin{array}{cccccc}{4}& {1}& {0}& {1}& {0}& {1}\\ {3}& {0}& {0}& {2}& {3}& {1}\end{array}\right]\\ {\mathrm{d}}{=}\left[\begin{array}{cc}{0}& {0}\\ {0}& {0}\end{array}\right]\end{array}\right$ (1)
 > $G≔\mathrm{LinearAlgebra}:-\mathrm{IdentityMatrix}\left(6\right):$
 > $Q≔\frac{2}{3}\mathrm{LinearAlgebra}:-\mathrm{IdentityMatrix}\left(6\right):$
 > $H≔\mathrm{Matrix}\left(\left[\left[1,0,0,1,2,-2\right],\left[0,3,5,7,-1,2\right]\right]\right):$
 > $R≔2\mathrm{LinearAlgebra}:-\mathrm{IdentityMatrix}\left(2\right):$
 > $\mathrm{Kgc}≔\mathrm{Kalman}\left(\mathrm{sys},G,H,Q,R\right):$
 > $\mathrm{Kgain}≔\mathrm{Kgc}\left[1\right]$
 ${\mathrm{Kgain}}{≔}\left[\begin{array}{cc}{0.192433463634531}& {0.00614696476597994}\\ {-0.0643037043577344}& {0.0264039604378602}\\ {-0.0638163203438628}& {-0.0655169281432432}\\ {0.00978367900149663}& {0.0963473659292315}\\ {0.108484789016212}& {0.0909526847294459}\\ {-0.0254223506098090}& {0.0116225919671224}\end{array}\right]$ (2)
 > $\mathrm{Kcov}≔\mathrm{Kgc}\left[2\right]$
 ${\mathrm{Kcov}}{≔}\left[\begin{array}{cccccc}{0.28619026502462421249216422557974673288293232592618}& {-0.17093249750486729793964027668869909748546520252115}& {-0.023090085729227154363628640070442235954898979569838}& {-0.19723589554649682144619488632748940798762022313999}& {-0.063829831128177815994146097916068876282064128595202}& {0.22859532762945828671415622539317735625002783932338}\\ {-0.17093249750486729793964027668869909748546520252115}& {0.19582591742182165967612470819388315902860811255798}& {0.057706881538749435965508378755301988692734248674966}& {0.12847648642595889565755005263308806727757128935525}& {-0.0016386017918392762807724156621809230998288592598214}& {-0.18026854463676903611658851547851644267659801796258}\\ {-0.023090085729227154363628640070442235954898979569838}& {0.057706881538749435965508378755301988692734248674966}& {3.3056011882889604243245501383529761632162692350168}& {-0.18269350977652883516212948916949839765570205397822}& {-2.1788360511969896530095223458096966715302998562266}& {-0.37940575725428501692384388757325100457563620518737}\\ {-0.19723589554649682144619488632748940798762022313999}& {0.12847648642595889565755005263308806727757128935525}& {-0.18269350977652883516212948916949839765570205397822}& {1.7859473284905272128326231780521898012234023009321}& {-0.050711404623049480966638606781444388971726417683354}& {-1.6431234374313737289058834295224106871103272678818}\\ {-0.063829831128177815994146097916068876282064128595202}& {-0.0016386017918392762807724156621809230998288592598214}& {-2.1788360511969896530095223458096966715302998562266}& {-0.050711404623049480966638606781444388971726417683354}& {2.1915085811133627110745889007046547886549312829194}& {-0.024827374445595292290923034042017137740920465257607}\\ {0.22859532762945828671415622539317735625002783932338}& {-0.18026854463676903611658851547851644267659801796258}& {-0.37940575725428501692384388757325100457563620518737}& {-1.6431234374313737289058834295224106871103272678818}& {-0.024827374445595292290923034042017137740920465257607}& {2.0297653609100465020733736810968951891825963803854}\end{array}\right]$ (3)
 > $\mathrm{LinearAlgebra}:-\mathrm{Eigenvalues}\left(\mathrm{sys}:-a-\mathrm{Kgain}·\mathrm{sys}:-c\right)$
 $\left[\begin{array}{c}{-3.93877830228837}{+}{0.}{}{I}\\ {-2.47171603376280}{+}{0.}{}{I}\\ {-0.229038486136632}{+}{0.832844151778282}{}{I}\\ {-0.229038486136632}{-}{0.832844151778282}{}{I}\\ {-1.15841822127975}{+}{0.302560027651278}{}{I}\\ {-1.15841822127975}{-}{0.302560027651278}{}{I}\end{array}\right]$ (4)
 > $\mathrm{Kfilter}≔\mathrm{Kalman}\left(\mathrm{sys},G,H,Q,R,'\mathrm{output}'=\mathrm{filter}\right):$
 > $\mathrm{PrintSystem}\left(\mathrm{Kfilter}\right)$

Design a Kalman filter for a discrete system:

 > $\mathrm{dsys}≔\mathrm{ToDiscrete}\left(\mathrm{csys},1,'\mathrm{method}'=\mathrm{bilinear}\right):$
 > $\mathrm{sys}≔\mathrm{StateSpace}\left(\mathrm{dsys}\right):$
 > $\mathrm{Kgc}≔\mathrm{Kalman}\left(\mathrm{sys},G,H,Q,R\right):$
 > $L≔\mathrm{Kgc}\left[1\right]$
 ${L}{≔}\left[\begin{array}{cc}{0.102357348091063}& {-0.000270311689505002}\\ {-0.0000225872756644528}& {0.0316301696710112}\\ {0.0324778264960475}& {-0.0304093684912018}\\ {0.0704309874351989}& {-0.0320525532654381}\\ {0.129070756561783}& {-0.0489238268444825}\\ {-0.175506475598478}& {0.0836901687155676}\end{array}\right]$ (5)
 > $M≔\mathrm{Kgc}\left[2\right]$
 ${M}{≔}\left[\begin{array}{cc}{0.0253685913778349}& {0.00580736350880106}\\ {0.0274697247286604}& {0.000676794860821479}\\ {-0.0218446273754245}& {0.00178225865532143}\\ {0.0372133592476799}& {-0.0820508802560722}\\ {0.00217310992508201}& {-0.103403563185930}\\ {-0.0216515967133475}& {-0.0367013113908555}\end{array}\right]$ (6)
 > $P≔\mathrm{Kgc}\left[3\right]$
 ${P}{≔}\left[\begin{array}{cccccc}{1.1900369256390078377586184628370039668475331991448}& {-0.0023320086090345049249859938698105927722038641180531}& {0.0061998827422618221294455827872920780525874972897137}& {0.014704192484813023622580936656881320686092202865071}& {-0.26910475791320750804979073203338265728777922953550}& {-0.17883726222393262145311402911160312135949479177824}\\ {-0.0023320086090345049249859938698105927722038641180531}& {0.61670692397166809254217990688699410868842846313117}& {0.062957575000545940463224654738305222803191417153972}& {0.033808441060154514359741367661977779127934579497919}& {0.076819002446584818836921297831759174977385306740545}& {-0.15462446618098261544168174277522672775638325502978}\\ {0.0061998827422618221294455827872920780525874972897137}& {0.062957575000545940463224654738305222803191417153972}& {14.025849333821809856790922021450562508283629456859}& {7.4346881925078578276089838791018867254508860879170}& {-3.5696824762744547720904033319872007356676381302352}& {-11.113108157713765146316160035522758848528561725755}\\ {0.014704192484813023622580936656881320686092202865071}& {0.033808441060154514359741367661977779127934579497919}& {7.4346881925078578276089838791018867254508860879170}& {13.426727719234365542941496863071620708460198331150}& {7.5154613955186568085059467231836511906099352421786}& {-3.4406863305018803177987802662013206227436745305880}\\ {-0.26910475791320750804979073203338265728777922953550}& {0.076819002446584818836921297831759174977385306740545}& {-3.5696824762744547720904033319872007356676381302352}& {7.5154613955186568085059467231836511906099352421786}& {12.866972987719699209572339910279283446718950849439}& {7.6916211935162691687987582863169769663886962498825}\\ {-0.17883726222393262145311402911160312135949479177824}& {-0.15462446618098261544168174277522672775638325502978}& {-11.113108157713765146316160035522758848528561725755}& {-3.4406863305018803177987802662013206227436745305880}& {7.6916211935162691687987582863169769663886962498825}& {12.493137943161183557844150615741546706412859530872}\end{array}\right]$ (7)
 > $Z≔\mathrm{Kgc}\left[4\right]$
 ${Z}{≔}\left[\begin{array}{cccccc}{1.18188087156736}& {-0.00894129364051063}& {0.0105368060799054}& {0.0386074205259520}& {-0.228656565276868}& {-0.159304648350176}\\ {-0.00894129364051063}& {0.609921640852156}& {0.0681998217561377}& {0.0301077499423651}& {0.0831297099445528}& {-0.146882483807686}\\ {0.0105368060799054}& {0.0681998217561377}& {14.0214547359271}& {7.44986437129508}& {-3.55919924152385}& {-11.1137202048741}\\ {0.0386074205259520}& {0.0301077499423651}& {7.44986437129508}& {12.9843151713309}& {6.96975114659318}& {-3.62844349992178}\\ {-0.228656565276868}& {0.0831297099445528}& {-3.55919924152385}& {6.96975114659318}& {12.1763352407015}& {7.44503056330966}\\ {-0.159304648350176}& {-0.146882483807686}& {-11.1137202048741}& {-3.62844349992178}& {7.44503056330966}& {12.4006152930078}\end{array}\right]$ (8)
 > $\mathrm{LinearAlgebra}:-\mathrm{Eigenvalues}\left(\mathrm{sys}:-a-L·\mathrm{sys}:-c\right)$
 $\left[\begin{array}{c}{0.557923700713317}{+}{0.764621079517396}{}{I}\\ {0.557923700713317}{-}{0.764621079517396}{}{I}\\ {-0.329933413527070}{+}{0.}{}{I}\\ {0.313799486006446}{+}{0.}{}{I}\\ {0.178331258920456}{+}{0.146122594396005}{}{I}\\ {0.178331258920456}{-}{0.146122594396005}{}{I}\end{array}\right]$ (9)
 > $\mathrm{Kfilter}≔\mathrm{Kalman}\left(\mathrm{sys},G,H,Q,R,'\mathrm{output}'=\mathrm{filter},'\mathrm{filtertype}'=\mathrm{current}\right):$
 > $\mathrm{PrintSystem}\left(\mathrm{Kfilter}\right)$
 > $\mathrm{Kfilter}≔\mathrm{Kalman}\left(\mathrm{sys},G,H,Q,R,'\mathrm{output}'=\mathrm{filter},'\mathrm{filtertype}'=\mathrm{delayed}\right):$
 > $\mathrm{PrintSystem}\left(\mathrm{Kfilter}\right)$

References

 [1] F. Lewis, Optimal Estimation, John Wiley & Sons, 1986.
 [2] G. F. Franklin, J. D. Powell and M. L. Workman, Digital Control of Dynamic Systems, 2nd Ed., Addison-Wesley, 1990.