Main Content

Unscented Kalman Filter

Estimate states of discrete-time nonlinear system using unscented Kalman filter

  • Library:
  • Control System Toolbox / State Estimation

    System Identification Toolbox / Estimators

  • ukf_block

Description

TheUnscented Kalman Filterblock estimates the states of a discrete-time nonlinear system using the discrete-time unscented Kalman filter algorithm.

Consider a plant with statesx, inputu, outputy, process noisew, and measurement noisev. Assume that you can represent the plant as a nonlinear system.

Using the state transition and measurement functions of the system and the unscented Kalman filter algorithm, the block produces state estimates x ^ for the current time step. For information about the algorithm, seeExtended and Unscented Kalman Filter Algorithms for Online State Estimation.

You create the nonlinear state transition function and measurement functions for the system and specify these functions in the block. The block supports state estimation of a system with multiple sensors that are operating at different sampling rates. You can specify up to five measurement functions, each corresponding to a sensor in the system. For more information, seeState Transition and Measurement Functions.

Ports

Input

expand all

Measured system outputs corresponding to each measurement function that you specify in the block. The number of ports equals the number of measurement functions in your system. You can specify up to five measurement functions. For example, if your system has two sensors, you specify two measurement functions in the block. The first porty1is available by default. When you clickApply, the software generates porty2corresponding to the second measurement function.

Specify the ports asN-dimensional vectors, whereNis the number of quantities measured by the corresponding sensor. For example, if your system has one sensor that measures the position and velocity of an object, then there is only one porty1. The port is specified as a 2-dimensional vector with values corresponding to position and velocity.

Dependencies

The first porty1is available by default. Portsy2toy5are generated when you clickAdd Measurement, and clickApply.

Data Types:single|double

Additional optional input argument to the state transition functionfother than the statexand process noisew. For information about state transition functions see,State Transition and Measurement Functions.

Suppose that your system has nonadditive process noise, and the state transition functionfhas the following form:

x(k+1) = f(x(k),w(k),StateTransitionFcnInputs).

Herekis the time step, andStateTransitionFcnInputsis an additional input argument other thanxandw.

If you createfusing a MATLAB®function (.mfile), the software generates the portStateTransitionFcnInputs当你点击Apply. You can specify the inputs to this port as a scalar, vector, or matrix.

If your state transition function has more than one additional input, use a金宝app仿真软件的功能(Simulink)block to specify the function. When you use a金宝app仿真软件的功能block, you provide the additional inputs directly to the金宝app仿真软件的功能block usingInport(Simulink)blocks. No input ports are generated for the additional inputs in theUnscented Kalman Filterblock.

Dependencies

This port is generated only if both of the following conditions are satisfied:

  • You specifyfinFunctionusing a MATLAB function, andfis on the MATLAB path.

  • f只需要一个额外的input argument apart fromxandw.

Data Types:single|double

Additional optional inputs to the measurement functions other than the statexand measurement noisev. For information about measurement functions see,State Transition and Measurement Functions.

MeasurementFcn1Inputscorresponds to the first measurement function that you specify, and so on. For example, suppose that your system has three sensors and nonadditive measurement noise, and the three measurement functionsh1,h2, andh3have the following form:

y1[k] = h1(x[k],v[k],MeasurementFcn1Inputs)

y2[k] = h2(x[k],v[k],MeasurementFcn2Inputs)

y3[k] = h3(x[k],v[k])

Herekis the time step, andMeasurementFcn1InputsandMeasurementFcn2Inputsare the additional input arguments toh1andh2.

If you specifyh1,h2, andh3using MATLAB functions (.mfiles) inFunction, the software generates portsMeasurementFcn1InputsandMeasurementFcn2Inputs当你点击Apply. You can specify the inputs to these ports as scalars, vectors, or matrices.

If your measurement functions have more than one additional input, use金宝app仿真软件的功能(Simulink)blocks to specify the functions. When you use a金宝app仿真软件的功能block, you provide the additional inputs directly to the金宝app仿真软件的功能block usingInport(Simulink)blocks. No input ports are generated for the additional inputs in theUnscented Kalman Filterblock.

Dependencies

一个港口corresponding to a measurement functionh只有以下两个生成conditi吗ons are satisfied:

  • You specifyhinFunctionusing a MATLAB function, andhis on the MATLAB path.

  • h只需要一个额外的input argument apart fromxandv.

