SigPack - the C++ signal processing library
kalman.h
Go to the documentation of this file.
1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 #ifndef KALMAN_H
5 #define KALMAN_H
6 
7 #include <functional>
8 namespace sp
9 {
10 #define FCN_XUW \
11  [=](arma::mat x, arma::mat u, \
12  arma::mat w) // Lambda function f(x,u,w) ([capture] by copy)
13 using fcn_t = std::function<double(arma::mat, arma::mat, arma::mat)>;
14 using fcn_v = std::vector<fcn_t>;
15 using fcn_m = std::vector<fcn_v>;
16 
25 arma_inline arma::mat eval_fcn(const fcn_v f, const arma::mat &x,
26  const arma::mat &u, const arma::mat &w)
27 {
28  arma::mat y((arma::uword)(f.size()), 1, arma::fill::zeros);
29  for (arma::uword n = 0; n < y.n_rows; n++)
30  y(n, 0) = f[n](x, u, w);
31  return y;
32 }
33 
41 arma_inline arma::mat eval_fcn(const fcn_v f, const arma::mat &x,
42  const arma::mat &u)
43 {
44  arma::mat w0(0, 0, arma::fill::zeros);
45  return eval_fcn(f, x, u, w0);
46 }
47 
54 arma_inline arma::mat eval_fcn(const fcn_v f, const arma::mat &x)
55 {
56  arma::mat w0(0, 0, arma::fill::zeros);
57  arma::mat u0(w0);
58  return eval_fcn(f, x, u0, w0);
59 }
60 
82 arma_inline void lti2discr(const arma::mat &F, const arma::mat &W,
83  const arma::mat &Qc, const double dT, arma::mat &A,
84  arma::mat &Q)
85 {
86  arma::uword M = F.n_rows;
87 
88  // Solve A
89  A = arma::expmat(F * dT);
90 
91  // Solve Q by using matrix fraction decomposition
92  arma::mat AB = arma::zeros(2 * M, M);
93  arma::mat CD = arma::zeros(2 * M, 2 * M);
94  arma::mat EF = arma::zeros(2 * M, M);
95  EF.submat(M, 0, 2 * M - 1, M - 1) = arma::eye(M, M);
96  CD.submat(0, 0, M - 1, M - 1) = F;
97  CD.submat(M, M, 2 * M - 1, 2 * M - 1) = -F.t();
98  CD.submat(0, M, M - 1, 2 * M - 1) = W * Qc * W.t();
99 
100  AB = arma::expmat(CD * dT) * EF;
101 
102  Q = AB.rows(0, M - 1) * arma::inv(AB.rows(M, 2 * M - 1));
103 }
104 
109 
129 class KF
130 {
131 protected:
132  arma::uword N;
133  arma::uword M;
134  arma::uword L;
135  bool lin_proc;
136  bool lin_meas;
137  arma::mat x;
138  arma::mat z_err;
139  arma::mat A;
140  arma::mat B;
141  arma::mat H;
142  arma::mat P;
143  arma::mat Q;
144  arma::mat R;
145  arma::mat K;
148 public:
152  KF(arma::uword _N, arma::uword _M, arma::uword _L)
153  {
154  N = _N; // Nr of states
155  M = _M; // Nr of measurements/observations
156  L = _L; // Nr of inputs
157  lin_proc = true;
158  lin_meas = true;
159  x.set_size(N, 1);
160  x.zeros();
161  z_err.set_size(M, 1);
162  z_err.zeros();
163  A.set_size(N, N);
164  A.eye();
165  B.set_size(N, L);
166  B.zeros();
167  H.set_size(M, N);
168  H.zeros();
169  P.set_size(N, N);
170  P.eye();
171  Q.set_size(N, N);
172  Q.eye();
173  R.set_size(M, M);
174  R.eye();
175  K.set_size(N, M);
176  K.zeros();
177  }
178 
182  ~KF() {}
183 
187  void clear(void)
188  {
189  K.zeros();
190  P.eye();
191  x.zeros();
192  }
193 
195  // Set/get functions
197  void set_state_vec(const arma::mat &_x) { x = _x; } // Set state vector.[Nx1]
198  void set_trans_mat(const arma::mat &_A)
199  {
200  A = _A;
201  } // Set state transition matrix.[NxN]
202  void set_control_mat(const arma::mat &_B)
203  {
204  B = _B;
205  } // Set input matrix.[NxL]
206  void set_meas_mat(const arma::mat &_H)
207  {
208  H = _H;
209  } // Set measurement matrix.[MxN]
210  void set_err_cov(const arma::mat &_P)
211  {
212  P = _P;
213  } // Set error covariance matrix.[NxN]
214  void set_proc_noise(const arma::mat &_Q)
215  {
216  Q = _Q;
217  } // Set process noise cov. matrix.
218  void set_meas_noise(const arma::mat &_R)
219  {
220  R = _R;
221  } // Set meas noise cov. matrix.
222  void set_kalman_gain(const arma::mat &_K)
223  {
224  K = _K;
225  } // Set Kalman gain matrix.[NxM]
226  void set_trans_fcn(fcn_v _f) // Set state transition functions
227  {
228  f = _f;
229  lin_proc = false;
230  }
231  void set_meas_fcn(fcn_v _h) // Set measurement functions
232  {
233  h = _h;
234  lin_meas = false;
235  }
236 
237  arma::mat get_state_vec(void) { return x; } // Get states [Nx1]
238  arma::mat get_err(void) { return z_err; } // Get pred error [Mx1]
239  arma::mat get_kalman_gain(void) { return K; } // Get Kalman gain [NxM]
240  arma::mat get_err_cov(void) { return P; } // Get error cov matrix [NxN]
241 
246  void predict(const arma::mat u)
247  {
248  x = A * x + B * u; // New state
249  P = A * P * A.t() + Q; // New error covariance
250  }
251 
255  void predict(void)
256  {
257  arma::mat u0(L, 1, arma::fill::zeros);
258  predict(u0);
259  }
260 
264  void update(const arma::mat z)
265  {
266  // Compute the Kalman gain
267  K = P * H.t() * inv(H * P * H.t() + R);
268 
269  // Update estimate with measurement z
270  z_err = z - H * x;
271  x = x + K * z_err;
272 
273  // Joseph’s form covariance update
274  arma::mat Jf = arma::eye<arma::mat>(N, N) - K * H;
275  P = Jf * P * Jf.t() + K * R * K.t();
276  }
277 
283  void rts_smooth(const arma::mat &Xf, const arma::cube &Pf, arma::mat &Xs,
284  arma::cube &Ps)
285  {
286  arma::uword Nf = Xf.n_cols;
287  arma::mat X_pred(N, 1);
288  arma::mat P_pred(N, N);
289  arma::mat C(N, N);
290 
291  // Copy forward data
292  Xs = Xf;
293  Ps = Pf;
294 
295  // Backward filter
296  for (arma::uword n = Nf - 2; n > 0; n--)
297  {
298  // Project state and error covariance
299  X_pred = A * Xf.col(n);
300  P_pred = A * Pf.slice(n) * A.t() + Q;
301 
302  // Update
303  C = Pf.slice(n) * A.t() * inv(P_pred);
304  Xs.col(n) += C * (Xs.col(n + 1) - X_pred);
305  Ps.slice(n) += C * (Ps.slice(n + 1) - P_pred) * C.t();
306  }
307  }
308 }; // End class KF
309 
332 class EKF : public KF
333 {
334 protected:
337  double dx;
338 public:
339  EKF(arma::uword _N, arma::uword _M, arma::uword _L) : KF(_N, _M, _L)
340  {
341  dx = 1e-7; // Default diff step size
342  }
343 
345  // Set/get functions
347  void set_diff_step(double _dx) { dx = _dx; } // Set diff step size
349  {
350  f_jac = _f;
351  } // Set EKF state transition jacobian
353  {
354  h_jac = _h;
355  } // Set EKF measurement transition jacobian
356 
367  void jacobian_diff(arma::mat &_F, fcn_v _f, const arma::mat &_x)
368  {
369  arma::uword nC = _F.n_cols;
370  arma::uword nR = static_cast<arma::uword>(_f.size());
371  arma::mat z0(
372  nC, 1, arma::fill::zeros); // Zero matrix, assume dim u and w <= states
373 
374  if (nR == 0 || nR != _F.n_rows)
375  err_handler("Function list is empty or wrong size");
376 
377  for (arma::uword c = 0; c < nC; c++)
378  {
379  arma::mat xp(_x);
380  arma::mat xm(_x);
381  xp(c, 0) += dx;
382  xm(c, 0) -= dx;
383 
384  // Finite diff approx, evaluate at x,u=0,w=0
385  for (arma::uword r = 0; r < nR; r++)
386  _F(r, c) = (_f[r](xp, z0, z0) - _f[r](xm, z0, z0)) / (2 * dx);
387  }
388  }
395  void jacobian_diff(arma::mat &_F, fcn_v _f)
396  {
397  jacobian_diff(_F, _f, x); // Use current state from object
398  }
399 
406  void jacobian_analytical(arma::mat &_F, fcn_m _f_m, const arma::mat &_x)
407  {
408  arma::uword nC = _F.n_cols;
409  arma::uword nR = static_cast<arma::uword>(_f_m.size());
410 
411  if (nR == 0 || nR != _F.n_rows)
412  err_handler("Function list is empty or wrong size");
413 
414  arma::mat z0(
415  nC, 1, arma::fill::zeros); // Zero matrix, assume dim u and w <= states
416  for (arma::uword c = 0; c < nC; c++)
417  {
418  for (arma::uword r = 0; r < nR; r++)
419  _F(r, c) = _f_m[r][c](_x, z0, z0);
420  }
421  }
427  void jacobian_analytical(arma::mat &_F, fcn_m _f_m)
428  {
429  jacobian_analytical(_F, _f_m, x); // Use current state from object
430  }
431 
436  void predict(const arma::mat u)
437  {
438  if (!lin_proc)
439  {
440  // Update A with jacobian approx or analytical if set
441  if (f_jac.size() > 0)
442  jacobian_analytical(A, f_jac);
443  else
444  jacobian_diff(A, f);
445 
446  // Predict state x+ = f(x,u,0)
447  x = eval_fcn(f, x, u);
448  }
449  else // Linear process
450  x = A * x + B * u;
451 
452  // Project error covariance
453  P = A * P * A.t() + Q;
454  }
455 
459  void predict(void)
460  {
461  arma::mat u0(L, 1, arma::fill::zeros);
462  predict(u0);
463  }
464 
468  void update(const arma::mat z)
469  {
470  arma::mat z_hat(M, 1);
471 
472  if (!lin_meas) // Nonlinear measurement
473  {
474  // Update H with jacobian approx or analytical if set
475  if (h_jac.size() > 0)
476  jacobian_analytical(H, h_jac);
477  else
478  jacobian_diff(H, h);
479 
480  // Update measurement
481  z_hat = eval_fcn(h, x);
482  }
483  else // Linear meas
484  z_hat = H * x;
485 
486  // Calc residual
487  z_err = z - z_hat;
488 
489  // Compute the Kalman gain
490  K = P * H.t() * inv(H * P * H.t() + R);
491 
492  // Update estimate with measurement residual
493  x = x + K * z_err;
494 
495  // Joseph’s form covariance update
496  arma::mat Jf = arma::eye<arma::mat>(N, N) - K * H;
497  P = Jf * P * Jf.t() + K * R * K.t();
498  }
499 
505  void rts_smooth(const arma::mat &Xf, const arma::cube &Pf, arma::mat &Xs,
506  arma::cube &Ps)
507  {
508  arma::uword Nf = Xf.n_cols;
509  arma::mat X_pred(N, 1);
510  arma::mat P_pred(N, N);
511  arma::mat C(N, N);
512 
513  // Copy forward data
514  Xs = Xf;
515  Ps = Pf;
516 
517  // Backward filter
518  for (arma::uword n = Nf - 2; n > 0; n--)
519  {
520  if (!lin_proc)
521  {
522  // Update A with jacobian approx or analytical if set
523  if (f_jac.size() > 0)
524  jacobian_analytical(A, f_jac, Xf.col(n));
525  else
526  jacobian_diff(A, f, Xf.col(n));
527 
528  // Project state
529  X_pred = eval_fcn(f, Xf.col(n));
530  }
531  else // Linear process
532  {
533  // Project state
534  X_pred = A * Xf.col(n);
535  }
536 
537  // Project error covariance
538  P_pred = A * Pf.slice(n) * A.t() + Q;
539 
540  // Update
541  C = Pf.slice(n) * A.t() * inv(P_pred);
542  Xs.col(n) += C * (Xs.col(n + 1) - X_pred);
543  Ps.slice(n) += C * (Ps.slice(n + 1) - P_pred) * C.t();
544  }
545  }
546 
547 }; // End class EKF
548 
563 class UKF : public KF
564 {
565 protected:
566  double alpha;
567  double beta;
568  double kappa;
569  double lambda;
570 
571  arma::mat X;
572  arma::mat S;
573  arma::mat C;
574  arma::vec Wx;
575  arma::vec Wp;
576 public:
577  UKF(arma::uword _N, arma::uword _M, arma::uword _L) : KF(_N, _M, _L)
578  {
579  alpha = 1e-3;
580  beta = 2.0;
581  kappa = 0;
582  lambda = alpha * alpha * (_N + kappa) - _N;
583  X.set_size(_N, 2 * _N + 1);
584  X.zeros();
585  Wx.set_size(2 * _N + 1);
586  Wx.zeros();
587  Wp.set_size(2 * _N + 1);
588  Wp.zeros();
589  }
590 
592  // Set/get functions
594  void set_alpha(double _a) { alpha = _a; } // Set alpha
595  void set_beta(double _b) { beta = _b; } // Set beta
596  void set_kappa(double _k) { kappa = _k; } // Set kappa
597  void set_lambda(double _l) { lambda = _l; } // Set lambda
598 
602  void update_weights(void)
603  {
604  // Update lambda
605  lambda = alpha * alpha * (N + kappa) - N;
606 
607  // Update weights
608  Wx(0) = lambda / (N + lambda);
609  Wp(0) = lambda / (N + lambda) + (1 - alpha * alpha + beta);
610 
611  for (arma::uword n = 1; n <= 2 * N; n++)
612  {
613  Wx(n) = 1 / (2 * (N + lambda));
614  Wp(n) = Wx(n);
615  }
616  }
617 
623  void update_sigma(const arma::mat &_x, const arma::mat &_P)
624  {
625  // Update sigma points using Cholesky decomposition
626  arma::mat _A = sqrt(N + lambda) * arma::chol(_P, "lower");
627 
628  X = arma::repmat(_x, 1, 2 * N + 1);
629  X.cols(1, N) += _A;
630  X.cols(N + 1, 2 * N) -= _A;
631  }
632 
636  arma::mat ut(const arma::mat &_x, const arma::mat &_P, const fcn_v _f)
637  {
638  arma::uword Ny = static_cast<arma::uword>(_f.size());
639  arma::mat y(Ny, 1);
640  S.set_size(Ny, Ny);
641  C.set_size(N, Ny);
642 
643  update_weights();
644  update_sigma(_x, _P);
645 
646  // Propagate sigma points through nonlinear function
647  arma::mat Xy(Ny, 2 * N + 1);
648  for (arma::uword n = 0; n < 2 * N + 1; n++)
649  Xy.col(n) = eval_fcn(_f, X.col(n));
650 
651  // New mean
652  y = Xy * Wx;
653 
654  // New cov
655  S = (Xy - arma::repmat(y, 1, 2 * N + 1)) * arma::diagmat(Wp) *
656  (Xy - arma::repmat(y, 1, 2 * N + 1)).t();
657 
658  // New crosscov
659  C = (X - arma::repmat(_x, 1, 2 * N + 1)) * arma::diagmat(Wp) *
660  (Xy - arma::repmat(y, 1, 2 * N + 1)).t();
661 
662  return y;
663  }
664 
669  void predict(const arma::mat u)
670  {
671  if (!lin_proc) // Nonlinear process
672  {
673  // Do the Unscented Transform
674  x = ut(x, P, f) + B * u;
675 
676  // Add process noise cov
677  P = S + Q;
678  }
679  else // Linear process
680  {
681  // Project state
682  x = A * x + B * u;
683 
684  // Project error covariance
685  P = A * P * A.t() + Q;
686  }
687  }
688 
692  void predict(void)
693  {
694  arma::mat u0(L, 1, arma::fill::zeros);
695  predict(u0);
696  }
697 
701  void update(const arma::mat z)
702  {
703  arma::mat z_hat(M, 1);
704  if (!lin_meas) // Nonlinear measurement
705  {
706  // Do the Unscented Transform
707  z_hat = ut(x, P, h);
708 
709  // Add measurement noise cov
710  S = S + R;
711 
712  // Compute the Kalman gain
713  K = C * arma::inv(S);
714 
715  // Update estimate with measurement residual
716  z_err = z - z_hat;
717  x = x + K * z_err;
718 
719  // Update covariance, TODO: improve numerical perf. Josephs form?
720  P = P - K * S * K.t();
721  }
722  else // Linear measurement
723  {
724  // Calc residual
725  z_err = z - H * x;
726 
727  // Compute the Kalman gain
728  K = P * H.t() * inv(H * P * H.t() + R);
729 
730  // Update estimate with measurement residual
731  x = x + K * z_err;
732 
733  // Joseph’s form covariance update
734  arma::mat Jf = arma::eye<arma::mat>(N, N) - K * H;
735  P = Jf * P * Jf.t() + K * R * K.t();
736  }
737  }
738 
744  void rts_smooth(const arma::mat &Xf, const arma::cube &Pf, arma::mat &Xs,
745  arma::cube &Ps)
746  {
747  arma::uword Nf = Xf.n_cols;
748  arma::mat X_pred(N, 1, arma::fill::zeros);
749  arma::mat P_pred(N, N, arma::fill::zeros);
750  arma::mat D_pred(N, N, arma::fill::zeros);
751 
752  // Copy forward data
753  Xs = Xf;
754  Ps = Pf;
755 
756  // Backward filter
757  for (arma::uword k = Nf - 2; k > 0; k--)
758  {
759  if (!lin_proc)
760  {
761  // Do the unscented transform
762  X_pred = ut(Xf.col(k), Pf.slice(k), f);
763  P_pred = S + Q;
764 
765  // Update
766  D_pred = C * inv(P_pred);
767  Xs.col(k) += D_pred * (Xs.col(k + 1) - X_pred);
768  Ps.slice(k) += D_pred * (Ps.slice(k + 1) - P_pred) * D_pred.t();
769  }
770  else // Linear process
771  {
772  // Project state
773  X_pred = A * Xf.col(k);
774 
775  // Project error covariance
776  P_pred = A * Pf.slice(k) * A.t() + Q;
777 
778  // Update
779  D_pred = Pf.slice(k) * A.t() * inv(P_pred);
780  Xs.col(k) += D_pred * (Xs.col(k + 1) - X_pred);
781  Ps.slice(k) += D_pred * (Ps.slice(k + 1) - P_pred) * D_pred.t();
782  }
783  }
784  }
785 }; // End class UKF
786 } // namespace sp
787 #endif // KALMAN_H
void set_beta(double _b)
Definition: kalman.h:595
KF(arma::uword _N, arma::uword _M, arma::uword _L)
Constructor.
Definition: kalman.h:152
void rts_smooth(const arma::mat &Xf, const arma::cube &Pf, arma::mat &Xs, arma::cube &Ps)
Rauch-Tung-Striebel smoother. See http://www.lce.hut.fi/~ssarkka/course_k2011/pdf/course_booklet_2011...
Definition: kalman.h:744
bool lin_meas
Linearity flag for measurement.
Definition: kalman.h:136
fcn_v h
Vector of Kalman measurement functions.
Definition: kalman.h:147
arma::mat get_state_vec(void)
Definition: kalman.h:237
arma::mat K
Kalman gain vector.
Definition: kalman.h:145
~KF()
Destructor.
Definition: kalman.h:182
arma::mat H
Measurement matrix.
Definition: kalman.h:141
arma::uword N
Number of states.
Definition: kalman.h:132
double dx
Finite difference approximation step size.
Definition: kalman.h:337
void update_sigma(const arma::mat &_x, const arma::mat &_P)
Calculate sigma points around a reference point.
Definition: kalman.h:623
double kappa
Scaling par.
Definition: kalman.h:568
void predict(void)
Predict the internal states, no control.
Definition: kalman.h:459
arma::mat R
Measurement noise.
Definition: kalman.h:144
fcn_m h_jac
Matrix of Extended Kalman measurement transition jacobian.
Definition: kalman.h:336
arma::vec Wp
Weights covariance.
Definition: kalman.h:575
arma::mat x
State vector.
Definition: kalman.h:137
void jacobian_analytical(arma::mat &_F, fcn_m _f_m)
Evaluate Jacobian matrix using analytical jacobian.
Definition: kalman.h:427
#define err_handler(msg)
Definition: base.h:213
void update(const arma::mat z)
Correct and update the internal states.
Definition: kalman.h:264
void set_meas_mat(const arma::mat &_H)
Definition: kalman.h:206
void set_diff_step(double _dx)
Definition: kalman.h:347
arma::mat X
Sigma points.
Definition: kalman.h:571
arma::mat A
State transition matrix.
Definition: kalman.h:139
std::function< double(arma::mat, arma::mat, arma::mat)> fcn_t
Definition: kalman.h:13
void set_trans_fcn(fcn_v _f)
Definition: kalman.h:226
arma::mat C
Cross covariance input-output.
Definition: kalman.h:573
Definition: base.h:7
arma::vec Wx
Weights states.
Definition: kalman.h:574
Unscented Kalman filter class.
Definition: kalman.h:563
double alpha
Spread factor of sigma points.
Definition: kalman.h:566
void set_lambda(double _l)
Definition: kalman.h:597
arma::mat S
Output covariance.
Definition: kalman.h:572
void predict(const arma::mat u)
Predict the internal states using a control input.
Definition: kalman.h:436
double beta
x distr. prior knowledge factor
Definition: kalman.h:567
std::vector< fcn_t > fcn_v
Definition: kalman.h:14
UKF(arma::uword _N, arma::uword _M, arma::uword _L)
Definition: kalman.h:577
double lambda
Definition: kalman.h:569
void jacobian_analytical(arma::mat &_F, fcn_m _f_m, const arma::mat &_x)
Evaluate Jacobian matrix using analytical jacobian.
Definition: kalman.h:406
arma::uword L
Number of measurements/observations.
Definition: kalman.h:134
arma_inline arma::mat eval_fcn(const fcn_v f, const arma::mat &x, const arma::mat &u, const arma::mat &w)
Evaluate function f(x,u,w)
Definition: kalman.h:25
void predict(const arma::mat u)
Predict the internal states using a control input.
Definition: kalman.h:669
void set_control_mat(const arma::mat &_B)
Definition: kalman.h:202
void update_weights(void)
Calculate sigma point weights.
Definition: kalman.h:602
std::vector< fcn_v > fcn_m
Definition: kalman.h:15
void predict(void)
Predict the internal states, no control.
Definition: kalman.h:255
void set_state_vec(const arma::mat &_x)
Definition: kalman.h:197
void update(const arma::mat z)
Correct and update the internal states. EKF.
Definition: kalman.h:468
EKF(arma::uword _N, arma::uword _M, arma::uword _L)
Definition: kalman.h:339
void set_alpha(double _a)
Definition: kalman.h:594
arma::mat z_err
Prediction error.
Definition: kalman.h:138
void set_meas_fcn(fcn_v _h)
Definition: kalman.h:231
void set_proc_noise(const arma::mat &_Q)
Definition: kalman.h:214
arma::mat get_kalman_gain(void)
Definition: kalman.h:239
arma::mat B
Input matrix.
Definition: kalman.h:140
Kalman filter class.
Definition: kalman.h:129
void set_kalman_gain(const arma::mat &_K)
Definition: kalman.h:222
void predict(void)
Predict the internal states, no control. Convenient function.
Definition: kalman.h:692
void predict(const arma::mat u)
Predict the internal states using a control input.
Definition: kalman.h:246
void clear(void)
Clear the internal states and pointer.
Definition: kalman.h:187
First order Extended Kalman filter class.
Definition: kalman.h:332
fcn_v f
Vector of Kalman state transition functions.
Definition: kalman.h:146
void jacobian_diff(arma::mat &_F, fcn_v _f)
Calculate and evaluate Jacobian matrix using finite difference approximation.
Definition: kalman.h:395
arma::uword M
Number of inputs.
Definition: kalman.h:133
void set_err_cov(const arma::mat &_P)
Definition: kalman.h:210
void set_meas_jac(fcn_m _h)
Definition: kalman.h:352
void set_trans_mat(const arma::mat &_A)
Definition: kalman.h:198
void rts_smooth(const arma::mat &Xf, const arma::cube &Pf, arma::mat &Xs, arma::cube &Ps)
Rauch-Tung-Striebel smoother. See http://www.lce.hut.fi/~ssarkka/course_k2011/pdf/course_booklet_2011...
Definition: kalman.h:505
fcn_m f_jac
Matrix of Extended Kalman state transition jacobian.
Definition: kalman.h:335
void update(const arma::mat z)
Correct and update the internal states. UKF.
Definition: kalman.h:701
void set_state_jac(fcn_m _f)
Definition: kalman.h:348
void rts_smooth(const arma::mat &Xf, const arma::cube &Pf, arma::mat &Xs, arma::cube &Ps)
Rauch-Tung-Striebel smoother. See http://www.lce.hut.fi/~ssarkka/course_k2011/pdf/course_booklet_2011...
Definition: kalman.h:283
arma::mat get_err(void)
Definition: kalman.h:238
void jacobian_diff(arma::mat &_F, fcn_v _f, const arma::mat &_x)
Calculate and evaluate Jacobian matrix using finite difference approximation.
Definition: kalman.h:367
bool lin_proc
Linearity flag for process.
Definition: kalman.h:135
void set_meas_noise(const arma::mat &_R)
Definition: kalman.h:218
arma_inline void lti2discr(const arma::mat &F, const arma::mat &W, const arma::mat &Qc, const double dT, arma::mat &A, arma::mat &Q)
Discretize to a state transition and state noise cov matrix from an LTI system.
Definition: kalman.h:82
arma::mat P
Error covariance matrix (estimated accuracy)
Definition: kalman.h:142
arma::mat Q
Process noise.
Definition: kalman.h:143
arma::mat ut(const arma::mat &_x, const arma::mat &_P, const fcn_v _f)
Calculate unscented transform.
Definition: kalman.h:636
void set_kappa(double _k)
Definition: kalman.h:596
arma::mat get_err_cov(void)
Definition: kalman.h:240