TS++ library: time series library
firfilters.h
Go to the documentation of this file.
1 
35 // include guard
36 #ifndef TF_FIRFILTERS_H_VERSION
37 
38 #define TF_FIRFILTERS_H_VERSION \
39  "TF_FIRFILTERS_H V1.0 "
40 
41 #include<iostream>
42 #include<string>
43 #include<aff/series.h>
44 #include<aff/iterator.h>
45 #include<tsxx/error.h>
46 
47 namespace ts {
48 
49  namespace fir {
50 
53  struct FIR {
54  const char* name;
55  const char* description;
56  const int points;
57  const int delay;
58  const bool symmetric;
59  const int decimation_factor;
60  const double gain;
61  const double* c;
62  }; // struct FIR
63 
66  extern const FIR SeisCompMP;
67  extern const FIR SeisCompLP;
68  extern const FIR SeisCompVLP;
69 
72  extern const FIR* FIRfilters[];
73 
74  /*----------------------------------------------------------------------*/
75 
78  std::ostream& operator<<(std::ostream& os, const FIR& fir);
79 
80  /*----------------------------------------------------------------------*/
81 
84  void help(std::ostream& os);
85 
86  /*----------------------------------------------------------------------*/
87 
97  template<class T>
98  class FIRfilter {
99  public:
100  typedef T Tvalue;
101  typedef aff::Series<Tvalue> Tseries;
102  typedef aff::Iterator<Tseries> Titerator;
103  FIRfilter(const FIR* fir): Mfir(fir), Ms(fir->points), Mi(Ms)
104  { this->clear(); }
105  FIRfilter(const std::string name): Mfir(0), Ms(1), Mi(Ms)
106  {
107  int i=0;
108  while (FIRfilters[i]!=0)
109  {
110  if (name == FIRfilters[i]->name) { Mfir=FIRfilters[i]; }
111  ++i;
112  }
113  TSXX_assert(Mfir != 0, "FIRfilter: unknown FIR filter name");
114  Ms=Tseries(Mfir->points);
115  Mi=Titerator(Ms);
116  this->clear();
117  }
118  void push(const Tvalue& v)
119  {
120  *Mi = v;
121  ++Mi;
122  }
123  Tvalue pop() const
124  {
125  Titerator Ml=Mi;
126  double sum=0;
127  if (Mfir->symmetric)
128  {
129  for (int i=0; i<Mfir->points / 2; ++i)
130  { sum += *Ml * Mfir->c[i] * Mfir->gain; --Ml; }
131  for (int i= Mfir->points/2 -1; i>=0; --i)
132  { sum += *Ml * Mfir->c[i] * Mfir->gain; --Ml; }
133  }
134  else
135  {
136  for (int i=0; i<Mfir->points; ++i)
137  { sum += *Ml * Mfir->c[i] * Mfir->gain; --Ml; }
138  }
139  return(Tvalue(sum));
140  }
141  void clear()
142  {
143  Mi.tofirst();
144  while (Mi.valid()) { *Mi = 0; ++Mi; }
145  Mi.tofirst();
146  }
147  const FIR& fir() const { return(*Mfir); }
148  private:
149  const FIR* Mfir;
152  }; // class FIRfilter
153 
154  } // namespace fir
155 
156 } // namespace ts
157 
158 #endif // TF_FIRFILTERS_H_VERSION (includeguard)
159 
160 /* ----- END OF firfilters.h ----- */
const char * description
Definition: firfilters.h:55
const FIR * FIRfilters[]
Definition: firfilters.cc:177
FIRfilter(const std::string name)
Definition: firfilters.h:105
const FIR & fir() const
Definition: firfilters.h:147
aff::Series< Tvalue > Tseries
Definition: firfilters.h:101
Tvalue pop() const
Definition: firfilters.h:123
const bool symmetric
Definition: firfilters.h:58
const FIR SeisCompVLP
Definition: firfilters.cc:164
error handling for libtsxx (prototypes)
void push(const Tvalue &v)
Definition: firfilters.h:118
const FIR SeisCompMP
Definition: firfilters.cc:55
aff::Iterator< Tseries > Titerator
Definition: firfilters.h:102
All stuff in this library will be placed within namespace ts.
Definition: anyfilter.cc:43
const FIR * Mfir
Definition: firfilters.h:149
void help(std::ostream &os)
Definition: firfilters.cc:203
const double gain
Definition: firfilters.h:60
FIRfilter(const FIR *fir)
Definition: firfilters.h:103
#define TSXX_assert(C, M)
Check an assertion and report by throwing an exception.
Definition: error.h:127
const FIR SeisCompLP
Definition: firfilters.cc:97
std::ostream & operator<<(std::ostream &os, const FIR &fir)
Definition: firfilters.cc:187
const char * name
Definition: firfilters.h:54
const int decimation_factor
Definition: firfilters.h:59
const int points
Definition: firfilters.h:56
const int delay
Definition: firfilters.h:57
const double * c
Definition: firfilters.h:61