Data Types:single|double

Time-varying process noise covariance, specified as a scalar, vector, or matrix depending on the value of theProcess noiseparameter:

  • Process noiseisAdditive— Specify the covariance as a scalar, anNs-element vector, or anNs-by-Ns米atrix, whereNsis the number of states of the system. Specify a scalar if there is no cross-correlation between process noise terms, and all the terms have the same variance. Specify a vector of lengthNs, if there is no cross-correlation between process noise terms, but all the terms have different variances.

  • Process noiseisNonadditive— Specify the covariance as aW-by-W米atrix, whereWis the number of process noise terms in the state transition function.

Dependencies

This port is generated if you specify the process noise covariance asTime-Varying. The port appears when you clickApply.

Data Types:single|double

Time-varying measurement noise covariances for up to five measurement functions of the system, specified as matrices. The sizes of the matrices depend on the value of theMeasurement noiseparameter for the corresponding measurement function:

  • Measurement noiseisAdditive— Specify the covariance as anN-by-N米atrix, whereNis the number of measurements of the system.

  • Measurement noiseisNonadditive— Specify the covariance as aV-by-V米atrix, whereVis the number of measurement noise terms in the corresponding measurement function.

Dependencies

一个港口is generated if you specify the measurement noise covariance asTime-Varyingfor the corresponding measurement function. The port appears when you clickApply.

Data Types:single|double

Suppose that measured output data is not available at all time points at the porty1that corresponds to the first measurement function. Use a signal value other than0at theEnable1port to enable the correction of estimated states when measured data is available. Specify the port value as0when measured data is not available. Similarly, if measured output data is not available at all time points at the portyifor theith米easurement function, specify the corresponding portEnableias a value other than0.

Dependencies

一个港口corresponding to a measurement function is generated if you selectAdd Enable portfor that measurement function. The port appears when you clickApply.

Data Types:single|double|Boolean

Output

expand all

Estimated states, returned as a vector of sizeNs, whereNsis the number of states of the system. To access the individual states, use theSelector(Simulink)block.

When theUse the current measurements to improve state estimatesparameter is selected, the block outputs the corrected state estimate x ^ [ k | k ] at time stepk, estimated using measured outputs until timek. If you clear this parameter, the block returns the predicted state estimate x ^ [ k | k 1 ] for timek, estimated using measured output until a previous timek-1. Clear this parameter if your filter is in a feedback loop and there is an algebraic loop in your Simulink®米odel.

Data Types:single|double

State estimation error covariance, returned as anNs-by-Ns米atrix, whereNsis the number of states of the system. To access the individual covariances, use theSelector(Simulink)block.

Dependencies

This port is generated if you selectOutput state estimation error covariancein theSystem Modeltab, and clickApply.

Data Types:single|double

Parameters

expand all

System Model Tab

State Transition

The state transition function calculates theNs-element state vector of the system at time stepk+1, given the state vector at time stepk.Nsis the number of states of the nonlinear system. You create the state transition function and specify the function name inFunction. For example, ifvdpStateFcn.mis the state transition function that you created and saved, specifyFunctionasvdpStateFcn.

The inputs to the function you create depend on whether you specify the process noise as additive or nonadditive inProcess noise.

  • Process noiseisAdditive— The state transition functionfspecifies how the states evolve as a function of state values at previous time step:

    x(k+1) = f(x(k),Us1(k),...,Usn(k)),

    wherex(k)is the estimated state at timek, andUs1,...,Usnare any additional input arguments required by your state transition function, such as system inputs or the sample time. To see an example of a state transition function with additive process noise, typeedit vdpStateFcnat the command line.

  • Process noiseisNonadditive— The state transition function also specifies how the states evolve as a function of the process noisew:

    x(k+1) = f(x(k),w(k),Us1(k),...,Usn(k)).

For more information, seeState Transition and Measurement Functions.

You can createfusing a金宝app仿真软件的功能(Simulink)block or as a MATLAB function (.mfile).

  • You can use a MATLAB function only iffhas one additional input argumentUs1other thanxandw.

    x(k+1) = f(x(k),w(k),Us1(k))

    The software generates an additional input portStateTransitionFcnInputsto specify this argument.

  • If you are using a金宝app仿真软件的功能block, specifyxandwusingArgument Inport(Simulink)blocks and the additional inputsUs1,...,UsnusingInport(Simulink)blocks in the金宝app仿真软件的功能block. You do not provideUs1,...,Usnto theUnscented Kalman Filterblock.

