Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Particle Filter

Estimate states of discrete-time nonlinear system using particle filter

  • Library:
  • System Identification Toolbox / Estimators

Description

The Particle Filter block estimates the states of a discrete-time nonlinear system using the discrete-time particle filter algorithm.

Consider a plant with states x, input u, output m, process noise w, and measurement y. Assume that you can represent the plant as a nonlinear system.

The algorithm computes the state estimates x^ of the nonlinear system using the state transition and measurement likelihood functions you specify.

You create the nonlinear state transition function and measurement likelihood 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 likelihood functions, each corresponding to a sensor in the system.

Ports

Input

expand all

Measured system outputs corresponding to each measurement likelihood function that you specify in the block. The number of ports equals the number of measurement likelihood functions in your system. You can specify up to five measurement likelihood functions. For example, if your system has two sensors, you specify two measurement likelihood functions in the block. The first port y1 is available by default. Click Add Measurement, to generate port y2 corresponding to the second measurement likelihood function.

Specify the ports as N-dimensional vectors, where N is 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 port y1. The port is specified as a two-dimensional vector with values corresponding to position and velocity.

Dependencies

The first port y1 is available by default. Ports y2 to y5 are generated when you click Add Measurement.

Optional input argument to the state transition function f other than the state x.

If you create f using a MATLAB® function (.m file), the software generates the port StateTransitionFcnInputs when you enter the name of your function, and click Apply.

If your state transition function has more than one additional input, use a Simulink Function block to specify the function. When you use a Simulink Function block, you provide the additional inputs directly to the Simulink Function block using Inport blocks. No input ports are generated for the additional inputs in the Particle Filter block.

Dependencies

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

  • You specify f in Function using a MATLAB function, and f is on the MATLAB path.

  • f requires only one additional input argument apart from particles.

Optional inputs to the measurement likelihood functions other than the state x and measurement y.

MeasurementLikelihoodFcn1Inputs corresponds to the first measurement likelihood function that you specify, and so on.

If you specify two measurement inputs using MATLAB functions (.m files) in Function, the software generates ports MeasurementLikelihoodFcn1Inputs and MeasurementLikelihoodFcn2Inputs when you click Apply. You can specify the inputs to these ports as scalars, vectors, or matrices.

If your measurement likelihood functions have more than one additional input, use Simulink Function blocks to specify the functions. When you use a Simulink Function block, you provide the additional inputs directly to the Simulink Function block using Inport blocks. No input ports are generated for the additional inputs in the Particle Filter block.

Dependencies

A port corresponding to a measurement likelihood function h is generated only if both of the following conditions are satisfied:

  • You specify measurement input h in Function using a MATLAB function, and h is on the MATLAB path.

  • h requires only one additional input argument apart from particles and measurement.

Enable correction of estimated states when measured data is available.

For example, consider that measured output data is not available at all time points at the port y1 that corresponds to the first measurement likelihood function. Then, use a signal value other than 0 at the Enable1 port to enable the correction of estimated states when measured data is available. Specify the port value as 0 when measured data is not available. Similarly, if measured output data is not available at all time points at the port yi for the ith measurement likelihood function, specify the corresponding port Enablei as a value other than 0.

Dependencies

If you select Add Enable port for a measurement likelihood function, a port corresponding to that measurement likelihood function is generated. The port appears when you click Apply.

Output

expand all

Estimated states, returned as a vector of size Ns, where Ns is the number of states of the system. To access the individual states, use the Selector block.

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

State estimation error covariance, returned as an Ns-by-Ns matrix, where Ns is the number of states of the system. To access the individual covariances, use the Selector block.

You can output the error covariance only if you select Output state estimation error covariance in the Block outputs, Multirate tab, and click Apply.

Dependencies

This parameter is available if in the Block outputs, Multirate tab, the State estimation method parameter is set to 'Mean'.

Particle values used for state estimation, returned as an Ns-by-Np or Np-by-Ns array. Ns is the number of states of the system, and Np is the number of particles.

  • If the StateOrientation parameter is specified as 'column', then Particles is returned as an Ns-by-Np array.

  • If the StateOrientation parameter is specified as 'row', then Particles is returned as an Np-by-Ns array.

Dependencies

This port is generated if you select Output all particles in the Block outputs, Multirate tab, and click Apply.

Particle weights used for state estimation, returned as a 1-by-Np or Np-by-1 vector, where Np is the number of particles used for state estimation.

  • If the StateOrientation parameter is specified as 'column', then Weights is returned as a 1-by-Np vector, where each weight is associated with the particle in the same column in the Particles array.

  • If the StateOrientation parameter is specified as 'row', then Weights is returned as a Np-by-1 vector, where each weight is associated with the particle in the same row in the Particles array.

Dependencies

