Main Page | Modules | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages | Examples

LKFfunctions.cpp

Go to the documentation of this file.
00001 /************************************************************************************************/
00002 /*! \file LKFfunctions.cpp
00003 *  \brief Definitions of the functions used by the KalmanFilter constructor.
00004 *  \author $Author: simpliciter $
00005 *  \version $Revision: 1.9 $
00006 *  \date    $Date: 2003/07/14 19:37:22 $
00007 ************************************************************************************************/
00008 /*! 
00009 *
00010 ************************************************************************************************/
00011 
00012 #include "LKFfunctions.h"
00013 
00014 void LKFStatePropagator(KalmanFilter* kf) {
00015         
00016         // Get sequential filter data
00017         Vector states, controls, measurements, parameters;
00018         states = kf->GetStateVector();
00019         controls = kf->GetControlVector();
00020         measurements = kf->GetMeasurementVector();
00021         parameters = kf->GetParameterVector();
00022         
00023         // Determine length of state vector
00024         int lengthOfStateVector;
00025         lengthOfStateVector = states.getIndexCount();
00026         
00027         // Calculate the phi matrix
00028         Matrix phi; //~ (lengthOfStateVector,lengthOfStateVector);
00029         phi = eye(lengthOfStateVector) + kf->GetStateJacobianMatrix() * kf->GetTimeStep();  // is this right?
00030         
00031         // Propagate the state vector
00032         states = phi * states;
00033         
00034         // Set the new state vector
00035         kf->SetStateVector(states);
00036         
00037 };
00038 
00039 void LKFCovarianceMatrixPropagator(KalmanFilter* kf) {
00040         
00041         // Get sequential filter data
00042         Vector states, controls, measurements, parameters;
00043         states = kf->GetStateVector();
00044         controls = kf->GetControlVector();
00045         measurements = kf->GetMeasurementVector();
00046         parameters = kf->GetParameterVector();
00047         
00048         // Get Kalman filter data
00049         Matrix covariance, kalmanGain;
00050         covariance = kf->GetCovarianceMatrix();
00051         kalmanGain = kf->GetKalmanGainMatrix();
00052         
00053         // Determine length of state vector
00054         int lengthOfStateVector;
00055         lengthOfStateVector = states.getIndexCount();
00056         
00057         // Calculate the phi matrix
00058         Matrix phi; //~ (lengthOfStateVector,lengthOfStateVector);
00059         phi = eye(lengthOfStateVector) + kf->GetStateJacobianMatrix() * kf->GetTimeStep();
00060         
00061         // Calculate Qk ??? a utility function to calculate Qk from Q
00062         Matrix Qk; //~ (lengthOfStateVector,lengthOfStateVector);
00063         Qk = kf->GetSystemProcessNoiseMatrix();
00064         
00065         // Propagate the covariance matrix
00066         covariance = phi * covariance * ~phi + Qk;
00067         
00068         // Set the new covariance matrix
00069         kf->SetCovarianceMatrix(covariance);
00070         
00071 };
00072 
00073 void LKFCalcualteKalmanGain(KalmanFilter* kf) {
00074         
00075         // Get sequential filter data
00076         /*Vector states, controls, measurements, parameters;
00077         states = kf->GetStateVector();
00078         controls = kf->GetControlVector();
00079         measurements = kf->GetMeasurementVector();
00080         parameters = kf->GetParameterVector();
00081         */
00082         
00083         // Get Kalman filter data
00084         Matrix covariance, kalmanGain;
00085         covariance = kf->GetCovarianceMatrix();
00086         //kalmanGain = kf->GetKalmanGainMatrix();
00087         
00088         // Determine length of state vector
00089         //~ int lengthOfStateVector;
00090         //~ lengthOfStateVector = states.getIndexCount();
00091         
00092         // Calculate measurement matrix
00093         Matrix Hk; //~ (lengthOfMeasurementVector,lengthOfStateVector);
00094         Hk = kf->GetMeasurementJacobianMatrix();
00095         
00096         // Calculate the Kalman gains
00097         kalmanGain = (covariance * ~Hk) * (Hk * covariance * ~Hk + kf->GetMeasurementCovarianceMatrix()).inverse();
00098         // Set the new Kalman Gain matrix
00099         kf->SetKalmanGainMatrix(kalmanGain);
00100         
00101 };
00102 
00103 void LKFStateMeasurementUpdate(KalmanFilter* kf) {
00104         
00105         // Get sequential filter data
00106         Vector states, controls, measurements, parameters;
00107         states = kf->GetStateVector();
00108         controls = kf->GetControlVector();
00109         measurements = kf->GetMeasurementVector();
00110         parameters = kf->GetParameterVector();
00111         
00112         // Get Kalman filter data
00113         Matrix covariance, kalmanGain;
00114         covariance = kf->GetCovarianceMatrix();
00115         kalmanGain = kf->GetKalmanGainMatrix();
00116         
00117         // Determine length of state vector
00118         //~ int lengthOfStateVector;
00119         //~ lengthOfStateVector = states.getIndexCount();
00120         
00121         // Calculate measurement matrix
00122         Matrix Hk;//~ (lengthOfStateVector,lengthOfStateVector);
00123         Hk = kf->GetMeasurementJacobianMatrix();
00124         
00125         // Update state vector
00126         states = states + kalmanGain * (measurements - kf->GetEstimatedMeasurements());
00127         
00128         // Set the new state vector
00129         kf->SetStateVector(states);
00130         
00131 };
00132 
00133 void LKFCovarianceMeasurementUpdate(KalmanFilter* kf) {
00134         
00135         // Get sequential filter data
00136         Vector states, controls, measurements, parameters;
00137         states = kf->GetStateVector();
00138         /*controls = kf->GetControlVector();
00139         measurements = kf->GetMeasurementVector();
00140         parameters = kf->GetParameterVector();
00141         */
00142         
00143         // Get Kalman filter data
00144         Matrix covariance, kalmanGain;
00145         covariance = kf->GetCovarianceMatrix();
00146         kalmanGain = kf->GetKalmanGainMatrix();
00147         
00148         // Determine length of state vector
00149         int lengthOfStateVector;
00150         lengthOfStateVector = states.getIndexCount();
00151         
00152         // Calculate measurement matrix
00153         Matrix Hk; //~ (lengthOfStateVector,lengthOfStateVector);
00154         Hk = kf->GetMeasurementJacobianMatrix();
00155         
00156         // Update covariance matrix
00157         covariance = (eye(lengthOfStateVector) - kalmanGain * Hk) * covariance;
00158         
00159         // Set the new covariance matrix
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 // Do not change the comments below - they will be added automatically by CVS
00209 /*****************************************************************************
00210 * $Log: LKFfunctions.cpp,v $
00211 * Revision 1.9  2003/07/14 19:37:22  simpliciter
00212 * Removed extraneous data calls.
00213 *
00214 * Revision 1.8  2003/07/03 00:35:03  simpliciter
00215 * Eliminitated unnecessary matrix size declarations.
00216 * Fixed Kalman Gain equation:  WAS (stuff + stuff)/(stuff)
00217 * IS (stuff) * (stuff+stuff).inverse()
00218 *
00219 * Revision 1.7  2003/06/30 21:10:10  mavandyk
00220 * Split up the relative time data into two absolute time stamps.
00221 *
00222 * Revision 1.6  2003/06/24 15:46:54  simpliciter
00223 * Functions modified to not use structs;
00224 * most now take a KalmanFilter*.
00225 *
00226 * Revision 1.5  2003/06/20 22:00:39  mavandyk
00227 * Changes made to reflect the altering of the kalmanFitlerData struct type and the KalmanFilter class.
00228 *
00229 * Revision 1.4  2003/06/19 23:13:08  mavandyk
00230 * Moved asterish from left to right side of the KalmanFilter types being passed into functions.
00231 *
00232 * Revision 1.3  2003/06/18 17:41:32  mavandyk
00233 * Added include lines for LKFfunctions.h changed the appropriate function pointer input types to reflect changes in KalmanFilter.h.
00234 *
00235 * Revision 1.2  2003/06/12 23:01:41  mavandyk
00236 * Added header and footer comments.
00237 *
00238 * Revision 1.1  2003/06/12 16:29:41  mavandyk
00239 * This file replaces IterativeFilter.h, and only differs by replacing iterative with sequential.
00240 *
00241 * Revision 1.1  2003/06/11 15:45:08  simpliciter
00242 * Initial submission, pulled out of KalmanFilter.h.
00243 * May require (desire) additional pure virtual functions.
00244 *
00245 *
00246 ******************************************************************************/

Generated on Wed Sep 5 12:54:21 2007 for DSACSS Operational Code by  doxygen 1.3.9.1