00001 #pragma ident "$Id$" 00002 00008 //============================================================================ 00009 // 00010 // This file is part of GPSTk, the GPS Toolkit. 00011 // 00012 // The GPSTk is free software; you can redistribute it and/or modify 00013 // it under the terms of the GNU Lesser General Public License as published 00014 // by the Free Software Foundation; either version 2.1 of the License, or 00015 // any later version. 00016 // 00017 // The GPSTk is distributed in the hope that it will be useful, 00018 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00020 // GNU Lesser General Public License for more details. 00021 // 00022 // You should have received a copy of the GNU Lesser General Public 00023 // License along with GPSTk; if not, write to the Free Software Foundation, 00024 // Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00025 // 00026 // Dagoberto Salazar - gAGE ( http://www.gage.es ). 2011 00027 // 00028 //============================================================================ 00029 00030 00031 #include "FIRDifferentiator5thOrder.hpp" 00032 00033 00034 00035 namespace gpstk 00036 { 00037 00038 00039 /* Return result. 00040 * 00041 * @param input Input data. 00042 */ 00043 double FIRDifferentiator5thOrder::Compute( double input ) 00044 { 00045 00046 // Be default, the filter is invalid 00047 valid = false; 00048 00049 // Default result 00050 double result( 0.0 ); 00051 00052 00053 // Check if there are enough stored data values 00054 if( X.size() == 10 ) 00055 { 00056 00057 // Compute the result. This implements the equation: 00058 // y[k] = k1*x[k+5] - k2*x[k+4] + k3*x[k+3] - k4*x[k+2] + k5*x[k+1] 00059 // - k5*x[k-1] + k4*x[k-2] - k3*x[k-3] + k2*x[k-4] - k1*x[k-5] 00060 00061 result = k1*(input - X[9]) + k2*(X[8] - X[0]) + k3*(X[1] - X[7]) 00062 + k4*(X[6] - X[2]) + k5*(X[3] - X[5]); 00063 00064 // Filter result is valid 00065 valid = true; 00066 } 00067 00068 // Update filter state 00069 00070 // Insert input in input vector 00071 X.push_front( input ); 00072 00073 // Delete old inputs 00074 if(X.size() > 10) X.pop_back(); 00075 00076 // Return result 00077 return result; 00078 00079 } // End of constructor 'FIRDifferentiator5thOrder::Compute()' 00080 00081 00082 00083 // Resets filter, cleaning its internal state. 00084 void FIRDifferentiator5thOrder::Reset(void) 00085 { 00086 // Clear stored input values 00087 X.clear(); 00088 00089 // Filter state is invalid 00090 valid = false; 00091 00092 // Return 00093 return; 00094 00095 } // End of constructor 'FIRDifferentiator5thOrder::Reset()' 00096 00097 00098 00099 /* Set the sampling period, in seconds. 00100 * 00101 * @param[in] period Sampling period, in seconds. 00102 * 00103 * @warning Only values higher that zero are allowed. Other values will 00104 * be ignored. 00105 * 00106 * @warning This operation resets the filter. 00107 */ 00108 FIRDifferentiator5thOrder& FIRDifferentiator5thOrder::setT( double period ) 00109 { 00110 // Check period 00111 if( period > 0.0 ) 00112 { 00113 T = period; 00114 Init(); 00115 Reset(); 00116 } 00117 00118 return (*this); 00119 00120 } // End of method 'FIRDifferentiator5thOrder::setT()' 00121 00122 00123 00124 // Initialization method 00125 void FIRDifferentiator5thOrder::Init( void ) 00126 { 00127 00128 // Generate filter parameters 00129 k1 = 1.0/(1260.0*T); 00130 k2 = k1*(12.5); 00131 k3 = k1*(75.0); 00132 k4 = k1*(300.0); 00133 k5 = k1*(1050.0); 00134 00135 // Filter parameters are set. Let's return 00136 return; 00137 00138 } // End of method 'FIRDifferentiator5thOrder::Init()' 00139 00140 00141 00142 } // End of namespace gpstk
1.3.9.1