fun_ofdm  1.0
802.11a Physical Layer for USRP
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Macros Pages
circular_accumulator.h
Go to the documentation of this file.
1 
11 #ifndef CIRCULAR_ACCUMULATOR_H
12 #define CIRCULAR_ACCUMULATOR_H
13 
14 #include <vector>
15 
16 namespace fun
17 {
24  template<typename T>
26  {
34  T sum;
35 
42  std::vector<T> samples;
43 
51  int index;
52 
59  int size;
60 
70  {
71  size = _size;
72  samples.resize(size);
73  index = 0;
74  for(int x = 0; x < size; x++) samples[x] = T(0);
75  sum = T(0);
76  }
77 
78  // circular_accumulator(){}
79 
88  void add(T sample)
89  {
90  if(sample != sample) sample = 0;
91  sum -= samples[index];
92  sum += sample;
93  samples[index++] = sample;
94  if(index >= size) index = 0;
95  }
96  };
97 
98 }
99 
100 #endif // CIRCULAR_ACCUMULATOR_H