Discrete Kalman Filter Function

Simulation VI and Function

Discrete Kalman Filter Function

Owning Palette: Discrete Linear Systems Functions

Installed With: Control Design and Simulation Module

Implements a discrete-time, linear time-variant, recursive Kalman filter. You define the system by specifying the stochastic state-space model and noise model as well as the inputs and outputs to the system. The Discrete Kalman Filter function calculates the predicted state estimates xhat(k+1|k), the corrected state estimates xhat(k|k), the corresponding gains used to calculate these estimates, and the associated estimation error covariances corresponding to these estimates. This function also calculates the estimated output yhat(k).

Refer to Chapter 16, Using Stochastic System Models, of the LabVIEW Control Design User Manual for information about using this function.

Details  

Dialog Box Options
Block Diagram Inputs
Block Diagram Outputs
 Place on the block diagram  Find on the Functions palette

Dialog Box Options

ParameterDescription
Polymorphic instanceSpecifies the behavior of this function:
  • Pred gain, w/ check—(Default) Performs prediction and correction with prediction gain; checks the model parameters.
  • Pred gain, w/o check—Performs prediction and correction with prediction gain; does not check the model parameters.
  • No pred gain, w/ check—Performs prediction and correction without prediction gain; checks the model parameters.
  • No pred gain, w/o check—Performs prediction and correction without prediction gain; does not check the model parameters.
  • No corr, w/ check—Performs only prediction with prediction gain; checks the model parameters.
  • No corr, w/o check—Performs only prediction with prediction gain; does not check the model parameters.
Refer to the Details section for a description of the equations this function uses to calculate the outputs for each of these polymorphic instances.
FeedthroughConfigures the function to be either a Direct or Indirect feedthrough function. Enable this control by selecting Stochastic State-Space Model from the Parameters list and then selecting Terminal from the Parameter source pull-down menu. If you select Configuration Dialog Box from the Parameter source pull-down menu, LabVIEW disables this control and calculates the feedthrough behavior automatically.

If you specify Direct feedthrough, the transmission matrix D in the Stochastic State-Space Model is non-zero. If you specify Indirect feedthrough, the transmission matrix D in the Stochastic State-Space Model is zero. You can use the Corrected State Estimate xhat(k|k) to design the input u(k) only if you specify Indirect feedthrough.

Refer to the Details section for a description of the parameters that determine the feedthrough behavior of this function.
ParametersLists all the parameters associated with this function. Select a parameter from this list to configure the parameter. When you select a parameter, the parameter and its associated Parameter source control appear in the Parameter Information section of the configuration dialog box.
PreviewDisplays a graphical preview, if available, of the function output or configuration.
Parameter InformationContains the parameters you can configure for this function. You must select a parameter from the Parameters list to make that parameter and its associated Parameter source control visible in the Parameter Information section of the configuration dialog box.
Parameter sourceSpecifies whether you configure this parameter using the Configuration Dialog Box or a Terminal on the simulation diagram. The default value is Configuration Dialog Box. If you select Terminal, LabVIEW displays an input for that parameter on the simulation diagram, and you can wire values to that input to configure this function programmatically. If you select Configuration Dialog Box, LabVIEW removes that input from the simulation diagram. You then must set the value for this parameter inside the configuration dialog box.
skewSpecifies the length of time by which you want to delay the execution of this function. The default value is 0.
Initial State Estimate xhat(0|–1)Specifies the initial states from which this function begins estimating the model states. If you do not specify a value for this parameter and you select one of the w/ check instances of this function, Initial State Estimate xhat(0|-1) is a vector of zeros.
Initial Estimation Error Covariance P(0|-1)Specifies the initial covariance matrix of the estimation error. If you do not specify a value for this parameter and you select one of the w/ check instances of this function, Initial Estimation Error Covariance P(0|-1) is the identity matrix. Initial Estimation Error Covariance P(0|-1) must be symmetric and positive semi-definite such that P (0|-1) = PT (0|–1) ≥ 0.
Initialize?Specifies whether to restart the calculation from any initial values you provide. The default is FALSE.
Second-Order Statistics Noise ModelSpecifies a mathematical representation of the noise model of a stochastic state-space model. You can create a noise model using the CD Construct Noise Model VI.
  • E{w}—Specifies the expected value or mean of the process noise vector. The default is 0.
  • Q—Specifies the covariance matrix of the process noise vector. The default is 0.01.
  • E{v}—Specifies the expected value or mean of the measurement noise vector. The default is 0.
  • R—Specifies the covariance matrix of the measurement noise vector. The default is 0.1.
  • N—Specifies the cross-covariance matrix between the process noise vector and the measurement noise vector. If these noise vectors are uncorrelated, N is a matrix of zeros. The default is 0.
