Revision 9, 1.1 kB
(checked in by smidl, 17 years ago)
|
|
Rev | Line | |
---|
[7] | 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 | |
---|
[8] | 13 | // Klaman filter |
---|
| 14 | mat A, B,C,D,R,Q,P0; |
---|
| 15 | vec mu0; |
---|
| 16 | mat Mu0;; |
---|
| 17 | // input from Matlab |
---|
[9] | 18 | it_file fin( "testKF.it" ); |
---|
[8] | 19 | mat Dt, Xt,Xt2; |
---|
| 20 | int Ndat; |
---|
[7] | 21 | |
---|
| 22 | fin >> Name( "d" ) >> Dt; |
---|
[8] | 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; |
---|
[7] | 36 | |
---|
[8] | 37 | Ndat = Dt.cols(); |
---|
| 38 | Xt=zeros( 2,Ndat ); |
---|
| 39 | Xt2=zeros( 2,Ndat ); |
---|
[7] | 40 | |
---|
[8] | 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 | |
---|
[7] | 45 | Xt.set_col( 0,KF.mu ); |
---|
[8] | 46 | Xt2.set_col( 0,KF.mu ); |
---|
[7] | 47 | for ( int t=1;t<Ndat;t++ ) { |
---|
| 48 | KF.bayes( Dt.get_col( t )); |
---|
[8] | 49 | KF2.bayes( Dt.get_col( t )); |
---|
[7] | 50 | Xt.set_col(t,KF.mu); |
---|
[8] | 51 | Xt2.set_col(t,KF2.mu); |
---|
[7] | 52 | // Kmu = KF.mu; |
---|
| 53 | // cout << "t:" <<t<< " " << dt<<" "<<Kmu <<endl; |
---|
| 54 | } |
---|
| 55 | |
---|
[9] | 56 | it_file fou( "testKF_res.it" ); |
---|
[7] | 57 | fou << Name("xth") << Xt; |
---|
[8] | 58 | fou << Name("xth2") << Xt2; |
---|
[7] | 59 | //Exit program: |
---|
| 60 | return 0; |
---|
| 61 | |
---|
| 62 | } |
---|