Struct linearkalman::KalmanFilter [] [src]

pub struct KalmanFilter {
    pub q: Matrix<f64>,
    pub r: Matrix<f64>,
    pub h: Matrix<f64>,
    pub f: Matrix<f64>,
    pub x0: Vector<f64>,
    pub p0: Matrix<f64>,
}

Container object with values for matrices used in the Kalman filtering procedure as well as initial values for state variables.

Fields

  • q: process noise covariance
  • r: measurement noise covariance
  • h: observation matrix
  • f: state transition matrix
  • x0: initial guess for state mean at time 1
  • p0: initial guess for state covariance at time 1

Fields

Methods

impl KalmanFilter
[src]

Takes in measurement data and returns filtered data based on specified KalmanFilter struct. filter actually returns a 2-uple with the first coordinate being filtered data whereas the second coordinate is the (a priori) prediction data that can be used later in the smoothing procedure.

Examples

extern crate rulinalg;
extern crate linearkalman;

use rulinalg::matrix::Matrix;
use rulinalg::vector::Vector;
use linearkalman::KalmanFilter;

fn main() {

  let kalman_filter = KalmanFilter {
    // All matrices are identity matrices
    q: Matrix::from_diag(&vec![1.0, 1.0]),
    r: Matrix::from_diag(&vec![1.0, 1.0]),
    h: Matrix::from_diag(&vec![1.0, 1.0]),
    f: Matrix::from_diag(&vec![1.0, 1.0]),
    x0: Vector::new(vec![1.0, 1.0]),
    p0: Matrix::from_diag(&vec![1.0, 1.0])
  };

  let data: Vec<Vector<f64>> = vec![Vector::new(vec![1.0, 1.0]),
                                    Vector::new(vec![1.0, 1.0])];

  let run_filter = kalman_filter.filter(&data);

  // Due to the setup, filtering is equal to the data
  assert_eq!(data[0], run_filter.0[0].x);
  assert_eq!(data[1], run_filter.0[1].x);
}

Takes in output from filter method and returns smoothed data. Smoothing procedure uses not only past values as is done by filter but also future values to better predict value of the underlying state variable. Underlying algorithm is known as Rauch-Tung-Striebel smoother for a fixed interval. Contrary to the filtering process, incremental smoothing would require re-running Kalman filter on the entire dataset.

Examples

extern crate rulinalg;
extern crate linearkalman;

use rulinalg::matrix::Matrix;
use rulinalg::vector::Vector;
use linearkalman::KalmanFilter;

fn main() {

  let kalman_filter = KalmanFilter {
    // All matrices are identity matrices
    q: Matrix::from_diag(&vec![1.0, 1.0]),
    r: Matrix::from_diag(&vec![1.0, 1.0]),
    h: Matrix::from_diag(&vec![1.0, 1.0]),
    f: Matrix::from_diag(&vec![1.0, 1.0]),
    x0: Vector::new(vec![1.0, 1.0]),
    p0: Matrix::from_diag(&vec![1.0, 1.0])
  };

  let data: Vec<Vector<f64>> = vec![Vector::new(vec![1.0, 1.0]),
                                    Vector::new(vec![1.0, 1.0])];

  let run_filter = kalman_filter.filter(&data);
  let run_smooth = kalman_filter.smooth(&run_filter.0, &run_filter.1);

  // Due to the setup, smoothing is equal to the data
  assert_eq!(data[0], run_smooth[0].x);
  assert_eq!(data[1], run_smooth[0].x);
}

Trait Implementations

impl Debug for KalmanFilter
[src]

Formats the value using the given formatter.