Stochastic State-Space ModelSpecifies a mathematical representation of a stochastic system. You can construct a stochastic state-space model using the CD Construct Stochastic Model VI.
  • A—Specifies the system matrix that describes the dynamics of the states of the system.
  • B—Specifies the input matrix that relates the inputs to the states.
  • G—Specifies the matrix that relates the process noise vector to the model states.
  • C—Specifies the output matrix that relates the outputs to the states.
  • D—Specifies the transmission matrix that relates the inputs to the outputs.
  • H—Specifies the matrix that relates the process noise vector to the model outputs.
  • Sampling Time (s)—Specifies the sampling time of the system model and determines whether the model represents a continuous-time or discrete-time system. If the model represents a continuous-time system, Sampling Time (s) must equal zero. If the model represents a discrete-time system, Sampling Time (s) must be greater than zero and equal to the sampling rate, in seconds, of the discrete system. The default is –1. If you specify a value of –1, this function inherits the discrete time step you specify for the simulation diagram. Otherwise, the value of Sampling Time (s) must be a multiple of the discrete time step you specify for the simulation diagram. This limitation applies only if you place this function inside a Simulation Loop.
    Note  If you use the inputs to create a continuous-time system, setting the Sampling Time (s) to a value greater than zero does not yield the discrete-time equivalent of the system. You must use the CD Convert Continuous Stochastic to Discrete VI to convert the continuous-time system to the discrete-time equivalent of the system.

Block Diagram Inputs

ParameterDescription
skewSpecifies the length of time by which you want to delay the execution of this function. The default value is 0.
Initial State Estimate xhat(0|–1)Specifies the initial states from which this function begins estimating the model states. If you do not specify a value for this parameter and you select one of the w/ check instances of this function, Initial State Estimate xhat(0|-1) is a vector of zeros.
Initial Estimation Error Covariance P(0|-1)Specifies the initial covariance matrix of the estimation error. If you do not specify a value for this parameter and you select one of the w/ check instances of this function, Initial Estimation Error Covariance P(0|-1) is the identity matrix. Initial Estimation Error Covariance P(0|-1) must be symmetric and positive semi-definite such that P (0|-1) = PT (0|–1) ≥ 0.
Initialize?Specifies whether to restart the calculation from any initial values you provide. The default is FALSE.
Second-Order Statistics Noise ModelSpecifies a mathematical representation of the noise model of a stochastic state-space model. You can create a noise model using the CD Construct Noise Model VI.
  • E{w}—Specifies the expected value or mean of the process noise vector. The default is 0.
  • Q—Specifies the covariance matrix of the process noise vector. The default is 0.01.
  • E{v}—Specifies the expected value or mean of the measurement noise vector. The default is 0.
  • R—Specifies the covariance matrix of the measurement noise vector. The default is 0.1.
  • N—Specifies the cross-covariance matrix between the process noise vector and the measurement noise vector. If these noise vectors are uncorrelated, N is a matrix of zeros. The default is 0.
