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.
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 
39 
41 
42  virtual ~FastFourierTransform();
43 
44  FastFourierTransform& operator=(const FastFourierTransform &rhs);
45 
46  bool init(const unsigned int windowSize,const unsigned int windowFunction = RECTANGULAR_WINDOW,const bool computeMagnitude = true,const bool computePhase = true,bool enableZeroPadding = true);
47 
48  bool computeFFT( VectorFloat &data );
49 
50  VectorFloat getMagnitudeData();
51  VectorFloat getPhaseData();
52  VectorFloat getPowerData();
53  Float getAveragePower();
54  Float *getMagnitudeDataPtr();
55  Float *getPhaseDataPtr();
56  Float *getPowerDataPtr();
57 
58  UINT getFFTSize(){ return windowSize; }
59 
60 protected:
61  bool windowData( VectorFloat &data );
62  bool realFFT( const VectorFloat &realIn, Float *realOut, Float *imagOut );
63  bool FFT(int NumSamples,bool InverseTransform,Float *realIn, Float *imagIn, Float *realOut, Float *imagOut);
64  int numberOfBitsNeeded(int PowerOfTwo);
65  int reverseBits(int index, int NumBits);
66  void initFFT();
67  inline int fastReverseBits(const int i, const int NumBits);
68  inline bool isPowerOfTwo(const unsigned int x);
69 
70  unsigned int windowSize;
71  unsigned int windowFunction;
72  bool initialized;
73  bool computeMagnitude;
74  bool computePhase;
75  bool enableZeroPadding;
76  VectorFloat fftReal;
77  VectorFloat fftImag;
78  VectorFloat tmpReal;
79  VectorFloat tmpImag;
80  VectorFloat magnitude;
81  VectorFloat phase;
82  VectorFloat power;
83  Float averagePower;
84  const static int MAX_FAST_BITS = 16;
85  Vector< Vector< int > > bitTable;
86 
87 public:
88  enum WindowFunctionOptions{RECTANGULAR_WINDOW=0,BARTLETT_WINDOW,HAMMING_WINDOW,HANNING_WINDOW};
89 
90 };
91 
92 GRT_END_NAMESPACE
93 
94 #endif //GRT_FAST_FOURIER_TRANSFORM_HEADER
Definition: FFT.h:56
Definition: Vector.h:41