21 #define GRT_DLL_EXPORTS 27 const std::string Derivative::id =
"Derivative";
35 init(derivativeOrder,delta,numDimensions,filterData,filterSize);
72 if( preProcessing == NULL )
return false;
91 errorLog <<
"deepCopyFrom(const PreProcessing *preProcessing) - PreProcessing Types Do Not Match!" << std::endl;
99 errorLog <<
"process(const VectorFloat &inputVector) - Not initialized!" << std::endl;
103 if( inputVector.
getSize() != numInputDimensions ){
104 errorLog <<
"process(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.size() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
110 if( processedData.size() == numOutputDimensions )
return true;
121 if( !file.is_open() ){
122 errorLog <<
"save(fstream &file) - The file is not open!" << std::endl;
126 file <<
"GRT_DERIVATIVE_FILE_V1.0" << std::endl;
128 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
129 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
131 file <<
"FilterSize: " <<
filterSize << std::endl;
132 file <<
"Delta: " <<
delta << std::endl;
133 file <<
"FilterData: " <<
filterData << std::endl;
140 if( !file.is_open() ){
141 errorLog <<
"load(fstream &file) - The file is not open!" << std::endl;
150 if( word !=
"GRT_DERIVATIVE_FILE_V1.0" ){
151 errorLog <<
"load(fstream &file) - Invalid file format!" << std::endl;
157 if( word !=
"NumInputDimensions:" ){
158 errorLog <<
"load(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
161 file >> numInputDimensions;
165 if( word !=
"NumOutputDimensions:" ){
166 errorLog <<
"load(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
169 file >> numOutputDimensions;
173 if( word !=
"DerivativeOrder:" ){
174 errorLog <<
"load(fstream &file) - Failed to read DerivativeOrder header!" << std::endl;
181 if( word !=
"FilterSize:" ){
182 errorLog <<
"load(fstream &file) - Failed to read FilterSize header!" << std::endl;
189 if( word !=
"Delta:" ){
190 errorLog <<
"load(fstream &file) - Failed to read Delta header!" << std::endl;
197 if( word !=
"FilterData:" ){
198 errorLog <<
"load(fstream &file) - Failed to read FilterData header!" << std::endl;
204 return init(derivativeOrder,delta,numInputDimensions,filterData,filterSize);
211 if( derivativeOrder != FIRST_DERIVATIVE && derivativeOrder != SECOND_DERIVATIVE ){
212 errorLog <<
"init(UINT derivativeOrder,Float delta,UINT numDimensions,bool filterData,UINT filterSize) - Unknown derivativeOrder!" << std::endl;
216 if( numDimensions == 0 ){
217 errorLog <<
"init(UINT derivativeOrder,Float delta,UINT numDimensions,bool filterData,UINT filterSize) - NumDimensions must be greater than 0!" << std::endl;
222 errorLog <<
"init(UINT derivativeOrder,Float delta,UINT numDimensions,bool filterData,UINT filterSize) - Delta must be greater than 0!" << std::endl;
226 if( filterSize == 0 ){
227 errorLog <<
"init(UINT derivativeOrder,Float delta,UINT numDimensions,bool filterData,UINT filterSize) - FilterSize must be greater than zero!" << std::endl;
233 this->numInputDimensions = numDimensions;
234 this->numOutputDimensions = numDimensions;
242 processedData.clear();
243 processedData.
resize(numDimensions,0);
250 if( numInputDimensions != 1 ){
251 errorLog <<
"computeDerivative(const Float x) - The Number Of Input Dimensions is not 1! NumInputDimensions: " << numInputDimensions << std::endl;
257 if( y.size() == 0 )
return 0 ;
265 errorLog <<
"computeDerivative(const VectorFloat &x) - Not Initialized!" << std::endl;
269 if( x.size() != numInputDimensions ){
270 errorLog <<
"computeDerivative(const VectorFloat &x) - The Number Of Input Dimensions (" << numInputDimensions <<
") does not match the size of the input vector (" << x.size() <<
")!" << std::endl;
279 for(UINT n=0; n<numInputDimensions; n++){
280 processedData[n] = (y[n]-
yy[n])/
delta;
286 for(UINT n=0; n<numInputDimensions; n++){
287 tmp = processedData[n];
288 processedData[n] = (processedData[n]-
yyy[n])/
delta;
293 return processedData;
297 if( derivativeOrder == FIRST_DERIVATIVE || derivativeOrder == SECOND_DERIVATIVE ){
302 errorLog <<
"setDerivativeOrder(UINT derivativeOrder) - Unkown derivativeOrder" << std::endl;
307 if( filterSize > 0 ){
312 errorLog <<
"setFilterSize(UINT filterSize) - FilterSize must be greater than zero!" << std::endl;
329 switch( derivativeOrder ){
331 return processedData[0];
333 case( FIRST_DERIVATIVE ):
336 case( SECOND_DERIVATIVE ):
340 warningLog <<
"getDerivative(UINT derivativeOrder) - Unkown derivativeOrder: " << derivativeOrder << std::endl;
349 switch( derivativeOrder ){
351 return processedData;
353 case( FIRST_DERIVATIVE ):
356 case( SECOND_DERIVATIVE ):
360 warningLog <<
"getDerivative(UINT derivativeOrder) - Unkown derivativeOrder: " << derivativeOrder << std::endl;
std::string getId() const
virtual bool save(std::fstream &file) const
UINT getFilterSize() const
UINT filterSize
The size of the filter used to filter the input data before the derivative is computed.
virtual bool resize(const unsigned int size)
VectorFloat yy
A buffer holding the previous input value(s)
bool setDerivativeOrder(const UINT derivativeOrder)
bool init(const UINT filterSize, const UINT numDimensions)
bool enableFiltering(const bool filterData)
VectorFloat yyy
A buffer holding the previous first derivative values.
Float computeDerivative(const Float x)
virtual bool load(std::fstream &file)
bool setFilterSize(const UINT filterSize)
Derivative & operator=(const Derivative &rhs)
Float filter(const Float x)
static std::string getId()
Derivative(const UINT derivativeOrder=FIRST_DERIVATIVE, const Float delta=1, const UINT numDimensions=1, const bool filterData=true, const UINT filterSize=3)
virtual bool process(const VectorFloat &inputVector)
bool filterData
Flags if the input data should be filtered before the derivative is computed.
The Derivative class computes either the first or second order derivative of the input signal...
Float delta
The estimated time between sensor samples.
bool copyBaseVariables(const PreProcessing *preProcessingModule)
UINT derivativeOrder
The order of the derivative that will be computed (either FIRST_DERIVATIVE or SECOND_DERIVATIVE) ...
virtual bool deepCopyFrom(const PreProcessing *preProcessing)
Float getDerivative(const UINT derivativeOrder=FIRST_DERIVATIVE) const
VectorFloat getDerivatives(const UINT derivativeOrder=FIRST_DERIVATIVE) const
MovingAverageFilter filter
The filter used to low pass filter the input data.