GNU Radio Manual and C++ API Reference 3.10.5.1
The Free & Open Software Radio Ecosystem
agc.h
Go to the documentation of this file.
1/* -*- c++ -*- */
2/*
3 * Copyright 2006,2012 Free Software Foundation, Inc.
4 *
5 * This file is part of GNU Radio
6 *
7 * SPDX-License-Identifier: GPL-3.0-or-later
8 *
9 */
10
11#ifndef INCLUDED_ANALOG_AGC_H
12#define INCLUDED_ANALOG_AGC_H
13
14#include <gnuradio/analog/api.h>
15#include <gnuradio/gr_complex.h>
16#include <cmath>
17
18namespace gr {
19namespace analog {
20namespace kernel {
21
22/*!
23 * \brief high performance Automatic Gain Control class for complex signals.
24 * \ingroup level_controllers_blk
25 *
26 * \details
27 * For Power the absolute value of the complex number is used.
28 */
30{
31public:
32 /*!
33 * Construct a complex value AGC loop implementation object.
34 *
35 * \param rate the update rate of the loop.
36 * \param reference reference value to adjust signal power to.
37 * \param gain initial gain value.
38 * \param max_gain maximum gain value (0 for unlimited).
39 */
40 agc_cc(float rate = 1e-4,
41 float reference = 1.0,
42 float gain = 1.0,
43 float max_gain = 0.0)
44 : _rate(rate), _reference(reference), _gain(gain), _max_gain(max_gain){};
45
46 virtual ~agc_cc(){};
47
48 float rate() const { return _rate; }
49 float reference() const { return _reference; }
50 float gain() const { return _gain; }
51 float max_gain() const { return _max_gain; }
52
53 void set_rate(float rate) { _rate = rate; }
54 void set_reference(float reference) { _reference = reference; }
55 void set_gain(float gain) { _gain = gain; }
56 void set_max_gain(float max_gain) { _max_gain = max_gain; }
57
59 {
60 gr_complex output = input * _gain;
61
62 _gain += _rate * (_reference - std::sqrt(output.real() * output.real() +
63 output.imag() * output.imag()));
64 if (_max_gain > 0.0 && _gain > _max_gain) {
65 _gain = _max_gain;
66 }
67 return output;
68 }
69
70 void scaleN(gr_complex output[], const gr_complex input[], unsigned n)
71 {
72 for (unsigned i = 0; i < n; i++) {
73 output[i] = scale(input[i]);
74 }
75 }
76
77protected:
78 float _rate; // adjustment rate
79 float _reference; // reference value
80 float _gain; // current gain
81 float _max_gain; // max allowable gain
82};
83
84/*!
85 * \brief high performance Automatic Gain Control class for float signals.
86 *
87 * Power is approximated by absolute value
88 */
90{
91public:
92 /*!
93 * Construct a floating point value AGC loop implementation object.
94 *
95 * \param rate the update rate of the loop.
96 * \param reference reference value to adjust signal power to.
97 * \param gain initial gain value.
98 * \param max_gain maximum gain value (0 for unlimited).
99 */
100 agc_ff(float rate = 1e-4,
101 float reference = 1.0,
102 float gain = 1.0,
103 float max_gain = 0.0)
104 : _rate(rate), _reference(reference), _gain(gain), _max_gain(max_gain){};
105
107
108 float rate() const { return _rate; }
109 float reference() const { return _reference; }
110 float gain() const { return _gain; }
111 float max_gain() const { return _max_gain; }
112
113 void set_rate(float rate) { _rate = rate; }
114 void set_reference(float reference) { _reference = reference; }
115 void set_gain(float gain) { _gain = gain; }
116 void set_max_gain(float max_gain) { _max_gain = max_gain; }
117
118 float scale(float input)
119 {
120 float output = input * _gain;
121 _gain += (_reference - fabsf(output)) * _rate;
122 if (_max_gain > 0.0 && _gain > _max_gain)
123 _gain = _max_gain;
124 return output;
125 }
126
127 void scaleN(float output[], const float input[], unsigned n)
128 {
129 for (unsigned i = 0; i < n; i++)
130 output[i] = scale(input[i]);
131 }
132
133protected:
134 float _rate; // adjustment rate
135 float _reference; // reference value
136 float _gain; // current gain
137 float _max_gain; // maximum gain
138};
139
140} /* namespace kernel */
141} /* namespace analog */
142} /* namespace gr */
143
144#endif /* INCLUDED_ANALOG_AGC_H */
high performance Automatic Gain Control class for complex signals.
Definition: agc.h:30
virtual ~agc_cc()
Definition: agc.h:46
agc_cc(float rate=1e-4, float reference=1.0, float gain=1.0, float max_gain=0.0)
Definition: agc.h:40
float _max_gain
Definition: agc.h:81
float _gain
Definition: agc.h:80
gr_complex scale(gr_complex input)
Definition: agc.h:58
void set_gain(float gain)
Definition: agc.h:55
float _reference
Definition: agc.h:79
float rate() const
Definition: agc.h:48
void scaleN(gr_complex output[], const gr_complex input[], unsigned n)
Definition: agc.h:70
void set_rate(float rate)
Definition: agc.h:53
void set_reference(float reference)
Definition: agc.h:54
float _rate
Definition: agc.h:78
float gain() const
Definition: agc.h:50
float reference() const
Definition: agc.h:49
float max_gain() const
Definition: agc.h:51
void set_max_gain(float max_gain)
Definition: agc.h:56
high performance Automatic Gain Control class for float signals.
Definition: agc.h:90
float _gain
Definition: agc.h:136
float gain() const
Definition: agc.h:110
~agc_ff()
Definition: agc.h:106
void set_gain(float gain)
Definition: agc.h:115
float reference() const
Definition: agc.h:109
float _max_gain
Definition: agc.h:137
float _reference
Definition: agc.h:135
float rate() const
Definition: agc.h:108
float max_gain() const
Definition: agc.h:111
void scaleN(float output[], const float input[], unsigned n)
Definition: agc.h:127
void set_max_gain(float max_gain)
Definition: agc.h:116
agc_ff(float rate=1e-4, float reference=1.0, float gain=1.0, float max_gain=0.0)
Definition: agc.h:100
float _rate
Definition: agc.h:134
void set_reference(float reference)
Definition: agc.h:114
void set_rate(float rate)
Definition: agc.h:113
float scale(float input)
Definition: agc.h:118
#define ANALOG_API
Definition: gr-analog/include/gnuradio/analog/api.h:18
std::complex< float > gr_complex
Definition: gr_complex.h:15
GNU Radio logging wrapper.
Definition: basic_block.h:29