Commit 326d3fd0 authored by thomas.forbriger's avatar thomas.forbriger
Browse files

libtsxx [FEATURE]: provide filters lof and rsf

These filters effectively load a filter operator (be it IIR or FIR) with the
value of the first sample. This is done by first removing the value of the
first sample from the entire time series and by restoring this value after
application of the filter.
parent 7f1b585e
......@@ -399,6 +399,36 @@ namespace ts {
/*----------------------------------------------------------------------*/
/*! remove first
*/
Ttimeseries RemoveFirst::operator()(const Ttimeseries& s,
const bool& debug) const
{
Tindex f=s.f();
RemoveFirst::Mf=s(f);
std::cout << "DBUG: remove " << RemoveFirst::Mf << std::endl;
s -= RemoveFirst::Mf;
return s;
}
//! definition of static member data is required
double RemoveFirst::Mf=0;
/*----------------------------------------------------------------------*/
/*! restore first
*/
Ttimeseries RestoreFirst::operator()(const Ttimeseries& s,
const bool& debug) const
{
std::cout << "DBUG: restore " << RemoveFirst::Mf << std::endl;
s += RemoveFirst::Mf;
RemoveFirst::Mf=0.;
return s;
}
/*----------------------------------------------------------------------*/
//! function to generate filter class
Tfilterhandle make_filter(std::string s,
const bool& debug)
......@@ -456,6 +486,10 @@ namespace ts {
} else if (ID=="nrm") {
is >> v;
fh=Tfh(new Normalize(v));
} else if (ID=="lof") {
fh=Tfh(new RemoveFirst());
} else if (ID=="rsf") {
fh=Tfh(new RestoreFirst());
} else {
TSXX_debug(debug, "make_filter", " filter ID " + ID + " is unknown" );
TSXX_UnknownFilterAbort("ts::filter::make_filter", ID.c_str());
......
......@@ -324,6 +324,43 @@ namespace ts {
/*----------------------------------------------------------------------*/
/*! \brief remove value of first sample from series
*
* \ingroup filter
*
* Subtract the value of the first sample from the entire series and store
* this value for later reference. This is useful to effectively load
* filters operators with the value of the first sample.
*/
class RemoveFirst: public ts::filter::BasicFilter {
friend class RestoreFirst;
public:
RemoveFirst() { RemoveFirst::Mf=0.; }
Ttimeseries operator()(const Ttimeseries& s,
const bool& debug=false) const;
private:
static double Mf;
}; // class RemoveFirst
/*----------------------------------------------------------------------*/
/*! \brief restore value of first sample to series
*
* \ingroup filter
*
* The value of the first sample previously subtracted by RemoveFirst will
* now be restored again. The stored value of the first sample is reset to
* zero after the operation.
*/
class RestoreFirst: public ts::filter::BasicFilter {
public:
RestoreFirst() { }
Ttimeseries operator()(const Ttimeseries& s,
const bool& debug=false) const;
}; // class RestoreFirst
/*----------------------------------------------------------------------*/
/*! create a filter
* \ingroup filter
*/
......
......@@ -32,5 +32,8 @@ cus calculate cumulative sum
iset n1,n2,v
set samples n1-n2 to value v
noi a add Gaussian random noise of rms amplitude a
lof load filters effectively with value of first sample by subtracting
first sample from entire series
rsf restore first sample, if lof was used previously
#
# ----- END OF filter_usage_text.txt -----
Supports Markdown
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