21 #define GRT_DLL_EXPORTS 27 const std::string HighPassFilter::id =
"HighPassFilter";
35 init(filterFactor,gain,numDimensions);
37 if( cutoffFrequency != -1 && delta != -1 ){
64 if( preProcessing == NULL )
return false;
80 errorLog <<
"deepCopyFrom(const PreProcessing *preProcessing) - PreProcessing Types Do Not Match!" << std::endl;
88 errorLog <<
"process(const VectorFloat &inputVector) - Not initialized!" << std::endl;
92 if( inputVector.size() != numInputDimensions ){
93 errorLog <<
"process(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.size() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
97 processedData =
filter( inputVector );
99 if( processedData.size() == numOutputDimensions )
return true;
111 if( !file.is_open() ){
112 errorLog <<
"save(fstream &file) - The file is not open!" << std::endl;
116 file <<
"GRT_HIGH_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_HIGH_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;
206 processedData.clear();
207 processedData.
resize(numDimensions,0);
217 errorLog <<
"filter(const Float x) - The filter has not been initialized!" << std::endl;
223 if( y.size() == 0 )
return 0;
231 errorLog <<
"filter(const VectorFloat &x) - Not Initialized!" << std::endl;
235 if( x.size() != numInputDimensions ){
236 errorLog <<
"filter(const VectorFloat &x) - The Number Of Input Dimensions (" << numInputDimensions <<
") does not match the size of the input vector (" << x.size() <<
")!" << std::endl;
240 for(UINT n=0; n<numInputDimensions; n++){
248 processedData[n] =
yy[n];
250 return processedData;
264 errorLog <<
"setGain(Float gain) - Gain value must be greater than 0!" << std::endl;
269 if( filterFactor > 0.0 && filterFactor <= 1.0 ){
273 errorLog <<
"setFilterFactor(Float filterFactor) - FilterFactor value must be greater than 0!" << std::endl;
278 if( cutoffFrequency > 0 && delta > 0 ){
279 Float RC = (1.0/TWO_PI) / cutoffFrequency;
virtual bool deepCopyFrom(const PreProcessing *preProcessing)
std::string getId() const
Float filterFactor
The filter factor (alpha) of the filter.
virtual bool load(std::fstream &file)
virtual bool resize(const unsigned int size)
VectorFloat yy
The previous output value(s)
HighPassFilter & operator=(const HighPassFilter &rhs)
virtual bool process(const VectorFloat &inputVector)
Float gain
The gain factor of the filter.
HighPassFilter(const Float filterFactor=0.99, const Float gain=1, const UINT numDimensions=1, const Float cutoffFrequency=-1, const Float delta=-1)
bool setGain(const Float gain)
virtual ~HighPassFilter()
VectorFloat xx
The previous input value(s)
bool setFilterFactor(const Float filterFactor)
bool copyBaseVariables(const PreProcessing *preProcessingModule)
Float filter(const Float x)
bool setCutoffFrequency(const Float cutoffFrequency, const Float delta)
static std::string getId()
This class implements a High Pass Filter.
virtual bool save(std::fstream &file) const
Float getFilterFactor() const
VectorFloat getFilteredValues() const