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.
GRT::FFT Class Reference
Inheritance diagram for GRT::FFT:
GRT::FeatureExtraction GRT::MLBase GRT::GRTBase GRT::Observer< TrainingResult > GRT::Observer< TestInstanceResult >

Public Types

enum  FFTWindowFunctionOptions { RECTANGULAR_WINDOW =0, BARTLETT_WINDOW, HAMMING_WINDOW, HANNING_WINDOW }
 
- Public Types inherited from GRT::FeatureExtraction
typedef std::map< string, FeatureExtraction *(*)() > StringFeatureExtractionMap
 
- Public Types inherited from GRT::MLBase
enum  BaseTypes { BASE_TYPE_NOT_SET =0, CLASSIFIER, REGRESSIFIER, CLUSTERER }
 

Public Member Functions

 FFT (UINT fftWindowSize=512, UINT hopSize=1, UINT numDimensions=1, UINT fftWindowFunction=RECTANGULAR_WINDOW, bool computeMagnitude=true, bool computePhase=true)
 
 FFT (const FFT &rhs)
 
virtual ~FFT (void)
 
FFToperator= (const FFT &rhs)
 
virtual bool deepCopyFrom (const FeatureExtraction *featureExtraction)
 
virtual bool computeFeatures (const VectorDouble &inputVector)
 
virtual bool clear ()
 
virtual bool reset ()
 
virtual bool saveModelToFile (fstream &file) const
 
virtual bool loadModelFromFile (fstream &file)
 
bool init (UINT fftWindowSize, UINT hopSize, UINT numDimensions, UINT windowFunction, bool computeMagnitude, bool computePhase)
 
bool update (const double x)
 
bool update (const VectorDouble &x)
 
UINT getHopSize ()
 
UINT getDataBufferSize ()
 
UINT getFFTWindowSize ()
 
UINT getFFTWindowFunction ()
 
UINT getHopCounter ()
 
bool getComputeMagnitude ()
 
bool getComputePhase ()
 
vector< FastFourierTransformgetFFTResults ()
 
vector< FastFourierTransform > & getFFTResultsPtr ()
 
VectorDouble getFrequencyBins (const unsigned int sampleRate)
 
bool setHopSize (UINT hopSize)
 
bool setFFTWindowSize (UINT fftWindowSize)
 
bool setFFTWindowFunction (UINT fftWindowFunction)
 
bool setComputeMagnitude (bool computeMagnitude)
 
bool setComputePhase (bool computePhase)
 
- Public Member Functions inherited from GRT::FeatureExtraction
 FeatureExtraction ()
 
virtual ~FeatureExtraction ()
 
bool copyBaseVariables (const FeatureExtraction *featureExtractionModule)
 
string getFeatureExtractionType () const
 
UINT getNumInputDimensions () const
 
UINT getNumOutputDimensions () const
 
bool getInitialized () const
 
bool getFeatureDataReady () const
 
VectorDouble getFeatureVector () const
 
FeatureExtractioncreateNewInstance () const
 
- Public Member Functions inherited from GRT::MLBase
 MLBase (void)
 
virtual ~MLBase (void)
 
bool copyMLBaseVariables (const MLBase *mlBase)
 
virtual bool train (ClassificationData trainingData)
 
virtual bool train_ (ClassificationData &trainingData)
 
virtual bool train (RegressionData trainingData)
 
virtual bool train_ (RegressionData &trainingData)
 
virtual bool train (TimeSeriesClassificationData trainingData)
 
virtual bool train_ (TimeSeriesClassificationData &trainingData)
 
virtual bool train (TimeSeriesClassificationDataStream trainingData)
 
virtual bool train_ (TimeSeriesClassificationDataStream &trainingData)
 
virtual bool train (UnlabelledData trainingData)
 
virtual bool train_ (UnlabelledData &trainingData)
 
virtual bool train (MatrixDouble data)
 
