61 #define TF_FILTER_CC_VERSION \ 70 #include <aff/functions/avg.h> 71 #include <aff/functions/absmax.h> 72 #include <aff/seriesoperators.h> 73 #include <aff/subarray.h> 88 const bool& debug)
const 117 n= (n < x.size()) ? n : x.size();
127 double w11=2.*(2.*dn+1.)/(dn*(dn-1));
128 double w12=-6./(dn*(dn-1.));
130 double w22=12./(dn*(dn+1.)*(dn-1.));
136 L2 += double(l)*x(l);
143 double a = L1 * w11 + L2 * w12;
144 double b = L1 * w21 + L2 * w22;
145 for (
Tindex l=x.f(); l<=x.l(); ++l)
146 { x(l) -= (a+double(l)*b); }
154 const bool& debug)
const 157 int ifirst=x.f() >
Mn1? x.f() :
Mn1;
158 int ilast=x.l() <
Mn2? x.l() :
Mn2;
160 "ERROR (SetByIndex): illegal sample index range");
161 for (
Tindex l=ifirst; l<=ilast; ++l)
170 const bool& debug)
const 173 for (
Tindex l=x.f(); l<=x.l(); ++l)
174 { x(l) = std::sqrt(x(l)); }
182 const bool& debug)
const 185 for (
Tindex l=x.f(); l<=x.l(); ++l)
186 { x(l) = x(l)*x(l); }
194 const bool& debug)
const 197 for (
Tindex l=x.f(); l<=x.l(); ++l)
198 { x(l) = std::pow(x(l),
Mv); }
206 const bool& debug)
const 218 const bool& debug)
const 221 for (
Tindex l=x.f(); l<=x.l(); ++l)
222 { x(l) = x(l)<0 ? -x(l) : x(l); }
230 const bool& debug)
const 235 for (
Tindex l=x.f()+1; l<=x.l(); ++l)
245 const bool& debug)
const 248 n= (n < s.size()) ? n : s.size();
251 s -= aff::func::avg<Tseries>(aff::subarray<Tseries>(s)(f,l));
266 const bool& debug)
const 268 double p=double(2.*M_PI/s.size());
269 for (
Tindex i=s.f(); i<=s.l(); ++i)
270 { s(i) *= M_SQRT1_2*(1.-cos(p*(i-s.f()))); }
278 const bool& debug)
const 279 { s *=
Mv;
return s; }
285 const bool& debug)
const 286 { s +=
Mv;
return s; }
292 const bool& debug)
const 295 int n1= (
Mn1 < 1) ? 1 :
Mn1;
298 int n2= (
Mn2 < 1) ? n1 :
Mn2;
307 Tvalue avg1=aff::func::avg<Tseries>(aff::subarray<Tseries>(s)(s1,e1));
308 Tvalue avg2=aff::func::avg<Tseries>(aff::subarray<Tseries>(s)(s2,e2));
309 double a=(avg2-avg1)/
double(m2-m1);
310 for (
Tindex i=s.f(); i<=s.l(); ++i)
311 { s(i) -= (a*double(i-m1)+avg1); }
319 const bool& debug)
const 326 while ((k<ek) && (l>el))
345 const bool& debug)
const 348 double a=aff::func::absmax(s);
366 const bool& debug)
const 371 double dishift=-(this->
Mv)/header.dt;
372 int iashift=
int(dishift);
374 if (dishift < 0) { --iashift; }
else { ++ibshift; }
375 double ibfac=dishift-double(iashift);
376 double iafac=double(ibshift)-dishift;
391 for (
int i=s.f(); i<=s.l(); ++i)
393 if (((i+iashift) >= s.f()) && (i+iashift) <= s.l())
394 { s1=src(i+iashift); }
395 if (((i+ibshift) >= s.f()) && (i+ibshift) <= s.l())
396 { s2=src(i+ibshift); }
397 s(i)=s1*iafac+s2*ibfac;
407 const bool& debug)
const 423 const bool& debug)
const 434 const bool& debug)
const 449 std::replace(s.begin(),s.end(),
',',
' ');
450 TSXX_debug(debug,
"make_filter",
"process " + s );
454 std::istringstream is(s);
456 TSXX_debug(debug,
"make_filter",
" filter ID is " + ID );
462 }
else if (ID==
"iset") {
465 }
else if (ID==
"avg") {
468 }
else if (ID==
"han") {
470 }
else if (ID==
"fac") {
472 fh=Tfh(
new Scale(v));
473 }
else if (ID==
"add") {
475 TSXX_debug(debug,
"make_filter",
" filter is: Add(" << v <<
")" );
477 }
else if (ID==
"fbl") {
480 }
else if (ID==
"pow") {
483 }
else if (ID==
"rev") {
485 }
else if (ID==
"sqr") {
487 }
else if (ID==
"sqt") {
489 }
else if (ID==
"rec") {
491 }
else if (ID==
"cus") {
493 }
else if (ID==
"del") {
495 fh=Tfh(
new Delay(v));
496 }
else if (ID==
"noi") {
499 }
else if (ID==
"nrm") {
502 }
else if (ID==
"lof") {
504 }
else if (ID==
"rsf") {
506 }
else if (ID==
"pad") {
510 TSXX_debug(debug,
"make_filter",
" filter ID " + ID +
" is unknown" );
Tdseries dugauss(const int &n)
return gaussian uniform noise (standard dev=1, zero mean)
tfxx::Handle< BasicFilter > Tfilterhandle
handle to pass filters
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
take each sample to the power of a given exponent
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
square signal
some time series filter classes (prototypes)
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
set values selected by index
remove value of first sample from series
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
square root of signal
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
add offset to sample values
force signal to a baseline.The filter removes a linear trend from the time series. After this operation the average in the index ranges [i1,i2] and [i3,i4] will vanish. The index range limits are
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
Ttimeseries::Tvalue Tvalue
we always work in double precision
error handling for libtsxx (prototypes)
#define TSXX_debug(C, N, M)
produce debug output
Ttimeseries::Tseries Tseries
Add random Gaussian noise.
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
remove average
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
add Gaussian noise
Tfilterhandle make_filter(std::string s, const bool &debug)
function to generate filter class
Structure to hold the data samples of a series together with header information to form a time series...
static double Mf
definition of static member data is required
All stuff in this library will be placed within namespace ts.
Ttimeseries::Tseries Tseries
Theader header
data header fields
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
hanning taper
#define TSXX_assert(C, M)
Check an assertion and report by throwing an exception.
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
remove trend
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
scale sample values
#define TSXX_UnknownFilterAbort(M, F)
set sample values selected by index
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
restore value of first sample to series
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
rectification
create a random series (prototypes)
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
force signal to baseline
double Tvalue
type of sample values
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
append additional samples
void print_help(std::ostream &os)
print usage information
#define TF_FILTER_CC_VERSION
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
cumulative sum
Ttimeseries operator()(const Ttimeseries &s, const bool &debug=false) const
reverse time series