Stochastic State-Space ModelSpecifies a mathematical representation of a stochastic system. You can construct a stochastic state-space model using the CD Construct Stochastic Model VI.
  • A—Specifies the system matrix that describes the dynamics of the states of the system.
  • B—Specifies the input matrix that relates the inputs to the states.
  • G—Specifies the matrix that relates the process noise vector to the model states.
  • C—Specifies the output matrix that relates the outputs to the states.
  • D—Specifies the transmission matrix that relates the inputs to the outputs.
  • H—Specifies the matrix that relates the process noise vector to the model outputs.
  • Sampling Time (s)—Specifies the sampling time of the system model and determines whether the model represents a continuous-time or discrete-time system. If the model represents a continuous-time system, Sampling Time (s) must equal zero. If the model represents a discrete-time system, Sampling Time (s) must be greater than zero and equal to the sampling rate, in seconds, of the discrete system. The default is –1. If you specify a value of –1, this function inherits the discrete time step you specify for the simulation diagram. Otherwise, the value of Sampling Time (s) must be a multiple of the discrete time step you specify for the simulation diagram. This limitation applies only if you place this function inside a Simulation Loop.
    Note  If you use the inputs to create a continuous-time system, setting the Sampling Time (s) to a value greater than zero does not yield the discrete-time equivalent of the system. You must use the CD Convert Continuous Stochastic to Discrete VI to convert the continuous-time system to the discrete-time equivalent of the system.
Output y(k)Specifies measurements made on the Stochastic State-Space Model. You can use the Discrete Stochastic State-Space function to simulate the model and obtain this parameter. You also can wire in measurements made from a hardware sensor.
input u(k)Specifies the control action this function applies to the model.

Block Diagram Outputs

ParameterDescription
Estimated Output yhat(k)Returns the estimated model output at time k.
Corrected State Estimate xhat(k|k)Returns the corrected Kalman state estimate at time k, given all measurements up to and including time k. The length of this vector is equal to the number of model states. This parameter is not available if you select one of the No corr instances of this function.
Predicted State Estimate xhat(k+1|k)Returns the predicted state estimate for the next time step k + 1, given all measurements up to and including time k. The length of this vector is equal to the number of model states.
Kalman Filter Gain M(k)Returns the Kalman filtered gain matrix this function uses to calculate the Corrected State Estimate xhat(k|k). This parameter is not available if you select one of the No corr instances of this function.
Kalman Predictor Gain L(k)Returns the gain matrix this function uses to calculate the Predicted State Estimate xhat(k+1|k). This parameter is not available if you select one of the No pred gain instances of this function.
Filter Error Covariance P(k|k)Returns the covariance matrix of the estimation error associated with the Corrected State Estimate xhat(k|k). This parameter is not available if you select one of the No corr instances of this function.
Prediction Error Covariance P(k+1|k)Returns the covariance matrix of the estimation error associated with the Predicted State Estimate xhat(k+1|k), given all measurements up to and including time k.

Discrete Kalman Filter Details

This function adapts to changes in the Stochastic State-Space Model and the Second-Order Statistics Noise Model as long as the model dimensions do not change. Therefore, you can use this function with linear time-variant (LTV) models.

This function uses the Second-Order Statistics Noise Model to obtain the values of E{w(k)}, E{v(k)}, Q(k), R(k), and N(k). The following equations define these terms:

whereδkl is the Kronecker delta function. The following equations defines this function: δkl = 1 when k = l; δkl = 0 when kl.
w(k) is the process noise vector.
v(k) is the measurement noise vector.
Q(k) is the covariance matrix of w(k).
R(k) is the covariance matrix of v(k).
N(k) is the cross-covariance matrix between w(k) and v(k). If these noise vectors are uncorrelated, N(k) is a matrix of zeros.
E{} denotes the expected value or the mean of the enclosed term(s).

The noise covariance matrices must satisfy the following conditions:

Q(k) = QT(k) ≥ 0

R(k) = RT(k) > 0

This function assumes the process noise and measurement noise vectors to be temporally uncorrelated between time steps. This function also assumes the Initial State Estimate xhat(0|–1) to be uncorrelated with the noise vectors. If the noise vectors are Gaussian-distributed, this function is an optimal minimum mean square error (MMSE) estimator. However, if these vectors are not Gaussian-distributed, this function is an optimal affine MMSE estimator.

