Operator Reference

filter_kalmanT_filter_kalmanFilterKalmanFilterKalmanfilter_kalman (Operator)

filter_kalmanT_filter_kalmanFilterKalmanFilterKalmanfilter_kalman — Estimate the current state of a system with the help of the Kalman filtering.

Warning

filter_kalmanfilter_kalmanFilterKalmanFilterKalmanfilter_kalman is obsolete and is only provided for reasons of backward compatibility.

Signature

Herror T_filter_kalman(const Htuple Dimension, const Htuple Model, const Htuple Measurement, const Htuple PredictionIn, Htuple* PredictionOut, Htuple* Estimate)

void FilterKalman(const HTuple& Dimension, const HTuple& Model, const HTuple& Measurement, const HTuple& PredictionIn, HTuple* PredictionOut, HTuple* Estimate)

static HTuple HMisc::FilterKalman(const HTuple& Dimension, const HTuple& Model, const HTuple& Measurement, const HTuple& PredictionIn, HTuple* Estimate)

def filter_kalman(dimension: Sequence[int], model: Sequence[float], measurement: Sequence[float], prediction_in: Sequence[float]) -> Tuple[Sequence[float], Sequence[float]]

Description

The operator filter_kalmanfilter_kalmanFilterKalmanFilterKalmanfilter_kalman returns an estimate of the current state (or also a prediction of a future state) of a discrete, stochastically disturbed, linear system. In practice, Kalman filters are used successfully in image processing in the analysis of image sequences (background identification, lane tracking with the help of line tracing or region analysis, etc.). A short introduction concerning the theory of the Kalman filters will be followed by a detailed description of the routine filter_kalmanfilter_kalmanFilterKalmanFilterKalmanfilter_kalman itself.

KALMAN FILTER: A discrete, stochastically disturbed, linear system is characterized by the following markers:

  • State : Describes the current state of the system (speeds, temperatures,...).

  • Parameter : Inputs from outside into the system.

  • Measurement : Measurements gained by observing the system. They indicate the state of the system (or at least parts of it).

  • An output function describing the dependence of the measurements on the state.

  • A transition function indicating how the state changes with regard to time, the current value and the parameters.

The output function and the transition function are linear. Their application can therefore be written as a multiplication with a matrix.

The transition function is described with the help of the transition matrix and the parameter matrix , the initial function is described by the measurement matrix . Hereby characterizes the dependency of the new state on the old, indicates the dependency on the parameters. In practice it is rarely possible (or at least too time consuming) to describe a real system and its behavior in a complete and exact way. Normally only a relatively small number of variables will be used to simulate the behavior of the system. This leads to an error, the so called system error (also called system disturbance) .

The output function, too, is usually not exact. Each measurement is faulty. The measurement errors will be called . Therefore the following system equations arise: x(t+1) = A(t)x(t) + G(t)u(t) + v(t) y(t) = c(t)x(t) + w(t) The system error and the measurement error are not known. As far as systems are concerned which are interpreted with the help of the Kalman filter, these two errors are considered as Gaussian distributed random vectors (therefore the expression “stochastically disturbed systems”). Therefore the system can be calculated, if the corresponding expected values for and as well as the covariance matrices are known.

The estimation of the state of the system is carried out in the same way as in the Gaussian-Markov-estimation. However, the Kalman filter is a recursive algorithm which is based only on the current measurements and the latest state . The latter implicitly also includes the knowledge about earlier measurements.

A suitable estimate value , which is interpreted as the expected value of a random variable for , must be indicated for the initial value . This variable should have an expected error value of 0 and the covariance matrix which also has to be indicated. At a certain time the expected values of both disturbances and should be 0 and their covariances should be and . , and will usually be assumed to be not correlated (any kind of noise-process can be modeled - however the development of the necessary matrices by the user will be considerably more demanding). The following conditions must be met by the searched estimate values :

  • The estimate values are linearly dependent on the actual value and on the measurement sequence , , , .

  • { being hereby considered to meet its expectations, i.e. .}

  • The grade criterion for is the criterion of minimal variance, i.e. the variance of the estimation error defined as , being as small as possible.

