Révision 250
Ajouté par magraffin il y a presque 4 ans
sp4a3_kalman.c | ||
---|---|---|
}
|
||
}
|
||
}
|
||
|
||
void copie_mat(int na,int ma,double A[na][ma],double B[na][ma]){
|
||
int i,j;
|
||
for (i=0;i<na;i++){
|
||
for (j=0;j<ma;j++){
|
||
B[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 Res1[4][1];
|
||
Mul_Mat_Mat(4,4,F,4,1,X,Res1);
|
||
copie_mat(4,1,Res1,X);
|
||
|
||
Plot_Mat(X," X(k+1|k) = ");
|
||
|
||
//P = F*P*F'+Q;
|
||
//P = F*P*F'+Q;
|
||
double Res2[4][4],Res3[4][4],Res4[4][4],Res5[4][4];
|
||
Transpose_Mat(4,4,F,Res2); //F'
|
||
Mul_Mat_Mat(4,4,F,4,4,P,Res3); //F*P
|
||
Mul_Mat_Mat(4,4,Res3,4,4,Res2,Res4); //F*P*F'
|
||
Add_Mat_Mat(4,4,Res4,4,4,Q,Res5); //F*P*F'+Q
|
||
copie_mat(4,4,Res5,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);
|
||
double Res6[4][2],Res7[2][2],Res8[2][2],Res9[4][2];
|
||
Transpose_Mat(2,4,H,Res6); // H'
|
||
Mul_Mat_Mat(4,4,P,4,2,Res2,Res9); //P*H'
|
||
Mul_Mat_Mat(2,4,H,4,2,Res9,Res7); //H*P*H'
|
||
Add_Mat_Mat(2,2,Res7,2,2,R,Res8); //H*P*H'+R
|
||
Inverse_Mat_22(2,2,Res8,Res7); //H*P*H'+R ** (-1)
|
||
Mul_Mat_Mat(4,2,Res9,2,2,Res7,Res6);
|
||
copie_mat(4,2,Res6,K);
|
||
|
||
|
||
Plot_Mat(K,"K = ");
|
||
|
||
//X = X + K*([xb(i);yb(i)]-H*X);
|
||
//X = X + K*([xb(i);yb(i)]-H*X);
|
||
double Res10[2][1],Vect[2][1],Res11[2][1],Res12[4][1],Res13[4][1];
|
||
Mul_Mat_Mat(2,4,H,4,1,X,Res10);//H*X
|
||
Vect[0][0]=x;
|
||
Vect[1][0]=y;
|
||
Sub_Mat_Mat(2,1,Vect,2,1,Res10,Res11); //[xb(i);yb(i)]-H*X
|
||
Mul_Mat_Mat(4,2,K,2,1,Res11,Res12); //K*([xb(i);yb(i)]-H*X)
|
||
Add_Mat_Mat(4,1,X,4,1,Res12,Res13);// X + K*([xb(i);yb(i)]-H*X);
|
||
copie_mat(4,1,Res13,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 = ");
|
||
|
||
// P = P - K*H*P;
|
||
// P = P - K*H*P;
|
||
Mul_Mat_Mat(4,2,K,2,4,H,Res2); //K*H
|
||
Mul_Mat_Mat(4,4,Res2,4,4,P,Res3); //K*H*P
|
||
Sub_Mat_Mat(4,4,P,4,4,Res4,Res2);
|
||
copie_mat(4,4,Res2,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 ///
|
||
... | ... | |
system ("gnuplot -p -e \"plot 'output.dat' u 5:6 w l, '' u 2:3 w l\";");
|
||
system ("gnuplot -p -e \"plot 'output.dat' u 1:9 w l, '' u 1:4 w l\";");
|
||
system ("gnuplot -p -e \"plot 'vitesse_reelle.dat' u 2 w l, 'output.dat' u 9 w l\";");
|
||
return 0;
|
||
}
|
||
return 0;
|
||
|
||
}
|
||
|
Formats disponibles : Unified diff
Fin de l'implémentation du filtre il reste une erreur sur K