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.
FFT.h
Go to the documentation of this file.
1 
27 #ifndef GRT_FFT_HEADER
28 #define GRT_FFT_HEADER
29 
30 #include "../../CoreModules/FeatureExtraction.h"
31 #include "FastFourierTransform.h"
32 
33 GRT_BEGIN_NAMESPACE
34 
57 class GRT_API FFT : public FeatureExtraction
58 {
59 public:
60  enum FFTWindowFunctionOptions{RECTANGULAR_WINDOW=0,BARTLETT_WINDOW,HAMMING_WINDOW,HANNING_WINDOW};
61 
75  FFT(const UINT fftWindowSize=512,const UINT hopSize=1,const UINT numDimensions=1,const UINT fftWindowFunction=RECTANGULAR_WINDOW,const bool computeMagnitude=true,const bool computePhase=true);
76 
82  FFT(const FFT &rhs);
83 
87  virtual ~FFT(void);
88 
95  FFT& operator=(const FFT &rhs);
96 
105  virtual bool deepCopyFrom(const FeatureExtraction *featureExtraction);
106 
115  virtual bool computeFeatures(const VectorFloat &inputVector);
116 
125  virtual bool computeFeatures(const MatrixFloat &inputMatrix);
126 
134  virtual bool clear();
135 
143  virtual bool reset();
144 
152  virtual bool save( std::fstream &file ) const;
153 
161  virtual bool load( std::fstream &file );
162 
180  bool init(const UINT fftWindowSize,const UINT hopSize=1,const UINT numDimensions=1,const UINT windowFunction=RECTANGULAR_WINDOW,const bool computeMagnitude=true,const bool computePhase=true,const DataType inputType = DATA_TYPE_VECTOR,const DataType outputType = DATA_TYPE_VECTOR);
181 
190  bool update(const Float x);
191 
200  bool update(const VectorFloat &x);
201 
210  bool update(const MatrixFloat &x);
211 
217  UINT getHopSize() const;
218 
224  UINT getDataBufferSize() const;
225 
231  UINT getFFTWindowSize() const;
232 
238  UINT getFFTWindowFunction() const;
239 
245  UINT getHopCounter() const;
246 
252  bool getComputeMagnitude() const { if(initialized){ return computeMagnitude; } return false; }
253 
259  bool getComputePhase() const { if(initialized){ return computePhase; } return false; }
260 
267 
274 
280  const Vector< FastFourierTransform >& getFFTResultsPtr() const { return fft; }
281 
282  VectorFloat getFrequencyBins(const unsigned int sampleRate) const;
283 
294  bool setHopSize(const UINT hopSize);
295 
303  bool setFFTWindowSize(const UINT fftWindowSize);
304 
311  bool setFFTWindowFunction(const UINT fftWindowFunction);
312 
319  bool setComputeMagnitude(const bool computeMagnitude);
320 
327  bool setComputePhase(const bool computePhase);
328 
329  //Tell the compiler we are using the following functions from the MLBase class to stop hidden virtual function warnings
330  using MLBase::save;
331  using MLBase::load;
332 
338  static std::string getId();
339 
340 protected:
341  bool isPowerOfTwo(UINT x);
342  bool validateFFTWindowFunction(UINT fftWindowFunction);
343 
344  UINT hopSize;
348  UINT hopCounter;
354  std::map< unsigned int, unsigned int > windowSizeMap;
355 
356 private:
357  static RegisterFeatureExtractionModule< FFT > registerModule;
358  static std::string id;
359 
360 };
361 
362 GRT_END_NAMESPACE
363 
364 #endif //GRT_FFT_HEADER
365 
bool getComputePhase() const
Definition: FFT.h:259
std::string getId() const
Definition: GRTBase.cpp:85
UINT dataBufferSize
Stores how much previous input data is stored in the dataBuffer.
Definition: FFT.h:345
Vector< FastFourierTransform > fft
A buffer used to store the FFT results.
Definition: FFT.h:353
virtual bool reset()
Definition: MLBase.cpp:147
CircularBuffer< VectorFloat > dataBuffer
A circular buffer used to store the previous M inputs.
Definition: FFT.h:352
Vector< FastFourierTransform > & getFFTResultsPtr()
Definition: FFT.h:273
UINT fftWindowFunction
The current windowFunction used for the FFT.
Definition: FFT.h:347
bool computePhase
Tracks if the phase of the FFT needs to be computed.
Definition: FFT.h:350
UINT hopSize
The current hopSize, this sets how often the fft should be computed.
Definition: FFT.h:344
UINT hopCounter
Keeps track of how many input samples the FFT has seen.
Definition: FFT.h:348
bool getComputeMagnitude() const
Definition: FFT.h:252
VectorFloat tempBuffer
A temporary buffer used to store the input data for the FFT.
Definition: FFT.h:351
virtual bool save(const std::string &filename) const
Definition: MLBase.cpp:167
Definition: FFT.h:57
std::map< unsigned int, unsigned int > windowSizeMap
A map to relate the FFTWindowSize enumerations to actual values.
Definition: FFT.h:354
Vector< FastFourierTransform > getFFTResults() const
Definition: FFT.h:266
virtual bool computeFeatures(const VectorFloat &inputVector)
UINT fftWindowSize
Stores the size of the fft (and also the dataBuffer)
Definition: FFT.h:346
const Vector< FastFourierTransform > & getFFTResultsPtr() const
Definition: FFT.h:280
bool computeMagnitude
Tracks if the magnitude (and power) of the FFT need to be computed.
Definition: FFT.h:349
virtual bool clear() override
virtual bool load(const std::string &filename)
Definition: MLBase.cpp:190
virtual bool deepCopyFrom(const FeatureExtraction *rhs)