root/tests/testKF.cpp @ 33

Revision 33, 1.9 kB (checked in by smidl, 16 years ago)

Oprava PF a MPF + jejich implementace pro pmsm system

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        // Kalman 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,Xtf;
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        Xtf=zeros( 2,Ndat );
45        XtE=zeros( 2,Ndat );
46
47//      cout << KF;
48        RV rx("1","{x}","2","0");
49        RV ru("2","{u}","1","0");
50        RV ry("3","{y}","1","0");
51        //
52        Kalman<ldmat> KF(rx,ry,ru);
53        KF.set_parameters(A,B,C,D,ldmat(R),ldmat(Q));
54        KF.set_est(mu0,ldmat(P0) );
55        //
56        Kalman<fsqmat> KFf(rx,ry,ru);
57        KFf.set_parameters(A,B,C,D,fsqmat(R),fsqmat(Q));
58        KFf.set_est(mu0,fsqmat(P0) );
59        //
60        KalmanFull KF2( A,B,C,D,R,Q,P0,mu0 );
61        //
62        bilinfn fxu(rx,ru,A,B);
63        bilinfn hxu(rx,ru,C,D);
64        EKF<ldmat> KFE(rx,ry,ru);
65        KFE.set_parameters(&fxu,&hxu,Q,R);
66        KFE.set_est(mu0,P0);
67
68        epdf& KFep = KF._epdf();
69        epdf& KFfep = KFf._epdf();
70        epdf& KFEep = KFE._epdf();
71       
72        Xt.set_col( 0,KFep.mean() );
73        Xtf.set_col( 0,KFfep.mean() );
74        Xt2.set_col( 0,KF2.mu );
75        XtE.set_col( 0,KFEep.mean() );
76        for ( int t=1;t<Ndat;t++ ) {
77                KFf.bayes( Dt.get_col( t ));
78                KF.bayes( Dt.get_col( t ));
79                KF2.bayes( Dt.get_col( t ));
80                KFE.bayes( Dt.get_col( t ));
81                Xt.set_col( t,KFep.mean() );
82                Xtf.set_col( t,KFfep.mean() );
83                Xt2.set_col(t,KF2.mu);
84                XtE.set_col( t,KFEep.mean() );
85        }
86
87        it_file fou( "testKF_res.it" );
88        fou << Name("xth") << Xt;
89        fou << Name("xthf") << Xtf;
90        fou << Name("xth2") << Xt2;
91        fou << Name("xthE") << XtE;
92        //Exit program:
93        return 0;
94
95}
Note: See TracBrowser for help on using the browser.