This port is generated if you select Output weights in the Block outputs, Multirate tab, and click Apply.

Parameters

expand all

System Model Tab

State Transition

The particle filter state transition function calculates the particles at time step k+1, given particles at time step k per the dynamics of your system and process noise. This function has the syntax:

particlesNext = f(particles, param1, param2, ...)

where, particles and particlesNext have dimensions Ns-by-Np if State Orientation is specified as 'column', or Np-by-Ns if State Orientation is specified as 'row'. Also, param_i represents optional input arguments you may specify. For more information on optional input arguments, see StateTransitionFcnInputs.

You create the state transition function and specify the function name in Function. For example, if vdpParticleFilterStateFcn.m is the state transition function that you created and saved, specify Function as 'vdpParticleFilterStateFcn'.

You can create Function using a Simulink Function block or as a MATLAB function (.m file).

Programmatic Use

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

Initialization

Number of particles used in the filter, specified as a positive scalar integer. Each particle represents a state hypothesis in the system. A higher number of particles increases the state estimation accuracy, but also increases the computational effort required to run the filter.

Programmatic Use

Block Parameter: NumberOfParticles
Type: positive scalar integer
Default: 1000

Initial distribution of particles, specified as 'Gaussian', 'Uniform', or 'Custom'.

If you choose 'Gaussian', the initial set of particles or state hypotheses are distributed per the multivariate Gaussian distribution, where you specify the Mean and Covariance. The initial weight of all particles is assumed to be equal.

If you choose 'Uniform', the initial set of particles are distributed per the uniform distribution, where you specify the upper and lower State bounds. The initial weight of all particles is assumed to be equal.

'Custom' allows you to specify your own set of initial particles and their weights. You can use arbitrary probability distributions for Particles and Weights to initialize the filter.

Programmatic Use

Block Parameter: InitialDistribution
Type: character vector
Values: 'Gaussian', 'Uniform', 'Custom'
Default: 'Gaussian'

Initial mean value of particles, specified as a vector. The number of states to be estimated defines the length of the vector.

Dependencies

This parameter is available if in the System model tab, the Distribution parameter is set to Gaussian.

Programmatic Use

Block Parameter: InitialMean
Type: array
Default: [0,0]

Initial covariance of particles, specified as a scalar, vector, or matrix.

If Covariance is specified as:

  • A scalar, then it must be positive. The covariance is assumed to be a [Ns Ns] matrix with this scalar on the diagonals. Here, Ns is the number of states.

  • A vector, then each element must be positive. The covariance is assumed to be a [Ns Ns] matrix with the elements of the vector on the diagonals.

  • A matrix, then it must be positive semidefinite.

Dependencies

This parameter is available if in the System model tab, the Distribution parameter is set to Gaussian.

Programmatic Use

Block Parameter: InitialCovariance
Type: scalar, vector, or matrix
Default: 1

Circular variables used for state estimation, specified as a scalar, or Ns-element vector, where Ns is the number of states.

If Circular Variables is specified as a scalar, the software extends it to a vector where each element is equal to this scalar. Circular (or angular) distributions use a probability density function with a range of [ π]. Use circular variables if some of the states in your system represent angular quantities like the orientation of an object.

Programmatic Use

Block Parameter: CircularVariables
Type: scalar, vector
Default: 0

Orientation of system states, specified as 'column' or 'row'.

If State Orientation is specified as:

  • 'column', then the first input argument to the state transition and measurement likelihood function is [Ns Np]. In this case, ith column of this matrix is the ith particle (state hypothesis). Also, the states estimates xhat is output as a [Ns 1] vector. Here, Ns is the number of states, and Np is the number of particles.

  • 'row', then the first input argument to the state transition and measurement likelihood function is [Np Ns], and each row of this matrix contains a particle. Also, the states estimates xhat is output as a [1 Ns] vector.

Programmatic Use

Block Parameter: StateOrientation
Type: character vector
Values: 'column', 'row'
Default: 'column'

Initial bounds on system states, specified as an Ns-by-2 array, where Ns is the number of states.

The ith row lists the lower and upper bound of the uniform distribution for the initial distribution of particles of the ith state.

Dependencies

This parameter is available if in the System model tab, the Distribution parameter is set to Uniform.

Programmatic Use

Block Parameter: InitialStateBounds
Type: array
Default: [-3 3;-3 3]

Custom particle distribution for state estimation, specified as an Ns-by-Np or Np-by-Ns array. Ns is the number of states of the system, and Np is the number of particles.

  • If the StateOrientation parameter is specified as 'column', then Particles is an Ns-by-Np array.

  • If the StateOrientation parameter is specified as 'row', then Particles is an Np-by-Ns array.

Dependencies

This parameter is available if in the System model tab, the Distribution parameter is set to Custom.

Programmatic Use

