TS++ library: time series library
tapers.h
Go to the documentation of this file.
1 
38 // include guard
39 #ifndef TF_TAPERS_H_VERSION
40 
41 #define TF_TAPERS_H_VERSION \
42  "TF_TAPERS_H V1.3"
43 
44 namespace ts {
45 
46  namespace tapers {
47 
55  class Taper {
56  public:
57  virtual ~Taper() { }
59  template<class C>
60  void apply(C c) const;
62  template<class C>
63  void psdapply(C c) const;
71  virtual double psdnorm() const =0;
72  private:
77  virtual void init(const int& f, const int& l) const =0;
83  virtual double value(const int& i) const =0;
84  }; // class Taper
85 
86  /*----------------------------------------------------------------------*/
87 
93  class Cosine: public Taper {
94  public:
95  Cosine(const double& f=0.1);
96  ~Cosine() { }
97  private:
98  void init(const int& f, const int& l) const;
99  double value(const int& i) const;
100  double psdnorm() const;
101  mutable int Mf,Ml; //<! index of first and last sample
102  mutable int Msf; //<! sample index fraction
103  mutable double Mfac; //<! sine function argument scaling
104  double Mfrac; //<! taper fraction
105  }; // class Hanning
106 
107  /*----------------------------------------------------------------------*/
108 
111  class Hanning: public Taper {
112  public:
113  ~Hanning() { }
114  private:
115  void init(const int& f, const int& l) const;
116  double value(const int& i) const;
117  double psdnorm() const;
118  mutable int Mf; //<! first index
119  mutable double Mfac; //<! sine function argument scaling
120  }; // class Hanning
121 
122  /*----------------------------------------------------------------------*/
123 
140  class FourPoint: public Taper {
141  public:
142  FourPoint(const double& t1=0.,
143  const double& t2=0.1,
144  const double& t3=0.9,
145  const double& t4=1.);
147  private:
148  void init(const int& f, const int& l) const;
149  double value(const int& i) const;
150  double psdnorm() const;
152  double Mt1, Mt2, Mt3, Mt4;
154  mutable double Mti1, Mti2, Mti3, Mti4;
155  mutable double Mfac1, Mfac2;
156  }; // class FourPoint
157 
158  /*----------------------------------------------------------------------*/
159 
161  template<class C>
162  void Taper::apply(C c) const
163  {
164  this->init(c.f(), c.l());
165  for (int i=c.f(); i<=c.l(); ++i)
166  { c(i) *= this->value(i); }
167  } // template<class C> void Taper::apply(C c)
168 
170  template<class C>
171  void Taper::psdapply(C c) const
172  {
173  this->init(c.f(), c.l());
174  for (int i=c.f(); i<=c.l(); ++i)
175  { c(i) *= this->value(i)/this->psdnorm(); }
176  } // template<class C> void Taper::psdapply(C c)
177 
178  } // namespace tapers
179 
180 } // namespace ts
181 
182 #endif // TF_TAPERS_H_VERSION (includeguard)
183 
184 /* ----- END OF tapers.h ----- */
void apply(C c) const
apply taper to series container c.
Definition: tapers.h:162
double value(const int &i) const
Definition: tapers.cc:162
Taper abstract base class.
Definition: tapers.h:55
void init(const int &f, const int &l) const
Definition: tapers.cc:154
virtual double psdnorm() const =0
return normalization for PSD calculation. The taper coefficients have to be devided by the return va...
double Mti1
times in units of sampling interval relative to sample index zero
Definition: tapers.h:154
Cosine(const double &f=0.1)
Definition: tapers.cc:148
virtual double value(const int &i) const =0
void init(const int &f, const int &l) const
Definition: tapers.cc:55
double psdnorm() const
Definition: tapers.cc:140
virtual void init(const int &f, const int &l) const =0
All stuff in this library will be placed within namespace ts.
Definition: anyfilter.cc:43
double psdnorm() const
return normalization for PSD calculation. The taper coefficients have to be devided by the return va...
Definition: tapers.cc:268
void psdapply(C c) const
apply taper to series container c for PSD calculation.
Definition: tapers.h:171
double Mt1
times in units of time series duration relative to first sample
Definition: tapers.h:152
Provides a Cosine taper.
Definition: tapers.h:93
FourPoint(const double &t1=0., const double &t2=0.1, const double &t3=0.9, const double &t4=1.)
Definition: tapers.cc:186
double value(const int &i) const
Definition: tapers.cc:61
double psdnorm() const
return normalization for PSD calculation. The taper coefficients have to be devided by the return va...
Definition: tapers.cc:170
void init(const int &f, const int &l) const
Definition: tapers.cc:199
virtual ~Taper()
Definition: tapers.h:57
Provides a 4-point taper.
Definition: tapers.h:140
double value(const int &i) const
Definition: tapers.cc:232
Provides a Hanning taper (no parameters):
Definition: tapers.h:111