virtual bool train_ (MatrixDouble &data)
 
virtual bool predict (VectorDouble inputVector)
 
virtual bool predict_ (VectorDouble &inputVector)
 
virtual bool predict (MatrixDouble inputMatrix)
 
virtual bool predict_ (MatrixDouble &inputMatrix)
 
virtual bool map (VectorDouble inputVector)
 
virtual bool map_ (VectorDouble &inputVector)
 
virtual bool print () const
 
virtual bool save (const string filename) const
 
virtual bool load (const string filename)
 
virtual bool saveModelToFile (string filename) const
 
virtual bool loadModelFromFile (string filename)
 
virtual bool getModel (ostream &stream) const
 
double scale (const double &x, const double &minSource, const double &maxSource, const double &minTarget, const double &maxTarget, const bool constrain=false)
 
virtual string getModelAsString () const
 
UINT getBaseType () const
 
UINT getNumInputFeatures () const
 
UINT getNumInputDimensions () const
 
UINT getNumOutputDimensions () const
 
UINT getMinNumEpochs () const
 
UINT getMaxNumEpochs () const
 
UINT getValidationSetSize () const
 
UINT getNumTrainingIterationsToConverge () const
 
double getMinChange () const
 
double getLearningRate () const
 
double getRootMeanSquaredTrainingError () const
 
double getTotalSquaredTrainingError () const
 
bool getUseValidationSet () const
 
bool getRandomiseTrainingOrder () const
 
bool getTrained () const
 
bool getModelTrained () const
 
bool getScalingEnabled () const
 
bool getIsBaseTypeClassifier () const
 
bool getIsBaseTypeRegressifier () const
 
bool getIsBaseTypeClusterer () const
 
bool enableScaling (bool useScaling)
 
bool setMaxNumEpochs (const UINT maxNumEpochs)
 
bool setMinNumEpochs (const UINT minNumEpochs)
 
bool setMinChange (const double minChange)
 
bool setLearningRate (double learningRate)
 
bool setUseValidationSet (const bool useValidationSet)
 
bool setValidationSetSize (const UINT validationSetSize)
 
bool setRandomiseTrainingOrder (const bool randomiseTrainingOrder)
 
bool registerTrainingResultsObserver (Observer< TrainingResult > &observer)
 
bool registerTestResultsObserver (Observer< TestInstanceResult > &observer)
 
bool removeTrainingResultsObserver (const Observer< TrainingResult > &observer)
 
bool removeTestResultsObserver (const Observer< TestInstanceResult > &observer)
 
bool removeAllTrainingObservers ()
 
bool removeAllTestObservers ()
 
bool notifyTrainingResultsObservers (const TrainingResult &data)
 
bool notifyTestResultsObservers (const TestInstanceResult &data)
 
MLBasegetMLBasePointer ()
 
const MLBasegetMLBasePointer () const
 
vector< TrainingResultgetTrainingResults () const
 
- Public Member Functions inherited from GRT::GRTBase
 GRTBase (void)
 
virtual ~GRTBase (void)
 
bool copyGRTBaseVariables (const GRTBase *GRTBase)
 
string getClassType () const
 
string getLastWarningMessage () const
 
string getLastErrorMessage () const
 
string getLastInfoMessage () const
 
GRTBasegetGRTBasePointer ()
 
const GRTBasegetGRTBasePointer () const
 
- Public Member Functions inherited from GRT::Observer< TrainingResult >
virtual void notify (const TrainingResult &data)
 
- Public Member Functions inherited from GRT::Observer< TestInstanceResult >
virtual void notify (const TestInstanceResult &data)
 

Protected Member Functions

bool isPowerOfTwo (UINT x)
 A helper function to compute if the input is a power of two.
 
bool validateFFTWindowFunction (UINT fftWindowFunction)
 
- Protected Member Functions inherited from GRT::FeatureExtraction
bool init ()
 
