SigPack - the C++ signal processing library
 
Loading...
Searching...
No Matches
Kalman

Classes

class  sp::KF
 
class  sp::EKF
 
class  sp::UKF
 

Functions

 sp::KF::KF (arma::uword _N, arma::uword _M, arma::uword _L)
 
 sp::KF::~KF ()
 
void sp::KF::clear (void)
 
void sp::KF::set_state_vec (const arma::mat &_x)
 
void sp::KF::set_trans_mat (const arma::mat &_A)
 
void sp::KF::set_control_mat (const arma::mat &_B)
 
void sp::KF::set_meas_mat (const arma::mat &_H)
 
void sp::KF::set_err_cov (const arma::mat &_P)
 
void sp::KF::set_proc_noise (const arma::mat &_Q)
 
void sp::KF::set_meas_noise (const arma::mat &_R)
 
void sp::KF::set_kalman_gain (const arma::mat &_K)
 
void sp::KF::set_trans_fcn (fcn_v _f)
 
void sp::KF::set_meas_fcn (fcn_v _h)
 
arma::mat sp::KF::get_state_vec (void)
 
arma::mat sp::KF::get_err (void)
 
arma::mat sp::KF::get_kalman_gain (void)
 
arma::mat sp::KF::get_err_cov (void)
 
void sp::KF::predict (const arma::mat u)
 
void sp::KF::predict (void)
 
void sp::KF::update (const arma::mat z)
 
void sp::KF::rts_smooth (const arma::mat &Xf, const arma::cube &Pf, arma::mat &Xs, arma::cube &Ps)
 
 sp::EKF::EKF (arma::uword _N, arma::uword _M, arma::uword _L)
 
void sp::EKF::set_diff_step (double _dx)
 
void sp::EKF::set_state_jac (fcn_m _f)
 
void sp::EKF::set_meas_jac (fcn_m _h)
 
void sp::EKF::jacobian_diff (arma::mat &_F, fcn_v _f, const arma::mat &_x)
 
void sp::EKF::jacobian_diff (arma::mat &_F, fcn_v _f)
 
void sp::EKF::jacobian_analytical (arma::mat &_F, fcn_m _f_m, const arma::mat &_x)
 
void sp::EKF::jacobian_analytical (arma::mat &_F, fcn_m _f_m)
 
void sp::EKF::predict (const arma::mat u)
 
void sp::EKF::predict (void)
 
void sp::EKF::update (const arma::mat z)
 
void sp::EKF::rts_smooth (const arma::mat &Xf, const arma::cube &Pf, arma::mat &Xs, arma::cube &Ps)
 
 sp::UKF::UKF (arma::uword _N, arma::uword _M, arma::uword _L)
 
void sp::UKF::set_alpha (double _a)
 
void sp::UKF::set_beta (double _b)
 
void sp::UKF::set_kappa (double _k)
 
void sp::UKF::set_lambda (double _l)
 
void sp::UKF::update_weights (void)
 
void sp::UKF::update_sigma (const arma::mat &_x, const arma::mat &_P)
 
arma::mat sp::UKF::ut (const arma::mat &_x, const arma::mat &_P, const fcn_v _f)
 
void sp::UKF::predict (const arma::mat u)
 
void sp::UKF::predict (void)
 
void sp::UKF::update (const arma::mat z)
 
void sp::UKF::rts_smooth (const arma::mat &Xf, const arma::cube &Pf, arma::mat &Xs, arma::cube &Ps)
 

Variables

arma::uword sp::KF::N
 
arma::uword sp::KF::M
 
arma::uword sp::KF::L
 
bool sp::KF::lin_proc
 
bool sp::KF::lin_meas
 
arma::mat sp::KF::x
 
arma::mat sp::KF::z_err
 
arma::mat sp::KF::A
 
arma::mat sp::KF::B
 
arma::mat sp::KF::H
 
arma::mat sp::KF::P
 
arma::mat sp::KF::Q
 
arma::mat sp::KF::R
 
arma::mat sp::KF::K
 
fcn_v sp::KF::f
 
fcn_v sp::KF::h
 
fcn_m sp::EKF::f_jac
 
fcn_m sp::EKF::h_jac
 
double sp::EKF::dx
 
double sp::UKF::alpha
 
double sp::UKF::beta
 
double sp::UKF::kappa
 
double sp::UKF::lambda
 
arma::mat sp::UKF::X
 
arma::mat sp::UKF::S
 
arma::mat sp::UKF::C
 
arma::vec sp::UKF::Wx
 
arma::vec sp::UKF::Wp
 

Detailed Description

Function Documentation

◆ clear()

void sp::KF::clear ( void  )
inline

Clear the internal states and pointer.

Definition at line 184 of file kalman.h.

References sp::KF::K, sp::KF::P, and sp::KF::x.

◆ EKF()

sp::EKF::EKF ( arma::uword  _N,
arma::uword  _M,
arma::uword  _L 
)
inline

Definition at line 362 of file kalman.h.

References sp::EKF::dx.

◆ get_err()

arma::mat sp::KF::get_err ( void  )
inline
Examples
kalman_UKF.cpp, and kalman_linear.cpp.

Definition at line 251 of file kalman.h.

References sp::KF::z_err.

Referenced by main().

◆ get_err_cov()

arma::mat sp::KF::get_err_cov ( void  )
inline
Examples
kalman_UKF.cpp, and kalman_linear.cpp.

Definition at line 261 of file kalman.h.

References sp::KF::P.

Referenced by main().

◆ get_kalman_gain()

arma::mat sp::KF::get_kalman_gain ( void  )
inline
Examples
kalman_UKF.cpp.

Definition at line 256 of file kalman.h.

References sp::KF::K.

Referenced by main().

◆ get_state_vec()

arma::mat sp::KF::get_state_vec ( void  )
inline
Examples
kalman_UKF.cpp, and kalman_linear.cpp.

Definition at line 246 of file kalman.h.

References sp::KF::x.

Referenced by main().

◆ jacobian_analytical() [1/2]

void sp::EKF::jacobian_analytical ( arma::mat &  _F,
fcn_m  _f_m 
)
inline

Evaluate Jacobian matrix using analytical jacobian.

Parameters
_FJacobian matrix d/dx evaluated at x
_f_mJacobian function matrix

Definition at line 455 of file kalman.h.

References sp::EKF::jacobian_analytical(), and sp::KF::x.

Here is the call graph for this function:

◆ jacobian_analytical() [2/2]

void sp::EKF::jacobian_analytical ( arma::mat &  _F,
fcn_m  _f_m,
const arma::mat &  _x 
)
inline

Evaluate Jacobian matrix using analytical jacobian.

Parameters
_FJacobian matrix d/dx evaluated at x
_f_mJacobian function matrix
_xState vector

Definition at line 434 of file kalman.h.

References err_handler.

Referenced by sp::EKF::jacobian_analytical(), sp::EKF::predict(), sp::EKF::rts_smooth(), and sp::EKF::update().

◆ jacobian_diff() [1/2]

void sp::EKF::jacobian_diff ( arma::mat &  _F,
fcn_v  _f 
)
inline

Calculate and evaluate Jacobian matrix using finite difference approximation.

Parameters
_FJacobian matrix d/dx evaluated at x
_fFunction vector [ f0(x,u,w) ... fN(x,u,w)]

Definition at line 423 of file kalman.h.

References sp::EKF::jacobian_diff(), and sp::KF::x.

Here is the call graph for this function:

◆ jacobian_diff() [2/2]

void sp::EKF::jacobian_diff ( arma::mat &  _F,
fcn_v  _f,
const arma::mat &  _x 
)
inline

Calculate and evaluate Jacobian matrix using finite difference approximation.

Parameters
_FJacobian matrix d/dx evaluated at x
_fFunction vector [ f0(x,u,w) ... fN(x,u,w)]
_xState vector

Alternative: Complex Step Diff: http://blogs.mathworks.com/cleve/2013/10/14/complex-step-differentiation/

Definition at line 395 of file kalman.h.

References sp::EKF::dx, and err_handler.

