Extract best state estimate and covariance from particles
returns the best state estimate based on the current set of particles. The estimate
is extracted based on the
State = getStateEstimate(
StateEstimationMethod property from the
also returns the covariance of the state estimate. The covariance is a measure of
the uncertainty of the state estimate. Not all state estimation methods support
covariance output. In this case,
StateCovariance as [ ].
can directly be accessed as properties of the particle filter object pf, as
when both these quantities are needed, using the
getStateEstimation method with two output arguments is more
Create a particle filter, and set the state transition and measurement likelihood functions.
myPF = particleFilter(@vdpParticleFilterStateFcn,@vdpMeasurementLikelihoodFcn);
Initialize the particle filter at state
[2; 0] with unit covariance, and use
initialize(myPF, 1000, [2;0], eye(2));
mean state estimation and
systematic resampling methods.
myPF.StateEstimationMethod = 'mean'; myPF.ResamplingMethod = 'systematic'; myPF
myPF = particleFilter with properties: NumStateVariables: 2 NumParticles: 1000 StateTransitionFcn: @vdpParticleFilterStateFcn MeasurementLikelihoodFcn: @vdpMeasurementLikelihoodFcn IsStateVariableCircular: [0 0] ResamplingPolicy: [1x1 particleResamplingPolicy] ResamplingMethod: 'systematic' StateEstimationMethod: 'mean' StateOrientation: 'column' Particles: [2x1000 double] Weights: [1x1000 double] State: 'Use the getStateEstimate function to see the value.' StateCovariance: 'Use the getStateEstimate function to see the value.'
Assuming a measurement
2.1, run one predict and correct step.
[PredictedState, PredictedStateCovariance] = predict(myPF); [CorrectedState, CorrectedStateCovariance] = correct(myPF,2.1);
Get the best state estimate and covariance based on the
[State, StateCovariance] = getStateEstimate(myPF)
State = 2×1 2.1018 -0.1413
StateCovariance = 2×2 0.0175 -0.0096 -0.0096 0.5394
State— Best state estimate
Best state estimate, defined as a vector based on the condition of the
State is a
StateCovariance— Current estimate of state estimation error covariance
NumStateVariablesarray (default) | [ ] | array
Current estimate of state estimation error covariance, defined as an
StateCovariance is calculated based on the
StateEstimationMethod. If you specify a state
estimation method that does not support covariance, then the function
StateCovariance as [ ].