Projet

Général

Profil

« Précédent | Suivant » 

Révision 459

Ajouté par ahkurklu il y a presque 4 ans

Implémentation des itération du filtre Kalman.

Voir les différences:

branch/KURKLU/sp4a3/sp4a3_kalman.c
}
void Copy_Mat(int n,int m,double tab1[n][m],double tab2[n][m]){
int i,j;
for(i=0;i<n;i++){
for(j=0;j<m;j++)
tab2[i][j] = tab1[i][j];
}
}
......
double FT[4][4];
Transpose_Mat(4,4,F,FT);
double tmp[4][4] = {{0, 0, 0, 0},
double tmp1[4][4] = {{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0}};
{0, 0, 0, 0}};
double tmp2[4][4] = {{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0},
{0, 0, 0, 0}};
double obs[2][1];
double delta[2][1];
while(fscanf(fichier, "%lf %lf %lf", &t, &x, &y)>0){
printf("-------------%04d--------------\n",cpt);
......
debug=1; ///Mettre à 1 pour afficher les matrices.
///Ajouter votre code ci-dessous///
// Kalman
Plot_Mat(X," X(k|k) = ");
// X = F*X
Mul_Mat_Mat(4,4,F,4,1,X,X);
Mul_Mat_Mat(4,4,F,4,1,X,tmp1);
Copy_Mat(4,1,tmp1,X);
Plot_Mat(X," X(k+1|k) = ");
Plot_Mat(P,"P(k|k) = ");
//P = F*P*F'+Q;
/*
Mul_Mat_Mat(4,4,F,4,4,P,tmp);
Mul_Mat_Mat(4,4,tmp,4,4,FT,tmp);
Add_Mat_Mat(4,4,tmp,4,4,Q,P);
Mul_Mat_Mat(4,4,F,4,4,P,tmp1);
Mul_Mat_Mat(4,4,tmp1,4,4,FT,tmp2);
Add_Mat_Mat(4,4,tmp2,4,4,Q,P);
Plot_Mat(P,"P(k+1|k) = F.P(k|k).FT + Q = ");
*/
// K = P*H' / ( H*P*H' + R);
/*
Mul_Mat_Mat(4,2,K,2,4,HT,K);
Mul_Mat_Mat(2,4,H,4,4,P,tmp);
Mul_Mat_Mat(2,4,tmp,4,2,HT,tmp);
Add_Mat_Mat(2,2,tmp,2,2,R,tmp);
Inverse_Mat_22(2,2,tmp,tmp);
Mul_Mat_Mat(4,2,K,2,2,tmp,K);
Mul_Mat_Mat(2,4,H,4,4,P,tmp1);//H*P
Mul_Mat_Mat(2,4,tmp1,4,2,HT,tmp2);//H*P*H'
Add_Mat_Mat(2,2,tmp2,2,2,R,tmp1);//H*P*H' + R
Inverse_Mat_22(2,2,tmp1,tmp2);
Mul_Mat_Mat(4,4,P,4,2,HT,tmp1);//P*H'
Mul_Mat_Mat(4,2,tmp1,2,2,tmp2,K);//K = P*H' / ( H*P*H' + R)
Plot_Mat(K,"K = ");
//X = X + K*([xb(i);yb(i)]-H*X);
*/
//Plot_Mat(Delta,"DELTA = Obs - H.X(k+1|k)");
obs[0][0] = x;
obs[1][0] = y;
Plot_Mat(obs,"obs = ");
Mul_Mat_Mat(2,4,H,4,1,X,tmp1);
Sub_Mat_Mat(2,1,obs,2,1,tmp1,delta);
Plot_Mat(delta,"DELTA = Obs - H.X(k+1|k)");
Mul_Mat_Mat(4,2,K,2,1,delta,tmp2);
Add_Mat_Mat(4,1,X,4,1,tmp2,tmp1);
Copy_Mat(4,1,tmp1,X);
Plot_Mat(X," X(k+1|k+1) = X(k+1|k) + K.Delta = ");
// P = P - K*H*P;
// P = P - K*H*P;
Mul_Mat_Mat(4,2,K,2,4,H,tmp1);
Mul_Mat_Mat(4,4,tmp1,4,4,P,tmp2);
Sub_Mat_Mat(4,4,P,4,4,tmp2,tmp1);
Copy_Mat(4,4,tmp1,P);
Plot_Mat(P," P(k+1|k+1) = P(k+1|k) - K.H.P(k+1|k) = ");
/// La matrice X doit contenir la position filtrée ///

Formats disponibles : Unified diff