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

proceeding

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: 2186
SVN UUID:     67feda4a-a26e-11df-9d6e-31afc202ad0c
parent 391d0aa7
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: dropcontainer.h,v 1.1 2006-11-21 12:16:43 tforb Exp $
* $Id: dropcontainer.h,v 1.2 2006-11-21 15:31:12 tforb Exp $
* \author Thomas Forbriger
* \date 21/11/2006
*
......@@ -39,7 +39,7 @@
#define TF_DROPCONTAINER_H_VERSION \
"TF_DROPCONTAINER_H V1.0"
#define TF_DROPCONTAINER_H_CVSID \
"$Id: dropcontainer.h,v 1.1 2006-11-21 12:16:43 tforb Exp $"
"$Id: dropcontainer.h,v 1.2 2006-11-21 15:31:12 tforb Exp $"
#include<tsxx/tsxx.h>
......@@ -47,8 +47,60 @@ namespace ts {
namespace drop {
/*! abstract base class
/*! Abstract base class
*
* The DropContainer class is an abstract base class.
* It is used to collect time series samples and to decimate them on the
* fly. Derived classes have to be defined for this interface in oder to
* provide proper downsampling.
*
* The interface works as follows (code is given only for illustration; in
* your application you will use different classes):
* -# Declare the required downsamplers:
* \code
ts::drop::DropDropContainer<int> d1(3);
ts::drop::DropDropContainer<int> d2(2);
ts::drop::DropDropContainer<int> d3(2);
\endcode
* -# Combine downsamplers:
* \code
d1.attach(d2)->attach(d3);
\endcode
d1 will pass samples to a copy of d2 which again passes its output
to a copy of d3.
* -# Initizalize the linked list of downsamplers:
* \code
d1.initialize(a.size());
\endcode
* This will create a series container at the other end of the process.
* Initialization of the same downsampler list may be done for
* different numers of samples several times.
* -# Perform downsampling.
* -# Extract result through
\code
DUMP( d1.container() );
\endcode
*
* The full code as used in tstest.cc is as follows:
\code
aff::Series<int> a(1,36);
for (int i=a.f(); i<=a.l(); ++i) { a(i)=i; }
ts::drop::DropDropContainer<int> d1(3);
ts::drop::DropDropContainer<int> d2(2);
ts::drop::DropDropContainer<int> d3(2);
d1.attach(d2)->attach(d3);
d1.initialize(a.size());
for (int i=a.f(); i<=a.l(); ++i) { d1.drop(a(i)); }
DUMP( a );
DUMP( d1.container() );
\endcode
*
* The DropContainer class sets up a linked list of pointers. It keeps
* track of initialized pointers and call the delete appropriately.
*
* The total downsampling factor is returned by member function
* downsampling_factor() and the overall gain is provided by member
* function gain().
*/
template<class T>
class DropContainer {
......@@ -57,16 +109,30 @@ namespace ts {
typedef DropContainer<Tvalue>* PDropContainer;
typedef aff::Series<Tvalue> Tseries;
DropContainer(): Moutput(0) { }
~DropContainer()
virtual ~DropContainer()
{ if (Moutput != 0) { delete Moutput; } }
//! initialize for n samples input
virtual void initialize(const int& n);
//! this function accepts samples
virtual void drop(const Tvalue& v)=0;
void attach(const DropContainer& c)
{ Moutput=c.clone(); }
virtual PDropContainer attach(const DropContainer& c)
{
if (Moutput!=0) { Moutput->attach(c); }
else { Moutput=c.clone(); }
return this;
}
virtual Tseries container() const
{ return(attached()->container()); }
virtual int downsampling_factor() const
{
if (Moutput!=0) { return(Moutput->downsampling_factor()); }
return 1;
}
virtual Tvalue gain() const
{
if (Moutput!=0) { return(Moutput->gain()); }
return 1;
}
protected:
virtual PDropContainer clone() const=0;
virtual void initializenext(const int& n)=0;
......@@ -79,6 +145,13 @@ namespace ts {
PDropContainer Moutput;
}; // class DropContainer
/*----------------------------------------------------------------------*/
/*! Series Container
*
* This class is used at the other end of the linked list of downsamplers
* to collect the results.
*/
template<class T>
class SeriesDropContainer: public DropContainer<T> {
public:
......@@ -87,7 +160,8 @@ namespace ts {
typedef DropContainer<Tvalue>* PDropContainer;
typedef typename Tbase::Tseries Tseries;
typedef aff::Tsubscript Tsubscript;
SeriesDropContainer(const int& n): Ms(n) { }
SeriesDropContainer(): Ms(1), Mi(0) { }
virtual ~SeriesDropContainer() { }
virtual void drop(const Tvalue& v)
{
TSXX_assert(Mi <= Ms.l(),
......@@ -95,9 +169,18 @@ namespace ts {
Ms(Mi)=v;
++Mi;
}
virtual int downsampling_factor() const { return(1); }
virtual Tvalue gain() const { return(1); }
virtual PDropContainer attach(const Tbase& c)
{ TFXX_abort("SeriesDropContainer: "
"do not attach after initialization!"); }
protected:
virtual PDropContainer clone() const
{ PDropContainer retval(new SeriesDropContainer(Ms.size())); }
{
SeriesDropContainer<T>* retval(new SeriesDropContainer);
retval->initializenext(Ms.size());
return(retval);
}
virtual void initializenext(const int& n)
{ Ms=Tseries(n); Mi=Ms.f(); }
virtual Tseries container() const { return(Ms); }
......@@ -106,13 +189,22 @@ namespace ts {
Tsubscript Mi;
}; // class SeriesDropContainer
/*----------------------------------------------------------------------*/
/*! Simple decimating Drop Container
*
* This class performs downsampling without low-pass filtering. Its
* rathers used as an example than as a serious tool of signal processing.
* The downsampling ratio must be passed to the constructor.
*/
template<class T>
class DropDropContainer: public DropContainer<T> {
public:
typedef DropContainer<T> Tbase;
typedef typename Tbase::Tvalue Tvalue;
typedef DropContainer<Tvalue>* PDropContainer;
DropDropContainer(const int& n): Mn(n) { }
DropDropContainer(const int& n): Mn(n), Mi(0) { }
~DropDropContainer() { }
virtual void drop(const Tvalue& v)
{
++Mi;
......@@ -122,21 +214,55 @@ namespace ts {
attached()->drop(v);
}
}
virtual int downsampling_factor() const
{ return(Mn*Tbase::downsampling_factor()); }
protected:
virtual PDropContainer clone() const
{ PDropContainer retval(new DropDropContainer(Mn)); }
{
DropDropContainer<T>* retval(new DropDropContainer(Mn));
return(retval);
}
virtual void initializenext(const int& n)
{ Moutput->initialize(n/Mn); Mi=0; }
private:
int Mn, Mi;
}; // class DropDropContainer
/*----------------------------------------------------------------------*/
/*! Simple allpass Drop Container
*
* This class simply passes all samples.
*/
template<class T>
class PassDropContainer: public DropContainer<T> {
public:
typedef DropContainer<T> Tbase;
typedef typename Tbase::Tvalue Tvalue;
typedef DropContainer<Tvalue>* PDropContainer;
PassDropContainer() { }
~PassDropContainer() { }
virtual void drop(const Tvalue& v)
{ attached()->drop(v); }
protected:
virtual PDropContainer clone() const
{
PassDropContainer<T>* retval(new PassDropContainer);
return(retval);
}
virtual void initializenext(const int& n)
{ Moutput->initialize(n); }
private:
}; // class PassDropContainer
/*----------------------------------------------------------------------*/
template<class T>
void DropContainer<T>::initialize(const int& n)
{
if (Moutput == 0)
{ Moutput=new SeriesDropContainer<T>(n); } else
{ this->initializenext(n); }
{ Moutput=new SeriesDropContainer<T>; }
this->initializenext(n);
}
} // namespace drop
......
......@@ -3,7 +3,7 @@
*
* ----------------------------------------------------------------------------
*
* $Id: tstest.cc,v 1.5 2006-11-21 12:16:43 tforb Exp $
* $Id: tstest.cc,v 1.6 2006-11-21 15:31:13 tforb Exp $
* \author Thomas Forbriger
* \date 20/12/2003
*
......@@ -38,7 +38,7 @@
#define TSTEST_VERSION \
"TSTEST V1.2 test time series modules"
#define TSTEST_CVSID \
"$Id: tstest.cc,v 1.5 2006-11-21 12:16:43 tforb Exp $"
"$Id: tstest.cc,v 1.6 2006-11-21 15:31:13 tforb Exp $"
#include <iostream>
#include <tsxx/tsxx.h>
......@@ -196,12 +196,20 @@ int main(int iargc, char* argv[])
if (opt.droptest)
{
cout << "test drop containers" << endl;
aff::Series<int> a(36);
aff::Series<int> a(1,108);
for (int i=a.f(); i<=a.l(); ++i) { a(i)=i; }
ts::drop::DropDropContainer<int> d1(3);
ts::drop::DropDropContainer<int> d2(2);
d1.attach(d2);
ts::drop::DropDropContainer<int> d3(2);
ts::drop::PassDropContainer<int> pass;
cout << "downsampling with factor " << d1.downsampling_factor() << endl;
cout << "downsampling with gain " << d1.gain() << endl;
d1.attach(d2)->attach(d3)->attach(pass)->attach(d1);
cout << "downsampling with factor " << d1.downsampling_factor() << endl;
cout << "downsampling with gain " << d1.gain() << endl;
d1.initialize(a.size());
cout << "downsampling with factor " << d1.downsampling_factor() << endl;
cout << "downsampling with gain " << d1.gain() << endl;
for (int i=a.f(); i<=a.l(); ++i) { d1.drop(a(i)); }
DUMP( a );
DUMP( d1.container() );
......
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