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.
SavitzkyGolayFilter.h
Go to the documentation of this file.
1 
28 #ifndef GRT_SAVITZKY_GOLAY_FILTER_HEADER
29 #define GRT_SAVITZKY_GOLAY_FILTER_HEADER
30 
31 #include "../CoreModules/PreProcessing.h"
32 #include "../Util/LUDecomposition.h"
33 
34 GRT_BEGIN_NAMESPACE
35 
39 class GRT_API SavitzkyGolayFilter : public PreProcessing{
40 public:
50  SavitzkyGolayFilter(const UINT numLeftHandPoints=10,const UINT numRightHandPoints=10,const UINT derivativeOrder=0,const UINT smoothingPolynomialOrder=2,const UINT numDimensions = 1);
51 
58 
62  virtual ~SavitzkyGolayFilter();
63 
70  SavitzkyGolayFilter& operator=(const SavitzkyGolayFilter &rhs);
71 
80  virtual bool deepCopyFrom(const PreProcessing *preProcessing);
81 
90  virtual bool process(const VectorFloat &inputVector);
91 
99  virtual bool reset();
100 
108  virtual bool save(std::fstream &file) const;
109 
117  virtual bool load(std::fstream &file);
118 
125  bool init(const UINT numLeftHandPoints,const UINT numRightHandPoints,const UINT derivativeOrder,const UINT smoothingPolynomialOrder,const UINT numDimensions);
126 
133  Float filter(const Float x);
134 
141  VectorFloat filter(const VectorFloat &x);
142 
148  VectorFloat getFilteredData() const;
149 
155  static std::string getId();
156 
157  //Tell the compiler we are using the following functions from the MLBase class to stop hidden virtual function warnings
158  using MLBase::save;
159  using MLBase::load;
160 
161 protected:
162  inline int min_(int a,int b) {return b < a ? (b) : (a);}
163  inline Float min_(Float a,Float b) {return b < a ? (b) : (a);}
164  bool calCoeff();
165 
166  UINT numPoints; //The physical length of the output array
167  UINT numLeftHandPoints; //Num of leftward (past) points to use
168  UINT numRightHandPoints; //Num of rightward (future) points to use
169  UINT derivativeOrder; //Order of the derivative desired
170  UINT smoothingPolynomialOrder; //Order of smoothing polynomial
171  CircularBuffer< VectorFloat > data; //A buffer to hold the input data
172  VectorFloat yy; //The filtered values
173  VectorFloat coeff; //Buffer for the filter coefficients
174 
175 private:
176  static const std::string id;
178 
179 };
180 
181 GRT_END_NAMESPACE
182 
183 #endif //GRT_SAVITZKY_GOLAY_FILTER_HEADER
184 
std::string getId() const
Definition: GRTBase.cpp:85
virtual bool deepCopyFrom(const PreProcessing *rhs)
Definition: PreProcessing.h:58
virtual bool save(const std::string &filename) const
Definition: MLBase.cpp:167
virtual bool reset() override
This implements a Savitzky-Golay filter. This code is based on the Savitzky Golay filter code from Nu...
virtual bool process(const VectorFloat &inputVector)
Definition: PreProcessing.h:74
virtual bool load(const std::string &filename)
Definition: MLBase.cpp:190