Révision 422
Ajouté par frkanaan il y a presque 4 ans
branch/KANAAN/sp4a3/sp4a3_kalman.c | ||
---|---|---|
|
||
void Mul_Mat_Mat(int na,int ma,double A[na][ma], int nb,int mb,double B[nb][mb], double out[na][mb])
|
||
{
|
||
|
||
if(ma==nb)
|
||
{
|
||
int i,j,k;
|
||
double temp[nb][mb];
|
||
|
||
for(i=0; i<nb; i++)
|
||
for(j=0; j<mb; j++)
|
||
temp[i][j]=B[i][j];
|
||
|
||
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];
|
||
out[i][j] += A[i][k] * temp[k][j];
|
||
}
|
||
}
|
||
}
|
||
... | ... | |
|
||
printf("Execution des tests unitaires.\n");
|
||
Transpose_Mat(2,4,T24,R42);
|
||
if (!Equal_Mat_Mat(RTT24,R42)) error("Erreur calcul Transposition 2x4");
|
||
if (!Equal_Mat_Mat(RTT24,R42))
|
||
error("Erreur calcul Transposition 2x4");
|
||
Transpose_Mat(4,4,T44a,R44);
|
||
if (!Equal_Mat_Mat(RTT44,R44)) error("Erreur calcul Transposition 4x4");
|
||
if (!Equal_Mat_Mat(RTT44,R44))
|
||
error("Erreur calcul Transposition 4x4");
|
||
Inverse_Mat_22(2,2,T22a,R22);
|
||
if (!Equal_Mat_Mat(RInvT22,R22)) error("Erreur calcul Inversion 2x2");
|
||
if (!Equal_Mat_Mat(RInvT22,R22))
|
||
error("Erreur calcul Inversion 2x2");
|
||
Add_Mat_Mat(2,2,T22a,2,2,T22b,R22);
|
||
if (!Equal_Mat_Mat(RAT22,R22)) error("Erreur calcul Addition 2x2");
|
||
if (!Equal_Mat_Mat(RAT22,R22))
|
||
error("Erreur calcul Addition 2x2");
|
||
Add_Mat_Mat(4,4,T44a,4,4,T44b,R44);
|
||
if (!Equal_Mat_Mat(RAT44,R44)) error("Erreur calcul Addition 4x4");
|
||
if (!Equal_Mat_Mat(RAT44,R44))
|
||
error("Erreur calcul Addition 4x4");
|
||
Add_Mat_Mat(4,1,T41a,4,1,T41b,R41);
|
||
if (!Equal_Mat_Mat(RAT41,R41)) error("Erreur calcul Addition 4x1");
|
||
if (!Equal_Mat_Mat(RAT41,R41))
|
||
error("Erreur calcul Addition 4x1");
|
||
Sub_Mat_Mat(2,1,T21a,2,1,T21b,R21);
|
||
if (!Equal_Mat_Mat(RST21,R21)) error("Erreur calcul Soustraction 2x1");
|
||
if (!Equal_Mat_Mat(RST21,R21))
|
||
error("Erreur calcul Soustraction 2x1");
|
||
Sub_Mat_Mat(4,4,T44a,4,4,T44b,R44);
|
||
if (!Equal_Mat_Mat(RST44,R44)) error("Erreur calcul Soustraction 4x4");
|
||
if (!Equal_Mat_Mat(RST44,R44))
|
||
error("Erreur calcul Soustraction 4x4");
|
||
Mul_Mat_Mat(4,4,T44a,4,4,T44b,R44);
|
||
if (!Equal_Mat_Mat(RMT44T44,R44)) error("Erreur calcul Multiplication 4x4 4x4");
|
||
if (!Equal_Mat_Mat(RMT44T44,R44))
|
||
error("Erreur calcul Multiplication 4x4 4x4");
|
||
Mul_Mat_Mat(4,4,T44a,4,1,T41a,R41);
|
||
if (!Equal_Mat_Mat(RMT44T41,R41)) error("Erreur calcul Multiplication 4x4 4x1");
|
||
if (!Equal_Mat_Mat(RMT44T41,R41))
|
||
error("Erreur calcul Multiplication 4x4 4x1");
|
||
Mul_Mat_Mat(4,4,T44a,4,2,T42a,R42);
|
||
if (!Equal_Mat_Mat(RMT44T42,R42)) error("Erreur calcul Multiplication 4x4 4x2");
|
||
if (!Equal_Mat_Mat(RMT44T42,R42))
|
||
error("Erreur calcul Multiplication 4x4 4x2");
|
||
Mul_Mat_Mat(4,2,T42a,2,1,T21a,R41);
|
||
if (!Equal_Mat_Mat(RMT42T21,R41)) error("Erreur calcul Multiplication 4x2 2x1");
|
||
if (!Equal_Mat_Mat(RMT42T21,R41))
|
||
error("Erreur calcul Multiplication 4x2 2x1");
|
||
Mul_Mat_Mat(4,2,T42a,2,2,T22a,R42);
|
||
if (!Equal_Mat_Mat(RMT42T22,R42)) error("Erreur calcul Multiplication 4x2 2x2");
|
||
if (!Equal_Mat_Mat(RMT42T22,R42))
|
||
error("Erreur calcul Multiplication 4x2 2x2");
|
||
Mul_Mat_Mat(4,2,T42a,2,4,T24,R44);
|
||
if (!Equal_Mat_Mat(RMT42T24,R44)) error("Erreur calcul Multiplication 4x2 2x4");
|
||
if (!Equal_Mat_Mat(RMT42T24,R44))
|
||
error("Erreur calcul Multiplication 4x2 2x4");
|
||
Mul_Mat_Mat(2,4,T24,4,1,T41a,R21);
|
||
if (!Equal_Mat_Mat(RMT24T41,R21)) error("Erreur calcul Multiplication 2x4 4x1");
|
||
if (!Equal_Mat_Mat(RMT24T41,R21))
|
||
error("Erreur calcul Multiplication 2x4 4x1");
|
||
Mul_Mat_Mat(2,4,T24,4,2,T42a,R22);
|
||
if (!Equal_Mat_Mat(RMT24T42,R22)) error("Erreur calcul Multiplication 2x4 4x2");
|
||
if (!Equal_Mat_Mat(RMT24T42,R22))
|
||
error("Erreur calcul Multiplication 2x4 4x2");
|
||
Mul_Mat_Mat(2,4,T24,4,4,T44a,R24);
|
||
if (!Equal_Mat_Mat(RMT24T44,R24)) error("Erreur calcul Multiplication 2x4 4x4");
|
||
if (!Equal_Mat_Mat(RMT24T44,R24))
|
||
error("Erreur calcul Multiplication 2x4 4x4");
|
||
printf("Test unitaires OK.\n");
|
||
}
|
||
|
||
... | ... | |
debug=1; ///Mettre à 1 pour afficher les matrices.
|
||
///Ajouter votre code ci-dessous///
|
||
// Kalman
|
||
|
||
Plot_Mat(X," X(k|k) = ");
|
||
// X = F*X
|
||
Mul_Mat_Mat(4, 4, F, 4, 1, X, X);
|
||
Plot_Mat(X," X(k+1|k) = ");
|
||
|
||
Plot_Mat(P," P(k|k) = ");
|
||
//P = F*P*F'+Q;
|
||
double FP[4][4];
|
||
double FPFT[4][4];
|
||
... | ... | |
Add_Mat_Mat(2, 2, HPHT, 2, 2, R, denom);
|
||
Inverse_Mat_22(2, 2, denom, inv_denom);
|
||
Mul_Mat_Mat(4, 2, PHT, 2, 2, inv_denom, K);
|
||
|
||
Plot_Mat(PHT,"P(k+1|k).HT = ");
|
||
Plot_Mat(denom,"H.P(k+1|k).HT + R = ");
|
||
Plot_Mat(inv_denom,"INV(H.P(k+1|k).HT + R) = ");
|
||
Plot_Mat(K,"K = ");
|
||
|
||
//X = X + K*([xb(i);yb(i)]-H*X);
|
||
... | ... | |
Sub_Mat_Mat(2, 1, obs, 2, 1, HX, temp);
|
||
Mul_Mat_Mat(4, 2, K, 2, 1, temp, Ktemp);
|
||
Add_Mat_Mat(4, 1, X, 4, 1, Ktemp, X);
|
||
Plot_Mat(obs,"Obs = ");
|
||
Plot_Mat(temp,"DELTA = Obs - H.X(k+1|k)");
|
||
|
||
//Plot_Mat(Delta,"DELTA = Obs - H.X(k+1|k)");
|
||
Plot_Mat(X," X(k+1|k+1) = X(k+1|k) + K.Delta = ");
|
Formats disponibles : Unified diff
fixed an error with Mul_Mat_Mat