Programmatic Use

Block Parameter:StateTransitionFcn
Type:character vector, string
Default:'myStateTransitionFcn'

Process noise characteristics, specified as one of the following values:

  • Additive— Process noisewis additive, and the state transition functionfthat you specify inFunctionhas the following form:

    x(k+1) = f(x(k),Us1(k),...,Usn(k)),

    wherex(k)is the estimated state at timek, andUs1,...,Usnare any additional input arguments required by your state transition function.

  • Nonadditive— Process noise is nonadditive, and the state transition function specifies how the states evolve as a function of the stateandprocess noise at the previous time step:

    x(k+1) = f(x(k),w(k),Us1(k),...,Usn(k)).

Programmatic Use

Block Parameter:HasAdditiveProcessNoise
Type:character vector
Values:'Additive','Nonadditive'
Default:'Additive'

Time-invariant process noise covariance, specified as a scalar, vector, or matrix depending on the value of theProcess noiseparameter:

  • Process noiseisAdditive— Specify the covariance as a scalar, anNs-element vector, or anNs-by-Ns米atrix, whereNsis the number of states of the system. Specify a scalar if there is no cross-correlation between process noise terms and all the terms have the same variance. Specify a vector of lengthNs, if there is no cross-correlation between process noise terms but all the terms have different variances.

  • Process noiseisNonadditive— Specify the covariance as aW-by-W米atrix, whereWis the number of process noise terms.

If the process noise covariance is time-varying, selectTime-varying. The block generates input portQto specify the time-varying covariance.

Dependencies

This parameter is enabled if you do not specify the process noise asTime-Varying.

Programmatic Use

Block Parameter:ProcessNoise
Type:character vector, string
Default:'1'

如果你select this parameter, the block includes an additional input portQto specify the time-varying process noise covariance.

Programmatic Use

Block Parameter:HasTimeVaryingProcessNoise
Type:character vector
Values:'off',“上”
Default:'off'
Initialization

Initial state estimate value, specified as anNs-element vector, whereNsis the number of states in the system. Specify the initial state values based on your knowledge of the system.

Programmatic Use

Block Parameter:InitialState
Type:character vector, string
Default:'0'

State estimation error covariance, specified as a scalar, anNs-element vector, or anNs-by-Ns米atrix, whereNsis the number of states of the system. If you specify a scalar or vector, the software creates anNs-by-Nsdiagonal matrix with the scalar or vector elements on the diagonal.

指定一个高价值的协方差时do not have confidence in the initial state values that you specify inInitial state.

Programmatic Use

Block Parameter:InitialStateCovariance
Type:character vector, string
Default:'1'
Unscented Transformation Parameters

The unscented Kalman filter algorithm treats the state of the system as a random variable with a mean state value and variance. To compute the state and its statistical properties at the next time step, the algorithm first generates a set of state values distributed around the mean value by using the unscented transformation. These generated state values are called sigma points. The algorithm uses each of the sigma points as an input to the state transition and measurement functions to get a new set of transformed state points and measurements. The transformed points are used to compute the state and state estimation error covariance value at the next time step.

The spread of the sigma points around the mean state value is controlled by two parametersAlphaandKappa. A third parameter,Beta, impacts the weights of the transformed points during state and measurement covariance calculations:

  • Alpha— Determines the spread of the sigma points around the mean state value. Specify as a scalar value between 0 and 1 (0<Alpha<=1). It is usually a small positive value. The spread of sigma points is proportional toAlpha. Smaller values correspond to sigma points closer to the mean state.

  • Kappa— A second scaling parameter that is typically set to 0. Smaller values correspond to sigma points closer to the mean state. The spread is proportional to the square-root ofKappa.

  • Beta— Incorporates prior knowledge of the distribution of the state. For Gaussian distributions,Beta= 2 is optimal.

If you know the distribution of state and state covariance, you can adjust these parameters to capture the transformation of higher-order moments of the distribution. The algorithm can track only a single peak in the probability distribution of the state. If there are multiple peaks in the state distribution of your system, you can adjust these parameters so that the sigma points stay around a single peak. For example, choose a smallAlphato generate sigma points close to the mean state value.

For more information, seeUnscented Kalman Filter Algorithm.

