00001
00002
00004 #ifndef __Sample__
00005 #define __Sample__
00006
00007 #include "CUtils.h"
00008 #include "TMath.h"
00009
00010 #define NORDER 20
00011 #define NORDERHP 12
00012
00013 using namespace std;
00014
00021 class ZPGFilter {
00022
00023 public:
00024 friend class Sample;
00025 friend class IIRFilter;
00026
00027 private:
00028
00029 ZPGFilter(const unsigned int numZeros, const unsigned int numPoles);
00030 virtual ~ZPGFilter(void);
00031
00032 bool WToZ(void);
00033
00034 unsigned int nzeros;
00035 unsigned int npoles;
00036 double *zeros[2];
00037 double *poles[2];
00038 double gain[2];
00039 };
00040
00041
00048 class IIRFilter {
00049
00050 public:
00051 friend class Sample;
00052
00053 private:
00054
00055 IIRFilter(ZPGFilter *zpgFilter);
00056 virtual ~IIRFilter(void);
00057
00058 unsigned int nzeros;
00059 unsigned int npoles;
00060 double *zeros[2];
00061 double *poles[2];
00062 double gain[2];
00063 unsigned int numDirect;
00064 unsigned int numRecurs;
00065 double *directCoef;
00066 double *recursCoef;
00067 double *history;
00068 double *history_init;
00069
00070 };
00071
00072
00083 class Sample {
00084
00085 public:
00086
00095 Sample(const int aVerbosity=0);
00096
00100 virtual ~Sample(void);
00110 void SetDCRemoval(const bool aDCremove=true){ fRemoveDC=aDCremove; };
00111
00118 bool SetWindows(const double aTukeyFraction);
00119
00129 bool SetFrequencies(const int aNativeFrequency, const int aWorkingFrequency, const double aHighPassFrequency=0.0);
00130
00136 bool SetNativeFrequency(const int aNativeFrequency);
00137
00145 bool SetWorkingFrequency(const int aWorkingFrequency);
00146
00154 bool SetHighPassFrequency(const double aHighPassFrequency);
00155
00166 bool Transform(const int invectorsize, double *invector, const int outvectorsize, double *outvector);
00167
00171 inline int GetNativeFrequency(void){ return fNativeFrequency; };
00172
00176 inline int GetWorkingFrequency(void){ return fWorkingFrequency; };
00177
00181 inline double GetHighPassFrequency(void){ return fHighPassFrequency; };
00182
00186 inline double GetTukeyFraction(void){ return fTukeyFraction; };
00187
00188
00189 protected:
00190
00191 bool fRemoveDC;
00192 double fTukeyFraction;
00193 int fWorkingFrequency;
00194 int fNativeFrequency;
00195 int fVerbosity;
00196 double fHighPassFrequency;
00197
00198 private:
00199
00200
00201 bool MakeSamplingFilters(void);
00202 bool Resample(int invectorsize, double *invector, double *outvector);
00203 bool presample;
00204 int fResampleFactor;
00205 int fIntermediateFrequency;
00206 IIRFilter *iirFilter[NORDER];
00207 bool PreSample(int &datavectorsize, double *datavector);
00208
00209
00210
00211 bool MakeHighPassFilters(void);
00212 bool HighPass(const int invectorsize, double *invector);
00213 IIRFilter *iirFilterHP[NORDERHP];
00214
00215
00216 bool ApplyFilter(const int datavectorsize, double *datavector, IIRFilter *filter);
00217
00218
00219 bool ApplyTukeyWindow(const int datavectorsize, double *datavector);
00220
00221
00222 void RemoveDC(const int datavectorsize, double *datavector);
00223
00224 ClassDef(Sample,0)
00225
00226 };
00227
00228 #endif
00229
00230