00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 #include "LKFfunctions.h"
00013 
00014 void LKFStatePropagator(KalmanFilter* kf) {
00015         
00016         
00017         Vector states, controls, measurements, parameters;
00018         states = kf->GetStateVector();
00019         controls = kf->GetControlVector();
00020         measurements = kf->GetMeasurementVector();
00021         parameters = kf->GetParameterVector();
00022         
00023         
00024         int lengthOfStateVector;
00025         lengthOfStateVector = states.getIndexCount();
00026         
00027         
00028         Matrix phi; 
00029         phi = eye(lengthOfStateVector) + kf->GetStateJacobianMatrix() * kf->GetTimeStep();  
00030         
00031         
00032         states = phi * states;
00033         
00034         
00035         kf->SetStateVector(states);
00036         
00037 };
00038 
00039 void LKFCovarianceMatrixPropagator(KalmanFilter* kf) {
00040         
00041         
00042         Vector states, controls, measurements, parameters;
00043         states = kf->GetStateVector();
00044         controls = kf->GetControlVector();
00045         measurements = kf->GetMeasurementVector();
00046         parameters = kf->GetParameterVector();
00047         
00048         
00049         Matrix covariance, kalmanGain;
00050         covariance = kf->GetCovarianceMatrix();
00051         kalmanGain = kf->GetKalmanGainMatrix();
00052         
00053         
00054         int lengthOfStateVector;
00055         lengthOfStateVector = states.getIndexCount();
00056         
00057         
00058         Matrix phi; 
00059         phi = eye(lengthOfStateVector) + kf->GetStateJacobianMatrix() * kf->GetTimeStep();
00060         
00061         
00062         Matrix Qk; 
00063         Qk = kf->GetSystemProcessNoiseMatrix();
00064         
00065         
00066         covariance = phi * covariance * ~phi + Qk;
00067         
00068         
00069         kf->SetCovarianceMatrix(covariance);
00070         
00071 };
00072 
00073 void LKFCalcualteKalmanGain(KalmanFilter* kf) {
00074         
00075         
00076         
00077 
00078 
00079 
00080 
00081 
00082         
00083         
00084         Matrix covariance, kalmanGain;
00085         covariance = kf->GetCovarianceMatrix();
00086         
00087         
00088         
00089         
00090         
00091         
00092         
00093         Matrix Hk; 
00094         Hk = kf->GetMeasurementJacobianMatrix();
00095         
00096         
00097         kalmanGain = (covariance * ~Hk) * (Hk * covariance * ~Hk + kf->GetMeasurementCovarianceMatrix()).inverse();
00098         
00099         kf->SetKalmanGainMatrix(kalmanGain);
00100         
00101 };
00102 
00103 void LKFStateMeasurementUpdate(KalmanFilter* kf) {
00104         
00105         
00106         Vector states, controls, measurements, parameters;
00107         states = kf->GetStateVector();
00108         controls = kf->GetControlVector();
00109         measurements = kf->GetMeasurementVector();
00110         parameters = kf->GetParameterVector();
00111         
00112         
00113         Matrix covariance, kalmanGain;
00114         covariance = kf->GetCovarianceMatrix();
00115         kalmanGain = kf->GetKalmanGainMatrix();
00116         
00117         
00118         
00119         
00120         
00121         
00122         Matrix Hk;
00123         Hk = kf->GetMeasurementJacobianMatrix();
00124         
00125         
00126         states = states + kalmanGain * (measurements - kf->GetEstimatedMeasurements());
00127         
00128         
00129         kf->SetStateVector(states);
00130         
00131 };
00132 
00133 void LKFCovarianceMeasurementUpdate(KalmanFilter* kf) {
00134         
00135         
00136         Vector states, controls, measurements, parameters;
00137         states = kf->GetStateVector();
00138         
00139 
00140 
00141 
00142         
00143         
00144         Matrix covariance, kalmanGain;
00145         covariance = kf->GetCovarianceMatrix();
00146         kalmanGain = kf->GetKalmanGainMatrix();
00147         
00148         
00149         int lengthOfStateVector;
00150         lengthOfStateVector = states.getIndexCount();
00151         
00152         
00153         Matrix Hk; 
00154         Hk = kf->GetMeasurementJacobianMatrix();
00155         
00156         
00157         covariance = (eye(lengthOfStateVector) - kalmanGain * Hk) * covariance;
00158         
00159         
00160         kf->SetCovarianceMatrix(covariance);
00161         
00162 };
00163 
00164 Matrix Fmatrix(KalmanFilter* kf) {
00165         
00166         Matrix temp(2,2);
00167         
00168         temp(1,1) = 0.1; temp(1,2) = 0.0;
00169         temp(2,1) = 0.0; temp(2,2) = 0.1;
00170         
00171         return temp;
00172         
00173 };
00174 
00175 Matrix Hmatrix(KalmanFilter* kf) {
00176         
00177         Matrix temp(2,2);
00178         
00179         temp(1,1) = 0.1; temp(1,2) = 0.0;
00180         temp(2,1) = 0.0; temp(2,2) = 0.1;
00181         
00182         return temp;
00183         
00184 };
00185 
00186 Matrix Qmatrix(KalmanFilter* kf) {
00187         
00188         Matrix temp(2,2);
00189         
00190         temp(1,1) = 0.1; temp(1,2) = 0.0;
00191         temp(2,1) = 0.0; temp(2,2) = 0.1;
00192 
00193         return temp;
00194 
00195 };
00196 
00197 Matrix Rmatrix(KalmanFilter* kf) {
00198         
00199         Matrix temp(2,2);
00200         
00201         temp(1,1) = 0.1; temp(1,2) = 0.0;
00202         temp(2,1) = 0.0; temp(2,2) = 0.1;
00203         
00204         return temp;
00205         
00206 };
00207 
00208 
00209 
00210 
00211 
00212 
00213 
00214 
00215 
00216 
00217 
00218 
00219 
00220 
00221 
00222 
00223 
00224 
00225 
00226 
00227 
00228 
00229 
00230 
00231 
00232 
00233 
00234 
00235 
00236 
00237 
00238 
00239 
00240 
00241 
00242 
00243 
00244 
00245 
00246