Referenced by sp::EKF::jacobian_diff(), sp::EKF::predict(), sp::EKF::rts_smooth(), and sp::EKF::update().

◆ KF()

sp::KF::KF ( arma::uword  _N,
arma::uword  _M,
arma::uword  _L 
)
inline

◆ predict() [1/6]

void sp::KF::predict ( const arma::mat  u)
inline

Predict the internal states using a control input.

Parameters
uInput/control signal
Examples
kalman_linear.cpp.

Definition at line 270 of file kalman.h.

References sp::KF::A, sp::KF::B, sp::KF::P, sp::KF::Q, and sp::KF::x.

Referenced by main().

◆ predict() [2/6]

void sp::EKF::predict ( const arma::mat  u)
inline

Predict the internal states using a control input.

Parameters
uInput/control signal

Definition at line 464 of file kalman.h.

References sp::KF::A, sp::KF::B, sp::eval_fcn(), sp::KF::f, sp::EKF::f_jac, sp::EKF::jacobian_analytical(), sp::EKF::jacobian_diff(), sp::KF::lin_proc, sp::KF::P, sp::KF::Q, and sp::KF::x.

Here is the call graph for this function:

◆ predict() [3/6]

void sp::UKF::predict ( const arma::mat  u)
inline

Predict the internal states using a control input.

Parameters
uInput/control signal
Examples
kalman_UKF.cpp.

Definition at line 709 of file kalman.h.

References sp::KF::A, sp::KF::B, sp::KF::f, sp::KF::lin_proc, sp::KF::P, sp::KF::Q, sp::UKF::S, sp::UKF::ut(), and sp::KF::x.

Referenced by main().

Here is the call graph for this function:

◆ predict() [4/6]

void sp::KF::predict ( void  )
inline

Predict the internal states, no control.

Definition at line 279 of file kalman.h.

References sp::KF::L, and sp::KF::predict().

Referenced by sp::KF::predict().

Here is the call graph for this function:

◆ predict() [5/6]

void sp::EKF::predict ( void  )
inline

Predict the internal states, no control.

Definition at line 487 of file kalman.h.

References sp::KF::L, and sp::EKF::predict().

Referenced by sp::EKF::predict().

Here is the call graph for this function:

◆ predict() [6/6]

void sp::UKF::predict ( void  )
inline

Predict the internal states, no control. Convenient function.

Definition at line 732 of file kalman.h.

References sp::KF::L, and sp::UKF::predict().

Referenced by sp::UKF::predict().

Here is the call graph for this function:

◆ rts_smooth() [1/3]

void sp::KF::rts_smooth ( const arma::mat &  Xf,
const arma::cube &  Pf,
arma::mat &  Xs,
arma::cube &  Ps 
)
inline

Rauch-Tung-Striebel smoother. See https://users.aalto.fi/~ssarkka/course_k2012/full_course_booklet_2012.pdf.

Examples
kalman_linear.cpp.

Definition at line 307 of file kalman.h.

References sp::KF::A, sp::KF::N, and sp::KF::Q.

Referenced by main().

◆ rts_smooth() [2/3]

void sp::EKF::rts_smooth ( const arma::mat &  Xf,
const arma::cube &  Pf,
arma::mat &  Xs,
arma::cube &  Ps 
)
inline

◆ rts_smooth() [3/3]

void sp::UKF::rts_smooth ( const arma::mat &  Xf,
const arma::cube &  Pf,
arma::mat &  Xs,
arma::cube &  Ps 
)
inline

Rauch-Tung-Striebel smoother. See https://users.aalto.fi/~ssarkka/course_k2012/full_course_booklet_2012.pdf.

Examples
kalman_UKF.cpp.

Definition at line 784 of file kalman.h.

References sp::KF::A, sp::UKF::C, sp::KF::f, sp::KF::lin_proc, sp::KF::N, sp::KF::Q, sp::UKF::S, and sp::UKF::ut().

Referenced by main().

Here is the call graph for this function:

◆ set_alpha()

void sp::UKF::set_alpha ( double  _a)
inline

Definition at line 621 of file kalman.h.

