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
25#include <deque>
26
27namespace gr {
28namespace satnogs {
29
30/*!
31 * \brief Simple moving sum template using std::deque
32 *
33 */
34template <typename T>
36{
37public:
38 moving_sum(int len, T init_val) : d_val(len * init_val), d_buf(len, init_val) {}
39
40 T insert(T newval);
41
42 T val();
43
44private:
45 T d_val;
46 std::deque<T> d_buf;
47};
48
49template <class T>
51{
52 T old = d_buf.front();
53 d_buf.pop_front();
54 d_buf.push_back(newval);
55 d_val += newval;
56 d_val -= old;
57 return d_val;
58}
59
60template <class T>
62{
63 return d_val;
64}
65
66} // namespace satnogs
67} // namespace gr
68
69#endif /* INCLUDED_SATNOGS_MOVING_SUM_H */
#define SATNOGS_API
Definition: api.h:19
Simple moving sum template using std::deque.
Definition: moving_sum.h:36
moving_sum(int len, T init_val)
Definition: moving_sum.h:38
T val()
Definition: moving_sum.h:61
T insert(T newval)
Definition: moving_sum.h:50
Definition: amsat_duv_decoder.h:29