21 #define GRT_DLL_EXPORTS
31 classType =
"LowPassFilter";
32 preProcessingType = classType;
33 debugLog.setProceedingText(
"[DEBUG LowPassFilter]");
34 errorLog.setProceedingText(
"[ERROR LowPassFilter]");
35 warningLog.setProceedingText(
"[WARNING LowPassFilter]");
36 init(filterFactor,gain,numDimensions);
38 if( cutoffFrequency != -1 && delta != -1 ){
44 classType =
"LowPassFilter";
45 preProcessingType = classType;
46 debugLog.setProceedingText(
"[DEBUG LowPassFilter]");
47 errorLog.setProceedingText(
"[ERROR LowPassFilter]");
48 warningLog.setProceedingText(
"[WARNING LowPassFilter]");
68 if( preProcessing == NULL )
return false;
78 errorLog <<
"clone(const PreProcessing *preProcessing) - PreProcessing Types Do Not Match!" << std::endl;
86 errorLog <<
"process(const VectorFloat &inputVector) - Not initialized!" << std::endl;
90 if( inputVector.size() != numInputDimensions ){
91 errorLog <<
"process(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.size() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
95 processedData =
filter( inputVector );
97 if( processedData.size() == numOutputDimensions )
return true;
109 if( !file.is_open() ){
110 errorLog <<
"save(fstream &file) - The file is not open!" << std::endl;
114 file <<
"GRT_LOW_PASS_FILTER_FILE_V1.0" << std::endl;
116 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
117 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
119 file <<
"Gain: " <<
gain << std::endl;
126 if( !file.is_open() ){
127 errorLog <<
"load(fstream &file) - The file is not open!" << std::endl;
136 if( word !=
"GRT_LOW_PASS_FILTER_FILE_V1.0" ){
137 errorLog <<
"load(fstream &file) - Invalid file format!" << std::endl;
143 if( word !=
"NumInputDimensions:" ){
144 errorLog <<
"load(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
147 file >> numInputDimensions;
151 if( word !=
"NumOutputDimensions:" ){
152 errorLog <<
"load(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
155 file >> numOutputDimensions;
159 if( word !=
"FilterFactor:" ){
160 errorLog <<
"load(fstream &file) - Failed to read FilterFactor header!" << std::endl;
167 if( word !=
"Gain:" ){
168 errorLog <<
"load(fstream &file) - Failed to read Gain header!" << std::endl;
174 return init(filterFactor,gain,numInputDimensions);
181 if( numDimensions == 0 ){
182 errorLog <<
"init(Float filterFactor,Float gain,UINT numDimensions) - NumDimensions must be greater than 0!" << std::endl;
186 if( filterFactor <= 0 ){
187 errorLog <<
"init(Float filterFactor,Float gain,UINT numDimensions) - FilterFactor must be greater than 0!" << std::endl;
192 errorLog <<
"init(Float filterFactor,Float gain,UINT numDimensions) - Gain must be greater than 0!" << std::endl;
198 this->numInputDimensions = numDimensions;
199 this->numOutputDimensions = numDimensions;
202 processedData.clear();
203 processedData.
resize(numDimensions,0);
213 errorLog <<
"filter(Float x) - The filter has not been initialized!" << std::endl;
219 if( y.size() == 0 )
return 0;
227 errorLog <<
"filter(const VectorFloat &x) - Not Initialized!" << std::endl;
231 if( x.size() != numInputDimensions ){
232 errorLog <<
"filter(const VectorFloat &x) - The Number Of Input Dimensions (" << numInputDimensions <<
") does not match the size of the input vector (" << x.size() <<
")!" << std::endl;
237 for(UINT n=0; n<numInputDimensions; n++){
239 yy[n] = processedData[n];
241 return processedData;
250 errorLog <<
"setGain(Float gain) - Gain value must be greater than 0!" << std::endl;
255 if( filterFactor > 0 ){
260 errorLog <<
"setFilterFactor(Float filterFactor) - FilterFactor value must be greater than 0!" << std::endl;
265 if( cutoffFrequency > 0 && delta > 0 ){
266 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.
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 save(std::fstream &file) const
virtual bool deepCopyFrom(const PreProcessing *preProcessing)
virtual bool load(std::fstream &file)
bool copyBaseVariables(const PreProcessing *preProcessingModule)
bool setCutoffFrequency(Float cutoffFrequency, Float delta)