References sp::UKF::alpha.

◆ set_beta()

void sp::UKF::set_beta ( double  _b)
inline

Definition at line 626 of file kalman.h.

References sp::UKF::beta.

◆ set_control_mat()

void sp::KF::set_control_mat ( const arma::mat &  _B)
inline

Definition at line 204 of file kalman.h.

References sp::KF::B.

◆ set_diff_step()

void sp::EKF::set_diff_step ( double  _dx)
inline

Definition at line 370 of file kalman.h.

References sp::EKF::dx.

◆ set_err_cov()

void sp::KF::set_err_cov ( const arma::mat &  _P)
inline
Examples
kalman_UKF.cpp, and kalman_linear.cpp.

Definition at line 214 of file kalman.h.

References sp::KF::P.

Referenced by main().

◆ set_kalman_gain()

void sp::KF::set_kalman_gain ( const arma::mat &  _K)
inline

Definition at line 229 of file kalman.h.

References sp::KF::K.

◆ set_kappa()

void sp::UKF::set_kappa ( double  _k)
inline

Definition at line 631 of file kalman.h.

References sp::UKF::kappa.

◆ set_lambda()

void sp::UKF::set_lambda ( double  _l)
inline

Definition at line 636 of file kalman.h.

References sp::UKF::lambda.

◆ set_meas_fcn()

void sp::KF::set_meas_fcn ( fcn_v  _h)
inline
Examples
kalman_UKF.cpp.

Definition at line 240 of file kalman.h.

References sp::KF::h, and sp::KF::lin_meas.

Referenced by main().

◆ set_meas_jac()

void sp::EKF::set_meas_jac ( fcn_m  _h)
inline

Definition at line 380 of file kalman.h.

References sp::EKF::h_jac.

◆ set_meas_mat()

void sp::KF::set_meas_mat ( const arma::mat &  _H)
inline
Examples
kalman_linear.cpp.

Definition at line 209 of file kalman.h.

References sp::KF::H.

Referenced by main().

◆ set_meas_noise()

void sp::KF::set_meas_noise ( const arma::mat &  _R)
inline
Examples
kalman_UKF.cpp, and kalman_linear.cpp.

Definition at line 224 of file kalman.h.

References sp::KF::R.

Referenced by main().

◆ set_proc_noise()

void sp::KF::set_proc_noise ( const arma::mat &  _Q)
inline
Examples
kalman_UKF.cpp, and kalman_linear.cpp.

Definition at line 219 of file kalman.h.

References sp::KF::Q.

Referenced by main().

◆ set_state_jac()

void sp::EKF::set_state_jac ( fcn_m  _f)
inline

Definition at line 375 of file kalman.h.

References sp::EKF::f_jac.

◆ set_state_vec()

void sp::KF::set_state_vec ( const arma::mat &  _x)
inline
Examples
kalman_UKF.cpp, and kalman_linear.cpp.

Definition at line 194 of file kalman.h.

References sp::KF::x.

Referenced by main().

◆ set_trans_fcn()

void sp::KF::set_trans_fcn ( fcn_v  _f)
inline

Definition at line 234 of file kalman.h.

References sp::KF::f, and sp::KF::lin_proc.

◆ set_trans_mat()

void sp::KF::set_trans_mat ( const arma::mat &  _A)
inline
Examples
kalman_UKF.cpp, and kalman_linear.cpp.

Definition at line 199 of file kalman.h.

References sp::KF::A.

Referenced by main().

◆ UKF()

sp::UKF::UKF ( arma::uword  _N,
arma::uword  _M,
arma::uword  _L 
)
inline

◆ update() [1/3]

void sp::KF::update ( const arma::mat  z)
inline

Correct and update the internal states.

Examples
kalman_linear.cpp.

Definition at line 288 of file kalman.h.

References sp::KF::H, sp::KF::K, sp::KF::N, sp::KF::P, sp::KF::R, sp::KF::x, and sp::KF::z_err.

Referenced by main().

◆ update() [2/3]

void sp::EKF::update ( const arma::mat  z)
inline

Correct and update the internal states. EKF.