Block Parameter: InitialParticles
Type: array
Default: []

Custom particle weight values for state estimation, specified as a 1-by-Np or Np-by-1 positive vector, where Np is the number of particles used for state estimation.

  • If the StateOrientation parameter is specified as 'column', then Weights is a 1-by-Np vector. Each weight in the vector is associated with the particle in the same column in the Particles array.

  • If the StateOrientation parameter is specified as 'row', then Weights is a Np-by-1 vector. Each weight in the vector is associated with the particle in the same row in the Particles array.

Dependencies

This parameter is available if in the System model tab, the Distribution parameter is set to Custom.

Programmatic Use

Block Parameter: InitialWeights
Type: positive vector
Default: []

Measurement

The measurement likelihood function calculates the likelihood of particles (state hypotheses) using the sensor measurements. For each state hypothesis (particle), the function first calculates an Nm-element measurement hypothesis vector. Then the likelihood of each measurement hypothesis is calculated based on the sensor measurement and the measurement noise probability distribution. this function has the syntax:

likelihood = h(particles, measurement, param1, param2, ...)
where, likelihood is an Np-element vector, where Np is the number of particles. particles have dimensions Ns-by-Np if State Orientation is specified as 'column', or Np-by-Ns if State Orientation is specified as 'row'. measurement is an Nm-element vector where, Nm is the number of measurements your sensor provides. param_i represents optional input arguments you may specify. For more information on optional input arguments, see MeasurementLikelihoodFcn1Inputs,...,MeasurementLikelihoodFcn5Inputs.

You create the measurement likelihood function and specify the function name in Function. For example, if vdpMeasurementLikelihoodFcn.m is the measurement likelihood function that you created and saved, specify Function as 'vdpMeasurementLikelihoodFcn'.

You can create Function using a Simulink Function block or as a MATLAB function (.m file).

  • You can use a MATLAB function only if h has zero or one additional input argument param_i other than Particles and Measurement.

    The software generates an additional input port MeasurementLikelihoodFcniInputs to specify this argument for the ith measurement likelihood function, and click Apply.

  • If you are using a Simulink Function block, specify x and y using Argument Inport blocks and the additional inputs param_i using Inport blocks in the Simulink Function block. You do not provide param_i to the Particle Filter block.

If you have multiple sensors in your system, you can specify multiple measurement likelihood functions. You can specify up to five measurement likelihood functions using the Add Measurement button. To remove measurement likelihood functions, use Remove Measurement.

Programmatic Use

Block Parameter: MeasurementLikelihoodFcn1, MeasurementLikelihoodFcn2, MeasurementLikelihoodFcn3, MeasurementLikelihoodFcn4, MeasurementLikelihoodFcn5
Type: character vector, string
Default: 'vdpMeasurementLikelihoodFcn'

Suppose that measured output data is not available at all time points at the port y1 that corresponds to the first measurement likelihood function. To generate an input port Enable1, select Add Enable port. 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 port yi for the ith measurement likelihood function, select the corresponding Add Enable port.

Programmatic Use

Block Parameter: HasMeasurementEnablePort1, HasMeasurementEnablePort2, HasMeasurementEnablePort3, HasMeasurementEnablePort4, HasMeasurementEnablePort5
Type: character vector
Values: 'off', 'on'
Default: 'off'

Resampling

Method used for particle resampling, specified as one of the following:

  • 'Multinomial'

  • 'Systematic'

  • 'Stratified'

Programmatic Use

Block Parameter: ResamplingMethod
Type: character vector
Values: 'Multinomial', 'Systemic', 'Stratified'
Default: 'Multinomial'

Method to determine when resampling occurs, specified as either 'Ratio' or 'Interval'. The 'Ratio' value triggers resampling based on the ratio of effective total particles. The 'Interval' value triggers resampling at regular time steps of the particle filter operation.

Programmatic Use

Block Parameter: TriggerMethod
Type: character vector
Values: 'Ratio', 'Interval'
Default: 'Ratio'

Minimum desired ratio of the effective number of particles to the total number of particles, specified as a positive scalar. The effective number of particles is a measure of how well the current set of particles approximates the posterior distribution. A lower effective particle ratio implies that a lower number of particles are contributing to the estimation and resampling is required.

If the ratio of the effective number of particles to the total number of particles falls below the minimum effective particle ratio, a resampling step is triggered.

Specify minimum effective particle ratio as any value from 0 through 1.

Dependencies

This parameter is available if in the System model tab, the Trigger method parameter is set to Ratio.

Programmatic Use

Block Parameter: MinEffectiveParticleRatio
Type: scalar
Values: Range [0,1]
Default: 0.5

Fixed interval between resampling, specified as a positive scalar integer. The sampling interval determines during which correction steps the resampling is executed. For example, a value of two means the resampling is executed every second correction step. A value of inf means that resampling is never executed.

