SigPack - the C++ signal processing library
timing.h
Go to the documentation of this file.
1 // This Source Code Form is subject to the terms of the Mozilla Public
2 // License, v. 2.0. If a copy of the MPL was not distributed with this
3 // file, You can obtain one at http://mozilla.org/MPL/2.0/.
4 #ifndef SP_TIMING_H
5 #define SP_TIMING_H
6 namespace sp
7 {
12 
18 template <class T1> class Delay
19 {
20 private:
21  arma::uword D;
22  arma::uword cur_p;
23  arma::Col<T1> buf;
24 public:
29  {
30  cur_p = 0;
31  D = 0;
32  }
33 
38  Delay(const arma::uword _D)
39  {
40  set_delay(_D);
41  clear();
42  }
43 
47  ~Delay() {}
48 
52  void clear(void)
53  {
54  buf.zeros();
55  cur_p = 0;
56  }
57 
62  void set_delay(const arma::uword _D)
63  {
64  D = _D + 1;
65  buf.set_size(D);
66  }
67 
72  T1 operator()(const T1 &in)
73  {
74  buf[cur_p] = in; // Insert new sample
75  // Move insertion point
76  if (cur_p == 0)
77  cur_p = D - 1;
78  else
79  cur_p--;
80 
81  return buf[cur_p];
82  }
83 
88  arma::Col<T1> delay(const arma::Col<T1> &in)
89  {
90  arma::uword sz = in.size();
91  arma::Col<T1> out(sz);
92  for (arma::uword n = 0; n < sz; n++)
93  out[n] = this->operator()(in[n]);
94  return out;
95  }
96 };
98 
99 } // namespace sp
100 #endif
Definition: base.h:7
arma::uword D
The delay value.
Definition: timing.h:21
Delay(const arma::uword _D)
Constructor with delay input.
Definition: timing.h:38
A delay class.
Definition: timing.h:18
arma::uword cur_p
Pointer to current sample in buffer.
Definition: timing.h:22
~Delay()
Destructor.
Definition: timing.h:47
T1 operator()(const T1 &in)
A delay operator.
Definition: timing.h:72
arma::Col< T1 > delay(const arma::Col< T1 > &in)
A delay operator (vector version).
Definition: timing.h:88
Delay()
Constructor.
Definition: timing.h:28
void clear(void)
Clears internal state.
Definition: timing.h:52
void set_delay(const arma::uword _D)
Sets delay.
Definition: timing.h:62
arma::Col< T1 > buf
Signal buffer.
Definition: timing.h:23