root/tests/testKF.cpp @ 28

Revision 28, 1.8 kB (checked in by smidl, 16 years ago)

prelozitelna verze

Line 
1#include <itpp/itbase.h>
2#include <estim/libKF.h>
3
4using namespace itpp;
5
6//These lines are needed for use of cout and endl
7using std::cout;
8using std::endl;
9
10int main() {
11
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
20        mat Dt, Xt,Xt2,XtE;
21        int Ndat;
22
23        bool xxx= fin.seek( "d" );
24        if (!xxx){ it_error("testKF.it not found");}
25        fin >>Dt;
26        fin.seek( "A" ); 
27        fin >> A;
28        fin.seek( "B" ); 
29        fin >> B;
30        fin.seek( "C" ); 
31        fin >> C;
32        fin.seek( "D" ); 
33        fin >> D;
34        fin.seek( "R" ); 
35        fin >> R;
36        fin.seek( "Q" ); fin >> Q;
37        fin.seek( "P0" ); fin >> P0;
38        fin.seek( "mu0" ); fin >> Mu0; 
39        mu0=Mu0.get_col(0);
40       
41        Ndat = Dt.cols();
42        Xt=zeros( 2,Ndat );
43        Xt2=zeros( 2,Ndat );
44        XtE=zeros( 2,Ndat );
45
46//      cout << KF;
47        RV rx("1","{x}","2","0","0");
48        RV ru("2","{u}","1","0","0");
49        RV ry("3","{y}","1","0","0");
50        //
51        Kalman<ldmat> KF(rx,ry,ru);
52        KF.set_parameters(A,B,C,D,ldmat(R),ldmat(Q));
53        KF.set_est(mu0,ldmat(P0) );
54        //
55        Kalman<fsqmat> KFf(rx,ry,ru);
56        KFf.set_parameters(A,B,C,D,fsqmat(R),fsqmat(Q));
57        KFf.set_est(mu0,fsqmat(P0) );
58        //
59        KalmanFull KF2( A,B,C,D,R,Q,P0,mu0 );
60        //
61        bilinfn fxu(rx,ru,A,B);
62        bilinfn hxu(rx,ru,C,D);
63        EKF<ldmat> KFE(rx,ry,ru);
64        KFE.set_parameters(&fxu,&hxu,Q,R);
65        KFE.set_est(mu0,P0);
66
67        Xt.set_col( 0,*((enorm<ldmat>*)(KF._epdf()))->_mu() );
68        Xt2.set_col( 0,KF2.mu );
69        XtE.set_col( 0,*((enorm<ldmat>*)(KFE._epdf()))->_mu() );
70        for ( int t=1;t<Ndat;t++ ) {
71                KFf.bayes( Dt.get_col( t ));
72                KF.bayes( Dt.get_col( t ));
73                KF2.bayes( Dt.get_col( t ));
74//              KFE.bayes( Dt.get_col( t ));
75                Xt.set_col(t,*((enorm<ldmat>*)(KF._epdf()))->_mu());
76                Xt2.set_col(t,KF2.mu);
77                XtE.set_col(t,*((enorm<ldmat>*)(KFE._epdf()))->_mu());
78        }
79
80        it_file fou( "testKF_res.it" );
81        fou << Name("xth") << Xt;
82        fou << Name("xth2") << Xt2;
83        fou << Name("xthE") << XtE;
84        //Exit program:
85        return 0;
86
87}
Note: See TracBrowser for help on using the browser.