bool saveFeatureExtractionSettingsToFile (fstream &file) const
 
bool loadFeatureExtractionSettingsFromFile (fstream &file)
 
- Protected Member Functions inherited from GRT::MLBase
bool saveBaseSettingsToFile (fstream &file) const
 
bool loadBaseSettingsFromFile (fstream &file)
 
- Protected Member Functions inherited from GRT::GRTBase
double SQR (const double &x) const
 

Protected Attributes

UINT hopSize
 The current hopSize, this sets how often the fft should be computed.
 
UINT dataBufferSize
 Stores how much previous input data is stored in the dataBuffer.
 
UINT fftWindowSize
 Stores the size of the fft (and also the dataBuffer)
 
UINT fftWindowFunction
 The current windowFunction used for the FFT.
 
UINT hopCounter
 Keeps track of how many input samples the FFT has seen.
 
bool computeMagnitude
 Tracks if the magnitude (and power) of the FFT need to be computed.
 
bool computePhase
 Tracks if the phase of the FFT needs to be computed.
 
GRT::VectorDouble tempBuffer
 A temporary buffer used to store the input data for the FFT.
 
CircularBuffer< VectorDouble > dataBuffer
 A circular buffer used to store the previous M inputs.
 
vector< FastFourierTransformfft
 A buffer used to store the FFT results.
 
std::map< unsigned int, unsigned int > windowSizeMap
 A map to relate the FFTWindowSize enumerations to actual values.
 
- Protected Attributes inherited from GRT::FeatureExtraction
string featureExtractionType
 
bool initialized
 
bool featureDataReady
 
VectorDouble featureVector
 
- Protected Attributes inherited from GRT::MLBase
bool trained
 
bool useScaling
 
UINT baseType
 
UINT numInputDimensions
 
UINT numOutputDimensions
 
UINT numTrainingIterationsToConverge
 
UINT minNumEpochs
 
UINT maxNumEpochs
 
UINT validationSetSize
 
double learningRate
 
double minChange
 
double rootMeanSquaredTrainingError
 
double totalSquaredTrainingError
 
bool useValidationSet
 
bool randomiseTrainingOrder
 
Random random
 
vector< TrainingResulttrainingResults
 
TrainingResultsObserverManager trainingResultsObserverManager
 
TestResultsObserverManager testResultsObserverManager
 
- Protected Attributes inherited from GRT::GRTBase
string classType
 
DebugLog debugLog
 
ErrorLog errorLog
 
InfoLog infoLog
 
TrainingLog trainingLog
 
TestingLog testingLog
 
WarningLog warningLog
 

Static Protected Attributes

static RegisterFeatureExtractionModule< FFTregisterModule
 

Additional Inherited Members

- Static Public Member Functions inherited from GRT::FeatureExtraction
static FeatureExtractioncreateInstanceFromString (string const &featureExtractionType)
 
- Static Public Member Functions inherited from GRT::GRTBase
static string getGRTVersion (bool returnRevision=true)
 
static string getGRTRevison ()
 
- Static Protected Member Functions inherited from GRT::FeatureExtraction
static StringFeatureExtractionMapgetMap ()
 

Detailed Description

Definition at line 56 of file FFT.h.

Constructor & Destructor Documentation

GRT::FFT::FFT ( UINT  fftWindowSize = 512,
UINT  hopSize = 1,
UINT  numDimensions = 1,
UINT  fftWindowFunction = RECTANGULAR_WINDOW,
bool  computeMagnitude = true,
bool  computePhase = true 
)

Constructor, sets the fftWindowSize, hopSize, fftWindowFunction, if the magnitude and phase should be computed during the FFT and the number of dimensions in the input signal.