Dependencies

This parameter is available if in the System model tab, the Trigger method parameter is set to Interval.

Programmatic Use

Block Parameter: SamplingInterval
Type: positive scalar integer
Default: 1

Random Number Generator Options

Whether the random numbers are repeatable, specified as either 'Repeatable' or 'Not repeatable'. If you want to be able to produce the same result more than once, set Randomness to 'Repeatable', and specify the same random number generator seed value in Seed.

Programmatic Use

Block Parameter: Randomness
Type: character vector
Values: 'Repeatable', 'Not repeatable'
Default: 'Repeatable'

Seed value for repeatable random numbers, specified as a scalar.

Dependencies

This parameter is available if in the System model tab, the Randomness parameter is set to 'Repeatable'.

Programmatic Use

Block Parameter: Seed
Type: scalar
Default: 0

Settings

Block sample time, specified as a positive scalar.

Use the Sample time parameter if your state transition and all measurement likelihood functions have the same sample time. Otherwise, select the Enable multirate operation option in the Multirate tab, and specify sample times in the same tab.

Dependencies

This parameter is available if in the Block output, Multirate tab, the Enable multirate operation parameter is off.

Programmatic Use

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

Block Outputs, Multirate Tab

Outputs

Method used for extracting a state estimate from particles, specified as one of the following:

  • 'Mean' — The Particle Filter block outputs the weighted mean of the particles, depending on the parameters Weights and Particles, as the state estimate.

  • 'Maxweight' — The Particle Filter block outputs the particle with the highest weight as the state estimate.

  • 'None' — Use this option to implement a custom state estimation method by accessing all particles using the Output all particles parameter from the Block outputs, Multirate tab.

Programmatic Use

Block Parameter: StateEstimationMethod
Type: character vector, string
Values: 'Mean', 'MaxWeight', 'None'
Default: 'Mean'

If you select this parameter, an output port for particles used in the estimation, Particles is generated in the block.

  • If the StateOrientation parameter is specified as 'column', then the particles are output as an Ns-by-Np array. Ns is the number of states of the system, and Np is the number of particles.

  • If the StateOrientation parameter is specified as 'row', then the particles are output as an Np-by-Ns array.

Programmatic Use

Block Parameter: OutputParticles
Type: character vector
Values: 'off', 'on'
Default: 'off'

If you select this parameter, an output port for particle weights used in the estimation, Weights is generated in the block.

  • If the StateOrientation parameter is specified as 'column', then the particle weights are output as a 1-by-Np vector. Here, where each weight is associated with the particle in the same column in the Particles array. Np is the number of particles used for state estimation.

  • If the StateOrientation parameter is specified as 'row', then the particle weights are output as a Np-by-1 vector.

Programmatic Use

Block Parameter: OutputWeights
Type: character vector
Values: 'off', 'on'
Default: 'off'

If you select this parameter, a state estimation error covariance output port, P is generated in the block.

Dependencies

This parameter is available if in the Block outputs, Multirate tab, the State estimation method parameter is set to 'Mean'.

Programmatic Use

Block Parameter: OutputStateCovariance
Type: character vector
Values: 'off', 'on'
Default: 'off'

When this parameter is selected, the block outputs the corrected state estimate x^[k|k] at time step k, estimated using measured outputs until time k. If you clear this parameter, the block returns the predicted state estimate x^[k|k1] for time k, estimated using measured output until a previous time k-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: 'on', 'off'
Default: 'on'

Multirate

Select this parameter if the sample times of the state transition or any of the measurement likelihood functions differ from the rest. You specify the sample times in the Multirate tab, in Sample time.

Programmatic Use

Block Parameter: EnableMultirate
Type: character vector
Values: 'off', 'on'
Default: 'off'

If the sample times for state transition and measurement likelihood functions are different, specify Sample 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 function StateTransitionFcnInputs. 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 likelihood functions.

  • Ports corresponding to ith measurement likelihood function — Measured output yi, additional input to measurement likelihood function MeasurementLikelihoodFcniInputs, enable signal at port Enablei. The sample times of these ports for the same measurement likelihood function must always be the same, but can differ from the sample time for the state transition function and other measurement likelihood functions.

Dependencies

This parameter is available if in the Block outputs, Multirate tab, the Enable multirate operation parameter is on.

Programmatic Use

Block Parameter: StateTransitionFcnSampleTime, MeasurementLikelihoodFcn1SampleTime1, MeasurementLikelihoodFcn1SampleTime2, MeasurementLikelihoodFcn1SampleTime3, MeasurementLikelihoodFcn1SampleTime4, MeasurementLikelihoodFcn1SampleTime5
Type: character vector, string
Default: '1'

Extended Capabilities

Introduced in R2018a

Was this topic helpful?