main content

estimate states of nonlinear system with multiple, multirate sensors -凯发k8网页登录

this example shows how to perform nonlinear state estimation in simulink™ for a system with multiple sensors operating at different sample rates. the extended kalman filter block in control system toolbox™ is used to estimate the position and velocity of an object using gps and radar measurements.

introduction

the toolbox has three simulink blocks for nonlinear state estimation:

  • extended kalman filter: implements the first-order discrete-time extended kalman filter algorithm.

  • unscented kalman filter: implements the discrete-time unscented kalman filter algorithm.

  • particle filter: implements a discrete-time particle filter algorithm.

these blocks support state estimation using multiple sensors operating at different sample rates. a typical workflow for using these blocks is as follows:

  1. model your plant and sensor behavior using matlab or simulink functions.

  2. configure the parameters of the block.

  3. simulate the filter and analyze results to gain confidence in filter performance.

  4. deploy the filter on your hardware. you can generate code for these filters using simulink coder™ software.

this example uses the extended kalman filter block to demonstrate the first two steps of this workflow. the last two steps are briefly discussed in the next steps section. the goal in this example is to estimate the states of an object using noisy measurements provided by a radar and a gps sensor. the states of the object are its position and velocity, which are denoted as xtrue in the simulink model.

if you are interested in the particle filter block, please see the example "parameter and state estimation in simulink using particle filter block".

plant modeling

the extended kalman filter (ekf) algorithm requires a state transition function that describes the evolution of states from one time step to the next. the block supports the following two function forms:

  • additive process noise:

  • nonadditive process noise:

here f(..) is the state transition function, x is the state, and w is the process noise. u is optional, and represents additional inputs to f, for instance system inputs or parameters. additive noise means that the next state and process noise are related linearly. if the relationship is nonlinear, use the nonadditive form.

the function f(...) can be a matlab function that comply with the restrictions of matlab coder™, or a simulink function block. after you create f(...), you specify the function name and whether the process noise is additive or nonadditive in the extended kalman filter block.

in this example, you are tracking the north and east positions and velocities of an object on a 2-dimensional plane. the estimated quantities are:

here is the discrete-time index. the state transition equation used is of the nonadditive form , where is the state vector, and is the process noise. the filter assumes that is a zero-mean, independent random variable with known variance . the a and g matrices are:

where is the sample time. the third row of a and g model the east velocity as a random walk: . in reality, position is a continuous-time variable and is the integral of velocity over time . the first row of a and g represent a discrete approximation to this kinematic relationship: . the second and fourth rows of a and g represent the same relationship between the north velocity and position. this state transition model is linear, but the radar measurement model is nonlinear. this nonlinearity necessitates the use of a nonlinear state estimator such as the extended kalman filter.

in this example you implement the state transition function using a simulink function block. to do so,

  • add a simulink function block to your model from the simulink/user-defined functions library

  • click on the name shown on the simulink function block. edit the function name, and add or remove input and output arguments, as necessary. in this example the name for the state transition function is statetransitionfcn. it has one output argument (xnext) and two input arguments (x, w).

  • though it is not required in this example, you can use any signals from the rest of your simulink model in the simulink function. to do so, add inport blocks from the simulink/sources library. note that these are different than the argin and argout blocks that are set through the signature of your function (xnext = statetransitionfcn(x, w)).

  • in the simulink function block, construct your function utilizing simulink blocks.

  • set the dimensions for the input and output arguments x, w, and xnext in the signal attributes tab of the argin and argout blocks. the data type and port dimensions must be consistent with the information you provide in the extended kalman filter block.

analytical jacobian of the state transition function is also implemented in this example. specifying the jacobian is optional. however, this reduces the computational burden, and in most cases increases the state estimation accuracy. implement the jacobian function as a simulink function because the state transition function is a simulink function.

open_system('multirateekfexample')
open_system('multirateekfexample/simulink function - state transition jacobian');

sensor modeling - radar

the extended kalman filter block also needs a measurement function that describes how the states are related to measurements. the following two function forms are supported:

  • additive measurement noise:

  • nonadditive measurement noise:

here h(..) is the measurement function, and v is the measurement noise. u is optional, and represents additional inputs to h, for instance system inputs or parameters. these inputs can differ from the inputs in the state transition function.

in this example a radar located at the origin measures the range and angle of the object at 20 hz. assume that both of the measurements have about 5% noise. this can be modeled by the following measurement equation:

here and are the measurement noise terms, each with variance 0.05^2. that is, most of the measurements have errors less than 5%. the measurement noise is nonadditive because and are not simply added to the measurements, but instead they depend on the states x. in this example, the radar measurement equation is implemented using a simulink function block.

open_system('multirateekfexample/simulink function - radar measurements');

sensor modeling - gps

a gps measures the east and north positions of the object at 1 hz. hence, the measurement equation for the gps sensor is:

