Projet

Général

Profil

« Précédent | Suivant » 

Révision 542

Ajouté par Titouan PODGORSKI il y a environ 3 ans

Ajout des différents calculs - filtre de kalman fonctionnel

Voir les différences:

branch/Podgorski/sp4a3/sp4a3_kalman.c
Res[0][0]=A[1][1]*determinant;
Res[1][1]=A[0][0]*determinant;
Res[0][1]=-A[0][1]*determinant;
Res[1][0]=-A[1][0]*determinant;
//printf("\n %f %f\n %f %f\n",R[0][0] ,R[0][1] ,R[1][0] ,R[1][1]);
Res[1][0]=-A[1][0]*determinant;
}
void Transpose_Mat(int n,int m,double A[n][m],double R[m][n]){
......
{0, 0, 1, 0},
{0, 0, 0, 1}};
double FT[4][4];
Transpose_Mat(4,4,F,FT);
Transpose_Mat(4,4,F,FT);
// Matrices tampons qui serviront au calcul des différentes itérations du filtre
double Zero[4][1]={{0},{0},{0},{0}};
double Zero4[4][4]={{0,0,0,0},{0,0,0,0},{0,0,0,0},{0,0,0,0}};
double Xtampon[4][1];
double Ptampon[4][4];
double FfoisP[4][4];
double FfoisPfoisFT[4][4];
double HfoisX[2][1];
double TrucmoinsHfoisX[2][1];
double KfoisTrucmoinsHfoisX [4][1];
double HfoisP[2][4];
double KfoisHfoisP [4][4];
double PfoisHT[4][2];
double HfoisPfoisHT[2][2];
double HfoisPfoisHTplusR[2][2];
double INV_HfoisPfoisHTplusR[2][2];
while(fscanf(fichier, "%lf %lf %lf", &t, &xobs, &yobs)>0){
printf("-------------%04d--------------\n",cpt);
......
{
t -= t0;xobs -= x0;yobs -= y0;
debug=0; ///Mettre à 1 pour afficher les matrices.
debug=1; ///Mettre à 1 pour afficher les matrices.
///Ajouter votre code ci-dessous///
// Kalman
double XY[2][1]={{xobs},{yobs}};
// X = F*X
Plot_Mat(X," X(k+1|k) = ");
// X = F*X
Mul_Mat_Mat(4,4,F,4,1,X,Xtampon);
Plot_Mat(Xtampon," X(k+1|k) = ");
//P = F*P*F'+Q;
//P = F*P*F'+Q;
Transpose_Mat(4,4,F,FT);
Mul_Mat_Mat(4,4,F,4,4,P,FfoisP);
Mul_Mat_Mat(4,4,FfoisP,4,4,FT,FfoisPfoisFT);
Add_Mat_Mat(4,4,FfoisPfoisFT,4,4,Q,P);
Plot_Mat(P,"P(k+1|k) = F.P(k|k).FT + Q = ");
// K = P*H' / ( H*P*H' + R);
// K = P*H' / ( H*P*H' + R);
Transpose_Mat(2,4,H,HT);
Mul_Mat_Mat(4,4,P,4,2,HT,PfoisHT);
Mul_Mat_Mat(2,4,H,4,2,PfoisHT,HfoisPfoisHT);
Add_Mat_Mat(2,2,HfoisPfoisHT,2,2,R,HfoisPfoisHTplusR);
Inverse_Mat_22(2,2,HfoisPfoisHTplusR,INV_HfoisPfoisHTplusR);
Mul_Mat_Mat(4,2,PfoisHT,2,2,INV_HfoisPfoisHTplusR,K);
Plot_Mat(K,"K = ");
//X = X + K*([xobs(i);yobs(i)]-H*X);
//Plot_Mat(Delta,"DELTA = Obs - H.X(k+1|k)");
//X = X + K*([xobs(i);yobs(i)]-H*X);
Mul_Mat_Mat(2,4,H,4,1,Xtampon,HfoisX);
Sub_Mat_Mat(2,1,XY,2,1,HfoisX,TrucmoinsHfoisX);
Mul_Mat_Mat(4,2,K,2,1,TrucmoinsHfoisX,KfoisTrucmoinsHfoisX);
Add_Mat_Mat(4,1,Xtampon,4,1,KfoisTrucmoinsHfoisX,X);
Plot_Mat(XY,"OBS = ");
Plot_Mat(TrucmoinsHfoisX,"DELTA = Obs - H.X(k+1|k)");
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(2,4,H,4,4,P,HfoisP);
Mul_Mat_Mat(4,2,K,2,4,HfoisP,KfoisHfoisP);
Sub_Mat_Mat(4,4,P,4,4,KfoisHfoisP,Ptampon);
Add_Mat_Mat(4,4,Ptampon,4,4,Zero4,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