Definition at line 496 of file kalman.h.

References sp::eval_fcn(), sp::KF::H, sp::KF::h, sp::EKF::h_jac, sp::EKF::jacobian_analytical(), sp::EKF::jacobian_diff(), sp::KF::K, sp::KF::lin_meas, sp::KF::M, sp::KF::N, sp::KF::P, sp::KF::R, sp::KF::x, and sp::KF::z_err.

Here is the call graph for this function:

◆ update() [3/3]

void sp::UKF::update ( const arma::mat  z)
inline

Correct and update the internal states. UKF.

Examples
kalman_UKF.cpp.

Definition at line 741 of file kalman.h.

References sp::UKF::C, sp::KF::H, sp::KF::h, sp::KF::K, sp::KF::lin_meas, sp::KF::M, sp::KF::N, sp::KF::P, sp::KF::R, sp::UKF::S, sp::UKF::ut(), sp::KF::x, and sp::KF::z_err.

Referenced by main().

Here is the call graph for this function:

◆ update_sigma()

void sp::UKF::update_sigma ( const arma::mat &  _x,
const arma::mat &  _P 
)
inline

Calculate sigma points around a reference point.

Parameters
_xState matrix
_PCovariance matrix

Definition at line 665 of file kalman.h.

References sp::UKF::lambda, sp::KF::N, and sp::UKF::X.

Referenced by sp::UKF::ut().

◆ update_weights()

void sp::UKF::update_weights ( void  )
inline

Calculate sigma point weights.

Definition at line 644 of file kalman.h.

References sp::UKF::alpha, sp::UKF::beta, sp::UKF::kappa, sp::UKF::lambda, sp::KF::N, sp::UKF::Wp, and sp::UKF::Wx.

Referenced by sp::UKF::ut().

◆ ut()

arma::mat sp::UKF::ut ( const arma::mat &  _x,
const arma::mat &  _P,
const fcn_v  _f 
)
inline

Calculate unscented transform.

Definition at line 678 of file kalman.h.

References sp::UKF::C, sp::eval_fcn(), sp::KF::N, sp::UKF::S, sp::UKF::update_sigma(), sp::UKF::update_weights(), sp::UKF::Wp, sp::UKF::Wx, and sp::UKF::X.

Referenced by sp::UKF::predict(), sp::UKF::rts_smooth(), and sp::UKF::update().

Here is the call graph for this function:

◆ ~KF()

sp::KF::~KF ( )
inline

Destructor.

Definition at line 177 of file kalman.h.

Variable Documentation

◆ A

arma::mat sp::KF::A
protected

◆ alpha

double sp::UKF::alpha
protected

Spread factor of sigma points.

Definition at line 593 of file kalman.h.

Referenced by sp::UKF::set_alpha(), sp::UKF::UKF(), and sp::UKF::update_weights().

◆ B

arma::mat sp::KF::B
protected

Input matrix.

Definition at line 135 of file kalman.h.

Referenced by sp::KF::KF(), sp::KF::predict(), sp::EKF::predict(), sp::UKF::predict(), and sp::KF::set_control_mat().

◆ beta

double sp::UKF::beta
protected

x distr. prior knowledge factor

Definition at line 594 of file kalman.h.

Referenced by sp::UKF::set_beta(), sp::UKF::UKF(), and sp::UKF::update_weights().

◆ C

arma::mat sp::UKF::C
protected

Cross covariance input-output.

Definition at line 600 of file kalman.h.

Referenced by sp::UKF::rts_smooth(), sp::UKF::update(), and sp::UKF::ut().

◆ dx

double sp::EKF::dx
protected

Finite difference approximation step size.

Definition at line 360 of file kalman.h.

Referenced by sp::EKF::EKF(), sp::EKF::jacobian_diff(), and sp::EKF::set_diff_step().

◆ f

fcn_v sp::KF::f
protected

Vector of Kalman state transition functions.

Definition at line 141 of file kalman.h.

Referenced by sp::EKF::predict(), sp::UKF::predict(), sp::EKF::rts_smooth(), sp::UKF::rts_smooth(), and sp::KF::set_trans_fcn().

