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.
FastFourierTransform.h
1 /*
2  GRT MIT License
3  Copyright (c) <2012> <Nicholas Gillian, Media Lab, MIT>
4 
5  Permission is hereby granted, free of charge, to any person obtaining a copy of this software
6  and associated documentation files (the "Software"), to deal in the Software without restriction,
7  including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
9  subject to the following conditions:
10 
11  The above copyright notice and this permission notice shall be included in all copies or substantial
12  portions of the Software.
13 
14  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT
15  LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
16  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
17  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
18  SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19  */
20 
21 /*
22  This code is based on Dominic Mazzoni's FFT c++ wrapper, which is based on a free FFT implementation
23  by Don Cross (http://www.intersrv.com/~dcross/fft.html) and the FFT algorithms from Numerical Recipes.
24  */
25 
26 #ifndef GRT_FAST_FOURIER_TRANSFORM_HEADER
27 #define GRT_FAST_FOURIER_TRANSFORM_HEADER
28 
29 #include "../../Util/GRTCommon.h"
30 #include "../../CoreModules/GRTBase.h"
31 
32 GRT_BEGIN_NAMESPACE
33 
34 class GRT_API FastFourierTransform : public GRTBase{
35 
36 public:
37 
38  enum WindowFunctionOptions{RECTANGULAR_WINDOW=0,BARTLETT_WINDOW,HAMMING_WINDOW,HANNING_WINDOW};
39 
41 
43 
44  virtual ~FastFourierTransform();
45 
46  FastFourierTransform& operator=(const FastFourierTransform &rhs);
47 
48  bool init(const unsigned int windowSize,const unsigned int windowFunction = RECTANGULAR_WINDOW,const bool computeMagnitude = true,const bool computePhase = true,bool enableZeroPadding = true);
49 
50  bool computeFFT( VectorFloat &data );
51 
52  VectorFloat getMagnitudeData() const;
53  VectorFloat getPhaseData() const;
54  VectorFloat getPowerData() const;
55  Float getAveragePower() const;
56  Float *getMagnitudeDataPtr();
57  Float *getPhaseDataPtr();
58  Float *getPowerDataPtr();
59 
60  UINT getFFTSize() const { return windowSize; }
61 
62 protected:
63  bool windowData( VectorFloat &data );
64  bool realFFT( const VectorFloat &realIn, Float *realOut, Float *imagOut );
65  bool FFT(int NumSamples,bool InverseTransform,Float *realIn, Float *imagIn, Float *realOut, Float *imagOut);
66  int numberOfBitsNeeded(int PowerOfTwo);
67  int reverseBits(int index, int NumBits);
68  void initFFT();
69  inline int fastReverseBits(const int i, const int NumBits);
70  inline bool isPowerOfTwo(const unsigned int x);
71 
72  unsigned int windowSize;
73  unsigned int windowFunction;
74  bool initialized;
75  bool computeMagnitude;
76  bool computePhase;
77  bool enableZeroPadding;
78  VectorFloat fftReal;
79  VectorFloat fftImag;
80  VectorFloat tmpReal;
81  VectorFloat tmpImag;
82  VectorFloat magnitude;
83  VectorFloat phase;
84  VectorFloat power;
85  Float averagePower;
86  const static int MAX_FAST_BITS = 16;
87  Vector< Vector< int > > bitTable;
88 };
89 
90 GRT_END_NAMESPACE
91 
92 #endif //GRT_FAST_FOURIER_TRANSFORM_HEADER
Definition: FFT.h:57
Definition: Vector.h:41