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

KalmanFilterHistory.cpp

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////////////////////////////
00002 /*! \file       KalmanFilterHistory.cpp
00003  *  \brief      A class to store additional data specific to the Kalman Filter.  Derived from SequentialFilter.
00004  *  \author $Author: rsharo $
00005  *  \version $Revision: 1.3 $
00006  *  \date    $Date: 2003/11/01 21:00:15 $
00007  *//////////////////////////////////////////////////////////////////////////////////////////////////
00008 /*  
00009  */
00010 //////////////////////////////////////////////////////////////////////////////////////////////////
00011 
00012 #include "KalmanFilterHistory.h"
00013 
00014 /*! \brief Only one constructor.  (No empty constructor.)
00015  * Builds an empty history for the filter instance passed in as a pointer.  */
00016 KalmanFilterHistory::KalmanFilterHistory(SequentialFilter* _ptr_filter)
00017 {
00018         // calls the initialization sequence in SequentialFilterHistory
00019     InitializeSequentialFilterHistory(_ptr_filter);
00020         
00021         // new Kalman Filter data to be stored:  the covariance and Kalman gain matrices.
00022         m_kfCovarianceHistory.reserve(HISTORY_RESERVE_SIZE);
00023         m_kfKalmanGainHistory.reserve(HISTORY_RESERVE_SIZE);
00024         
00025         // not doing interpolations at this time
00026         //m_kalmanFilterInterpolations.reserve(HISTORY_RESERVE_SIZE);
00027 }
00028 
00029 
00030 
00031 /*! \brief Add the filters's data, which occured at a time in seconds, to the history.
00032  *
00033  *  Appends the state at t=_appendTime. if the new state 
00034  *      occured at a time that is earlier than any of the stored values
00035  *      then the time history will be erased from the overlap point 
00036  *      and the new state will be appended.
00037  * @param _appendTime time (in seconds) to be added, t.
00038  * 
00039  */
00040 void KalmanFilterHistory::AppendHistory(const double& _appendTime)
00041 {
00042     AppendHistory(ssfTime(_appendTime));
00043 }    
00044 
00045 
00046 
00047 /*! \brief Add the filters's data, which occured at a time in ssfTime form, to the history.
00048  *
00049  *  Appends the state at t=_appendTime. if the new state 
00050  *      occured at a time that is earlier than any of the stored values
00051  *      then the time history will be erased from the overlap point 
00052  *      and the new state will be appended.
00053  * @param _appendTime the ssfTime object specifying when the state occured, t.
00054  *
00055  */
00056 void KalmanFilterHistory::AppendHistory(const ssfTime& _appendTime)
00057 {
00058         // This guy logs the time, states, controls, measurements, parameters.
00059         SequentialFilterHistory::AppendHistory(_appendTime);
00060         
00061         // And now the P and K matrices.
00062         m_kfCovarianceHistory.push_back( m_ptr_filter->GetCovarianceMatrix() );
00063         m_kfKalmanGainHistory.push_back( m_ptr_filter->GetKalmanGainMatrix() );
00064         
00065         return;
00066 }
00067 
00068 
00069 
00070 /*! \brief Erases the sequential filters's struct history */
00071 void KalmanFilterHistory::ResetHistory() { }
00072 
00073 
00074 
00075 /*! \brief Returns a matrix of the filter's basic history (no Kalman information).
00076  * @return This function returns a matrix in the form [t_k, state(t_k), control(t_k), measurement(t_k), parameter(t_k)]
00077  */
00078 Matrix KalmanFilterHistory::GetHistory()
00079 {
00080         Matrix returnMatrix;
00081         
00082         //Let SequentialFilterHistory do the work.
00083         returnMatrix = SequentialFilterHistory::GetHistory();
00084         
00085         return returnMatrix;
00086 }
00087 
00088 
00089 
00090 /*! Returns basic and Kalman history data by reference.
00091  *
00092  * @return This function returns a void but passes the default history and additional 
00093  * Kalman Filter history information by reference in two separate matrices.
00094  *
00095  * The first matrix has (num time steps) rows 
00096  * and is of the form [t_k, state(t_k), control(t_k), measurement(t_k), parameter(t_k)].
00097  * The second matrix has (num time steps)*(num states) rows and (num states + num measurements) columns;
00098  * data is stored as [ P(t_k), K(t_k) ].  Note that each matrix takes up (num states) rows.
00099  */
00100 void KalmanFilterHistory::GetKalmanHistory(Matrix& _sfHistMatrix, Matrix& _kfHistMatrix)
00101 {
00102         // sequential filter data
00103         _sfHistMatrix = SequentialFilterHistory::GetHistory();
00104         
00105         // kalman filter data
00106         // note that the covariance matrix is nxn and the kalman gain matrix is nxm
00107         int StateVectorSize = m_ptr_filter->GetStateVector().getIndexBound();                           // length n
00108         int MeasurementVectorSize = m_ptr_filter->GetMeasurementVector().getIndexBound();       // length m
00109                 
00110     Matrix rightSize(m_TimeHistory.size()*StateVectorSize, StateVectorSize + MeasurementVectorSize);
00111         
00112         _kfHistMatrix.initialize(rightSize); 
00113         
00114         for(unsigned int ii = 0; ii*StateVectorSize < m_TimeHistory.size()*StateVectorSize; ii++ )
00115         {
00116                 _kfHistMatrix( _( MatrixIndexBase + ii*StateVectorSize, MatrixIndexBase + ii*StateVectorSize + StateVectorSize - 1 ),
00117                                    _( MatrixIndexBase, MatrixIndexBase + StateVectorSize - 1 ) ) = m_kfCovarianceHistory[ii];
00118                 _kfHistMatrix( _( MatrixIndexBase + ii*StateVectorSize, MatrixIndexBase + ii*StateVectorSize + StateVectorSize - 1 ),
00119                                    _( MatrixIndexBase + StateVectorSize , MatrixIndexBase + StateVectorSize + MeasurementVectorSize - 1 ) ) = m_kfKalmanGainHistory[ii];
00120         }
00121 }
00122 
00123 
00124 
00125 
00126 // Do not change the comments below - they will be added automatically by CVS
00127 /*****************************************************************************
00128 *       $Log: KalmanFilterHistory.cpp,v $
00129 *       Revision 1.3  2003/11/01 21:00:15  rsharo
00130 *       changed "Time.h" includes to "utils/Time.h" includes. Also eliminated excess compile warnings.
00131 *       
00132 *       Revision 1.2  2003/06/28 00:46:06  simpliciter
00133 *       Finished GetKalmanHistory.  Huzzah!
00134 *       
00135 *       Revision 1.1  2003/06/27 01:52:50  simpliciter
00136 *       Fully commented!  And almost fully functional.
00137 *       Once I learn the best way to copy chunks of one Matrix
00138 *       into another I'll finish GetKalmanHistory.  Otherwise
00139 *       everything is done.  GetState is not implemented because
00140 *       it would require / desire interpolations, which seems out
00141 *       of spirit with tracking the effectiveness of a filter.
00142 *       
00143 *       Revision 1.1  2003/06/24 15:50:06  simpliciter
00144 *       Everything but the all important "GetHistory" command
00145 *       should work.  :)
00146 *       
00147 *       Revision 1.0  2003/06/06 18:44:15  simpliciter
00148 *       Initial submission.
00149 *       
00150 *
00151 ******************************************************************************/

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