Feedthrough Behavior

The value you specify for the D matrix of the Stochastic State-Space Model parameter determines the feedthrough behavior of this function.

  • If the D matrix is nonzero, all input/output pairs have direct feedthrough behavior.
  • If the D matrix is zero, the following input/output pairs have indirect feedthrough behavior.
    • Input u(k)Corrected State Estimate xhat(k|k)
    • Input u(k)Predicted State Estimate xhat(k|k–1)
    The remaining input/output pairs have direct feedthrough behavior.

When you use the configuration dialog box to configure the D matrix, LabVIEW verifies that the feedthrough behavior is correct. For example, if you set the Feedthrough parameter to Indirect, and you set the D matrix to nonzero, LabVIEW changes the Feedthrough parameter to Direct.

If you specify the value of the D matrix programmatically by wiring a value to the parameter terminal, LabVIEW does not adjust the feedthrough behavior for you. You must ensure that you specify the proper feedthrough behavior for the value of the D matrix that you specify.

Kalman Filter Structures

This function uses the following equations to calculate the outputs for each of the polymorphic instances.

Pred Gain Instances—Correction Stage

xhat(k|k) = xhat(k|k–1) + M(k) · [y(k) – yhat(k)]

yhat(k) = C(k) · xhat(k|k–1) + D(k) · u(k)

M(k) = P(k|k–1) · CT(k) · [C(k) · P(k|k–1) · CT(k) + H(k)Q(k)HT(k) + H(k)N(k) + NT(k)HT(k) + R(k)]–1

P(k|k) = P(k|k–1) – M(k) · C(k) · P(k|k–1)

Pred Gain Instances—Prediction Stage

xhat(k+1|k) = A(k) · xhat(k|k–1) + B(k) · u(k) + L(k) · [y(k) – yhat(k)]

yhat(k) = C(k) · xhat(k|k–1) + D(k) · u(k)

L(k) = [A(k) · P(k|k–1) · CT(k) + G(k)Q(k)HT(k) + G(k)N(k)] · [C(k) · P(k|k–1) · CT(k) + H(k)Q(k)HT(k) + H(k)N(k) + NT(k)HT(k) + R(k)]–1

P(k+1|k) = [A(k) · P(k|k–1) · AT(k) + G(k)Q(k)GT(k)] – L(k) · [A(k) · P(k|k–1) · CT(k) + G(k)Q(k)HT(k) + G(k)N(k)]T

No Pred Gain Instances—Correction Stage

xhat(k|k) = xhat(k|k–1) + M(k) · [y(k) – yhat(k)]

yhat(k) = C(k) · xhat(k|k–1) + D(k) · u(k)

M(k) = P(k|k–1) · CT(k) · [C(k) · P(k|k–1) · CT(k) + H(k)Q(k)HT(k) + H(k)N(k) + NT(k)HT(k) + R(k)]–1

P(k|k) = P(k|k–1) – M(k) · C(k) · P(k|k–1)

No Pred Gain Instances—Prediction Stage

xhat(k+1|k) = A(k)xhat(k|k–1) + B(k)u(k)

No Corr Instances—Prediction Stage

xhat(k+1|k) = A(k) · xhat(k|k–1) + B(k) · u(k) + L(k) · [y(k) – yhat(k)]

yhat(k) = C(k) · xhat(k|k–1) + D(k) · u(k)

L(k) = [A(k) · P(k|k–1) · CT(k) + G(k)Q(k)HT(k) + G(k)N(k)] · [C(k) · P(k|k–1) · CT(k) + H(k)Q(k)HT(k) + H(k)N(k) + NT(k)HT(k) + R(k)]–1

P(k+1|k) = [A(k) · P(k|k–1) · AT(k) + G(k)Q(k)GT(k)] – L(k) · [A(k) · P(k|k–1) · CT(k) + G(k)Q(k)HT(k) + G(k)N(k)]T