After the initialization at each point in time the Kalman filter executes the following calculation steps: Hereby is the covariance matrix of the estimation error, is the extrapolation value respective the prediction value of the state, are the covariances of the prediction error is the amplifier matrix (the so called Kalman gain), and is the transposed of a matrix .

Please note that the prediction of the future state is also possible with the equation (K-I). Sometimes this is very useful in image processing in order to determine “regions of interest” in the next image.

As mentioned above, it is much more demanding to model any kind of noise processes. If for example the system noise and the measurement noise are correlated with the corresponding covariance matrix , the equations for the Kalman gain and the error covariance matrix have to be modified: This means that the user himself has to establish the linear system equations from (K-I) up to (K-V) with respect to the actual problem. The user must therefore develop a mathematical model upon which the solution to the problem can be based. Statistical characteristics describing the inaccuracies of the system as well as the measurement errors, which are to be expected, thereby have to be estimated if they cannot be calculated exactly. Therefore the following individual steps are necessary:

  1. Developing a mathematical model

  2. Selecting characteristic state variables

  3. Establishing the equations describing the changes of these state variables and their linearization (matrices and )

  4. Establishing the equations describing the dependency of the measurement values of the system on the state variables and their linearization (matrix )

  5. Developing or estimating of statistical dependencies between the system disturbances (matrix )

  6. Developing or estimating of statistical dependencies between the measurement errors (matrix )

  7. Initialization of the initial state

As mentioned above, the initialization of the system (point 7) hereby necessitates to indicate an estimate of the state of the system at the time 0 and the corresponding covariance matrix . If the exact initial state is not known, it is recommendable to set the components of the vector to the average values of the corresponding range, and to set high values for (about the size of the squares of the range). After a few iterations (when the number of the accumulated measurement values in total has exceeded the number of the system values), the values which have been determined in this way are also usable.

If on the other hand the initial state is known exactly, all entries for have to be set to 0, because describes the covariances of the error between the estimated value and the actual value .

THE FILTER ROUTINE:

A Kalman filter is dependent on a range of data which can be organized in four groups:

Model parameter:

transition matrix , control matrix including the parameter and the measurement matrix

Model stochastic:

system-error covariance matrix , system-error - measurement-error covariance matrix , and measurement-error covariance matrix

Measurement vector:

History of the system:

extrapolation vector and extrapolation-error covariance matrix

Thereby many systems can work without input “from outside”, i.e. without and . Further, system errors and measurement errors are normally not correlated ( is dropped).

Actually the data necessary for the routine will be set by the following parameters:

DimensionDimensionDimensiondimensiondimension:

This parameter includes the dimensions of the status vector, the measurement vector and the controller vector. DimensionDimensionDimensiondimensiondimension thereby is a vector , whereby indicates the number of the state variables, the number of the measurement values and the number of the controller members. For a system without determining control (i.e. without influence “from outside”) therefore has to be passed.

ModelModelModelmodelmodel:

This parameter includes the lined up matrices (vectors) and (if necessary) having been stored in row-major order. ModelModelModelmodelmodel therefore is a vector of the length . The last summand is dropped, in case the system errors and measurement errors are not correlated, i.e. there is no value for .

MeasurementMeasurementMeasurementmeasurementmeasurement:

This parameter includes the matrix which has been stored in row-major order, and the measurement vector lined up. MeasurementMeasurementMeasurementmeasurementmeasurement therefore is a vector of the dimension .

PredictionInPredictionInPredictionInpredictionInprediction_in / PredictionOutPredictionOutPredictionOutpredictionOutprediction_out:

These two parameters include the matrix (the extrapolation-error covariance matrix) which has been stored in row-major order and the extrapolation vector lined up. This means, they are vectors of the length . PredictionInPredictionInPredictionInpredictionInprediction_in therefore is an input parameter, which must contain and at the current time . With PredictionOutPredictionOutPredictionOutpredictionOutprediction_out the routine returns the corresponding predictions and .

