# getEstimator

Obtain Kalman gains and model for estimator design

## Syntax

## Description

`[`

also returns
the system matrices used to calculate the estimator gains.`L`

,`M`

,`A,Cm,Bu,Bv,Dvm`

]
= getEstimator(`mpcobj`

)

## Examples

### Extract Parameters for State Estimation

The plant is a stable, discrete LTI state-space model with four states, three inputs, and three outputs. The manipulated variables are inputs 1 and 2. Input 3 is an unmeasured disturbance. Outputs 1 and 3 are measured. Output 2 is unmeasured.

Fix the number generator seed to ensure repeatable results.

rng(0)

Create a model of the plant and specify the signals for MPC.

plant = drss(4,3,3); plant.Ts = 0.25; plant = setmpcsignals(plant,MV=[1,2],UD=3,MO=[1 3],UO=2); plant.d(:,[1,2]) = 0;

The last command forces the plant to satisfy the assumption of no direct feedthrough.

Calculate the default model predictive controller for this plant.

mpcobj = mpc(plant);

-->"PredictionHorizon" is empty. Assuming default 10. -->"ControlHorizon" is empty. Assuming default 2. -->"Weights.ManipulatedVariables" is empty. Assuming default 0.00000. -->"Weights.ManipulatedVariablesRate" is empty. Assuming default 0.10000. -->"Weights.OutputVariables" is empty. Assuming default 1.00000. for output(s) y1 y3 and zero weight for output(s) y2

Obtain the parameters to be used in state estimation.

[L,M,A,Cm,Bu,Bv,Dvm] = getEstimator(mpcobj);

-->The "Model.Disturbance" property is empty: Assuming unmeasured input disturbance #3 is integrated white noise. -->Assuming output disturbance added to measured output #1 is integrated white noise. Assuming no disturbance added to measured output #3. -->"Model.Noise" is empty. Assuming white noise on each measured output.

Based on the estimator state equation, the estimator poles are given by the eigenvalues of `A - L*Cm`

. Calculate and display the poles.

Poles = eig(A - L*Cm)

`Poles = `*6×1*
-0.5409
-0.0026
0.2358
0.7628
0.8595
0.9718

Confirm that the default estimator is asymptotically stable.

max(abs(Poles))

ans = 0.9718

This value is less than 1, so the estimator is asymptotically stable.

Verify that in this case, `L = A*M`

.

L - A*M

ans =6×210^{-14}× 0.0527 -0.0094 -0.0916 0.0111 -0.1874 0.0305 -0.0111 -0.0099 0.0083 -0.0049 0.0042 -0.0087

## Input Arguments

`mpcobj`

— MPC controller

MPC controller object

MPC controller, specified as an MPC controller object. Use the `mpc`

command to create the MPC controller.

## Output Arguments

`L`

— Kalman gain matrix for time update

matrix

Kalman gain matrix for the time update, returned as a matrix. The dimensions of
`L`

are
*n _{x}*-by-

*n*, where

_{ym}*n*is the total number of controller states, and

_{x}*n*is the number of measured outputs.

_{ym}`M`

— Kalman gain matrix for measurement update

matrix

Kalman gain matrix for the measurement update, returned as a matrix. The dimensions of
`L`

are
*n _{x}*-by-

*n*, where

_{ym}*n*is the total number of controller states, and

_{x}*n*is the number of measured outputs.

_{ym}`A,Cm,Bu,Bv,Dvm`

— System matrices

matrices

System matrices used to calculate the estimator gains, returned as matrices of various dimensions. For definitions of these system matrices, see State Estimator Equations.

`model`

— System used for state-estimator design

state-space model

System used for state-estimator design, returned as a state-space
(`ss`

) model. The input to `model`

is
a vector signal comprising the following components, concatenated
in the following order:

Manipulated variables

Measured disturbance variables

1

Noise inputs to disturbance models

Noise inputs to measurement noise model

The number of noise inputs depends on the disturbance
and measurement noise models within `mpcobj`

.
For the category noise inputs to disturbance models, inputs to the
input disturbance model (if any) precede those entering the output
disturbance model (if any). The constant input, 1, accounts for nonequilibrium
nominal values (see MPC Prediction Models).

To make the calculation of gains `L`

and `M`

more
robust, additive white noise inputs are assumed to affect the manipulated
variables and measured disturbances (see Controller State Estimation). These
white noise inputs are not included in `model`

