26 RegisterFeatureExtractionModule< ZeroCrossingCounter > ZeroCrossingCounter::registerModule(
"ZeroCrossingCounter");
30 classType =
"ZeroCrossingCounter";
31 featureExtractionType = classType;
32 debugLog.setProceedingText(
"[DEBUG ZeroCrossingCounter]");
33 errorLog.setProceedingText(
"[ERROR ZeroCrossingCounter]");
34 warningLog.setProceedingText(
"[WARNING ZeroCrossingCounter]");
36 init(searchWindowSize,deadZoneThreshold,numDimensions,featureMode);
41 classType =
"ZeroCrossingCounter";
42 featureExtractionType = classType;
43 debugLog.setProceedingText(
"[DEBUG ZeroCrossingCounter]");
44 errorLog.setProceedingText(
"[ERROR ZeroCrossingCounter]");
45 warningLog.setProceedingText(
"[WARNING ZeroCrossingCounter]");
71 if( featureExtraction == NULL )
return false;
79 errorLog <<
"clone(FeatureExtraction *featureExtraction) - FeatureExtraction Types Do Not Match!" << endl;
87 errorLog <<
"computeFeatures(const VectorDouble &inputVector) - Not initialized!" << endl;
91 if( inputVector.size() != numInputDimensions ){
92 errorLog <<
"computeFeatures(const VectorDouble &inputVector) - The size of the inputVector (" << inputVector.size() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << endl;
111 file.open(filename.c_str(), std::ios::out);
125 file.open(filename.c_str(), std::ios::in);
139 if( !file.is_open() ){
140 errorLog <<
"saveModelToFile(fstream &file) - The file is not open!" << endl;
145 file <<
"GRT_ZERO_CROSSING_COUNTER_FILE_V1.0" << endl;
149 errorLog <<
"saveFeatureExtractionSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << endl;
163 if( !file.is_open() ){
164 errorLog <<
"loadModelFromFile(fstream &file) - The file is not open!" << endl;
173 if( word !=
"GRT_ZERO_CROSSING_COUNTER_FILE_V1.0" ){
174 errorLog <<
"loadModelFromFile(fstream &file) - Invalid file format!" << endl;
179 errorLog <<
"loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << endl;
184 if( word !=
"SearchWindowSize:" ){
185 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read SearchWindowSize header!" << endl;
191 if( word !=
"FeatureMode:" ){
192 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read FeatureMode header!" << endl;
198 if( word !=
"DeadZoneThreshold:" ){
199 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read DeadZoneThreshold header!" << endl;
205 return init(searchWindowSize,deadZoneThreshold,numInputDimensions,featureMode);
211 featureDataReady =
false;
213 if( searchWindowSize == 0 ){
214 errorLog <<
"init(UINT searchWindowSize,double deadZoneThreshold,UINT numDimensions,UINT featureMode) - The searchWindowSize must be greater than zero!" << endl;
218 if( deadZoneThreshold < 0 ){
219 errorLog <<
"init(UINT searchWindowSize,double deadZoneThreshold,UINT numDimensions,UINT featureMode) - The deadZoneThreshold must be greater than zero!" << endl;
223 if( numDimensions == 0 ){
224 errorLog <<
"init(UINT searchWindowSize,double deadZoneThreshold,UINT numDimensions,UINT featureMode) - The numDimensions must be greater than zero!" << endl;
228 if( featureMode != INDEPENDANT_FEATURE_MODE && featureMode != COMBINED_FEATURE_MODE ){
229 errorLog <<
"init(UINT searchWindowSize,double deadZoneThreshold,UINT numDimensions,UINT featureMode) - Unkown feature mode!" << endl;
237 numInputDimensions = numDimensions;
238 numOutputDimensions = (featureMode == INDEPENDANT_FEATURE_MODE ? TOTAL_NUM_ZERO_CROSSING_FEATURES * numInputDimensions : TOTAL_NUM_ZERO_CROSSING_FEATURES);
239 derivative.
init(Derivative::FIRST_DERIVATIVE, 1.0, numInputDimensions,
true, 5);
240 deadZone.
init(-deadZoneThreshold,deadZoneThreshold,numInputDimensions);
241 dataBuffer.
resize( searchWindowSize, vector< double >(numInputDimensions,NAN) );
242 featureVector.resize(numOutputDimensions,0);
252 return update(VectorDouble(1,x));
258 errorLog <<
"update(const VectorDouble &x) - Not Initialized!" << endl;
259 return vector<double>();
262 if( x.size() != numInputDimensions ){
263 errorLog <<
"update(const VectorDouble &x)- The Number Of Input Dimensions (" << numInputDimensions <<
") does not match the size of the input vector (" << x.size() <<
")!" << endl;
264 return vector<double>();
268 std::fill(featureVector.begin(),featureVector.end(),0);
280 for(UINT j=0; j<numInputDimensions; j++){
281 UINT colIndex = (
featureMode == INDEPENDANT_FEATURE_MODE ? (TOTAL_NUM_ZERO_CROSSING_FEATURES*j) : 0);
286 featureVector[ NUM_ZERO_CROSSINGS_COUNTED + colIndex ]++;
290 UINT searchSize = i > 5 ? 5 : i;
291 for(UINT n=0; n<searchSize; n++){
292 double value = fabs( dataBuffer[ i-n ][j] );
293 if( value > maxValue ) maxValue = value;
295 featureVector[ ZERO_CROSSING_MAGNITUDE + colIndex ] += maxValue;
301 featureDataReady =
true;
303 return featureVector;
307 if( searchWindowSize > 0 ){
309 if( initialized )
return reset();
312 errorLog <<
"setSearchWindowSize(UINT searchWindowSize) - The searchWindowSize must be larger than zero!" << endl;
317 if( deadZoneThreshold > 0 ){
319 if( initialized )
return reset();
322 errorLog <<
"setDeadZoneThreshold(UINT deadZoneThreshold) - The deadZoneThreshold must be larger than zero!" << endl;
327 if( featureMode == INDEPENDANT_FEATURE_MODE || featureMode == COMBINED_FEATURE_MODE ){
329 if( initialized )
return reset();
332 errorLog <<
"setFeatureMode(UINT featureMode) - Unkown feature mode!" << endl;
virtual bool saveModelToFile(string filename) const
bool init(double lowerLimit, double upperLimit, UINT numDimensions)
VectorDouble update(double x)
virtual bool computeFeatures(const VectorDouble &inputVector)
double filter(const double x)
virtual bool loadModelFromFile(string filename)
virtual ~ZeroCrossingCounter()
double deadZoneThreshold
The threshold value used for the dead zone filter.
CircularBuffer< VectorDouble > dataBuffer
A buffer used to store the previous derivative data.
bool push_back(const T &value)
bool init(UINT derivativeOrder, double delta, UINT numDimensions, bool filterData, UINT filterSize)
bool setSearchWindowSize(UINT searchWindowSize)
bool resize(const unsigned int newBufferSize)
unsigned int getSize() const
bool setFeatureMode(UINT featureMode)
VectorDouble getProcessedData() const
virtual bool deepCopyFrom(const FeatureExtraction *featureExtraction)
bool setDeadZoneThreshold(UINT deadZoneThreshold)
DeadZone deadZone
Used to remove small amounts of noise from the data.
ZeroCrossingCounter & operator=(const ZeroCrossingCounter &rhs)
ZeroCrossingCounter(UINT searchWindowSize=20, double deadZoneThreshold=0.01, UINT numDimensions=1, UINT featureMode=INDEPENDANT_FEATURE_MODE)
Derivative derivative
Used to compute the derivative of the input signal.
double computeDerivative(const double x)
UINT featureMode
The featureMode controls how the features are added to the feature vector.
UINT searchWindowSize
The size of the search window, i.e. the amount of previous data stored and searched.