GestureRecognitionToolkit  Version: 0.2.5
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
ThresholdCrossingDetector.h
Go to the documentation of this file.
1 
9 /*
10  GRT MIT License
11  Copyright (c) <2012> <Nicholas Gillian, Media Lab, MIT>
12 
13  Permission is hereby granted, free of charge, to any person obtaining a copy of this software
14  and associated documentation files (the "Software"), to deal in the Software without restriction,
15  including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
16  and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
17  subject to the following conditions:
18 
19  The above copyright notice and this permission notice shall be included in all copies or substantial
20  portions of the Software.
21 
22  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
23  LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
24  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
25  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27  */
28 
29 #ifndef GRT_THRESHOLD_CROSSING_DETECTOR_HEADER
30 #define GRT_THRESHOLD_CROSSING_DETECTOR_HEADER
31 
32 #include "../PreProcessingModules/MovingAverageFilter.h"
33 #include "../PreProcessingModules/Derivative.h"
34 #include "CircularBuffer.h"
35 
36 GRT_BEGIN_NAMESPACE
37 
39 public:
51  ThresholdCrossingDetector(UINT analysisMode = RAW_DATA_ANALYSIS_MODE,UINT thresholdCrossingMode = UPPER_THRESHOLD_CROSSING,UINT detectionTimeoutMode = TIMEOUT_COUNTER,Float lowerThreshold = -1,Float upperThreshold = 1,Float hysteresisThreshold = 0,UINT searchWindowSize = 20,UINT searchTimeoutDuration = 1000,UINT offsetFilterSize = 10);
52 
57 
64 
72 
79  bool update( const Float x );
80 
86  bool reset();
87 
93  bool triggerSearchTimeout();
94 
100  bool getThresholdCrossingDetected() const;
101 
105  bool getEnableSearch() const;
106 
110  UINT getAnalysisMode() const;
111 
115  UINT getThresholdCrossingMode() const;
116 
120  UINT getSearchWindowSize() const;
121 
125  UINT getOffsetFilterSize() const;
126 
130  UINT getSearchWindowIndex() const;
131 
135  UINT getSearchTimeoutCounter();
136 
140  UINT getSearchTimeoutDuration() const;
141 
145  Float getAnalysisValue() const;
146 
150  Float getUpperThreshold() const;
151 
155  Float getLowerThreshold() const;
156 
160  Float getHysteresisThreshold() const;
161 
169  bool setEnableSearch(const bool enableSearch);
170 
177  bool setAnalysisMode(const UINT analysisMode);
178 
185  bool setThresholdCrossingMode(const UINT thresholdCrossingMode);
186 
194  bool setSearchWindowSize(const UINT searchWindowSize);
195 
202  bool setOffsetFilterSize(const UINT offsetFilterSize);
203 
210  bool setSearchTimeoutDuration(const UINT searchTimeoutDuration);
211 
221  bool setDetectionTimeoutMode(const UINT detectionTimeoutMode);
222 
229  bool setLowerThreshold(const Float lowerThreshold);
230 
237  bool setUpperThreshold(const Float upperThreshold);
238 
245  bool setHysteresisThreshold(const Float hysteresisThreshold);
246 
247 protected:
248  Float analysisValue;
249  Float lowerThreshold;
250  Float upperThreshold;
251  Float hysteresisThreshold;
252  bool enableSearch;
253  bool thresholdCrossingDetected;
254  unsigned int analysisMode;
255  unsigned int thresholdCrossingMode;
256  unsigned int detectionTimeoutMode;
257  unsigned int searchTimeoutDuration;
258  unsigned int searchWindowSize;
259  unsigned int searchWindowIndex;
260  unsigned int offsetFilterSize;
261  unsigned int currentSearchState;
262  Timer searchTimeoutCounter;
263  MovingAverageFilter movingAverageFilter;
264  Derivative derivative;
265 
266 public:
267  enum SearchStates{SEARCHING_FOR_FIRST_THRESHOLD_CROSSING=0,SEARCHING_FOR_SECOND_THRESHOLD_CROSSING,NO_SEARCH_GATE_TIME_OUT};
268 
269  enum ThresholdCrossingModes{UPPER_THRESHOLD_CROSSING=0,
270  LOWER_THRESHOLD_CROSSING,
271  UPPER_OR_LOWER_THRESHOLD_CROSSING,
272  UPPER_THEN_LOWER_THRESHOLD_CROSSING,
273  LOWER_THEN_UPPER_THRESHOLD_CROSSING};
274 
275  enum AnalysisModes{RAW_DATA_ANALYSIS_MODE=0,MOVING_OFFSET_ANALYSIS_MODE,DERIVATIVE_ANALYSIS_MODE};
276 
277  enum DetectionTimeoutMode{TIMEOUT_COUNTER=0,HYSTERESIS_THRESHOLD};
278 
279 };
280 
281 GRT_END_NAMESPACE
282 
283 #endif //GRT_THRESHOLD_CROSSING_DETECTOR_HEADER
Definition: Timer.h:43
The MovingAverageFilter implements a low pass moving average filter.
The Derivative class computes either the first or second order derivative of the input signal...
Definition: Derivative.h:39