Go to the documentation of this file.00001 #ifndef FORIA_WAVELET_HH
00002 #define FORIA_WAVELET_HH
00003
00004 #include "ForIA/IFourMomentum.hh"
00005
00006 #include "ForIA/MessageBox.hh"
00007
00008 #include <gsl/gsl_wavelet.h>
00009
00010 #include <cmath>
00011 #include <vector>
00012 #include <ostream>
00013
00014 namespace ForIA{
00015
00016 using std::vector;
00017
00019 class Wavelet{
00020
00021 public:
00022
00023 Wavelet();
00024
00025 ~Wavelet();
00027 class Coefficient{
00028
00029 public:
00030
00031 Coefficient(): m_doTranslation(true){}
00032
00034 unsigned int scale()const{return m_scale;};
00035
00047 double translation()const{
00048 if(m_doTranslation){
00049 m_translation = 0.5 * (translationMax() + translationMin());
00050 m_doTranslation = false;
00051 }
00052 return m_translation;
00053 }
00054
00057 double translationMax()const{return m_upper;}
00058
00061 double translationMin()const{return m_lower;}
00062
00067 double magnitude()const{return m_magnitude;};
00068
00070 unsigned int arrayPosition()const{return m_arrayPosition;};
00071
00074 unsigned int level()const{return m_level;};
00075
00077 unsigned int index()const{return m_index;};
00078
00080 struct ByAmplitudeDown{
00081 bool operator()(const Coefficient &left, const Coefficient &right){
00082 return fabs(left.magnitude()) > fabs(right.magnitude());
00083 }
00084 };
00085
00086 private:
00087
00088 friend class Wavelet;
00089
00090 unsigned int m_scale;
00091
00092 mutable double m_translation;
00093
00094 mutable bool m_doTranslation;
00095
00096 double m_upper;
00097
00098 double m_lower;
00099
00100 double m_magnitude;
00101
00102 unsigned int m_arrayPosition;
00103
00104 unsigned int m_level;
00105
00106 unsigned int m_index;
00107
00108
00109 };
00110
00112 class FrequencyBand{
00113
00114 public:
00115
00116 FrequencyBand(): m_doEnergy(true), m_doVar(true), m_doAv(true){}
00117
00119 double lower_frequency()const{return m_lowerFreq;};
00120
00122 double upper_frequency()const{return m_upperFreq;};
00123
00127 double physicalScale()const{return m_physScale;}
00128
00130 unsigned int scale()const{return m_scale;}
00131
00132 double variance()const{
00133 if(m_doVar){
00134 m_var=0.;
00135 for(const_iterator c=begin(); c!= end(); ++c){
00136 double y = c->magnitude() - average();
00137 m_var += y*y;
00138 }
00139 m_var=sqrt(m_var / (double)nCoefficients());
00140 m_doVar = false;
00141 }
00142 return m_var;
00143 }
00144
00145
00147 double average()const{
00148 if(m_doAv){
00149 m_av=0.;
00150 for(const_iterator c=begin(); c!= end(); ++c){
00151 m_av += c->magnitude();
00152 }
00153 m_av /= (double)nCoefficients();
00154 m_doAv = false;
00155 }
00156 return m_av;
00157 }
00158
00163 double energy()const{
00164 if(m_doEnergy){
00165
00166 int p=1;
00167 p = p << level();
00168 m_inverse = vector<double>(p * nCoefficients(), 0.);
00169
00170 for(const_iterator c=begin(); c != end(); ++c){
00171
00172 m_inverse[c->arrayPosition()] = c->magnitude();
00173 }
00174
00175 m_parent->invert(m_inverse);
00176 m_energy=0.;
00177 for(vector<double>::const_iterator seg=m_inverse.begin();
00178 seg != m_inverse.end(); ++seg){
00179 m_energy += *seg;
00180 }
00181
00182 m_doEnergy = false;
00183 }
00184 return m_energy;
00185 }
00186
00190 unsigned int level()const{return m_level;};
00191
00192 unsigned int nCoefficients()const{return m_coefficients.size();}
00193
00194 const Coefficient &coefficient(unsigned int index)const{return m_coefficients[index];}
00195
00196 typedef vector<Coefficient>::const_iterator const_iterator;
00197
00198 typedef vector<Coefficient>::const_reverse_iterator const_reverse_iterator;
00199
00200 const_iterator begin()const{return m_coefficients.begin();}
00201
00202 const_reverse_iterator rbegin()const{return m_coefficients.rbegin();}
00203
00204 const_iterator end()const{return m_coefficients.end();}
00205
00206 const_reverse_iterator rend()const{return m_coefficients.rend();}
00207
00208 private:
00209
00210 friend class Wavelet;
00211
00212 friend std::ostream &operator << (std::ostream &out, const FrequencyBand &freq);
00213
00214 friend MessageBox &operator <<(MessageBox &box, const FrequencyBand &freq);
00215
00216 Wavelet *m_parent;
00217
00218 double m_lowerFreq;
00219
00220 double m_upperFreq;
00221
00222 double m_physScale;
00223
00224 mutable double m_energy;
00225
00226 mutable bool m_doEnergy;
00227
00228 mutable double m_var;
00229
00230 mutable bool m_doVar;
00231
00232 mutable double m_av;
00233
00234 mutable double m_doAv;
00235
00236 unsigned int m_scale;
00237
00238 unsigned int m_level;
00239
00240 vector<Coefficient> m_coefficients;
00241
00242 mutable vector<double> m_inverse;
00243 };
00244
00245
00246 typedef vector<FrequencyBand>::const_iterator const_iterator;
00247
00248 typedef vector<FrequencyBand>::const_reverse_iterator const_reverse_iterator;
00249
00251 void setGrid(const vector<double> &grid);
00252
00254 void setRangeStart(double min);
00255
00257 void setRangeEnd(double max);
00258
00260 unsigned int nSubBands()const;
00261
00263 void invert(vector<double> &sequence)const;
00264
00266 const_iterator begin()const{return m_bands.begin();}
00267
00269 const_reverse_iterator rbegin()const{return m_bands.rbegin();}
00270
00272 const_iterator end()const{return m_bands.end();}
00273
00275 const_reverse_iterator rend()const{return m_bands.rend();}
00276
00278 const FrequencyBand &frequencyBand(unsigned int level)const;
00279
00281 const Coefficient &coefficient(unsigned int level, unsigned int index)const;
00282
00283 double smoothingCoefficient()const{return m_smoothing;};
00284
00285 private:
00286
00287 void initialise();
00288
00289 bool m_doInitialise;
00290
00291 unsigned int m_nSegments;
00292
00293 vector<double> m_grid;
00294
00295 double m_min;
00296
00297 double m_max;
00298
00299 double m_range;
00300
00301 double m_freqMax;
00302
00303 double m_freqMin;
00304
00305 bool m_haveSetRangeStart;
00306
00307 bool m_haveSetRangeEnd;
00308
00309 int m_nSubSamples;
00310
00311 vector<FrequencyBand> m_bands;
00312
00313 double m_smoothing;
00314
00315 gsl_wavelet *m_wavelet;
00316
00317 gsl_wavelet_workspace *m_workspace;
00318
00319 };
00320 }
00321
00322 #endif