Programmatic Use

Block Parameter:Alpha
Type:character vector, string
Default:'1e-3'

Characterization of the state distribution that is used to adjust weights of transformed sigma points, specified as a scalar value greater than or equal to 0. For Gaussian distributions,Beta= 2 is the optimal choice.

For more information, see the description forAlpha.

Programmatic Use

Block Parameter:Beta
Type:character vector, string
Default:'2'

Spread of sigma points around mean state value, specified as a scalar value between 0 and 3 (0<=Kappa<=3).Kappais typically specified as0. Smaller values correspond to sigma points closer to the mean state. The spread is proportional to the square root ofKappa. For more information, see the description forAlpha.

Programmatic Use

Block Parameter:Kappa
Type:character vector, string
Default:'0'
Measurement

The measurement function calculates theN-element output measurement vector of the nonlinear system at time stepk, given the state vector at time stepk. You create the measurement function and specify the function name inFunction. For example, ifvdpMeasurementFcn.mis the measurement function that you created and saved, specifyFunctionasvdpMeasurementFcn.

The inputs to the function you create depend on whether you specify the measurement noise as additive or nonadditive inMeasurement noise.

  • Measurement noiseisAdditive— The measurement functionhspecifies how the measurements evolve as a function of state Values:

    y(k) = h(x(k),Um1(k),...,Umn(k)),

    wherey(k)andx(k)are the estimated output and estimated state at timek, andUm1,...,Umnare any optional input arguments required by your measurement function. For example, if you are using a sensor for tracking an object, an additional input could be the sensor position.

    To see an example of a measurement function with additive process noise, typeedit vdpMeasurementFcnat the command line.

  • Measurement noiseisNonadditive— The measurement function also specifies how the output measurement evolves as a function of the measurement noisev:

    y(k) = h(x(k),v(k),Um1(k),...,Umn(k)).

    To see an example of a measurement function with nonadditive process noise, typeedit vdpMeasurementNonAdditiveNoiseFcn.

For more information, seeState Transition and Measurement Functions.

You can createhusing a金宝app仿真软件的功能(Simulink)block or as a MATLAB function (.mfile).

  • You can use a MATLAB function only ifhhas one additional input argumentUm1other thanxandv.

    y[k] = h(x[k],v[k],Um1(k))

    The software generates an additional input portMeasurementFcnInputto specify this argument.

  • If you are using a金宝app仿真软件的功能block, specifyxandvusingArgument Inport(Simulink)blocks and the additional inputsUm1,...,UmnusingInport(Simulink)blocks in the金宝app仿真软件的功能block. You do not provideUm1,...,Umnto theUnscented Kalman Filterblock.

If you have multiple sensors in your system, you can specify multiple measurement functions. You can specify up to five measurement functions using theAdd Measurementbutton. To remove measurement functions, useRemove Measurement.

Programmatic Use

Block Parameter:MeasurementFcn1,MeasurementFcn2,MeasurementFcn3,MeasurementFcn4,MeasurementFcn5
Type:character vector, string
Default:'myMeasurementFcn'

Measurement noise characteristics, specified as one of the following values:

  • Additive— Measurement noisevis additive, and the measurement functionhthat you specify inFunctionhas the following form:

    y(k) = h(x(k),Um1(k),...,Umn(k)),

    wherey(k)andx(k)are the estimated output and estimated state at timek, andUm1,...,Umnare any optional input arguments required by your measurement function.

  • Nonadditive— Measurement noise is nonadditive, and the measurement function specifies how the output measurement evolves as a function of the stateand米easurement noise:

    y(k) = h(x(k),v(k),Um1(k),...,Umn(k)).

Programmatic Use

Block Parameter:HasAdditiveMeasurementNoise1,HasAdditiveMeasurementNoise2,HasAdditiveMeasurementNoise3,HasAdditiveMeasurementNoise4,HasAdditiveMeasurementNoise5
Type:character vector
Values:'Additive','Nonadditive'
Default:'Additive'

Time-invariant measurement noise covariance, specified as a matrix. The size of the matrix depends on the value of theMeasurement noiseparameter:

  • Measurement noiseisAdditive— Specify the covariance as anN-by-N米atrix, whereNis the number of measurements of the system.

  • Measurement noiseisNonadditive— Specify the covariance as aV-by-V米atrix, whereVis the number of measurement noise terms.

