TS++ library: time series library
tapers.cc
Go to the documentation of this file.
1 
37 #define TF_TAPERS_CC_VERSION \
38  "TF_TAPERS_CC V1.3"
39 
40 //#include <iostream>
41 #include <tsxx/tapers.h>
42 #include <tsxx/tsxx.h>
43 #include <tsxx/error.h>
44 //#include <tsxx/debug.h>
45 #include <cmath>
46 
47 //using std::cout;
48 //using std::endl;
49 
50 namespace ts {
51 
53  namespace tapers {
54 
55  void Hanning::init(const int& f, const int& l) const
56  {
57  Mf=f;
58  Mfac=3.1415926535897931/(l-f);
59  } // void Hanning::init(const int& f, const int& l) const
60 
61  double Hanning::value(const int& i) const
62  {
63  double s=std::sin((i-Mf)*Mfac);
64  return (s*s);
65  } // double Hanning::value(const int& i) const
66 
140  double Hanning::psdnorm() const
141  {
142  const double retval=std::sqrt(3./8.);
143  return (retval);
144  } // double Hanning::psdnorm() const
145 
146  /*======================================================================*/
147 
148  Cosine::Cosine(const double& f): Mfrac(f)
149  {
150  TSXX_assert(((0<=Mfrac) && (Mfrac<=1.)),
151  "Cosine taper fraction is outside meaningful range");
152  } // Cosine::Cosine(const double& f)
153 
154  void Cosine::init(const int& f, const int& l) const
155  {
156  Mf=f;
157  Ml=l;
158  Msf=int(0.5*Mfrac*double(Ml-Mf));
159  Mfac=0.5*3.1415926535897931/double(Msf);
160  } // void Cosine::init(const int& f, const int& l) const
161 
162  double Cosine::value(const int& i) const
163  {
164  double s=1.;
165  if (i<(Mf+Msf)) { s=std::sin((i-Mf)*Mfac); }
166  else if (i>(Ml-Msf)) { s=std::sin((Ml-i)*Mfac); }
167  return (s*s);
168  } // double Cosine::value(const int& i) const
169 
170  double Cosine::psdnorm() const
171  {
172  const double retval=1.;
173  TSXX_abort("Cosine::psdnorm() is not yet defined");
174  /*
175  *
176  * NOTICE:
177  * The transform of the cosine taper is available in fouriertrafo.tex
178  * in work/pjt/doz/mess
179  *
180  */
181  return (retval);
182  } // double Cosine::psdnorm() const
183 
184  /*======================================================================*/
185 
186  FourPoint::FourPoint(const double& t1,
187  const double& t2,
188  const double& t3,
189  const double& t4)
190  : Mt1(t1), Mt2(t2), Mt3(t3), Mt4(t4)
191  {
192  TSXX_assert(((0<=Mt1) && (Mt1<=Mt2) && (Mt2<=Mt3) && (Mt3<=Mt4) &&
193  (Mt4<=1.)),
194  "FourPoint taper times are not in increasing order");
195  } // FourPoint::FourPoint(...)
196 
197  /*----------------------------------------------------------------------*/
198 
199  void FourPoint::init(const int& f, const int& l) const
200  {
201  /*
202  TSXX_debug(true, "FourPoint::init",
203  TSXX_value(f) << " " <<
204  TSXX_value(l) << " " <<
205  TSXX_value(Mt1) << " " <<
206  TSXX_value(Mt2) << " " <<
207  TSXX_value(Mt3) << " " <<
208  TSXX_value(Mt4));
209  */
210  double F=static_cast<double>(f);
211  double L=static_cast<double>(l);
212  double T=L-F;
213  Mti1=F+T*Mt1;
214  Mti2=F+T*Mt2;
215  Mti3=F+T*Mt3;
216  Mti4=F+T*Mt4;
217  Mfac1=M_PI/(Mti2-Mti1);
218  Mfac2=M_PI/(Mti4-Mti3);
219  /*
220  TSXX_debug(true, "FourPoint::init",
221  TSXX_value(Mti1) << " " <<
222  TSXX_value(Mti2) << " " <<
223  TSXX_value(Mti3) << " " <<
224  TSXX_value(Mti4) << " " <<
225  TSXX_value(Mfac1) << " " <<
226  TSXX_value(Mfac2));
227  */
228  } // void FourPoint::init(const int& f, const int& l) const
229 
230  /*----------------------------------------------------------------------*/
231 
232  double FourPoint::value(const int& i) const
233  {
234  //cout << i << " ";
235  double retval=0.;
236  double t=static_cast<double>(i);
237  if (t<Mti1)
238  {
239  //cout << "t<Mti1" << " ";
240  retval=0.;
241  }
242  else if (t<=Mti2)
243  {
244  //cout << "t<=Mti2" << " ";
245  retval=0.5*(1.-cos(Mfac1*(t-Mti1)));
246  }
247  else if (t<Mti3)
248  {
249  //cout << "t<Mti3" << " ";
250  retval=1.;
251  }
252  else if (t<=Mti4)
253  {
254  //cout << "t<=Mti4" << " ";
255  retval=0.5*(1.+cos(Mfac2*(t-Mti3)));
256  }
257  else
258  {
259  //cout << "else" << " ";
260  retval=0.;
261  }
262  //cout << "retval=" << retval << endl;
263  return (retval);
264  } // double FourPoint::value(const int& i) const
265 
266  /*----------------------------------------------------------------------*/
267 
268  double FourPoint::psdnorm() const
269  {
270  const double retval=1.;
271  TSXX_abort("FourPoint::psdnorm() is not yet defined");
276  return (retval);
277  } // double FourPoint::psdnorm() const
278 
279  } // namespace tapers
280 
281 } // namespace ts
282 
283 /* ----- END OF tapers.cc ----- */
double value(const int &i) const
Definition: tapers.cc:162
#define TSXX_abort(M)
Abort and give a message.
Definition: error.h:135
void init(const int &f, const int &l) const
Definition: tapers.cc:154
error handling for libtsxx (prototypes)
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
void init(const int &f, const int &l) const
Definition: tapers.cc:55
double psdnorm() const
Definition: tapers.cc:140
All stuff in this library will be placed within namespace ts.
Definition: anyfilter.cc:43
#define TSXX_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:127
double psdnorm() const
return normalization for PSD calculation. The taper coefficients have to be devided by the return va...
Definition: tapers.cc:268
double Mt1
times in units of time series duration relative to first sample
Definition: tapers.h:152
basic modules of time series library in C++ (prototypes)
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
double value(const int &i) const
Definition: tapers.cc:232
provide signal tapers (prototypes)