Revision 9, 1.1 kB
(checked in by smidl, 17 years ago)
|
|
Line | |
---|
1 | #include <itpp/itbase.h> |
---|
2 | #include "libKF.h" |
---|
3 | #include "libDC.h" |
---|
4 | |
---|
5 | using namespace itpp; |
---|
6 | |
---|
7 | //These lines are needed for use of cout and endl |
---|
8 | using std::cout; |
---|
9 | using std::endl; |
---|
10 | |
---|
11 | int main() { |
---|
12 | |
---|
13 | // Klaman filter |
---|
14 | mat A, B,C,D,R,Q,P0; |
---|
15 | vec mu0; |
---|
16 | mat Mu0;; |
---|
17 | // input from Matlab |
---|
18 | it_file fin( "testKF.it" ); |
---|
19 | mat Dt, Xt,Xt2; |
---|
20 | int Ndat; |
---|
21 | |
---|
22 | fin >> Name( "d" ) >> Dt; |
---|
23 | fin.seek( "A" ); |
---|
24 | fin >> A; |
---|
25 | fin.seek( "B" ); |
---|
26 | fin >> B; |
---|
27 | fin.seek( "C" ); |
---|
28 | fin >> C; |
---|
29 | fin.seek( "D" ); |
---|
30 | fin >> D; |
---|
31 | fin.seek( "R" ); |
---|
32 | fin >> R; |
---|
33 | fin.seek( "Q" ); fin >> Q; |
---|
34 | fin.seek( "P0" ); fin >> P0; |
---|
35 | fin.seek( "mu0" ); fin >> Mu0; mu0=Mu0; |
---|
36 | |
---|
37 | Ndat = Dt.cols(); |
---|
38 | Xt=zeros( 2,Ndat ); |
---|
39 | Xt2=zeros( 2,Ndat ); |
---|
40 | |
---|
41 | Kalman<ldmat> KF( A,B,C,D,ldmat(R),ldmat(Q),ldmat(P0),mu0 ); |
---|
42 | // cout << KF; |
---|
43 | KalmanFull KF2( A,B,C,D,R,Q,P0,mu0 ); |
---|
44 | |
---|
45 | Xt.set_col( 0,KF.mu ); |
---|
46 | Xt2.set_col( 0,KF.mu ); |
---|
47 | for ( int t=1;t<Ndat;t++ ) { |
---|
48 | KF.bayes( Dt.get_col( t )); |
---|
49 | KF2.bayes( Dt.get_col( t )); |
---|
50 | Xt.set_col(t,KF.mu); |
---|
51 | Xt2.set_col(t,KF2.mu); |
---|
52 | // Kmu = KF.mu; |
---|
53 | // cout << "t:" <<t<< " " << dt<<" "<<Kmu <<endl; |
---|
54 | } |
---|
55 | |
---|
56 | it_file fou( "testKF_res.it" ); |
---|
57 | fou << Name("xth") << Xt; |
---|
58 | fou << Name("xth2") << Xt2; |
---|
59 | //Exit program: |
---|
60 | return 0; |
---|
61 | |
---|
62 | } |
---|