Main Content

initialize

Initialize the state of the particle filter

Description

initialize(pf,numParticles,mean,covariance) initializes the particle filter object, pf, with a specified number of particles, numParticles. The initial states of the particles in the state space are determined by sampling from the multivariate normal distribution with the specified mean and covariance.

example

initialize(pf,numParticles,stateBounds) determines the initial location of the particles by sample from the multivariate uniform distribution within the specified stateBounds.

initialize(___,Name,Value) initializes the particles with additional options specified by one or more Name,Value pair arguments.

Examples

collapse all

Create a stateEstimatorPF object, and execute a prediction and correction step for state estimation. The particle filter gives a predicted state estimate based on the return value of StateTransitionFcn. It then corrects the state based on a given measurement and the return value of MeasurementLikelihoodFcn.

Create a particle filter with the default three states.

pf = stateEstimatorPF
pf = 
  stateEstimatorPF with properties:

           NumStateVariables: 3
                NumParticles: 1000
          StateTransitionFcn: @nav.algs.gaussianMotion
    MeasurementLikelihoodFcn: @nav.algs.fullStateMeasurement
     IsStateVariableCircular: [0 0 0]
            ResamplingPolicy: [1x1 resamplingPolicyPF]
            ResamplingMethod: 'multinomial'
       StateEstimationMethod: 'mean'
            StateOrientation: 'row'
                   Particles: [1000x3 double]
                     Weights: [1000x1 double]
                       State: 'Use the getStateEstimate function to see the value.'
             StateCovariance: 'Use the getStateEstimate function to see the value.'

Specify the mean state estimation method and systematic resampling method.

pf.StateEstimationMethod = 'mean';
pf.ResamplingMethod = 'systematic';

Initialize the particle filter at state [4 1 9] with unit covariance (eye(3)). Use 5000 particles.

initialize(pf,5000,[4 1 9],eye(3));

Assuming a measurement [4.2 0.9 9], run one predict and one correct step.

[statePredicted,stateCov] = predict(pf);
[stateCorrected,stateCov] = correct(pf,[4.2 0.9 9]);

Get the best state estimate based on the StateEstimationMethod algorithm.

stateEst = getStateEstimate(pf)
stateEst = 1×3

    4.1562    0.9185    9.0202

Input Arguments

collapse all

stateEstimatorPF object, specified as a handle. See stateEstimatorPF for more information.

Number of particles used in the filter, specified as a scalar.

Mean of particle distribution, specified as a vector. The NumStateVariables property of pf is set based on the length of this vector.

Covariance of particle distribution, specified as an N-by-N matrix, where N is the value of NumStateVariables property from pf.

Bounds of state variables, specified as an n-by-2 matrix. The NumStateVariables property of pf is set based on the value of n. Each row corresponds to the lower and upper limit of the corresponding state variable.

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: "CircularVariables",[0 0 1]

Circular variables, specified as a logical vector. Each state variable that uses circular or angular coordinates is indicated with a 1. The length of the vector is equal to the NumStateVariables property of pf.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

Version History

Introduced in R2016a