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!" << std::endl;
87 errorLog <<
"computeFeatures(const VectorFloat &inputVector) - Not initialized!" << std::endl;
91 if( inputVector.size() != numInputDimensions ){
92 errorLog <<
"computeFeatures(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.size() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::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!" << std::endl;
145 file <<
"GRT_ZERO_CROSSING_COUNTER_FILE_V1.0" << std::endl;
149 errorLog <<
"saveFeatureExtractionSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << std::endl;
155 file <<
"FeatureMode: " <<
featureMode << std::endl;
163 if( !file.is_open() ){
164 errorLog <<
"loadModelFromFile(fstream &file) - The file is not open!" << std::endl;
173 if( word !=
"GRT_ZERO_CROSSING_COUNTER_FILE_V1.0" ){
174 errorLog <<
"loadModelFromFile(fstream &file) - Invalid file format!" << std::endl;
179 errorLog <<
"loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
184 if( word !=
"SearchWindowSize:" ){
185 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read SearchWindowSize header!" << std::endl;
191 if( word !=
"FeatureMode:" ){
192 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read FeatureMode header!" << std::endl;
198 if( word !=
"DeadZoneThreshold:" ){
199 errorLog <<
"loadModelFromFile(fstream &file) - Failed to read DeadZoneThreshold header!" << std::endl;
205 return init(searchWindowSize,deadZoneThreshold,numInputDimensions,featureMode);
211 featureDataReady =
false;
213 if( searchWindowSize == 0 ){
214 errorLog <<
"init(UINT searchWindowSize,Float deadZoneThreshold,UINT numDimensions,UINT featureMode) - The searchWindowSize must be greater than zero!" << std::endl;
218 if( deadZoneThreshold < 0 ){
219 errorLog <<
"init(UINT searchWindowSize,Float deadZoneThreshold,UINT numDimensions,UINT featureMode) - The deadZoneThreshold must be greater than zero!" << std::endl;
223 if( numDimensions == 0 ){
224 errorLog <<
"init(UINT searchWindowSize,Float deadZoneThreshold,UINT numDimensions,UINT featureMode) - The numDimensions must be greater than zero!" << std::endl;
228 if( featureMode != INDEPENDANT_FEATURE_MODE && featureMode != COMBINED_FEATURE_MODE ){
229 errorLog <<
"init(UINT searchWindowSize,Float deadZoneThreshold,UINT numDimensions,UINT featureMode) - Unkown feature mode!" << std::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);
242 featureVector.
resize(numOutputDimensions,0);
258 errorLog <<
"update(const VectorFloat &x) - Not Initialized!" << std::endl;
262 if( x.
getSize() != numInputDimensions ){
263 errorLog <<
"update(const VectorFloat &x)- The Number Of Input Dimensions (" << numInputDimensions <<
") does not match the size of the input vector (" << x.
getSize() <<
")!" << std::endl;
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 Float 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!" << std::endl;
317 if( featureMode == INDEPENDANT_FEATURE_MODE || featureMode == COMBINED_FEATURE_MODE ){
319 if( initialized )
return reset();
322 errorLog <<
"setFeatureMode(UINT featureMode) - Unkown feature mode!" << std::endl;
327 if( deadZoneThreshold > 0 ){
329 if( initialized )
return reset();
332 errorLog <<
"setDeadZoneThreshold(Float deadZoneThreshold) - The deadZoneThreshold must be larger than zero!" << std::endl;
bool push_back(const T &value)
bool setDeadZoneThreshold(Float deadZoneThreshold)
DeadZone deadZone
Used to remove small amounts of noise from the data.
VectorFloat update(Float x)
virtual bool resize(const unsigned int size)
virtual bool deepCopyFrom(const FeatureExtraction *featureExtraction)
Float filter(const Float x)
bool init(UINT derivativeOrder, Float delta, UINT numDimensions, bool filterData, UINT filterSize)
Float computeDerivative(const Float x)
unsigned int getSize() const
CircularBuffer< VectorFloat > dataBuffer
A buffer used to store the previous derivative data.
virtual ~ZeroCrossingCounter()
virtual bool saveModelToFile(std::string filename) const
UINT searchWindowSize
The size of the search window, i.e. the amount of previous data stored and searched.
bool init(Float lowerLimit, Float upperLimit, UINT numDimensions)
ZeroCrossingCounter & operator=(const ZeroCrossingCounter &rhs)
virtual bool computeFeatures(const VectorFloat &inputVector)
UINT featureMode
The featureMode controls how the features are added to the feature vector.
bool setSearchWindowSize(UINT searchWindowSize)
VectorFloat getProcessedData() const
virtual bool loadModelFromFile(std::string filename)
Float deadZoneThreshold
The threshold value used for the dead zone filter.
Derivative derivative
Used to compute the derivative of the input signal.
bool setFeatureMode(UINT featureMode)
unsigned int getSize() const
ZeroCrossingCounter(UINT searchWindowSize=20, Float deadZoneThreshold=0.01, UINT numDimensions=1, UINT featureMode=INDEPENDANT_FEATURE_MODE)
bool resize(const unsigned int newBufferSize)