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 covariancer
: measurement noise covarianceh
: observation matrixf
: state transition matrixx0
: initial condition for the state variablep0
: initial condition for the state covariance
Fields
q: Matrix<f64>
r: Matrix<f64>
h: Matrix<f64>
f: Matrix<f64>
x0: Vector<f64>
p0: Matrix<f64>
Methods
impl KalmanFilter
[src]
fn filter(&self,
data: &Vec<Vector<f64>>)
-> (Vec<KalmanState>, Vec<KalmanState>)
data: &Vec<Vector<f64>>)
-> (Vec<KalmanState>, Vec<KalmanState>)
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); }
fn smooth(&self,
filtered: &Vec<KalmanState>,
predicted: &Vec<KalmanState>)
-> Vec<KalmanState>
filtered: &Vec<KalmanState>,
predicted: &Vec<KalmanState>)
-> Vec<KalmanState>
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. Contrary to the filtering process, incremental smoothing
requires 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); }