EstimateEstimateEstimateestimateestimate:

With this parameter the routine returns the matrix (the estimation-error covariance matrix) which has been stored in row-major order and the estimated state lined up. EstimateEstimateEstimateestimateestimate therefore is a vector of the length .

Please note that the covariance matrices must of course be symmetric.

Execution Information

  • Multithreading type: reentrant (runs in parallel with non-exclusive operators).
  • Multithreading scope: global (may be called from any thread).
  • Processed without parallelization.

Parameters

DimensionDimensionDimensiondimensiondimension (input_control)  integer-array HTupleSequence[int]HTupleHtuple (integer) (int / long) (Hlong) (Hlong)

The dimensions of the state vector, the measurement and the controller vector.

Default: [3,1,0]

Value range: 0 ≤ Dimension Dimension Dimension dimension dimension ≤ 30

ModelModelModelmodelmodel (input_control)  real-array HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

The lined up matrices , possibly and , and if necessary which have been stored in row-major order.

Default: [1.0,1.0,0.5,0.0,1.0,1.0,0.0,0.0,1.0,1.0,0.0,0.0,54.3,37.9,48.0,37.9,34.3,42.5,48.0,42.5,43.7]

Value range: 0.0 ≤ Model Model Model model model ≤ 10000.0

MeasurementMeasurementMeasurementmeasurementmeasurement (input_control)  real-array HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

The matrix stored in row-major order and the measurement vector lined up.

Default: [1.2,1.0]

Value range: 0.0 ≤ Measurement Measurement Measurement measurement measurement ≤ 10000.0

PredictionInPredictionInPredictionInpredictionInprediction_in (input_control)  real-array HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

The matrix (the extrapolation-error covariances) stored in row-major order and the extrapolation vector lined up.

Default: [0.0,0.0,0.0,0.0,180.5,0.0,0.0,0.0,100.0,0.0,100.0,0.0]

Value range: 0.0 ≤ PredictionIn PredictionIn PredictionIn predictionIn prediction_in ≤ 10000.0

PredictionOutPredictionOutPredictionOutpredictionOutprediction_out (output_control)  real-array HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

The matrix (the extrapolation-error covariances)stored in row-major order and the extrapolation vector lined up.

EstimateEstimateEstimateestimateestimate (output_control)  real-array HTupleSequence[float]HTupleHtuple (real) (double) (double) (double)

The matrix (the estimation-error covariances) stored in row-major order and the estimated state lined up.

Example (HDevelop)

* Typical procedure:
* To initialize the variables, which describe the model, e.g., with
read_kalman('kalman.init',Dim,Mod,Meas,Pred)

* Generation of the first measurements (typical of the first image of an
* image series) with an appropriate problem-specific procedure (there is a
* fictitious procedure extract_features in example):
* extract_features(Image1,Meas,Meas1)

* first Kalman-Filtering:
filter_kalman(Dim,Mod,Meas1,Pred,Pred1,Est1)

* To use the estimate value (if need be the prediction too)
* with a problem-specific procedure (here use_est):
* use_est(Est1)

* To get the next measurements (e.g., from the next image):
* extract_next_features(Image2,Meas1,Meas2)

* if need be Update of the model parameter (a constant model)
* second Kalman-Filtering:
filter_kalman(Dim,Mod,Meas2,Pred1,Pred2,Est2)
* use_est(Est2)
* extract_next_features(Image3,Meas2,Meas3)
* etc.

Example (C)

/* Typical procedure: */
/* 1. To initialize the variables
      which describe the model, e.g., with */

read_kalman("kalman.init",Dim,Mod,Meas,Pred);

/* Generation of the first measurements (typically of the
   first image of an image series) with an appropriate
   problem-specific routine (there is a fictitious routine
   extract_features in this example):  */

extract_features(Image1,Meas,&Meas1);

/* first Kalman-Filtering: */

filter_kalman(Dim,Mod,Meas1,Pred,&Pred1,&Est1);

/* To use the estimate value (if need be the prediction too) */
/* with a problem-specific routine (here use_est): */

