Projet

Général

Profil

« Précédent | Suivant » 

Révision 568

Ajouté par Guillaume DAVID il y a environ 3 ans

ajout mise à jour et affichage(qui est faux)

Voir les différences:

branch/david_guillaume/sp4a3/sp4a3_kalman.c
t -= t0;xobs -= x0;yobs -= y0;
debug=0; ///Mettre à 1 pour afficher les matrices.
///Ajouter votre code ci-dessous///
// Kalman
/**< PREDICTION >**/
/** X = F*X **/
/** X1 = F*X **/
double X1[4][1];
Mul_Mat_Mat(4,4,F,4,1,X,X1);
/** P = F*P*Ft + Q **/
Plot_Mat(X1," X(k+1|k) = ");
/** P1 = F*P*Ft + Q **/
double Pint1[4][4],Pint2[4][4],P1[4][4];
Mul_Mat_Mat(4,4,P,4,4,FT,Pint1);
Mul_Mat_Mat(4,4,F,4,4,Pint1,Pint2);
Add_Mat_Mat(4,4,Pint1,4,4,Q,P1);
Plot_Mat(P1,"P(k+1|k) = F.P(k|k).FT + Q = ");
/**< GAIN >**/
/** K = P1*Ht*inv(H*P1*Ht + R) **/
double Kint1[4][4],Kint2[4][4],Kint3[4][4],Kint4[4][4],Kint5[4][4];
......
Mul_Mat_Mat(4,2,HT,2,2,Kint4,Kint5);
Mul_Mat_Mat(4,4,P1,4,2,Kint5,K);
Plot_Mat(K,"K = ");
/**< MISE A JOUR >**/
/** D = Obs - H*X1 **/
double Dint1[2][4],D[2][1];
double Obs[2][1]={{xobs},{yobs}};
Mul_Mat_Mat(2,4,H,4,1,X1,Dint1);
Sub_Mat_Mat(2,1,Obs,2,1,Dint1,D);
/** X11 = X1+ K*D **/
double X11int1[4][1],X11[4][1];
Mul_Mat_Mat(4,2,K,2,1,D,X11int1);
Add_Mat_Mat(4,1,X1,4,1,X11int1,X11);
Plot_Mat(X11," X(k+1|k+1) = X(k+1|k) + K.Delta = ");
/** P11 = P1 - K*H*P1 **/
double P11int1[4][1],P11int2[4][1],P11[4][1];
Mul_Mat_Mat(2,4,H,4,4,P1,P11int1);
Mul_Mat_Mat(4,2,K,2,4,P11int1,P11int2);
Sub_Mat_Mat(4,4,P1,4,4,P11int2,P11);
Plot_Mat(P11," P(k+1|k+1) = P(k+1|k) - K.H.P(k+1|k) = ");
/**< AFFICHAGE >**/
int i,j;
for(i=0;i<4;i++){
for(j=0;j<1;j++) {
X[i][j] = X11[i][j];
}
}
for(i=0;i<4;i++){
for(j=0;j<4;j++) {
P[i][j] = P11[i][j];
}
}
/**< FIN >**/
// X = F*X
Plot_Mat(X1," X(k+1|k) = ");
//P = F*P*F'+Q;
Plot_Mat(P1,"P(k+1|k) = F.P(k|k).FT + Q = ");
// K = P*H' / ( H*P*H' + R);
Plot_Mat(K,"K = ");
//X = X + K*([xobs(i);yobs(i)]-H*X);
//Plot_Mat(Delta,"DELTA = Obs - H.X(k+1|k)");
Plot_Mat(X11," X(k+1|k+1) = X(k+1|k) + K.Delta = ");
// P = P - K*H*P;
Plot_Mat(P11," P(k+1|k+1) = P(k+1|k) - K.H.P(k+1|k) = ");
/// La matrice X doit contenir la position filtrée ///
}
t = cpt * dt;
dx = (xobs - oldx)/dt;

Formats disponibles : Unified diff