GNU Radio 3.6.5 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2006,2012 Free Software Foundation, Inc. 00004 * 00005 * This file is part of GNU Radio 00006 * 00007 * GNU Radio is free software; you can redistribute it and/or modify 00008 * it under the terms of the GNU General Public License as published by 00009 * the Free Software Foundation; either version 3, or (at your option) 00010 * any later version. 00011 * 00012 * GNU Radio is distributed in the hope that it will be useful, 00013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00015 * GNU General Public License for more details. 00016 * 00017 * You should have received a copy of the GNU General Public License 00018 * along with GNU Radio; see the file COPYING. If not, write to 00019 * the Free Software Foundation, Inc., 51 Franklin Street, 00020 * Boston, MA 02110-1301, USA. 00021 */ 00022 00023 #ifndef INCLUDED_ANALOG_AGC_H 00024 #define INCLUDED_ANALOG_AGC_H 00025 00026 #include <analog/api.h> 00027 #include <gr_complex.h> 00028 #include <math.h> 00029 00030 namespace gr { 00031 namespace analog { 00032 namespace kernel { 00033 00034 /*! 00035 * \brief high performance Automatic Gain Control class for complex signals. 00036 * 00037 * \details 00038 * For Power the absolute value of the complex number is used. 00039 */ 00040 class ANALOG_API agc_cc 00041 { 00042 public: 00043 agc_cc(float rate = 1e-4, float reference = 1.0, 00044 float gain = 1.0, float max_gain = 0.0) 00045 : _rate(rate), _reference(reference), 00046 _gain(gain), _max_gain(max_gain) {}; 00047 00048 virtual ~agc_cc() {}; 00049 00050 float rate() const { return _rate; } 00051 float reference() const { return _reference; } 00052 float gain() const { return _gain; } 00053 float max_gain() const { return _max_gain; } 00054 00055 void set_rate(float rate) { _rate = rate; } 00056 void set_reference(float reference) { _reference = reference; } 00057 void set_gain(float gain) { _gain = gain; } 00058 void set_max_gain(float max_gain) { _max_gain = max_gain; } 00059 00060 gr_complex scale(gr_complex input) 00061 { 00062 gr_complex output = input * _gain; 00063 00064 _gain += _rate * (_reference - sqrt(output.real()*output.real() + 00065 output.imag()*output.imag())); 00066 if(_max_gain > 0.0 && _gain > _max_gain) { 00067 _gain = _max_gain; 00068 } 00069 return output; 00070 } 00071 00072 void scaleN(gr_complex output[], const gr_complex input[], unsigned n) 00073 { 00074 for(unsigned i = 0; i < n; i++) { 00075 output[i] = scale (input[i]); 00076 } 00077 } 00078 00079 protected: 00080 float _rate; // adjustment rate 00081 float _reference; // reference value 00082 float _gain; // current gain 00083 float _max_gain; // max allowable gain 00084 }; 00085 00086 /*! 00087 * \brief high performance Automatic Gain Control class for float signals. 00088 * 00089 * Power is approximated by absolute value 00090 */ 00091 class ANALOG_API agc_ff 00092 { 00093 public: 00094 agc_ff(float rate = 1e-4, float reference = 1.0, 00095 float gain = 1.0, float max_gain = 0.0) 00096 : _rate(rate), _reference(reference), _gain(gain), 00097 _max_gain(max_gain) {}; 00098 00099 ~agc_ff() {}; 00100 00101 float rate () const { return _rate; } 00102 float reference () const { return _reference; } 00103 float gain () const { return _gain; } 00104 float max_gain () const { return _max_gain; } 00105 00106 void set_rate (float rate) { _rate = rate; } 00107 void set_reference (float reference) { _reference = reference; } 00108 void set_gain (float gain) { _gain = gain; } 00109 void set_max_gain (float max_gain) { _max_gain = max_gain; } 00110 00111 float scale (float input) 00112 { 00113 float output = input * _gain; 00114 _gain += (_reference - fabsf (output)) * _rate; 00115 if(_max_gain > 0.0 && _gain > _max_gain) 00116 _gain = _max_gain; 00117 return output; 00118 } 00119 00120 void scaleN(float output[], const float input[], unsigned n) 00121 { 00122 for(unsigned i = 0; i < n; i++) 00123 output[i] = scale (input[i]); 00124 } 00125 00126 protected: 00127 float _rate; // adjustment rate 00128 float _reference; // reference value 00129 float _gain; // current gain 00130 float _max_gain; // maximum gain 00131 }; 00132 00133 } /* namespace kernel */ 00134 } /* namespace analog */ 00135 } /* namespace gr */ 00136 00137 #endif /* INCLUDED_ANALOG_AGC_H */