21 #define GRT_DLL_EXPORTS 27 std::string ZeroCrossingCounter::id =
"ZeroCrossingCounter";
35 init(searchWindowSize,deadZoneThreshold,numDimensions,featureMode);
64 if( featureExtraction == NULL )
return false;
66 if( this->
getId() == featureExtraction->
getId() ){
72 errorLog <<
"deepCopyFrom(FeatureExtraction *featureExtraction) - FeatureExtraction Types Do Not Match!" << std::endl;
80 errorLog <<
"computeFeatures(const VectorFloat &inputVector) - Not initialized!" << std::endl;
84 if( inputVector.
getSize() != numInputDimensions ){
85 errorLog <<
"computeFeatures(const VectorFloat &inputVector) - The size of the inputVector (" << inputVector.
getSize() <<
") does not match that of the filter (" << numInputDimensions <<
")!" << std::endl;
103 if( !file.is_open() ){
104 errorLog <<
"save(fstream &file) - The file is not open!" << std::endl;
109 file <<
"GRT_ZERO_CROSSING_COUNTER_FILE_V1.0" << std::endl;
113 errorLog <<
"saveFeatureExtractionSettingsToFile(fstream &file) - Failed to save base feature extraction settings to file!" << std::endl;
119 file <<
"FeatureMode: " <<
featureMode << std::endl;
127 if( !file.is_open() ){
128 errorLog <<
"load(fstream &file) - The file is not open!" << std::endl;
137 if( word !=
"GRT_ZERO_CROSSING_COUNTER_FILE_V1.0" ){
138 errorLog <<
"load(fstream &file) - Invalid file format!" << std::endl;
143 errorLog <<
"loadFeatureExtractionSettingsFromFile(fstream &file) - Failed to load base feature extraction settings from file!" << std::endl;
148 if( word !=
"SearchWindowSize:" ){
149 errorLog <<
"load(fstream &file) - Failed to read SearchWindowSize header!" << std::endl;
155 if( word !=
"FeatureMode:" ){
156 errorLog <<
"load(fstream &file) - Failed to read FeatureMode header!" << std::endl;
162 if( word !=
"DeadZoneThreshold:" ){
163 errorLog <<
"load(fstream &file) - Failed to read DeadZoneThreshold header!" << std::endl;
169 return init(searchWindowSize,deadZoneThreshold,numInputDimensions,featureMode);
175 featureDataReady =
false;
177 if( searchWindowSize == 0 ){
178 errorLog <<
"init(UINT searchWindowSize,Float deadZoneThreshold,UINT numDimensions,UINT featureMode) - The searchWindowSize must be greater than zero!" << std::endl;
182 if( deadZoneThreshold < 0 ){
183 errorLog <<
"init(UINT searchWindowSize,Float deadZoneThreshold,UINT numDimensions,UINT featureMode) - The deadZoneThreshold must be greater than zero!" << std::endl;
187 if( numDimensions == 0 ){
188 errorLog <<
"init(UINT searchWindowSize,Float deadZoneThreshold,UINT numDimensions,UINT featureMode) - The numDimensions must be greater than zero!" << std::endl;
192 if( featureMode != INDEPENDANT_FEATURE_MODE && featureMode != COMBINED_FEATURE_MODE ){
193 errorLog <<
"init(UINT searchWindowSize,Float deadZoneThreshold,UINT numDimensions,UINT featureMode) - Unkown feature mode!" << std::endl;
201 numInputDimensions = numDimensions;
202 numOutputDimensions = (featureMode == INDEPENDANT_FEATURE_MODE ? TOTAL_NUM_ZERO_CROSSING_FEATURES * numInputDimensions : TOTAL_NUM_ZERO_CROSSING_FEATURES);
203 derivative.
init(Derivative::FIRST_DERIVATIVE, 1.0, numInputDimensions,
true, 5);
204 deadZone.
init(-deadZoneThreshold,deadZoneThreshold,numInputDimensions);
206 featureVector.
resize(numOutputDimensions,0);
222 errorLog <<
"update(const VectorFloat &x) - Not Initialized!" << std::endl;
226 if( x.
getSize() != numInputDimensions ){
227 errorLog <<
"update(const VectorFloat &x)- The Number Of Input Dimensions (" << numInputDimensions <<
") does not match the size of the input vector (" << x.
getSize() <<
")!" << std::endl;
232 std::fill(featureVector.begin(),featureVector.end(),0);
244 for(UINT j=0; j<numInputDimensions; j++){
245 UINT colIndex = (
featureMode == INDEPENDANT_FEATURE_MODE ? (TOTAL_NUM_ZERO_CROSSING_FEATURES*j) : 0);
250 featureVector[ NUM_ZERO_CROSSINGS_COUNTED + colIndex ]++;
254 UINT searchSize = i > 5 ? 5 : i;
255 for(UINT n=0; n<searchSize; n++){
256 Float value = fabs( dataBuffer[ i-n ][j] );
257 if( value > maxValue ) maxValue = value;
259 featureVector[ ZERO_CROSSING_MAGNITUDE + colIndex ] += maxValue;
265 featureDataReady =
true;
267 return featureVector;
271 if( searchWindowSize > 0 ){
273 if( initialized )
return reset();
276 errorLog <<
"setSearchWindowSize(const UINT searchWindowSize) - The searchWindowSize must be larger than zero!" << std::endl;
281 if( featureMode == INDEPENDANT_FEATURE_MODE || featureMode == COMBINED_FEATURE_MODE ){
283 if( initialized )
return reset();
286 errorLog <<
"setFeatureMode(UINT featureMode) - Unkown feature mode!" << std::endl;
291 if( deadZoneThreshold > 0 ){
293 if( initialized )
return reset();
296 errorLog <<
"setDeadZoneThreshold(const Float deadZoneThreshold) - The deadZoneThreshold must be larger than zero!" << std::endl;
bool push_back(const T &value)
std::string getId() const
bool setDeadZoneThreshold(const Float deadZoneThreshold)
DeadZone deadZone
Used to remove small amounts of noise from the data.
virtual bool save(std::fstream &file) const
virtual bool load(std::fstream &file)
virtual bool resize(const unsigned int size)
virtual bool deepCopyFrom(const FeatureExtraction *featureExtraction)
Float filter(const Float x)
Float computeDerivative(const Float x)
CircularBuffer< VectorFloat > dataBuffer
A buffer used to store the previous derivative data.
ZeroCrossingCounter(const UINT searchWindowSize=20, const Float deadZoneThreshold=0.01, const UINT numDimensions=1, const UINT featureMode=INDEPENDANT_FEATURE_MODE)
virtual ~ZeroCrossingCounter()
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)
bool setFeatureMode(const UINT featureMode)
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.
static std::string getId()
VectorFloat getProcessedData() const
bool init(const UINT derivativeOrder, const Float delta, const UINT numDimensions, const bool filterData, const UINT filterSize)
Float deadZoneThreshold
The threshold value used for the dead zone filter.
Derivative derivative
Used to compute the derivative of the input signal.
VectorFloat update(const Float x)
bool setSearchWindowSize(const UINT searchWindowSize)
unsigned int getSize() const
bool resize(const unsigned int newBufferSize)