GestureRecognitionToolkit  Version: 1.0 Revision: 04-03-15
The Gesture Recognition Toolkit (GRT) is a cross-platform, open-source, c++ machine learning library for real-time gesture recognition.
FFT.h
Go to the documentation of this file.
1 
48 #ifndef GRT_FFT_HEADER
49 #define GRT_FFT_HEADER
50 
51 #include "../../CoreModules/FeatureExtraction.h"
52 #include "FastFourierTransform.h"
53 
54 namespace GRT{
55 
56 class FFT : public FeatureExtraction
57 {
58 public:
72  FFT(UINT fftWindowSize=512,UINT hopSize=1,UINT numDimensions=1,UINT fftWindowFunction=RECTANGULAR_WINDOW,bool computeMagnitude=true,bool computePhase=true);
73 
79  FFT(const FFT &rhs);
80 
84  virtual ~FFT(void);
85 
92  FFT& operator=(const FFT &rhs);
93 
102  virtual bool deepCopyFrom(const FeatureExtraction *featureExtraction);
103 
112  virtual bool computeFeatures(const VectorDouble &inputVector);
113 
121  virtual bool clear();
122 
130  virtual bool reset();
131 
139  virtual bool saveModelToFile(fstream &file) const;
140 
148  virtual bool loadModelFromFile(fstream &file);
149 
165  bool init(UINT fftWindowSize,UINT hopSize,UINT numDimensions,UINT windowFunction,bool computeMagnitude,bool computePhase);
166 
175  bool update(const double x);
176 
185  bool update(const VectorDouble &x);
186 
192  UINT getHopSize();
193 
199  UINT getDataBufferSize();
200 
206  UINT getFFTWindowSize();
207 
213  UINT getFFTWindowFunction();
214 
220  UINT getHopCounter();
221 
227  bool getComputeMagnitude(){ if(initialized){ return computeMagnitude; } return false; }
228 
234  bool getComputePhase(){ if(initialized){ return computePhase; } return false; }
235 
241  vector< FastFourierTransform > getFFTResults(){ return fft; }
242 
248  vector< FastFourierTransform >& getFFTResultsPtr(){ return fft; }
249 
250  VectorDouble getFrequencyBins(const unsigned int sampleRate);
251 
262  bool setHopSize(UINT hopSize);
263 
271  bool setFFTWindowSize(UINT fftWindowSize);
272 
280 
287  bool setComputeMagnitude(bool computeMagnitude);
288 
295  bool setComputePhase(bool computePhase);
296 
299 
300 protected:
301  bool isPowerOfTwo(UINT x);
302  bool validateFFTWindowFunction(UINT fftWindowFunction);
303 
304  UINT hopSize;
308  UINT hopCounter;
311  GRT::VectorDouble tempBuffer;
313  vector< FastFourierTransform > fft;
314  std::map< unsigned int, unsigned int > windowSizeMap;
315 
316  static RegisterFeatureExtractionModule< FFT > registerModule;
317 
318 public:
319  enum FFTWindowFunctionOptions{RECTANGULAR_WINDOW=0,BARTLETT_WINDOW,HAMMING_WINDOW,HANNING_WINDOW};
320 };
321 
322 } //End of namespace GRT
323 
324 #endif //GRT_FFT_HEADER
GRT::VectorDouble tempBuffer
A temporary buffer used to store the input data for the FFT.
Definition: FFT.h:311
bool setFFTWindowFunction(UINT fftWindowFunction)
Definition: FFT.cpp:410
virtual bool saveModelToFile(fstream &file) const
Definition: FFT.cpp:101
vector< FastFourierTransform > & getFFTResultsPtr()
Definition: FFT.h:248
virtual bool reset()
Definition: FFT.cpp:348
vector< FastFourierTransform > getFFTResults()
Definition: FFT.h:241
bool getComputePhase()
Definition: FFT.h:234
UINT hopSize
The current hopSize, this sets how often the fft should be computed.
Definition: FFT.h:304
Definition: AdaBoost.cpp:25
virtual bool saveModelToFile(fstream &file) const
FFT(UINT fftWindowSize=512, UINT hopSize=1, UINT numDimensions=1, UINT fftWindowFunction=RECTANGULAR_WINDOW, bool computeMagnitude=true, bool computePhase=true)
Definition: FFT.cpp:28
virtual ~FFT(void)
Definition: FFT.cpp:56
UINT getHopCounter()
Definition: FFT.cpp:374
virtual bool loadModelFromFile(fstream &file)
UINT dataBufferSize
Stores how much previous input data is stored in the dataBuffer.
Definition: FFT.h:305
virtual bool computeFeatures(const VectorDouble &inputVector)
Definition: FFT.cpp:247
UINT getFFTWindowSize()
Definition: FFT.cpp:363
bool getComputeMagnitude()
Definition: FFT.h:227
virtual bool deepCopyFrom(const FeatureExtraction *featureExtraction)
Definition: FFT.cpp:84
virtual bool clear()
Definition: FFT.cpp:335
bool computePhase
Tracks if the phase of the FFT needs to be computed.
Definition: FFT.h:310
bool setComputeMagnitude(bool computeMagnitude)
Definition: FFT.cpp:418
FFT & operator=(const FFT &rhs)
Definition: FFT.cpp:59
UINT fftWindowSize
Stores the size of the fft (and also the dataBuffer)
Definition: FFT.h:306
bool computeMagnitude
Tracks if the magnitude (and power) of the FFT need to be computed.
Definition: FFT.h:309
bool setFFTWindowSize(UINT fftWindowSize)
Definition: FFT.cpp:399
vector< FastFourierTransform > fft
A buffer used to store the FFT results.
Definition: FFT.h:313
CircularBuffer< VectorDouble > dataBuffer
A circular buffer used to store the previous M inputs.
Definition: FFT.h:312
bool update(const double x)
Definition: FFT.cpp:262
UINT getHopSize()
Definition: FFT.cpp:353
UINT getFFTWindowFunction()
Definition: FFT.cpp:369
bool isPowerOfTwo(UINT x)
A helper function to compute if the input is a power of two.
Definition: FFT.cpp:431
std::map< unsigned int, unsigned int > windowSizeMap
A map to relate the FFTWindowSize enumerations to actual values.
Definition: FFT.h:314
bool setHopSize(UINT hopSize)
Definition: FFT.cpp:389
bool setComputePhase(bool computePhase)
Definition: FFT.cpp:424
UINT fftWindowFunction
The current windowFunction used for the FFT.
Definition: FFT.h:307
UINT getDataBufferSize()
Definition: FFT.cpp:358
virtual bool loadModelFromFile(fstream &file)
Definition: FFT.cpp:127
Definition: FFT.h:56
UINT hopCounter
Keeps track of how many input samples the FFT has seen.
Definition: FFT.h:308