3 * Copyright 2002,2006 Free Software Foundation, Inc.
5 * This file is part of GNU Radio
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)
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.
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.
23 #ifndef INCLUDED_GRI_AGC_FF_H
24 #define INCLUDED_GRI_AGC_FF_H
29 * \brief high performance Automatic Gain Control class
31 * Power is approximated by absolute value
37 gri_agc_ff (float rate = 1e-4, float reference = 1.0,
38 float gain = 1.0, float max_gain = 0.0)
39 : _rate(rate), _reference(reference), _gain(gain), _max_gain(max_gain) {};
41 float rate () const { return _rate; }
42 float reference () const { return _reference; }
43 float gain () const { return _gain; }
44 float max_gain () const { return _max_gain; }
46 void set_rate (float rate) { _rate = rate; }
47 void set_reference (float reference) { _reference = reference; }
48 void set_gain (float gain) { _gain = gain; }
49 void set_max_gain (float max_gain) { _max_gain = max_gain; }
51 float scale (float input){
52 float output = input * _gain;
53 _gain += (_reference - fabsf (output)) * _rate;
54 if (_max_gain > 0.0 && _gain > _max_gain)
59 void scaleN (float output[], const float input[], unsigned n){
60 for (unsigned i = 0; i < n; i++)
61 output[i] = scale (input[i]);
65 float _rate; // adjustment rate
66 float _reference; // reference value
67 float _gain; // current gain
68 float _max_gain; // maximum gain
71 #endif /* INCLUDED_GRI_AGC_FF_H */