.

`index`

— Locations of variables within model

structure

Locations of variables within the inputs and outputs of `model`

.
The structure summarizes these locations with the following fields
and values.

Field Name | Value |
---|---|

`ManipulatedVariables` | Indices of manipulated variables within the input vector of `model` . |

`MeasuredDisturbances` | Indices of measured input disturbances within the input vector
of `model` . |

`Offset` | Index of the constant input 1 within the input vector of `model` . |

`WhiteNoise` | Indices of unmeasured disturbance inputs within the input vector
of `model` . |

`MeasuredOutputs` | Indices of measured outputs within the output vector of `model` . |

`UmeasuredOutputs` | Indices of unmeasured outputs within the output vector of `model` . |

## Algorithms

### State Estimator Equations

In general, the controller states are unmeasured and must be estimated. By default, the controller uses a steady-state Kalman filter that derives from the state observer. For more information, see Controller State Estimation.

At the beginning of the *k*th control interval, the controller state is estimated with the following steps:

Obtain the following data:

*x*(_{c}*k*|*k*–1) — Controller state estimate from previous control interval,*k*–1*u*(^{act}*k*–1) — Manipulated variable (MV) actually used in the plant from*k*–1 to*k*(assumed constant)*u*(^{opt}*k*–1) — Optimal MV recommended by MPC and assumed to be used in the plant from*k*–1 to*k**v*(*k*) — Current measured disturbances*y*(_{m}_{k}) — Current measured plant outputs*B*,_{u}*B*— Columns of observer parameter_{v}*B*corresponding to*u*(*k*) and*v*(*k*) inputs*C*— Rows of observer parameter C corresponding to measured plant outputs_{m}*D*— Rows and columns of observer parameter_{mv}*D*corresponding to measured plant outputs and measured disturbance inputs*L*,*M*— Constant Kalman gain matrices

Plant input and output signals are scaled to be dimensionless prior to use in calculations.

Revise

*x*(_{c}*k*|*k*–1) when*u*(^{act}*k*–1) and*u*(^{opt}*k*–1) are different.$${x}_{c}^{rev}\left(k\text{\hspace{0.17em}}\text{|}k-1\right)={x}_{c}\left(k\text{\hspace{0.17em}}\text{|}k-1\right)+{B}_{u}\left[{u}^{act}\left(k-1\right)-{u}^{opt}\left(k-1\right)\right]$$

Compute the innovation.

$e\left(k\right)={y}_{m}\left(k\right)-\left[{C}_{m}{x}_{c}^{rev}\left(k\text{\hspace{0.17em}}\text{|}k-1\right)+{D}_{mv}v\left(k\right)\right]$

Update the controller state estimate to account for the latest measurements.

${x}_{c}\left(k\text{\hspace{0.17em}}\text{|}k\right)={x}_{c}^{rev}\left(k\text{\hspace{0.17em}}\text{|}k-1\right)+Me\left(k\right)$

Then, the software uses the current state estimate

*x*(_{c}*k*|*k*) to solve the quadratic program at interval*k*. The solution is*u*(^{opt}*k*), the MPC-recommended manipulated-variable value to be used between control intervals*k*and*k*+1.Finally, the software prepares for the next control interval assuming that the unknown inputs,

*w*(_{id}*k*),*w*(_{od}*k*), and*w*(_{n}*k*) assume their mean value (zero) between times*k*and*k*+1. The software predicts the impact of the known inputs and the innovation as follows:$${x}_{c}\left(k+1|k\right)=A{x}_{c}^{rev}\left(k|k-1\right)+{B}_{u}{u}^{opt}\left(k\right)+{B}_{v}v\left(k\right)+Le\left(k\right)$$

## Version History

**Introduced in R2014b**

## See Also

### Functions

`setEstimator`

|`kalman`

|`getindist`

|`getoutdist`

|`get`

|`set`

|`sim`

### Objects

`mpc`

|`mpcstate`

|`mpcsimopt`

|`mpcmoveopt`

### Blocks

## Open Example

You have a modified version of this example. Do you want to open this example with your edits?

## MATLAB Command

You clicked a link that corresponds to this MATLAB command:

Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.

Select a Web Site

Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .

You can also select a web site from the following list:

## How to Get Best Site Performance

Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.

### Americas

- América Latina (Español)
- Canada (English)
- United States (English)

### Europe

- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)

- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)