Révision 356
Ajouté par jcguifodjo il y a presque 4 ans
sp4a3_kalman.c | ||
---|---|---|
#include "sp4a3_kalman_extra.h"
|
||
|
||
|
||
void Add_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double b[nb][mb], double out[na][ma]){
|
||
void Add_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double B[nb][mb], double out[na][ma]){
|
||
|
||
int i,j;
|
||
for(i=0;i<na;i++)
|
||
for(j=0;j<ma;j++)
|
||
out[i][j]=A[i][j]+B[i][j];
|
||
|
||
|
||
}
|
||
|
||
void Inverse_Mat_22(int n,int m,double A[n][m],double B[n][m]){
|
||
|
||
|
||
double det;
|
||
det=(A[0][0]*A[1][1])-(A[1][0]*A[0][1]);
|
||
B[0][0]=(A[1][1])/det;
|
||
B[0][1]=-(A[0][1])/det;
|
||
B[1][0]=-(A[1][0])/det;
|
||
B[1][1]=(A[0][0])/det;
|
||
}
|
||
|
||
void Transpose_Mat(int n,int m,double A[n][m],double R[m][n]){
|
||
... | ... | |
R[j][i]=A[i][j];
|
||
}
|
||
|
||
void Sub_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double b[nb][mb], double out[na][ma]){
|
||
|
||
void Sub_Mat_Mat(int na,int ma,double A[na][ma],int nb,int mb,double b[nb][mb], double out[na][ma]){
|
||
int i,j;
|
||
for(i=0;i<na;i++)
|
||
for(j=0;j<ma;j++)
|
||
out[i][j]=A[i][j]-b[i][j];
|
||
}
|
||
|
||
void Mul_Mat_Mat(int na,int ma,double A[na][ma], int nb,int mb,double B[nb][mb], double out[na][mb]){
|
||
|
||
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;
|
||
for (i=0; i<na; i++)
|
||
for (j=0; j<mb; j++)
|
||
{
|
||
out[i][j]=0;
|
||
for (k=0; k<ma; k++)
|
||
out[i][j] += (A[i][k])*(B[k][j]);
|
||
}
|
||
}
|
||
|
||
|
||
... | ... | |
{
|
||
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
|
||
Mul_Mat_Mat(4,4,F,4,1,X,X);
|
||
Plot_Mat(X," X(k+1|k) = ");
|
||
|
||
//P = F*P*F'+Q;
|
||
//P = F*P*F'+Q;
|
||
double A0[4][4],A1[4][4],A2[4][2],A3[2][4],A4[2][4],B[2][2],D[2][2],C[2][2],E[2][2];
|
||
double delta[2][1],Obs[2][1];
|
||
Mul_Mat_Mat(4,4,F,4,4,P,A0);
|
||
Mul_Mat_Mat(4,4,A0,4,4,FT,A1);
|
||
Add_Mat_Mat(4,4,A1,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);
|
||
Mul_Mat_Mat(4,4,P,4,2,HT,A2);
|
||
Mul_Mat_Mat(2,4,H,4,2,A2,B);
|
||
Add_Mat_Mat(2,2,B,2,2,R,C);
|
||
Inverse_Mat_22(2,2,C,D) ;
|
||
Mul_Mat_Mat(2,2,A2,2,2,D,K);
|
||
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);
|
||
|
||
//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(2,2,K,2,4,H,A3);
|
||
Mul_Mat_Mat(2,4,A3,4,4,P,A4);
|
||
Sub_Mat_Mat(4,4,P,2,4,A4,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
Q1 à Q6 Implantation des fonctions