GNU Radio 3.6.3.1 C++ API
gri_agc_cc.h
Go to the documentation of this file.
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2006 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 #ifndef INCLUDED_GRI_AGC_CC_H
24 #define INCLUDED_GRI_AGC_CC_H
25 
26 #include <gr_core_api.h>
27 #include <math.h>
28 
29 /*!
30  * \brief high performance Automatic Gain Control class
31  *
32  * For Power the absolute value of the complex number is used.
33  */
34 
36 
37  public:
38  gri_agc_cc (float rate = 1e-4, float reference = 1.0,
39  float gain = 1.0, float max_gain = 0.0)
40  : _rate(rate), _reference(reference),
41  _gain(gain), _max_gain(max_gain) {};
42 
43  float rate () const { return _rate; }
44  float reference () const { return _reference; }
45  float gain () const { return _gain; }
46  float max_gain() const { return _max_gain; }
47 
48  void set_rate (float rate) { _rate = rate; }
49  void set_reference (float reference) { _reference = reference; }
50  void set_gain (float gain) { _gain = gain; }
51  void set_max_gain(float max_gain) { _max_gain = max_gain; }
52 
54  gr_complex output = input * _gain;
55 
56  _gain += _rate * (_reference - sqrt(output.real()*output.real() +
57  output.imag()*output.imag()));
58  if (_max_gain > 0.0 && _gain > _max_gain)
59  _gain = _max_gain;
60  return output;
61  }
62 
63  void scaleN (gr_complex output[], const gr_complex input[], unsigned n){
64  for (unsigned i = 0; i < n; i++)
65  output[i] = scale (input[i]);
66  }
67 
68  protected:
69  float _rate; // adjustment rate
70  float _reference; // reference value
71  float _gain; // current gain
72  float _max_gain; // max allowable gain
73 };
74 
75 #endif /* INCLUDED_GRI_AGC_CC_H */