Projet

Général

Profil

« Précédent | Suivant » 

Révision 567

Ajouté par Louis JACQUET il y a presque 3 ans

filtre avancé dans les calculs, et entrees definies

Voir les différences:

branch/JACQUET/sp4a3/sp4a3_kalman.c
// kalman param
double sigma_etat = 10.0;
double sigma_observation = 2.0;
double X[4][1] = {{0},{0},{0},{0}};
double X[4][1] = {{0},{0},{0},{0}};
double X1[4][1];
double X2[4][1];
double P[4][4] = {{sigma_etat*sigma_etat, 0, 0, 0},
{0, sigma_etat*sigma_etat, 0, 0},
......
double R[2][2] = {{sigma_observation*sigma_observation, 0},
{0 , sigma_observation*sigma_observation}};
double K[4][2];
double K[4][2];
double K1[4][2];
double H[2][4] = {{1, 0, 0, 0},
{0, 1, 0, 0}};
double HT[4][2];
......
{0, 0, 1, 0},
{0, 0, 0, 1}};
double FT[4][4];
Transpose_Mat(4,4,F,FT);
Transpose_Mat(4,4,F,FT);
double P1[4][4]; // declaration matrice pour calcul
double P2[4][4];
double R1[4][4];
double R2[4][4];
double R3[2][4];
double R4[2][2];
double R5[2][2];
double R6[2][2];
double R7[2][1];
double R8[4][1];
double R9[4][4];
double R10[4][4];
double DELT[2][1];
while(fscanf(fichier, "%lf %lf %lf", &t, &xobs, &yobs)>0){
printf("-------------%04d--------------\n",cpt);
printf("-------------%04d--------------\n",cpt);
double Obs[2][1] = {{xobs},{yobs}};
int i,j;
if (cpt ==0)
{
t0=t;x0=xobs;y0=yobs;
......
{
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
// X = F*X
Plot_Mat(X," X(k+1|k) = ");
// X = F*X
Mul_Mat_Mat(4,4,F,4,1,X,X1);
Plot_Mat(X," X(k+1|k) = ");
//P = F*P*F'+Q;
Plot_Mat(P,"P(k+1|k) = F.P(k|k).FT + Q = ");
// K = P*H' / ( H*P*H' + R);
Plot_Mat(K,"K = ");
//P = F*P*F'+Q;
Mul_Mat_Mat(4,4,F,4,4,P,R1);
Mul_Mat_Mat(4,4,R1,4,4,FT,R2);
Add_Mat_Mat(4,4,R2,4,4,Q,P1);
//X = X + K*([xobs(i);yobs(i)]-H*X);
//Plot_Mat(Delta,"DELTA = Obs - H.X(k+1|k)");
Plot_Mat(X," X(k+1|k+1) = X(k+1|k) + K.Delta = ");
Plot_Mat(P,"P(k+1|k) = F.P(k|k).FT + Q = ");
// P = P - K*H*P;
Plot_Mat(P," P(k+1|k+1) = P(k+1|k) - K.H.P(k+1|k) = ");
// K = P*H' / ( H*P*H' + R);
//separation des deux blocs
Mul_Mat_Mat(4,4,P1,4,2,HT,K1); //numerateur
Mul_Mat_Mat(2,4,H,4,4,P1,R3); //denominateur
Mul_Mat_Mat(2,4,R3,4,2,HT,R4);
Add_Mat_Mat(2,2,R4,2,2,R,R5);
Inverse_Mat_22(2,2,R5,R6); // inversion denominateur
Mul_Mat_Mat(4,2,K1,2,2,R6,K); //multiplication numerateur et inverse denominateur
Plot_Mat(K,"K = ");
//Delt
Mul_Mat_Mat(2,4,H,4,1,X1,R7);
Sub_Mat_Mat(2,1,Obs,2,1,R7,DELT);
Plot_Mat(DELT,"DELT = Obs - H.X(k+1|k)");
//X = X + K*([xobs(i);yobs(i)]-H*X) = X + K*delt;
Mul_Mat_Mat(4,2,K,2,1,DELT,R8);
Add_Mat_Mat(4,1,X1,2,1,R8,X2);
Plot_Mat(X," X(k+1|k+1) = X(k+1|k) + K.DELT = ");
// P = P - K*H*P;
Mul_Mat_Mat(4,2,K,2,4,H,R9);
Mul_Mat_Mat(4,4,R9,4,4,P1,R10);
Sub_Mat_Mat(4,4,P1,4,4,R10,P2);
Plot_Mat(P," P(k+1|k+1) = P(k+1|k) - K.H.P(k+1|k) = ");
for (i=0;i<4;i++){
for(j=0;j<1;j++) {
X[i][j] = X2[i][j];
}
}
for (i=0;i<4;i++){
for(j=0;j<4;j++) {
P[i][j] = P2[i][j];
}
}
/// La matrice X doit contenir la position filtrée ///
}
t = cpt * dt;

Formats disponibles : Unified diff