Parameters
UINTfftWindowSize: sets the size of the fft, this should be a power of two. Default fftWindowSize=512
UINThopSize: sets how often the fft should be computed. If the hopSize parameter is set to 1 then the FFT will be computed everytime the classes computeFeatures(...) or computeFFT(...) functions are called. You may not want to compute the FFT of the input signal for every sample however, if this is the case then set the hopSize parameter to N, in which case the FFT will only be computed every N samples on the previous M values, where M is equal to the fftWindowSize. Default hopSize=1
UINTnumDimensions: the dimensionality of the input data to the FFT. Default numDimensions = 1
UINTfftWindowFunction: sets the window function of the FFT. This should be one of the FFTWindowFunctionOptions enumeration values. Default windowFunction=RECTANGULAR_WINDOW
boolcomputeMagnitude: sets if the magnitude (and power) of the spectrum should be computed on the results of the FFT. Default computeMagnitude=true
boolcomputePhase: sets if the phase of the spectrum should be computed on the results of the FFT. Default computePhase=true

Definition at line 28 of file FFT.cpp.

GRT::FFT::FFT ( const FFT rhs)

Copy Constructor, copies the FFT from the rhs instance to this instance

Parameters
constFFT &rhs: another instance of the FFT class from which the data will be copied to this instance

Definition at line 47 of file FFT.cpp.

GRT::FFT::~FFT ( void  )
virtual

Default Destructor

Definition at line 56 of file FFT.cpp.

Member Function Documentation

bool GRT::FFT::clear ( )
virtual

Sets the FeatureExtraction clear function, overwriting the base FeatureExtraction function. This function is called by the GestureRecognitionPipeline when the pipelines main clear() function is called. This function completely clears the FFT setup, you will need to initialize the instance again before you can use it.

Returns
true if the FFT was reset, false otherwise

Reimplemented from GRT::FeatureExtraction.

Definition at line 335 of file FFT.cpp.

bool GRT::FFT::computeFeatures ( const VectorDouble &  inputVector)
virtual

Sets the FeatureExtraction computeFeatures function, overwriting the base FeatureExtraction function. This function is called by the GestureRecognitionPipeline when any new input data needs to be processed (during the prediction phase for example). This function calls the FFT's computeFFT(...) function.

Parameters
constVectorDouble &inputVector: the inputVector that should be processed. Must have the same dimensionality as the FeatureExtraction module
Returns
true if the data was processed, false otherwise

Reimplemented from GRT::FeatureExtraction.

Definition at line 247 of file FFT.cpp.

bool GRT::FFT::deepCopyFrom ( const FeatureExtraction featureExtraction)
virtual

Sets the FeatureExtraction deepCopyFrom function, overwriting the base FeatureExtraction function. This function is used to deep copy the values from the input pointer to this instance of the FeatureExtraction module. This function is called by the GestureRecognitionPipeline when the user adds a new FeatureExtraction module to the pipeline.

Parameters
FeatureExtraction*featureExtraction: a pointer to another instance of an FFT, the values of that instance will be cloned to this instance
Returns
true if the deep copy was successful, false otherwise

Reimplemented from GRT::FeatureExtraction.

Definition at line 84 of file FFT.cpp.

bool GRT::FFT::getComputeMagnitude ( )
inline

Returns if the magnitude (and power) of the FFT spectrum is being computed.

Returns
true if the magnitude (and power) of the FFT spectrum is being computed and if the FFT has been initialized, otherwise false will be returned

Definition at line 227 of file FFT.h.

bool GRT::FFT::getComputePhase ( )
inline

Returns if the phase of the FFT spectrum is being computed.

Returns
true if the phase of the FFT spectrum is being computed and if the FFT has been initialized, otherwise false will be returned

Definition at line 234 of file FFT.h.

UINT GRT::FFT::getDataBufferSize ( )

Returns the current dataBufferSize, which is the same as the FFT window size.

Returns
returns the current dataBufferSize value if the FFT has been initialized, otherwise zero will be returned

Definition at line 358 of file FFT.cpp.

vector< FastFourierTransform > GRT::FFT::getFFTResults ( )
inline