here and are measurement noise terms with the covariance matrix [10^2 0; 0 10^2]. that is, the measurements are accurate up to approximately 10 meters, and the errors are uncorrelated. the measurement noise is additive because the noise terms affect the measurements linearly.

create this function, and save it in a file named gpsmeasurementfcn.m. when the measurement noise is additive, you must not specify the noise terms in the function. you provide this function name and measurement noise covariance in the extended kalman filter block.

type gpsmeasurementfcn
function y = gpsmeasurementfcn(x)
% gpsmeasurementfcn gps measurement function for state estimation
%
% assume the states x are:
%   [eastposition; northposition; eastvelocity; northvelocity]
%#codegen
% the %#codegen tag above is needed is you would like to use matlab coder to 
% generate c or c   code for your filter
y = x([1 2]); % position states are measured
end

filter construction

configure the extended kalman filter block to perform the estimation. you specify the state transition and measurement function names, initial state and state error covariance, and process and measurement noise characteristics.

in the system model tab of the block dialog, specify the following parameters:

state transition

  1. specify the state transition function, statetransitionfcn, in function. since you have the jacobian of this function, select jacobian, and specify the jacobian function, statetransitionjacobianfcn.

  2. select nonadditive in the process noise drop-down list because you explicitly stated how the process noise impacts the states in your function.

  3. specify the process noise covariance as [0.2 0; 0 0.2]. as explained in the plant modeling section of this example, process noise terms define the random walk of the velocities in each direction. the diagonal terms approximately capture how much the velocities can change over one sample time of the state transition function. the off-diagonal terms are set to zero, which is a naive assumption that velocity variations in the north and east directions are uncorrelated.

initialization

  1. specify your best initial state estimate in initial state. in this example, specify [100; 100; 0; 0].

  2. specify your confidence in your state estimate guess in initial covariance. in this example, specify 10. the software interprets this value as the true state values are likely to be within of your initial estimate. you can specify a separate value for each state by setting initial covariance as a vector. you can specify cross-correlations in this uncertainty by specifying it as a matrix.

since there are two sensors, click add measurement to specify a second measurement function.

measurement 1

  1. specify the name of your measurement function, radarmeasurementfcn, in function.

  2. select nonadditive in the measurement noise drop-down list because you explicitly stated how the process noise impacts the measurements in your function.

  3. specify the measurement noise covariance as [0.05^2 0; 0 0.05^2] per the discussion in the sensor modeling - radar section.

measurement 2

  1. specify the name of your measurement function, gpsmeasurementfcn, in function.

  2. this sensor model has additive noise. therefore, specify the gps measurement noise as additive in the measurement noise drop-down list.

  3. specify the measurement noise covariance as [100 0; 0 100].

in the multirate tab, since the two sensors are operating at different sample rates, perform the following configuration:

  1. select enable multirate operation.

  2. specify the state transition sample time. the state transition sample time must be the smallest, and all measurement sample times must be an integer multiple of the state transition sample time. specify state transition sample time as 0.05, the sample time of the fastest measurement. though not required in this example, it is possible to have a smaller sample time for state transition than all measurements. this means there will be some sample times without any measurements. for these sample times the filter generates state predictions using the state transition function.

  3. specify the measurement 1 sample time (radar) as 0.05 seconds and measurement 2 (gps) as 1 seconds.

simulation and results

test the performance of the extended kalman filter by simulating a scenario where the object travels in a square pattern with the following maneuvers:

  • at t = 0, the object starts at

  • it heads north at until t = 20 seconds.

  • it heads east at between t = 20 and t = 45 seconds.

  • it heads south at between t = 45 and t = 85 seconds.

  • it heads west at between t = 85 and t = 185 seconds.

generate the true state values corresponding to this motion:

ts = 0.05; % [s] sample rate for the true states
[t, xtrue] = generatetruestates(ts); % generate position and velocity profile over 0-185 seconds

simulate the model. for instance, look at the actual and estimated velocities in the east direction:

sim('multirateekfexample');
open_system('multirateekfexample/scope - east velocity');

the plot shows the true velocity in the east direction, and its extended kalman filter estimates. the filter successfully tracks the changes in velocity. the multirate nature of the filter is most apparent in the time range t = 20 to 30 seconds. the filter makes large corrections every second (gps sample rate), while the corrections due to radar measurements are visible every 0.05 seconds.

next steps

  1. validate the state estimation: the validation of unscented and extended kalman filter performance is typically done using extensive monte carlo simulations. for more information, see .

  2. generate code: the unscented and extended kalman filter blocks support c and c code generation using simulink coder™ software. the functions you provide to these blocks must comply with the restrictions of matlab coder™ software (if you are using matlab functions to model your system) and simulink coder software (if you are using simulink function blocks to model your system).

summary

this example has shown how to use the extended kalman filter block in system identification toolbox. you estimated position and velocity of an object from two different sensors operating at different sampling rates.

close_system('multirateekfexample', 0);

see also

| |

related topics

    网站地图