GNU Radio's LFAST Package
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 * 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_ANALOG_AGC_H
24#define INCLUDED_ANALOG_AGC_H
25
26#include <lfast/api.h>
27#include <gnuradio/gr_complex.h>
28#include <math.h>
29
30namespace gr {
31 namespace lfast {
32 namespace kernel {
33
34 /*!
35 * \brief high performance Automatic Gain Control class for complex signals.
36 * \ingroup level_controllers_blk
37 *
38 * \details
39 * For Power the absolute value of the complex number is used.
40 */
42 {
43 public:
44 /*!
45 * Construct a complex value AGC loop implementation object.
46 *
47 * \param rate the update rate of the loop.
48 * \param reference reference value to adjust signal power to.
49 * \param gain initial gain value.
50 * \param max_gain maximum gain value (0 for unlimited).
51 */
52 agc_cc(float rate = 1e-4, float reference = 1.0,
53 float gain = 1.0, float max_gain = 0.0)
56
57 virtual ~agc_cc() {};
58
59 float rate() const { return _rate; }
60 float reference() const { return _reference; }
61 float gain() const { return _gain; }
62 float max_gain() const { return _max_gain; }
63
64 void set_rate(float rate) { _rate = rate; }
66 void set_gain(float gain) { _gain = gain; }
68
69 gr_complex scale(gr_complex input)
70 {
71 gr_complex output = input * _gain;
72
73 _gain += _rate * (_reference - sqrt(output.real()*output.real() +
74 output.imag()*output.imag()));
75 if(_max_gain > 0.0 && _gain > _max_gain) {
77 }
78 return output;
79 }
80
81 void scaleN(gr_complex output[], const gr_complex input[], unsigned n)
82 {
83 for(unsigned i = 0; i < n; i++) {
84 output[i] = scale (input[i]);
85 }
86 }
87
88 protected:
89 float _rate; // adjustment rate
90 float _reference; // reference value
91 float _gain; // current gain
92 float _max_gain; // max allowable gain
93 };
94
95 /*!
96 * \brief high performance Automatic Gain Control class for float signals.
97 *
98 * Power is approximated by absolute value
99 */
101 {
102 public:
103 /*!
104 * Construct a floating point value AGC loop implementation object.
105 *
106 * \param rate the update rate of the loop.
107 * \param reference reference value to adjust signal power to.
108 * \param gain initial gain value.
109 * \param max_gain maximum gain value (0 for unlimited).
110 */
111 agc_ff(float rate = 1e-4, float reference = 1.0,
112 float gain = 1.0, float max_gain = 0.0)
115
117
118 float rate () const { return _rate; }
119 float reference () const { return _reference; }
120 float gain () const { return _gain; }
121 float max_gain () const { return _max_gain; }
122
123 void set_rate (float rate) { _rate = rate; }
125 void set_gain (float gain) { _gain = gain; }
127
128 float scale (float input)
129 {
130 float output = input * _gain;
131 _gain += (_reference - fabsf (output)) * _rate;
132 if(_max_gain > 0.0 && _gain > _max_gain)
134 return output;
135 }
136
137 void scaleN(float output[], const float input[], unsigned n)
138 {
139 for(unsigned i = 0; i < n; i++)
140 output[i] = scale (input[i]);
141 }
142
143 protected:
144 float _rate; // adjustment rate
145 float _reference; // reference value
146 float _gain; // current gain
147 float _max_gain; // maximum gain
148 };
149
150 } /* namespace kernel */
151 } /* namespace analog */
152} /* namespace gr */
153
154#endif /* INCLUDED_ANALOG_AGC_H */
#define LFAST_API
Definition api.h:30
void set_gain(float gain)
Definition agc.h:66
float gain() const
Definition agc.h:61
float _gain
Definition agc.h:91
float reference() const
Definition agc.h:60
float _rate
Definition agc.h:89
void set_rate(float rate)
Definition agc.h:64
agc_cc(float rate=1e-4, float reference=1.0, float gain=1.0, float max_gain=0.0)
Definition agc.h:52
float max_gain() const
Definition agc.h:62
gr_complex scale(gr_complex input)
Definition agc.h:69
float _max_gain
Definition agc.h:92
float _reference
Definition agc.h:90
void scaleN(gr_complex output[], const gr_complex input[], unsigned n)
Definition agc.h:81
void set_max_gain(float max_gain)
Definition agc.h:67
void set_reference(float reference)
Definition agc.h:65
float rate() const
Definition agc.h:59
virtual ~agc_cc()
Definition agc.h:57
agc_ff(float rate=1e-4, float reference=1.0, float gain=1.0, float max_gain=0.0)
Definition agc.h:111
void set_rate(float rate)
Definition agc.h:123
float _gain
Definition agc.h:146
float reference() const
Definition agc.h:119
void set_max_gain(float max_gain)
Definition agc.h:126
float rate() const
Definition agc.h:118
float _max_gain
Definition agc.h:147
float gain() const
Definition agc.h:120
float _rate
Definition agc.h:144
void set_gain(float gain)
Definition agc.h:125
float scale(float input)
Definition agc.h:128
float max_gain() const
Definition agc.h:121
float _reference
Definition agc.h:145
void scaleN(float output[], const float input[], unsigned n)
Definition agc.h:137
void set_reference(float reference)
Definition agc.h:124
~agc_ff()
Definition agc.h:116
Definition agc.h:32
Definition agc.h:31
Definition agc.h:30