use_est(Est1);

/* To get the next measurements (e.g., from the next image): */

extract_next_features(Image2,Meas1,&Meas2);

/* if need be Update of the  model parameter (a constant model) */
/* second Kalman-Filtering: */

filter_kalman(Dim,Mod,Meas2,Pred1,&Pred2,&Est2);
use_est(Est2);
extract_next_features(Image3,Meas2,&Meas3);

/* etc. */

Example (HDevelop)

* Typical procedure:
* To initialize the variables, which describe the model, e.g., with
read_kalman('kalman.init',Dim,Mod,Meas,Pred)

* Generation of the first measurements (typical of the first image of an
* image series) with an appropriate problem-specific procedure (there is a
* fictitious procedure extract_features in example):
* extract_features(Image1,Meas,Meas1)

* first Kalman-Filtering:
filter_kalman(Dim,Mod,Meas1,Pred,Pred1,Est1)

* To use the estimate value (if need be the prediction too)
* with a problem-specific procedure (here use_est):
* use_est(Est1)

* To get the next measurements (e.g., from the next image):
* extract_next_features(Image2,Meas1,Meas2)

* if need be Update of the model parameter (a constant model)
* second Kalman-Filtering:
filter_kalman(Dim,Mod,Meas2,Pred1,Pred2,Est2)
* use_est(Est2)
* extract_next_features(Image3,Meas2,Meas3)
* etc.

Example (HDevelop)

* Typical procedure:
* To initialize the variables, which describe the model, e.g., with
read_kalman('kalman.init',Dim,Mod,Meas,Pred)

* Generation of the first measurements (typical of the first image of an
* image series) with an appropriate problem-specific procedure (there is a
* fictitious procedure extract_features in example):
* extract_features(Image1,Meas,Meas1)

* first Kalman-Filtering:
filter_kalman(Dim,Mod,Meas1,Pred,Pred1,Est1)

* To use the estimate value (if need be the prediction too)
* with a problem-specific procedure (here use_est):
* use_est(Est1)

* To get the next measurements (e.g., from the next image):
* extract_next_features(Image2,Meas1,Meas2)

* if need be Update of the model parameter (a constant model)
* second Kalman-Filtering:
filter_kalman(Dim,Mod,Meas2,Pred1,Pred2,Est2)
* use_est(Est2)
* extract_next_features(Image3,Meas2,Meas3)
* etc.

Result

If the parameter values are correct, the operator filter_kalmanfilter_kalmanFilterKalmanFilterKalmanfilter_kalman returns the value 2 ( H_MSG_TRUE) . Otherwise an exception is raised.

Possible Predecessors

read_kalmanread_kalmanReadKalmanReadKalmanread_kalman

Possible Successors

update_kalmanupdate_kalmanUpdateKalmanUpdateKalmanupdate_kalman

See also

read_kalmanread_kalmanReadKalmanReadKalmanread_kalman, update_kalmanupdate_kalmanUpdateKalmanUpdateKalmanupdate_kalman

References

W.Hartinger: “Entwurf eines anwendungsunabhängigen Kalman-Filters mit Untersuchungen im Bereich der Bildfolgenanalyse”; Diplomarbeit; Technische Universität München, Institut für Informatik, Lehrstuhl Prof. Radig; 1991.
R.E.Kalman: “A New Approach to Linear Filtering and Prediction Problems”; Transactions ASME, Ser.D: Journal of Basic Engineering; Vol. 82, S.34-45; 1960.
R.E.Kalman, P.l.Falb, M.A.Arbib: “Topics in Mathematical System Theory”; McGraw-Hill Book Company, New York; 1969.
K-P. Karmann, A.von Brandt: “Moving Object Recognition Using an Adaptive Background Memory”; Time-Varying Image Processing and Moving Object Recognition 2 (ed.: V. Cappellini), Proc. of the 3rd Interantional Workshop, Florence, Italy, May, 29th - 31st, 1989; Elsevier, Amsterdam; 1990.

Module

Foundation