GestureRecognitionToolkit  Version: 0.2.0
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 GRT_BEGIN_NAMESPACE
55 
56 class GRT_API 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 VectorFloat &inputVector);
113 
122  virtual bool computeFeatures(const MatrixFloat &inputMatrix);
123 
131  virtual bool clear();
132 
140  virtual bool reset();
141 
149  virtual bool saveModelToFile( std::fstream &file ) const;
150 
158  virtual bool loadModelFromFile( std::fstream &file );
159 
177  bool init(UINT fftWindowSize,UINT hopSize,UINT numDimensions,UINT windowFunction,bool computeMagnitude,bool computePhase,DataType inputType = DATA_TYPE_VECTOR,DataType outputType = DATA_TYPE_VECTOR);
178 
187  bool update(const Float x);
188 
197  bool update(const VectorFloat &x);
198 
207  bool update(const MatrixFloat &x);
208 
214  UINT getHopSize();
215 
221  UINT getDataBufferSize();
222 
228  UINT getFFTWindowSize();
229 
235  UINT getFFTWindowFunction();
236 
242  UINT getHopCounter();
243 
249  bool getComputeMagnitude(){ if(initialized){ return computeMagnitude; } return false; }
250 
256  bool getComputePhase(){ if(initialized){ return computePhase; } return false; }
257 
264 
271 
272  VectorFloat getFrequencyBins(const unsigned int sampleRate);
273 
284  bool setHopSize(UINT hopSize);
285 
293  bool setFFTWindowSize(UINT fftWindowSize);
294 
301  bool setFFTWindowFunction(UINT fftWindowFunction);
302 
309  bool setComputeMagnitude(bool computeMagnitude);
310 
317  bool setComputePhase(bool computePhase);
318 
321 
322 protected:
323  bool isPowerOfTwo(UINT x);
324  bool validateFFTWindowFunction(UINT fftWindowFunction);
325 
326  UINT hopSize;
330  UINT hopCounter;
336  std::map< unsigned int, unsigned int > windowSizeMap;
337 
338  static RegisterFeatureExtractionModule< FFT > registerModule;
339 
340 public:
341  enum FFTWindowFunctionOptions{RECTANGULAR_WINDOW=0,BARTLETT_WINDOW,HAMMING_WINDOW,HANNING_WINDOW};
342 };
343 
344 GRT_END_NAMESPACE
345 
346 #endif //GRT_FFT_HEADER
bool getComputeMagnitude()
Definition: FFT.h:249
UINT dataBufferSize
Stores how much previous input data is stored in the dataBuffer.
Definition: FFT.h:327
Vector< FastFourierTransform > fft
A buffer used to store the FFT results.
Definition: FFT.h:335
CircularBuffer< VectorFloat > dataBuffer
A circular buffer used to store the previous M inputs.
Definition: FFT.h:334
Vector< FastFourierTransform > & getFFTResultsPtr()
Definition: FFT.h:270
UINT fftWindowFunction
The current windowFunction used for the FFT.
Definition: FFT.h:329
virtual bool saveModelToFile(std::fstream &file) const
bool computePhase
Tracks if the phase of the FFT needs to be computed.
Definition: FFT.h:332
UINT hopSize
The current hopSize, this sets how often the fft should be computed.
Definition: FFT.h:326
UINT hopCounter
Keeps track of how many input samples the FFT has seen.
Definition: FFT.h:330
VectorFloat tempBuffer
A temporary buffer used to store the input data for the FFT.
Definition: FFT.h:333
virtual bool loadModelFromFile(std::fstream &file)
Definition: FFT.h:56
std::map< unsigned int, unsigned int > windowSizeMap
A map to relate the FFTWindowSize enumerations to actual values.
Definition: FFT.h:336
virtual bool computeFeatures(const VectorFloat &inputVector)
virtual bool reset()
UINT fftWindowSize
Stores the size of the fft (and also the dataBuffer)
Definition: FFT.h:328
Vector< FastFourierTransform > getFFTResults()
Definition: FFT.h:263
bool computeMagnitude
Tracks if the magnitude (and power) of the FFT need to be computed.
Definition: FFT.h:331
virtual bool deepCopyFrom(const FeatureExtraction *rhs)
bool getComputePhase()
Definition: FFT.h:256