SigPack - the C++ signal processing library
 
Loading...
Searching...
No Matches
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
7namespace sp
8{
13
19template <class T1> class Delay
20{
21 private:
22 arma::uword D;
23 arma::uword cur_p;
24 arma::Col<T1> buf;
25 public:
30 {
31 cur_p = 0;
32 D = 0;
33 }
34
39 Delay( const arma::uword _D )
40 {
41 set_delay( _D );
42 clear();
43 }
44
49 {
50 }
51
55 void clear( void )
56 {
57 buf.zeros();
58 cur_p = 0;
59 }
60
65 void set_delay( const arma::uword _D )
66 {
67 D = _D + 1;
68 buf.set_size( D );
69 }
70
75 T1 operator()( const T1& in )
76 {
77 buf[cur_p] = in; // Insert new sample
78 // Move insertion point
79 if( cur_p == 0 )
80 cur_p = D - 1;
81 else
82 cur_p--;
83
84 return buf[cur_p];
85 }
86
91 arma::Col<T1> delay( const arma::Col<T1>& in )
92 {
93 arma::uword sz = in.size();
94 arma::Col<T1> out( sz );
95 for( arma::uword n = 0; n < sz; n++ )
96 out[n] = this->operator()( in[n] );
97 return out;
98 }
99};
100
102
103} // namespace sp
104#endif
A delay class.
Definition timing.h:20
~Delay()
Destructor.
Definition timing.h:48
arma::uword D
The delay value.
Definition timing.h:22
arma::Col< T1 > buf
Signal buffer.
Definition timing.h:24
void clear(void)
Clears internal state.
Definition timing.h:55
T1 operator()(const T1 &in)
A delay operator.
Definition timing.h:75
Delay()
Constructor.
Definition timing.h:29
void set_delay(const arma::uword _D)
Sets delay.
Definition timing.h:65
arma::uword cur_p
Pointer to current sample in buffer.
Definition timing.h:23
Delay(const arma::uword _D)
Constructor with delay input.
Definition timing.h:39
arma::Col< T1 > delay(const arma::Col< T1 > &in)
A delay operator (vector version).
Definition timing.h:91
Definition base.h:8