30 classType =
"LowPassFilter";
31 preProcessingType = classType;
32 debugLog.setProceedingText(
"[DEBUG LowPassFilter]");
33 errorLog.setProceedingText(
"[ERROR LowPassFilter]");
34 warningLog.setProceedingText(
"[WARNING LowPassFilter]");
35 init(filterFactor,gain,numDimensions);
37 if( cutoffFrequency != -1 && delta != -1 ){
43 classType =
"LowPassFilter";
44 preProcessingType = classType;
45 debugLog.setProceedingText(
"[DEBUG LowPassFilter]");
46 errorLog.setProceedingText(
"[ERROR LowPassFilter]");
47 warningLog.setProceedingText(
"[WARNING LowPassFilter]");
67 if( preProcessing == NULL )
return false;
77 errorLog <<
"clone(const PreProcessing *preProcessing) - PreProcessing Types Do Not Match!" << std::endl;
85 errorLog <<
"process(const VectorFloat &inputVector) - Not initialized!" << std::endl;
89 if( inputVector.size() != numInputDimensions ){
90 errorLog <<
"process(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.size() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
94 processedData =
filter( inputVector );
96 if( processedData.size() == numOutputDimensions )
return true;
109 errorLog <<
"saveModelToFile(string filename) - The HighPassFilter has not been initialized" << std::endl;
114 file.open(filename.c_str(), std::ios::out);
128 if( !file.is_open() ){
129 errorLog <<
"saveModelToFile(fstream &file) - The file is not open!" << std::endl;
133 file <<
"GRT_LOW_PASS_FILTER_FILE_V1.0" << std::endl;
135 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
136 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
138 file <<
"Gain: " <<
gain << std::endl;
146 file.open(filename.c_str(), std::ios::in);
161 if( !file.is_open() ){
162 errorLog <<
"loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
171 if( word !=
"GRT_LOW_PASS_FILTER_FILE_V1.0" ){
172 errorLog <<
"loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
178 if( word !=
"NumInputDimensions:" ){
179 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
182 file >> numInputDimensions;
186 if( word !=
"NumOutputDimensions:" ){
187 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
190 file >> numOutputDimensions;
194 if( word !=
"FilterFactor:" ){
195 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read FilterFactor header!" << std::endl;
202 if( word !=
"Gain:" ){
203 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read Gain header!" << std::endl;
209 return init(filterFactor,gain,numInputDimensions);
216 if( numDimensions == 0 ){
217 errorLog <<
"init(Float filterFactor,Float gain,UINT numDimensions) - NumDimensions must be greater than 0!" << std::endl;
221 if( filterFactor <= 0 ){
222 errorLog <<
"init(Float filterFactor,Float gain,UINT numDimensions) - FilterFactor must be greater than 0!" << std::endl;
227 errorLog <<
"init(Float filterFactor,Float gain,UINT numDimensions) - Gain must be greater than 0!" << std::endl;
233 this->numInputDimensions = numDimensions;
234 this->numOutputDimensions = numDimensions;
237 processedData.clear();
238 processedData.
resize(numDimensions,0);
248 errorLog <<
"filter(Float x) - The filter has not been initialized!" << std::endl;
254 if( y.size() == 0 )
return 0;
262 errorLog <<
"filter(const VectorFloat &x) - Not Initialized!" << std::endl;
266 if( x.size() != numInputDimensions ){
267 errorLog <<
"filter(const VectorFloat &x) - The Number Of Input Dimensions (" << numInputDimensions <<
") does not match the size of the input vector (" << x.size() <<
")!" << std::endl;
272 for(UINT n=0; n<numInputDimensions; n++){
274 yy[n] = processedData[n];
276 return processedData;
285 errorLog <<
"setGain(Float gain) - Gain value must be greater than 0!" << std::endl;
290 if( filterFactor > 0 ){
295 errorLog <<
"setFilterFactor(Float filterFactor) - FilterFactor value must be greater than 0!" << std::endl;
300 if( cutoffFrequency > 0 && delta > 0 ){
301 Float RC = (1.0/TWO_PI) /cutoffFrequency;
bool setFilterFactor(Float filterFactor)
LowPassFilter & operator=(const LowPassFilter &rhs)
virtual bool resize(const unsigned int size)
virtual bool process(const VectorFloat &inputVector)
Float gain
The gain factor of the filter.
virtual bool saveModelToFile(std::string filename) const
Float filterFactor
The filter factor (alpha) of the filter.
LowPassFilter(Float filterFactor=0.1, Float gain=1, UINT numDimensions=1, Float cutoffFrequency=-1, Float delta=-1)
std::string getPreProcessingType() const
The class implements a low pass filter, this is based on an Exponential moving average filter: https:...
Float filter(const Float x)
VectorFloat yy
The previous output value(s)
virtual bool deepCopyFrom(const PreProcessing *preProcessing)
bool copyBaseVariables(const PreProcessing *preProcessingModule)
virtual bool loadModelFromFile(std::string filename)
bool setCutoffFrequency(Float cutoffFrequency, Float delta)