Returns the FFT results computed from the last FFT of the input signal.

Returns
returns a vector of FastFourierTransform (where the size of the vector is equal to the number of input dimensions for the FFT). An empty vector will be returned if the FFT was not computed

Definition at line 241 of file FFT.h.

vector< FastFourierTransform >& GRT::FFT::getFFTResultsPtr ( )
inline

Returns a pointer to the FFT results computed from the last FFT of the input signal.

Returns
returns a pointer to the vector of FastFourierTransform (where the size of the vector is equal to the number of input dimensions for the FFT). An empty vector will be returned if the FFT was not computed

Definition at line 248 of file FFT.h.

UINT GRT::FFT::getFFTWindowFunction ( )

Returns the current FFT window function enumeration value.

Returns
returns the current FFT window function value if the FFT has been initialized, otherwise zero will be returned

Definition at line 369 of file FFT.cpp.

UINT GRT::FFT::getFFTWindowSize ( )

Returns the FFT window size.

Returns
returns the current FFT window size value if the FFT has been initialized, otherwise zero will be returned

Definition at line 363 of file FFT.cpp.

UINT GRT::FFT::getHopCounter ( )

Returns the current hop counter value.

Returns
returns the current hop counter value if the FFT has been initialized, otherwise zero will be returned

Definition at line 374 of file FFT.cpp.

UINT GRT::FFT::getHopSize ( )

Returns the current hopSize.

Returns
returns the current hopSize value if the FFT has been initialized, otherwise zero will be returned

Definition at line 353 of file FFT.cpp.

bool GRT::FFT::init ( UINT  fftWindowSize,
UINT  hopSize,
UINT  numDimensions,
UINT  windowFunction,
bool  computeMagnitude,
bool  computePhase 
)

Initializes the FFT. Should be called before calling the computeFFT(...) or computeFeatures(...) methods. This function is automatically called by the constructor.

Parameters
UINTfftWindowSize: sets the size of the fft, this must be a power of two
UINThopSize: sets how often the fft should be computed. If the hopSize parameter is set to 1 then the FFT will be computed everytime the classes computeFeatures(...) or computeFFT(...) functions are called. You may not want to compute the FFT of the input signal for every sample however, if this is the case then set the hopSize parameter to N, in which case the FFT will only be computed every N samples on the previous M values, where M is equal to the fftWindowSize
UINTnumDimensions: the dimensionality of the input data to the FFT
UINTwindowFunction: sets the window function of the FFT. This should be one of the WindowFunctionOptions enumeration values
boolcomputeMagnitude: sets if the magnitude (and power) of the spectrum should be computed on the results of the FFT
boolcomputePhase: sets if the phase of the spectrum should be computed on the results of the FFT
Returns
true if the FTT was initialized, false otherwise

Definition at line 188 of file FFT.cpp.

bool GRT::FFT::loadModelFromFile ( fstream &  file)
virtual

This loads the feature extraction settings from a file. This overrides the loadSettingsFromFile function in the FeatureExtraction base class.

Parameters
fstream&file: a reference to the file to load the settings from
Returns
returns true if the settings were loaded successfully, false otherwise

Reimplemented from GRT::FeatureExtraction.

Definition at line 127 of file FFT.cpp.

FFT & GRT::FFT::operator= ( const FFT rhs)

Sets the equals operator, copies the data from the rhs instance to this instance

Parameters
constFFT &rhs: another instance of the FFT class from which the data will be copied to this instance
Returns
a reference to this instance of FFT

Definition at line 59 of file FFT.cpp.

bool GRT::FFT::reset ( )
virtual

Sets the FeatureExtraction reset function, overwriting the base FeatureExtraction function. This function is called by the GestureRecognitionPipeline when the pipelines main reset() function is called. This function resets the FFT by re-initiliazing the instance.

Returns
true if the FFT was reset, false otherwise

