26 RegisterPreProcessingModule< LowPassFilter > LowPassFilter::registerModule(
"LowPassFilter");
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!" << endl;
85 errorLog <<
"process(const VectorDouble &inputVector) - Not initialized!" << endl;
89 if( inputVector.size() != numInputDimensions ){
90 errorLog <<
"process(const VectorDouble &inputVector) - The size of the inputVector (" << inputVector.size() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << endl;
94 processedData =
filter( inputVector );
96 if( processedData.size() == numOutputDimensions )
return true;
109 errorLog <<
"saveModelToFile(string filename) - The HighPassFilter has not been initialized" << 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!" << endl;
133 file <<
"GRT_LOW_PASS_FILTER_FILE_V1.0" << endl;
135 file <<
"NumInputDimensions: " << numInputDimensions << endl;
136 file <<
"NumOutputDimensions: " << numOutputDimensions << endl;
138 file <<
"Gain: " <<
gain << 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!" << endl;
171 if( word !=
"GRT_LOW_PASS_FILTER_FILE_V1.0" ){
172 errorLog <<
"loadModelFromFile(fstream &file) - Invalid file format!" << endl;
178 if( word !=
"NumInputDimensions:" ){
179 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumInputDimensions header!" << endl;
182 file >> numInputDimensions;
186 if( word !=
"NumOutputDimensions:" ){
187 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read NumOutputDimensions header!" << endl;
190 file >> numOutputDimensions;
194 if( word !=
"FilterFactor:" ){
195 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read FilterFactor header!" << endl;
202 if( word !=
"Gain:" ){
203 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read Gain header!" << endl;
209 return init(filterFactor,gain,numInputDimensions);
216 if( numDimensions == 0 ){
217 errorLog <<
"init(double filterFactor,double gain,UINT numDimensions) - NumDimensions must be greater than 0!" << endl;
221 if( filterFactor <= 0 ){
222 errorLog <<
"init(double filterFactor,double gain,UINT numDimensions) - FilterFactor must be greater than 0!" << endl;
227 errorLog <<
"init(double filterFactor,double gain,UINT numDimensions) - Gain must be greater than 0!" << endl;
233 this->numInputDimensions = numDimensions;
234 this->numOutputDimensions = numDimensions;
236 yy.resize(numDimensions,0);
237 processedData.clear();
238 processedData.resize(numDimensions,0);
248 errorLog <<
"filter(double x) - The filter has not been initialized!" << endl;
252 VectorDouble y =
filter(VectorDouble(1,x));
254 if( y.size() == 0 )
return 0;
262 errorLog <<
"filter(const VectorDouble &x) - Not Initialized!" << endl;
263 return VectorDouble();
266 if( x.size() != numInputDimensions ){
267 errorLog <<
"filter(const VectorDouble &x) - The Number Of Input Dimensions (" << numInputDimensions <<
") does not match the size of the input vector (" << x.size() <<
")!" << endl;
268 return VectorDouble();
271 for(UINT n=0; n<numInputDimensions; n++){
273 yy[n] = processedData[n];
275 return processedData;
284 errorLog <<
"setGain(double gain) - Gain value must be greater than 0!" << endl;
289 if( filterFactor > 0 ){
294 errorLog <<
"setFilterFactor(double filterFactor) - FilterFactor value must be greater than 0!" << endl;
299 if( cutoffFrequency > 0 && delta > 0 ){
300 double RC = (1.0/TWO_PI) /cutoffFrequency;
bool setFilterFactor(double filterFactor)
LowPassFilter & operator=(const LowPassFilter &rhs)
bool setCutoffFrequency(double cutoffFrequency, double delta)
virtual bool process(const VectorDouble &inputVector)
bool setGain(double gain)
double filterFactor
The filter factor (alpha) of the filter.
string getPreProcessingType() const
LowPassFilter(double filterFactor=0.1, double gain=1, UINT numDimensions=1, double cutoffFrequency=-1, double delta=-1)
virtual bool saveModelToFile(string filename) const
The class implements a low pass filter.
bool copyBaseVariables(const PreProcessing *preProcessingModule)
VectorDouble yy
The previous output value(s)
double gain
The gain factor of the filter.
virtual bool loadModelFromFile(string filename)
virtual bool deepCopyFrom(const PreProcessing *preProcessing)
double filter(const double x)