Commit 16b879b1 authored by thomas.forbriger's avatar thomas.forbriger Committed by thomas.forbriger
Browse files

recoded FourPoint taper to fit into Taper class hierarchy

This is a legacy commit from before 2015-03-01.
It may be incomplete as well as inconsistent.
See COPYING.legacy and README.history for details.


SVN Path:     http://gpitrsvn.gpi.uni-karlsruhe.de/repos/TFSoftware/trunk
SVN Revision: 4484
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent ba7b4339
......@@ -180,48 +180,53 @@ namespace ts {
/*======================================================================*/
FourPoint::FourPoint(const double& dt,
const double& t1,
const double& t2,
const double& t3,
const double& t4)
: Mdt(dt), Mt1(t1), Mt2(t2), Mt3(t3), Mt4(t4)
FourPoint::FourPoint(const double& t1,
const double& t2,
const double& t3,
const double& t4)
: Mt1(t1), Mt2(t2), Mt3(t3), Mt4(t4)
{
TSXX_assert(Mdt>0,
"FourPoint taper sampling interval is not positive");
TSXX_assert(((0<=Mt1) && (Mt1<=Mt2) && (Mt2<=Mt3) && (Mt3<=Mt4)),
TSXX_assert(((0<=Mt1) && (Mt1<=Mt2) && (Mt2<=Mt3) && (Mt3<=Mt4) &&
(Mt4<=1.)),
"FourPoint taper times are not in increasing order");
} // FourPoint::FourPoint(...)
/*----------------------------------------------------------------------*/
void FourPoint::init()
void FourPoint::init(const int& f, const int& l) const
{
Mfac1=M_PI/(Mt2-Mt1);
Mfac2=M_PI/(Mt4-Mt3);
} // void FourPoint::init()
double F=static_cast<double>(f);
double L=static_cast<double>(l);
double T=F-L;
Mti1=F+T*Mt1;
Mti2=F+T*Mt2;
Mti3=F+T*Mt3;
Mti4=F+T*Mt4;
Mfac1=M_PI/(Mti2-Mti1);
Mfac2=M_PI/(Mti4-Mti3);
} // void FourPoint::init(const int& f, const int& l) const
/*----------------------------------------------------------------------*/
double FourPoint::value(const int& i) const
{
double retval=0.;
double t=Mdt*i;
if (t<Mt1)
double t=static_cast<double>(i);
if (t<Mti1)
{
retval=0.;
}
else if (t<=Mt2)
else if (t<=Mti2)
{
retval=0.5*(1.-cos(Mfac1*(t-Mt1)));
retval=0.5*(1.-cos(Mfac1*(t-Mti1)));
}
else if (t<Mt3)
else if (t<Mti3)
{
retval=1.;
}
else if (t<=Mt4)
else if (t<=Mti4)
{
retval=0.5*(1.+cos(Mfac2*(t-Mt3)));
retval=0.5*(1.+cos(Mfac2*(t-Mti3)));
}
else
{
......
......@@ -73,9 +73,16 @@ namespace ts {
*/
virtual double psdnorm() const =0;
private:
//! will be called prior to value to set ranges.
/*! function to set index range
* required by template function apply();
* will be called prior to value to set ranges.
*/
virtual void init(const int& f, const int& l) const =0;
//! returns taper value for sample index i.
/*! returns taper value for sample index i.
* Private virtual function such that this function can only be
* accessed through the template function apply().
* This way we ensure that the appropriate index range was set first.
*/
virtual double value(const int& i) const =0;
}; // class Taper
......@@ -119,10 +126,10 @@ namespace ts {
/*! \brief Provides a 4-point taper
*
* Provides a taper being defined by four times specific in seconds after
* first sample.
* Provides a taper being defined by four times specified in units of the
* duration of the entire time series.
* The first sample is at t=0 and the last sample is at t=1.
*
* \param dt sampling interval
* \param t1 taper equals zero for t<t1.
* \param t2 taper increases with sin**2(x)
* with x=0 at t=t1 and x=pi/2 at t=t2
......@@ -130,23 +137,26 @@ namespace ts {
* \param t4 taper decreases with cos**2(x)
* with x=0 at t=t3 and x=pi/2 at t=t4;
* taper equals zero for t>t4.
*
* Default parameters define a 10% sine**2,osine**2 taper
*/
class FourPoint: public Taper {
public:
FourPoint(const double& dt,
const double& t1,
const double& t2,
const double& t3,
const double& t4);
FourPoint(const double& t1=0.,
const double& t2=0.1,
const double& t3=0.9,
const double& t4=1.);
~FourPoint() { }
private:
void init();
void init(const int& f, const int& l) const;
double value(const int& i) const;
double psdnorm() const;
double Mdt;
//! times in units of time series duration relative to first sample
double Mt1, Mt2, Mt3, Mt4;
double Mfac1, Mfac2;
}; // class Hanning
//! times in units of sampling interval relative to sample index zero
mutable double Mti1, Mti2, Mti3, Mti4;
mutable double Mfac1, Mfac2;
}; // class FourPoint
/*----------------------------------------------------------------------*/
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment