GNU Radio C++ API Reference: agc.h Source File

| GNU Radio C++ API Reference 3.10.12.0 The Free & Open Software Radio Ecosystem |

Loading...
Searching...
No Matches
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 {
19 namespace analog {
20 namespace 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 */
29 class ANALOG_API agc_cc
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
58 gr_complex scale(gr_complex input)
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 */
89 class ANALOG_API agc_ff
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
106 ~agc_ff(){};
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 */
gr::analog::kernel::agc_cc::~agc_cc
virtual ~agc_cc()
Definition agc.h:46
gr::analog::kernel::agc_cc::agc_cc
agc_cc(float rate=1e-4, float reference=1.0, float gain=1.0, float max_gain=0.0)
Definition agc.h:40
gr::analog::kernel::agc_cc::_max_gain
float _max_gain
Definition agc.h:81
gr::analog::kernel::agc_cc::_gain
float _gain
Definition agc.h:80
gr::analog::kernel::agc_cc::scale
gr_complex scale(gr_complex input)
Definition agc.h:58
gr::analog::kernel::agc_cc::set_gain
void set_gain(float gain)
Definition agc.h:55
gr::analog::kernel::agc_cc::_reference
float _reference
Definition agc.h:79
gr::analog::kernel::agc_cc::rate
float rate() const
Definition agc.h:48
gr::analog::kernel::agc_cc::scaleN
void scaleN(gr_complex output[], const gr_complex input[], unsigned n)
Definition agc.h:70
gr::analog::kernel::agc_cc::set_rate
void set_rate(float rate)
Definition agc.h:53
gr::analog::kernel::agc_cc::set_reference
void set_reference(float reference)
Definition agc.h:54
gr::analog::kernel::agc_cc::_rate
float _rate
Definition agc.h:78
gr::analog::kernel::agc_cc::gain
float gain() const
Definition agc.h:50
gr::analog::kernel::agc_cc::reference
float reference() const
Definition agc.h:49
gr::analog::kernel::agc_cc::max_gain
float max_gain() const
Definition agc.h:51
gr::analog::kernel::agc_cc::set_max_gain
void set_max_gain(float max_gain)
Definition agc.h:56
gr::analog::kernel::agc_ff::_gain
float _gain
Definition agc.h:136
gr::analog::kernel::agc_ff::gain
float gain() const
Definition agc.h:110
gr::analog::kernel::agc_ff::~agc_ff
~agc_ff()
Definition agc.h:106
gr::analog::kernel::agc_ff::set_gain
void set_gain(float gain)
Definition agc.h:115
gr::analog::kernel::agc_ff::reference
float reference() const
Definition agc.h:109
gr::analog::kernel::agc_ff::_max_gain
float _max_gain
Definition agc.h:137
gr::analog::kernel::agc_ff::_reference
float _reference
Definition agc.h:135
gr::analog::kernel::agc_ff::rate
float rate() const
Definition agc.h:108
gr::analog::kernel::agc_ff::max_gain
float max_gain() const
Definition agc.h:111
gr::analog::kernel::agc_ff::scaleN
void scaleN(float output[], const float input[], unsigned n)
Definition agc.h:127
gr::analog::kernel::agc_ff::set_max_gain
void set_max_gain(float max_gain)
Definition agc.h:116
gr::analog::kernel::agc_ff::agc_ff
agc_ff(float rate=1e-4, float reference=1.0, float gain=1.0, float max_gain=0.0)
Definition agc.h:100
gr::analog::kernel::agc_ff::_rate
float _rate
Definition agc.h:134
gr::analog::kernel::agc_ff::set_reference
void set_reference(float reference)
Definition agc.h:114
gr::analog::kernel::agc_ff::set_rate
void set_rate(float rate)
Definition agc.h:113
gr::analog::kernel::agc_ff::scale
float scale(float input)
Definition agc.h:118
api.h
ANALOG_API
#define ANALOG_API
Definition gr-analog/include/gnuradio/analog/api.h:18
gr_complex.h
gr_complex
std::complex< float > gr_complex
Definition gr_complex.h:15
gr::analog::kernel
Definition agc.h:20
gr::analog
Definition agc.h:19
gr
GNU Radio logging wrapper.
Definition basic_block.h:29