GNU Radio Manual and C++ API Reference  3.8.1.0
The Free & Open Software Radio Ecosystem
moving_average.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2008,2013,2017,2018 Free Software Foundation, Inc.
4  *
5  * This file is part of GNU Radio
6  *
7  * GNU Radio 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, or (at your option)
10  * any later version.
11  *
12  * GNU Radio 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 GNU Radio; see the file COPYING. If not, write to
19  * the Free Software Foundation, Inc., 51 Franklin Street,
20  * Boston, MA 02110-1301, USA.
21  */
22 
23 
24 #ifndef MOVING_AVERAGE_H
25 #define MOVING_AVERAGE_H
26 
27 #include <gnuradio/blocks/api.h>
28 #include <gnuradio/sync_block.h>
29 #include <cstdint>
30 
31 namespace gr {
32 namespace blocks {
33 
34 /*!
35  * \brief output is the moving sum of the last N samples, scaled by the scale factor
36  * \ingroup level_controllers_blk
37  */
38 template <class T>
39 class BLOCKS_API moving_average : virtual public sync_block
40 {
41 public:
42  // gr::blocks::moving_average::sptr
43  typedef boost::shared_ptr<moving_average<T>> sptr;
44 
45  /*!
46  * Create a moving average block.
47  *
48  * \param length Number of samples to use in the average.
49  * \param scale scale factor for the result.
50  * \param max_iter limits how long we go without flushing the accumulator
51  * This is necessary to avoid numerical instability for float and complex.
52  * \param vlen When > 1, do a per-vector-element moving average
53  */
54  static sptr make(int length, T scale, int max_iter = 4096, unsigned int vlen = 1);
55 
56  /*!
57  * Get the length used in the avaraging calculation.
58  */
59  virtual int length() const = 0;
60 
61  /*!
62  * Get the scale factor being used.
63  */
64  virtual T scale() const = 0;
65 
66  /*!
67  * Set both the length and the scale factor together.
68  */
69  virtual void set_length_and_scale(int length, T scale) = 0;
70 
71  /*!
72  * Set the length.
73  */
74  virtual void set_length(int length) = 0;
75 
76  /*!
77  * Set the scale factor.
78  */
79  virtual void set_scale(T scale) = 0;
80 };
81 
86 } /* namespace blocks */
87 } /* namespace gr */
88 
89 #endif /* MOVING_AVERAGE_H */
moving_average< float > moving_average_ff
Definition: moving_average.h:84
output is the moving sum of the last N samples, scaled by the scale factor
Definition: moving_average.h:39
boost::shared_ptr< moving_average< T > > sptr
Definition: moving_average.h:43
GNU Radio logging wrapper for log4cpp library (C++ port of log4j)
Definition: basic_block.h:43
#define BLOCKS_API
Definition: gr-blocks/include/gnuradio/blocks/api.h:30
synchronous 1:1 input to output with historyOverride work to provide the signal processing implementa...
Definition: sync_block.h:37
PMT_API size_t length(const pmt_t &v)
Return the number of elements in v.
moving_average< std::int32_t > moving_average_ii
Definition: moving_average.h:83
moving_average< gr_complex > moving_average_cc
Definition: moving_average.h:85
moving_average< std::int16_t > moving_average_ss
Definition: moving_average.h:82