GNU Radio's SATNOGS Package
moving_sum.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * gr-satnogs: SatNOGS GNU Radio Out-Of-Tree Module
4  *
5  * Copyright (C) 2019, Libre Space Foundation <http://libre.space>
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
21 #ifndef INCLUDED_SATNOGS_MOVING_SUM_H
22 #define INCLUDED_SATNOGS_MOVING_SUM_H
23 
24 #include <satnogs/api.h>
25 #include <deque>
26 
27 namespace gr {
28 namespace satnogs {
29 
30 /*!
31  * \brief Simple moving sum template using std::deque
32  *
33  */
34 template<typename T>
36 public:
37  moving_sum(int len, T init_val) :
38  d_val(len * init_val),
39  d_buf(len, init_val)
40  {
41  }
42 
43  T
44  insert(T newval);
45 
46  T
47  val();
48 
49 private:
50  T d_val;
51  std::deque<T> d_buf;
52 };
53 
54 template<class T> T
56 {
57  T old = d_buf.front();
58  d_buf.pop_front();
59  d_buf.push_back(newval);
60  d_val += newval;
61  d_val -= old;
62  return d_val;
63 }
64 
65 template <class T> T
67 {
68  return d_val;
69 }
70 
71 } // namespace satnogs
72 } // namespace gr
73 
74 #endif /* INCLUDED_SATNOGS_MOVING_SUM_H */
T insert(T newval)
Definition: moving_sum.h:55
moving_sum(int len, T init_val)
Definition: moving_sum.h:37
Definition: amsat_duv_decoder.h:29
Simple moving sum template using std::deque.
Definition: moving_sum.h:35
#define SATNOGS_API
Definition: api.h:30
T val()
Definition: moving_sum.h:66