Estimate states of discrete-time nonlinear system using unscented Kalman filter
Control System Toolbox / State Estimation
System Identification Toolbox / Estimators
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 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.
y1,y2,y3,y4,y5
— Measured system outputsMeasured 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.
The first porty1is available by default. Portsy2toy5are generated when you clickAdd Measurement, and clickApply.
Data Types:single
|double
StateTransitionFcnInputs
— Additional optional input argument to state transition functionAdditional optional input argument to the state transition functionf
other than the statex
and 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 functionf
has the following form:
x(k+1) = f(x(k),w(k),StateTransitionFcnInputs)
.
Herek
is the time step, andStateTransitionFcnInputs
is an additional input argument other thanx
andw
.
If you createf
using a MATLAB®function (.m
file), 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.
This port is generated only if both of the following conditions are satisfied:
You specifyf
inFunctionusing a MATLAB function, andf
is on the MATLAB path.
f
只需要一个额外的input argument apart fromx
andw
.
Data Types:single
|double
MeasurementFcn1Inputs,MeasurementFcn2Inputs,MeasurementFcn3Inputs,MeasurementFcn4Inputs,MeasurementFcn5Inputs
— Additional optional input argument to each measurement functionAdditional optional inputs to the measurement functions other than the statex
and 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
, andh3
have 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])
Herek
is the time step, andMeasurementFcn1Inputs
andMeasurementFcn2Inputs
are the additional input arguments toh1
andh2
.
If you specifyh1
,h2
, andh3
using MATLAB functions (.m
files) 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.
一个港口corresponding to a measurement functionh
只有以下两个生成conditi吗ons are satisfied:
You specifyh
inFunctionusing a MATLAB function, andh
is on the MATLAB path.
h
只需要一个额外的input argument apart fromx
andv
.
Data Types:single
|double
Q
— Time-varying process noise covarianceTime-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.
This port is generated if you specify the process noise covariance asTime-Varying. The port appears when you clickApply.
Data Types:single
|double
R1,R2,R3,R4,R5
— Time-varying measurement noise covarianceTime-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.
一个港口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
Enable1、Enable2 Enable3、Enable4 Enable5
— Enable correction of estimated states when measured data is availableSuppose 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 than0
at theEnable1port to enable the correction of estimated states when measured data is available. Specify the port value as0
when measured data is not available. Similarly, if measured output data is not available at all time points at the portyi
for theith米easurement function, specify the corresponding portEnablei
as a value other than0
.
一个港口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
xhat
— Estimated statesEstimated 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
at time stepk
, estimated using measured outputs until timek
. If you clear this parameter, the block returns the predicted state estimate
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
P
— State estimation error covarianceState 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.
This port is generated if you selectOutput state estimation error covariancein theSystem Modeltab, and clickApply.
Data Types:single
|double
Function
— State transition function name米yStateTransitionFcn
(default) | function nameThe 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.m
is 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,...,Usn
are 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 vdpStateFcn
at 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 (.m
file).
You can use a MATLAB function only iffhas one additional input argumentUs1
other thanx
andw
.
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, specifyx
andw
usingArgument Inport(Simulink)blocks and the additional inputsUs1,...,Usn
usingInport(Simulink)blocks in the金宝app仿真软件的功能block. You do not provideUs1,...,Usn
to theUnscented Kalman Filterblock.
Block Parameter:StateTransitionFcn |
Type:character vector, string |
Default:'myStateTransitionFcn' |
Process noise
— Process noise characteristicsAdditive
(default) |Nonadditive
Process noise characteristics, specified as one of the following values:
Additive
— Process noisew
is 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,...,Usn
are 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))
.
Block Parameter:HasAdditiveProcessNoise |
Type:character vector |
Values:'Additive' ,'Nonadditive' |
Default:'Additive' |
Covariance
— Time-invariant process noise covariance1
(default) | scalar | vector | matrixTime-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.
This parameter is enabled if you do not specify the process noise asTime-Varying.
Block Parameter:ProcessNoise |
Type:character vector, string |
Default:'1' |
Time-varying
— Time-varying process noise covariance'off'
(default) |“上”
如果你select this parameter, the block includes an additional input portQto specify the time-varying process noise covariance.
Block Parameter:HasTimeVaryingProcessNoise |
Type:character vector |
Values:'off' ,“上” |
Default:'off' |
Initial state
— Initial state estimate0
(default) | vectorInitial 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.
Block Parameter:InitialState |
Type:character vector, string |
Default:'0' |
Initial covariance
— State estimation error covariance1
(default) | scalar | vector | matrixState 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.
Block Parameter:InitialStateCovariance |
Type:character vector, string |
Default:'1' |
Alpha
— Spread of sigma points1e-3
(default) | scalar value between 0 and 1The 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.
Block Parameter:Alpha |
Type:character vector, string |
Default:'1e-3' |
Beta
— Characterization of state distribution2
(default) | scalar value greater than or equal to 0Characterization 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.
Block Parameter:Beta |
Type:character vector, string |
Default:'2' |
Kappa
— Spread of sigma points0
(default) | scalar value between 0 and 3Spread 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.
Block Parameter:Kappa |
Type:character vector, string |
Default:'0' |
Function
— Measurement function name米yMeasurementFcn
(default) | function nameThe 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.m
is 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,...,Umn
are 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 vdpMeasurementFcn
at 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 (.m
file).
You can use a MATLAB function only ifhhas one additional input argumentUm1
other thanx
andv
.
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, specifyx
andv
usingArgument Inport(Simulink)blocks and the additional inputsUm1,...,Umn
usingInport(Simulink)blocks in the金宝app仿真软件的功能block. You do not provideUm1,...,Umn
to 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.
Block Parameter:MeasurementFcn1 ,MeasurementFcn2 ,MeasurementFcn3 ,MeasurementFcn4 ,MeasurementFcn5 |
Type:character vector, string |
Default:'myMeasurementFcn' |
Measurement noise
— Measurement noise characteristicsAdditive
(default) |Nonadditive
Measurement noise characteristics, specified as one of the following values:
Additive
— Measurement noisev
is 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,...,Umn
are 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))
.
Block Parameter:HasAdditiveMeasurementNoise1 ,HasAdditiveMeasurementNoise2 ,HasAdditiveMeasurementNoise3 ,HasAdditiveMeasurementNoise4 ,HasAdditiveMeasurementNoise5 |
Type:character vector |
Values:'Additive' ,'Nonadditive' |
Default:'Additive' |
Covariance
— Time-invariant measurement noise covariance1
(default) | matrixTime-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 portRi
to specify the time-varying covariance for theith米easurement function.
This parameter is enabled if you do not specify the process noise asTime-Varying.
Block Parameter:MeasurementNoise1 ,MeasurementNoise2 ,MeasurementNoise3 ,MeasurementNoise4 ,MeasurementNoise5 |
Type:character vector, string |
Default:'1' |
Time-varying
— Time-varying measurement noise covarianceoff
(default) |on
如果你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 portRi
to specify the time-varying measurement noise covariance for that function.
Block Parameter:HasTimeVaryingMeasurementNoise1 ,HasTimeVaryingMeasurementNoise2 ,HasTimeVaryingMeasurementNoise3 ,HasTimeVaryingMeasurementNoise4 ,HasTimeVaryingMeasurementNoise5 |
Type:character vector |
Values:'off' ,“上” |
Default:'off' |
添加启用端口
— Enable correction of estimated states only when measured data is availableoff
(default) |on
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 portyi
for theith米easurement function, select the correspondingAdd Enable port.
Block Parameter:HasMeasurementEnablePort1 ,HasMeasurementEnablePort2 ,HasMeasurementEnablePort3 ,HasMeasurementEnablePort4 ,HasMeasurementEnablePort5 |
Type:character vector |
Values:'off' ,“上” |
Default:'off' |
Use the current measurements to improve state estimates
— Choose between corrected or predicted state estimateon
(default) |off
When this parameter is selected, the block outputs the corrected state estimate
at time stepk
, estimated using measured outputs until timek
. If you clear this parameter, the block returns the predicted state estimate
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.
Block Parameter:UseCurrentEstimator |
Type:character vector |
Values:'off' ,“上” |
Default:“上” |
Output state estimation error covariance
— Output state estimation error covarianceoff
(default) |on
如果你select this parameter, a state estimation error covariance output portPis generated in the block.
Block Parameter:OutputStateCovariance |
Type:character vector |
Values:'off' ,“上” |
Default:'off' |
Data type
— Data type for block parametersdouble
(default) |single
Use this parameter to specify the data type for all block parameters.
Block Parameter:DataType |
Type:character vector |
Values:'single' ,'double' |
Default:'double' |
Sample time
— Block sample time1
(default) | positive scalarBlock 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.
This parameter is available if in theMultiratetab, theEnable multirate operationparameter isoff
.
Block Parameter:SampleTime |
Type:character vector, string |
Default:'1' |
Enable multirate operation
— Enable specification of different sample times for state transition and measurement functionsoff
(default) |on
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.
Block Parameter:EnableMultirate |
Type:character vector |
Values:'off' ,“上” |
Default:'off' |
Sample times
— State transition and measurement function sample timesIf 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 functionMeasurementFcni
Inputs, 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.
This parameter is available if in theMultiratetab, theEnable multirate operationparameter ison
.
Block Parameter:StateTransitionFcnSampleTime ,MeasurementFcn1SampleTime1 ,MeasurementFcn1SampleTime2 ,MeasurementFcn1SampleTime3 ,MeasurementFcn1SampleTime4 ,MeasurementFcn1SampleTime5 |
Type:character vector, string |
Default:'1' |
The algorithm computes the state estimates of the nonlinear system using state transition and measurement functions specified by you. You can specify up to five measurement functions, each corresponding to a sensor in the system. The software lets you specify the noise in these functions as additive or nonadditive.
Additive Noise Terms— The state transition and measurements equations have the following form:
Herefis a nonlinear state transition function that describes the evolution of statesx
from one time step to the next. The nonlinear measurement functionhrelatesx
to the measurementsy
at time stepk
.w
andv
are the zero-mean, uncorrelated process and measurement noises, respectively. These functions can also have additional optional input arguments that are denoted byus
andu米
in the equations. For example, the additional arguments could be time stepk
or the inputsu
to the nonlinear system. There can be multiple such arguments.
Note that the noise terms in both equations are additive. That is,x(k+1)
is linearly related to the process noisew(k)
, andy(k)
is linearly related to the measurement noisev(k)
. For additive noise terms, you do not need to specify the noise terms in the state transition and measurement functions. The software adds the terms to the output of the functions.
Nonadditive Noise Terms— The software also supports more complex state transition and measurement functions where the statex[k] and measurementy[k] are nonlinear functions of the process noise and measurement noise, respectively. When the noise terms are nonadditive, the state transition and measurements equation have the following form:
Behavior changed in R2020b
Starting in R2020b, numerical improvements in theUnscented Kalman Filteralgorithm might produce results that are different from the results you obtained in previous versions.
The state transition and measurement functions that you specify must use only the MATLAB commands and Simulink blocks that support code generation. For a list of blocks that support code generation, seeSimulink Built-In Blocks That Support Code Generation(Simulink Coder). For a list of commands that support code generation, seeFunctions and Objects Supported for C/C++ Code Generation(MATLAB Coder).
Generated code uses an algorithm that is different from the algorithm that theUnscented Kalman Filterblock itself uses. You might see some numerical differences in the results obtained using the two methods.
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.
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:.
Selectweb siteYou can also select a web site from the following list:
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.