00001
00002
00004 #ifndef __Spectrum__
00005 #define __Spectrum__
00006
00007 #include "CUtils.h"
00008 #include "FFT.h"
00009 #include "TMath.h"
00010 #include "TGraph.h"
00011 #include "TH1.h"
00012 #include "TFile.h"
00013 #include <gsl/gsl_errno.h>
00014 #include <gsl/gsl_spline.h>
00015
00016 using namespace std;
00017
00036 class Spectrum{
00037
00038 public:
00039
00056 Spectrum(const int aSpectrumSize,
00057 const int aDataDuration,
00058 const int aDataSamplingFrequency,
00059 const int aVerbosity=0);
00060
00064 virtual ~Spectrum(void);
00074 void Reset(void);
00075
00089 bool AddData(const int aDataSize, const double *aData, const int aDataStart=0);
00090
00098 bool LoadData(const int aDataSize, const double *aData, const int aDataStart=0);
00099
00111 double GetPower(const double aFrequency);
00112
00117 TGraph* GetPSD(void);
00118
00125 TGraph* GetPSD(const double aFrequencyMin, const double aFrequencyMax);
00126
00131 TGraph* GetASD(void);
00132
00139 TGraph* GetASD(const double aFrequencyMin, const double aFrequencyMax);
00140
00147 TGraph* GetSubPSD(const int aParity, const int aIndex);
00148
00155 TGraph* GetSubASD(const int aParity, const int aIndex);
00156
00161 bool WriteSubPSD(const string aOutFileName);
00162
00167 bool WriteSubASD(const string aOutFileName);
00168
00173 inline int GetSpectrumSize(void){ return fft_psd->GetSize_f(); };
00174
00179 inline double GetSpectrumFrequency(const int aIndex){ return f_PSD[aIndex]; };
00180
00184 inline double GetSpectrumResolution(void){ return (double)DataSamplingFrequency/2.0/(double)fft_psd->GetSize_f(); };
00185
00189 inline int GetSpectrumNyquist(void){ return DataSamplingFrequency/2; };
00190
00194 inline bool GetStatus(void){ return status_OK; };
00195
00200 inline int GetNSubSegmentsMax(const int aParity){
00201 return nSubSegments[aParity%2];
00202 };
00203
00207 inline int GetDataBufferLength(void){ return nSubSegments[0]*(fft_psd->GetSize_t()/DataSamplingFrequency); };
00208
00213 inline bool IsBufferEmpty(void){
00214 if(stop_buffer[0]<0&&stop_buffer[1]<0) return true;
00215 return false;
00216 };
00217
00218
00219 private:
00220
00221 bool status_OK;
00222 int fVerbosity;
00223
00224
00225 int DataSamplingFrequency;
00226
00227
00228 int nSubSegments[2];
00229
00230
00231 double *HannWindow;
00232 double *PSD;
00233 double *f_PSD;
00234 double **PSD_buffer[2];
00235 bool *flag_buffer[2];
00236 int stop_buffer[2];
00237
00238 fft *fft_psd;
00239
00240 gsl_interp_accel *acc;
00241 gsl_spline *interp_psd;
00242
00243 double* GetHannWindow(const int aSize);
00244 void ComputeMedianMean(void);
00245
00246 ClassDef(Spectrum,0)
00247 };
00248
00249 #endif
00250
00251