16 arma::uword Nsamp = 120;
32 arma::mat x = {0, 10, 1, 50, -0.08, -9};
35 arma::mat A = {{1, 0, dT, 0, dT * dT / 2, 0},
36 {0, 1, 0, dT, 0, dT * dT / 2},
43 arma::mat H = {{1, 0, 0, 0, 0, 0}, {0, 1, 0, 0, 0, 0}};
46 arma::mat P = P0 * arma::eye(N, N);
48 arma::mat Q = arma::zeros(N, N);
54 arma::mat R = R0 * arma::eye(M, M);
58 arma::mat z(M, Nsamp, arma::fill::zeros);
59 arma::mat z0(M, Nsamp, arma::fill::zeros);
61 arma::mat xx(N, 1, arma::fill::zeros);
63 for (arma::uword n = 1; n < Nsamp; n++)
65 xx = A * xx + 0.1 * Q * arma::randn(N, 1);
69 z.row(0) = z0.row(0) + 0.001 * R0 * arma::randn(1, Nsamp);
70 z.row(1) = z0.row(1) + 0.8 * R0 * arma::randn(1, Nsamp);
72 arma::mat x_log(N, Nsamp);
73 arma::mat e_log(M, Nsamp);
74 arma::cube P_log(N, N, Nsamp);
75 arma::mat xs_log(M, Nsamp);
76 arma::cube Ps_log(N, N, Nsamp);
79 for (arma::uword n = 0; n < Nsamp; n++)
85 e_log.col(n) = kalman.
get_err();
90 kalman.
rts_smooth(x_log, P_log, xs_log, Ps_log);
94 gp0.
window(
"Plot", 10, 10, 500, 500);
96 gp0.
plot_add(z0.row(0), z0.row(1),
"True Y",
97 "lines dashtype 2 linecolor \"black\"");
98 gp0.
plot_add(z.row(0), z.row(1),
"Meas Y",
"points");
99 gp0.
plot_add(x_log.row(0), x_log.row(1),
"Kalman");
100 gp0.
plot_add(xs_log.row(0), xs_log.row(1),
"RTS smooth");
arma::mat get_state_vec(void)
void update(const arma::mat z)
Correct and update the internal states.
void set_meas_mat(const arma::mat &_H)
void plot_show(void)
Show plots.
void set_state_vec(const arma::mat &_x)
void set_proc_noise(const arma::mat &_Q)
void set_term(const char *ttype)
Set output terminal.
void predict(const arma::mat u)
Predict the internal states using a control input.
void set_err_cov(const arma::mat &_P)
void set_trans_mat(const arma::mat &_A)
void window(const int fig, const char *name, const int x, const int y, const int width, const int height)
Configure the figure used Windows environment.
void plot_add(const T1 &x, const T2 &y, const std::string lb, const std::string ls="lines")
Push plot y vs. x with label and linespec.
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...
void set_meas_noise(const arma::mat &_R)
arma::mat get_err_cov(void)