21 #define GRT_DLL_EXPORTS 27 const std::string LowPassFilter::id =
"LowPassFilter";
35 init(filterFactor,gain,numDimensions);
37 if( cutoffFrequency != -1 && delta != -1 ){
63 if( preProcessing == NULL )
return false;
73 errorLog <<
"deepCopyFrom(const PreProcessing *preProcessing) - PreProcessing Types Do Not Match!" << std::endl;
81 errorLog <<
"process(const VectorFloat &inputVector) - Not initialized!" << std::endl;
85 if( inputVector.size() != numInputDimensions ){
86 errorLog <<
"process(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.size() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
90 processedData =
filter( inputVector );
92 if( processedData.size() == numOutputDimensions )
return true;
102 processedData.clear();
103 processedData.
resize(numInputDimensions,0);
111 if( !file.is_open() ){
112 errorLog <<
"save(fstream &file) - The file is not open!" << std::endl;
116 file <<
"GRT_LOW_PASS_FILTER_FILE_V1.0" << std::endl;
118 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
119 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
121 file <<
"Gain: " <<
gain << std::endl;
128 if( !file.is_open() ){
129 errorLog <<
"load(fstream &file) - The file is not open!" << std::endl;
138 if( word !=
"GRT_LOW_PASS_FILTER_FILE_V1.0" ){
139 errorLog <<
"load(fstream &file) - Invalid file format!" << std::endl;
145 if( word !=
"NumInputDimensions:" ){
146 errorLog <<
"load(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
149 file >> numInputDimensions;
153 if( word !=
"NumOutputDimensions:" ){
154 errorLog <<
"load(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
157 file >> numOutputDimensions;
161 if( word !=
"FilterFactor:" ){
162 errorLog <<
"load(fstream &file) - Failed to read FilterFactor header!" << std::endl;
169 if( word !=
"Gain:" ){
170 errorLog <<
"load(fstream &file) - Failed to read Gain header!" << std::endl;
176 return init(filterFactor,gain,numInputDimensions);
183 if( numDimensions == 0 ){
184 errorLog <<
"init(Float filterFactor,Float gain,UINT numDimensions) - NumDimensions must be greater than 0!" << std::endl;
188 if( filterFactor <= 0 ){
189 errorLog <<
"init(Float filterFactor,Float gain,UINT numDimensions) - FilterFactor must be greater than 0!" << std::endl;
194 errorLog <<
"init(Float filterFactor,Float gain,UINT numDimensions) - Gain must be greater than 0!" << std::endl;
200 this->numInputDimensions = numDimensions;
201 this->numOutputDimensions = numDimensions;
204 processedData.clear();
205 processedData.
resize(numDimensions,0);
215 errorLog <<
"filter(Float x) - The filter has not been initialized!" << std::endl;
221 if( y.size() == 0 )
return 0;
229 errorLog <<
"filter(const VectorFloat &x) - Not Initialized!" << std::endl;
233 if( x.size() != numInputDimensions ){
234 errorLog <<
"filter(const VectorFloat &x) - The Number Of Input Dimensions (" << numInputDimensions <<
") does not match the size of the input vector (" << x.size() <<
")!" << std::endl;
239 for(UINT n=0; n<numInputDimensions; n++){
241 yy[n] = processedData[n];
243 return processedData;
258 errorLog <<
"setGain(Float gain) - Gain value must be greater than 0!" << std::endl;
263 if( filterFactor >= 0 && filterFactor <= 1.0 ){
268 errorLog <<
"setFilterFactor(Float filterFactor) - FilterFactor value must be greater than 0!" << std::endl;
273 if( cutoffFrequency > 0 && delta > 0 ){
274 Float RC = ONE_OVER_TWO_PI / cutoffFrequency;
279 errorLog <<
"setCutoffFrequency(const Float cutoffFrequency,const Float delta) - cutoffFrequency and delta must be greater than 0!" << std::endl;
std::string getId() const
LowPassFilter & operator=(const LowPassFilter &rhs)
VectorFloat getFilteredValues() const
virtual bool resize(const unsigned int size)
virtual bool process(const VectorFloat &inputVector)
Float gain
The gain factor of the filter.
bool setCutoffFrequency(const Float cutoffFrequency, const Float delta)
Float filterFactor
The filter factor (alpha) of the filter.
The class implements a low pass filter, this is based on an Exponential moving average filter: https:...
static std::string getId()
Float filter(const Float x)
VectorFloat yy
The previous output value(s)
bool setFilterFactor(const Float filterFactor)
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 setGain(const Float gain)
Float getFilterFactor() const
LowPassFilter(const Float filterFactor=0.995, const Float gain=1, const UINT numDimensions=1, const Float cutoffFrequency=-1, const Float delta=-1)