21 #define GRT_DLL_EXPORTS 27 const std::string MovingAverageFilter::id =
"MovingAverageFilter";
35 init(filterSize,numDimensions);
60 if( rhs.initialized ){
73 if( preProcessing == NULL )
return false;
83 errorLog <<
"deepCopyFrom(const PreProcessing *preProcessing) - PreProcessing Types Do Not Match!" << std::endl;
92 errorLog <<
"process(const VectorFloat &inputVector) - The filter has not been initialized!" << std::endl;
96 if( inputVector.
getSize() != numInputDimensions ){
97 errorLog <<
"process(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
103 if( processedData.
getSize() == numOutputDimensions )
return true;
115 if( !file.is_open() ){
116 errorLog <<
"save(fstream &file) - The file is not open!" << std::endl;
120 file <<
"GRT_MOVING_AVERAGE_FILTER_FILE_V1.0" << std::endl;
122 file <<
"NumInputDimensions: " << numInputDimensions << std::endl;
123 file <<
"NumOutputDimensions: " << numOutputDimensions << std::endl;
124 file <<
"FilterSize: " <<
filterSize << std::endl;
131 if( !file.is_open() ){
132 errorLog <<
"load(fstream &file) - The file is not open!" << std::endl;
141 if( word !=
"GRT_MOVING_AVERAGE_FILTER_FILE_V1.0" ){
142 errorLog <<
"load(fstream &file) - Invalid file format!" << std::endl;
148 if( word !=
"NumInputDimensions:" ){
149 errorLog <<
"load(fstream &file) - Failed to read NumInputDimensions header!" << std::endl;
152 file >> numInputDimensions;
156 if( word !=
"NumOutputDimensions:" ){
157 errorLog <<
"load(fstream &file) - Failed to read NumOutputDimensions header!" << std::endl;
160 file >> numOutputDimensions;
164 if( word !=
"FilterSize:" ){
165 errorLog <<
"load(fstream &file) - Failed to read FilterSize header!" << std::endl;
171 return init(filterSize,numInputDimensions);
180 if( filterSize == 0 ){
181 errorLog <<
"init(UINT filterSize,UINT numDimensions) - Filter size can not be zero!" << std::endl;
185 if( numDimensions == 0 ){
186 errorLog <<
"init(UINT filterSize,UINT numDimensions) - The number of dimensions must be greater than zero!" << std::endl;
192 this->numInputDimensions = numDimensions;
193 this->numOutputDimensions = numDimensions;
194 processedData.clear();
195 processedData.
resize(numDimensions,0);
199 errorLog <<
"init(UINT filterSize,UINT numDimensions) - Failed to resize dataBuffer!" << std::endl;
209 errorLog <<
"filter(const Float x) - The filter has not been initialized!" << std::endl;
215 if( y.size() == 0 )
return 0;
223 errorLog <<
"filter(const VectorFloat &x) - The filter has not been initialized!" << std::endl;
227 if( x.size() != numInputDimensions ){
228 errorLog <<
"filter(const VectorFloat &x) - The size of the input vector (" << x.
getSize() <<
") does not match that of the number of dimensions of the filter (" << numInputDimensions <<
")!" << std::endl;
237 for(
unsigned int j=0; j<numInputDimensions; j++){
238 processedData[j] = 0;
242 processedData[j] /= Float(inputSampleCounter);
245 return processedData;
virtual bool process(const VectorFloat &inputVector)
bool push_back(const T &value)
std::string getId() const
virtual bool save(std::fstream &file) const
static std::string getId()
The MovingAverageFilter implements a low pass moving average filter.
virtual bool resize(const unsigned int size)
CircularBuffer< VectorFloat > dataBuffer
A buffer to store the previous N values, N = filterSize.
virtual bool deepCopyFrom(const PreProcessing *preProcessing)
VectorFloat getFilteredData() const
Float filter(const Float x)
UINT filterSize
The size of the filter.
MovingAverageFilter & operator=(const MovingAverageFilter &rhs)
virtual bool load(std::fstream &file)
bool copyBaseVariables(const PreProcessing *preProcessingModule)
UINT inputSampleCounter
A counter to keep track of the number of input samples.
UINT getFilterSize() const
MovingAverageFilter(const UINT filterSize=5, const UINT numDimensions=1)
virtual ~MovingAverageFilter()
bool resize(const unsigned int newBufferSize)