◆ f_jac

fcn_m sp::EKF::f_jac
protected

Matrix of Extended Kalman state transition jacobian.

Definition at line 358 of file kalman.h.

Referenced by sp::EKF::predict(), sp::EKF::rts_smooth(), and sp::EKF::set_state_jac().

◆ H

arma::mat sp::KF::H
protected

Measurement matrix.

Definition at line 136 of file kalman.h.

Referenced by sp::KF::KF(), sp::KF::set_meas_mat(), sp::KF::update(), sp::EKF::update(), and sp::UKF::update().

◆ h

fcn_v sp::KF::h
protected

Vector of Kalman measurement functions.

Definition at line 142 of file kalman.h.

Referenced by sp::KF::set_meas_fcn(), sp::EKF::update(), and sp::UKF::update().

◆ h_jac

fcn_m sp::EKF::h_jac
protected

Matrix of Extended Kalman measurement transition jacobian.

Definition at line 359 of file kalman.h.

Referenced by sp::EKF::set_meas_jac(), and sp::EKF::update().

◆ K

arma::mat sp::KF::K
protected

◆ kappa

double sp::UKF::kappa
protected

Scaling par.

Definition at line 595 of file kalman.h.

Referenced by sp::UKF::set_kappa(), sp::UKF::UKF(), and sp::UKF::update_weights().

◆ L

arma::uword sp::KF::L
protected

Number of measurements/observations.

Definition at line 129 of file kalman.h.

Referenced by sp::KF::KF(), sp::KF::predict(), sp::EKF::predict(), and sp::UKF::predict().

◆ lambda

double sp::UKF::lambda
protected

◆ lin_meas

bool sp::KF::lin_meas
protected

Linearity flag for measurement.

Definition at line 131 of file kalman.h.

Referenced by sp::KF::KF(), sp::KF::set_meas_fcn(), sp::EKF::update(), and sp::UKF::update().

◆ lin_proc

bool sp::KF::lin_proc
protected

Linearity flag for process.

Definition at line 130 of file kalman.h.

Referenced by sp::KF::KF(), sp::EKF::predict(), sp::UKF::predict(), sp::EKF::rts_smooth(), sp::UKF::rts_smooth(), and sp::KF::set_trans_fcn().

◆ M

arma::uword sp::KF::M
protected

Number of inputs.

Definition at line 128 of file kalman.h.

Referenced by sp::KF::KF(), sp::EKF::update(), and sp::UKF::update().

◆ N

◆ P

arma::mat sp::KF::P
protected

◆ Q

arma::mat sp::KF::Q
protected

◆ R

arma::mat sp::KF::R
protected

Measurement noise.

Definition at line 139 of file kalman.h.

Referenced by sp::KF::KF(), sp::KF::set_meas_noise(), sp::KF::update(), sp::EKF::update(), and sp::UKF::update().

◆ S

arma::mat sp::UKF::S
protected

Output covariance.

Definition at line 599 of file kalman.h.

Referenced by sp::UKF::predict(), sp::UKF::rts_smooth(), sp::UKF::update(), and sp::UKF::ut().

◆ Wp

arma::vec sp::UKF::Wp
protected

Weights covariance.

Definition at line 602 of file kalman.h.

Referenced by sp::UKF::UKF(), sp::UKF::update_weights(), and sp::UKF::ut().

◆ Wx

arma::vec sp::UKF::Wx
protected

Weights states.

Definition at line 601 of file kalman.h.

Referenced by sp::UKF::UKF(), sp::UKF::update_weights(), and sp::UKF::ut().

◆ x

◆ X

arma::mat sp::UKF::X
protected

Sigma points.

Definition at line 598 of file kalman.h.

Referenced by sp::UKF::UKF(), sp::UKF::update_sigma(), and sp::UKF::ut().

◆ z_err

arma::mat sp::KF::z_err
protected

Prediction error.

Definition at line 133 of file kalman.h.

Referenced by sp::KF::get_err(), sp::KF::KF(), sp::KF::update(), sp::EKF::update(), and sp::UKF::update().