If the measurement noise covariance is time-varying, selectTime-varying. The block generates input portRito specify the time-varying covariance for theith米easurement function.

Dependencies

This parameter is enabled if you do not specify the process noise asTime-Varying.

Programmatic Use

Block Parameter:MeasurementNoise1,MeasurementNoise2,MeasurementNoise3,MeasurementNoise4,MeasurementNoise5
Type:character vector, string
Default:'1'

如果你select this parameter for the measurement noise covariance of the first measurement function, the block includes an additional input portR1. You specify the time-varying measurement noise covariance inR1. Similarly, if you selectTime-varyingfor theith米easurement function, the block includes an additional input portRito specify the time-varying measurement noise covariance for that function.

Programmatic Use

Block Parameter:HasTimeVaryingMeasurementNoise1,HasTimeVaryingMeasurementNoise2,HasTimeVaryingMeasurementNoise3,HasTimeVaryingMeasurementNoise4,HasTimeVaryingMeasurementNoise5
Type:character vector
Values:'off',“上”
Default:'off'

Suppose that measured output data is not available at all time points at the porty1that corresponds to the first measurement function. SelectAdd Enable portto generate an input portEnable1. Use a signal at this port to enable the correction of estimated states only when measured data is available. Similarly, if measured output data is not available at all time points at the portyifor theith米easurement function, select the correspondingAdd Enable port.

Programmatic Use

Block Parameter:HasMeasurementEnablePort1,HasMeasurementEnablePort2,HasMeasurementEnablePort3,HasMeasurementEnablePort4,HasMeasurementEnablePort5
Type:character vector
Values:'off',“上”
Default:'off'
Settings

When this parameter is selected, the block outputs the corrected state estimate x ^ [ k | k ] at time stepk, estimated using measured outputs until timek. If you clear this parameter, the block returns the predicted state estimate x ^ [ k | k 1 ] for timek, estimated using measured output until a previous timek-1. Clear this parameter if your filter is in a feedback loop and there is an algebraic loop in your Simulink model.

Programmatic Use

Block Parameter:UseCurrentEstimator
Type:character vector
Values:'off',“上”
Default:“上”

如果你select this parameter, a state estimation error covariance output portPis generated in the block.

Programmatic Use

Block Parameter:OutputStateCovariance
Type:character vector
Values:'off',“上”
Default:'off'

Use this parameter to specify the data type for all block parameters.

Programmatic Use

Block Parameter:DataType
Type:character vector
Values:'single','double'
Default:'double'

Block sample time, specified as a positive scalar. If the sample times of your state transition and measurement functions are different, selectEnable multirate operationin theMultiratetab, and specify the sample times in theMultiratetab instead.

Dependencies

This parameter is available if in theMultiratetab, theEnable multirate operationparameter isoff.

Programmatic Use

Block Parameter:SampleTime
Type:character vector, string
Default:'1'

Multirate Tab

Select this parameter if the sample times of the state transition and measurement functions are different. You specify the sample times in theMultiratetab, inSample time.

Programmatic Use

Block Parameter:EnableMultirate
Type:character vector
Values:'off',“上”
Default:'off'

If the sample times for state transition and measurement functions are different, specifySample time. Specify the sample times for the measurement functions as positive integer multiples of the state transition sample time. The sample times you specify correspond to the following input ports:

  • Ports corresponding to state transition function — Additional input to state transition functionStateTransitionFcnInputsand time-varying process noise covarianceQ. The sample times of these ports must always equal the state transition function sample time, but can differ from the sample time of the measurement functions.

  • Ports corresponding toith米easurement function — Measured outputyi, additional input to measurement functionMeasurementFcniInputs, enable signal at portEnablei, and time-varying measurement noise covarianceRi. The sample times of these ports for the same measurement function must always be the same, but can differ from the sample time for the state transition function and other measurement functions.

Dependencies

This parameter is available if in theMultiratetab, theEnable multirate operationparameter ison.

Programmatic Use

Block Parameter:StateTransitionFcnSampleTime,MeasurementFcn1SampleTime1,MeasurementFcn1SampleTime2,MeasurementFcn1SampleTime3,MeasurementFcn1SampleTime4,MeasurementFcn1SampleTime5
Type:character vector, string
Default:'1'

More About

expand all

Compatibility Considerations

expand all

Behavior changed in R2020b

Extended Capabilities

Introduced in R2017a