Révision 421
Ajouté par anclaud il y a presque 4 ans
sp4a3_kalman.c | ||
---|---|---|
}
|
||
}
|
||
}
|
||
|
||
|
||
// Fonction qui effectue l'operation out = A * B (matrice)
|
||
void Mul_Mat_Mat(int na,int ma,double A[na][ma], int nb,int mb,double B[nb][mb], double out[na][mb])
|
||
{
|
||
int i, j, k;
|
||
... | ... | |
}
|
||
}
|
||
}
|
||
|
||
void Copie_Mat(int na,int ma,double A[na][ma], double out[na][ma]){
|
||
int i=0, j=0;
|
||
for (i=0; i<na; i++)
|
||
for (j=0; j<ma; j++){
|
||
out[i][j]=A[i][j];
|
||
}
|
||
}
|
||
|
||
|
||
|
||
void tests_unitaires(void){
|
||
//Matrices d'entrée
|
||
double T21a[2][1]={{7},{-5}};
|
||
... | ... | |
{
|
||
t -= t0;x -= x0;y -= 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
|
||
// X = F*X
|
||
double mat_copie[4][1];
|
||
Copie_Mat(4,1,X,mat_copie);
|
||
Mul_Mat_Mat(4,4,F,4,1,mat_copie,X);
|
||
Plot_Mat(X," X(k+1|k) = ");
|
||
|
||
//P = F*P*F'+Q;
|
||
//P = F*P*F'+Q;
|
||
double mat_inter[4][4], mat_inter_bis[4][4];
|
||
Mul_Mat_Mat(4,4,F,4,4,P,mat_inter);
|
||
Mul_Mat_Mat(4,4,mat_inter,4,4,FT,mat_inter_bis);
|
||
Add_Mat_Mat(4,4,mat_inter_bis,4,4,Q,P);
|
||
Plot_Mat(P,"P(k+1|k) = F.P(k|k).FT + Q = ");
|
||
|
||
// K = P*H' / ( H*P*H' + R);
|
||
Plot_Mat(K,"K = ");
|
||
// K = P*H' / ( H*P*H' + R);
|
||
double mat_inter1[4][2];
|
||
Mul_Mat_Mat(4, 4, P, 4, 2, HT, mat_inter1); // P*H'
|
||
Plot_Mat(mat_inter1,"P(k+1|k).HT = ");
|
||
|
||
double mat_inter2[2][2], mat_inter3[2][2];
|
||
Mul_Mat_Mat(2, 4, H, 4, 2, mat_inter1, mat_inter2); // H*P*H'
|
||
Add_Mat_Mat(2, 2, mat_inter2, 2, 2, R, mat_inter3); // H*P*H' + R
|
||
Plot_Mat(mat_inter3, "H.P(k+1|k).HT + R = ");
|
||
|
||
double mat_inter4[2][2];
|
||
Inverse_Mat_22(2, 2, mat_inter3, mat_inter4); // inv(H*P*H' + R)
|
||
Plot_Mat(mat_inter4, "INV(H.P(k+1|k).HT + R) = ");
|
||
|
||
Mul_Mat_Mat(4, 2, mat_inter1, 2, 2, mat_inter4, 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)");
|
||
//X = X + K*([xb(i);yb(i)]-H*X);
|
||
|
||
double Obs[2][1]= {{x},
|
||
{y}};
|
||
double Delta[2][1], mat_inter5[2][1];
|
||
Mul_Mat_Mat(2,4,H,4,1,X,mat_inter5); // H*X
|
||
Sub_Mat_Mat(2,1,Obs,2,1,mat_inter5,Delta); // Delta = Obs - H*X
|
||
Plot_Mat(Delta,"DELTA = Obs - H.X(k+1|k)");
|
||
|
||
double mat_inter6[2][1];
|
||
Mul_Mat_Mat(4,2,K,2,1,Delta,mat_inter6); // K*Delta
|
||
Add_Mat_Mat(4,1,X,4,1,mat_inter6,X); // X = X + K*Delta
|
||
Plot_Mat(X," X(k+1|k+1) = X(k+1|k) + K.Delta = ");
|
||
|
||
// P = P - K*H*P;
|
||
// P = P - K*H*P;
|
||
double mat_inter7[4][4], mat_inter8[4][4];
|
||
Mul_Mat_Mat(4,2,K,2,4,H,mat_inter7);
|
||
Mul_Mat_Mat(4,4,mat_inter7,4,4,P,mat_inter8);
|
||
Sub_Mat_Mat(4,4,P,4,4,mat_inter8,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
Filtre Kalman OK