Reimplemented from GRT::FeatureExtraction.

Definition at line 348 of file FFT.cpp.

bool GRT::FFT::saveModelToFile ( fstream &  file) const
virtual

This saves the feature extraction settings to a file. This overrides the saveSettingsToFile function in the FeatureExtraction base class.

Parameters
fstream&file: a reference to the file to save the settings to
Returns
returns true if the settings were saved successfully, false otherwise

Reimplemented from GRT::FeatureExtraction.

Definition at line 101 of file FFT.cpp.

bool GRT::FFT::setComputeMagnitude ( bool  computeMagnitude)

Sets if the magnitude (and power) of the FFT spectrum should be computed.

Parameters
boolcomputeMagnitude: the new computeMagnitude parameter
Returns
returns true if the computeMagnitude parameter was successfully updated, false otherwise

Definition at line 418 of file FFT.cpp.

bool GRT::FFT::setComputePhase ( bool  computePhase)

Sets if the phase of the FFT spectrum should be computed.

Parameters
boolcomputePhase: the new computeMagnitude parameter
Returns
returns true if the computePhase parameter was successfully updated, false otherwise

Definition at line 424 of file FFT.cpp.

bool GRT::FFT::setFFTWindowFunction ( UINT  fftWindowFunction)

Sets the fftWindowFunction parameter, this should be one of the FFTWindowFunctionOptions enumeration values.

Parameters
UINTfftWindowFunction: the new fftWindowFunction parameter, must be one of the FFTWindowFunctionOptions enumeration values
Returns
returns true if the fftWindowFunction parameter was successfully updated, false otherwise

Definition at line 410 of file FFT.cpp.

bool GRT::FFT::setFFTWindowSize ( UINT  fftWindowSize)

Sets the fftWindowSize parameter, this sets the size of the fft, this must be a power of two. Setting this value will also re-initialize the FFT.

Parameters
UINTfftWindowSize: the new fftWindowSize parameter, this must be a power of two.
Returns
returns true if the fftWindowSize parameter was successfully updated, false otherwise

Definition at line 399 of file FFT.cpp.

bool GRT::FFT::setHopSize ( UINT  hopSize)

Sets the hopSize parameter, this sets how often the fft should be computed. If the hopSize parameter is set to 1 then the FFT will be computed everytime the classes' computeFeatures(...) or computeFFT(...) functions are called. You may not want to compute the FFT of the input signal for every sample however, if this is the case then set the hopSize parameter to N, in which case the FFT will only be computed every N samples on the previous M values, where M is equal to the fftWindowSize. The hopSize must be greater than zero. Setting the hopSize will also reset the hop counter.

Parameters
UINThopSize: the new hopSize parameter, must be greater than zero
Returns
returns true if the hopSize parameter was successfully updated, false otherwise

Definition at line 389 of file FFT.cpp.

bool GRT::FFT::update ( const double  x)

Computes the FFT of the previous M input samples, where M is the size of the fft window set by the constructor. The FFT of the input will only be computed if the current hop counter value matches the hopSize. This function should only be used if the dimensionality of the FFT has been set to 1.

Parameters
constdouble x: the new sample, this will be added to a buffer and the FFT will be computed for the data in the buffer
Returns
true if the FTT was updated successfully, false otherwise

Definition at line 262 of file FFT.cpp.

bool GRT::FFT::update ( const VectorDouble &  x)

Computes the FFT of the previous M input samples, where M is the size of the fft window set by the constructor. The FFT of the input will only be computed if the current hop counter value matches the hopSize. The dimensionality of the input vector must match the number of dimensions for the FFT.

Parameters
constVectorDouble &x: the new N-dimensional sample, this will be added to a buffer and the FFT will be computed for the data in the buffer
Returns
true if the FTT was updated successfully, false otherwise

Definition at line 277 of file FFT.cpp.


The documentation for this class was generated from the following files: