GNU Radio 3.5.3.2 C++ API
|
00001 /* -*- c++ -*- */ 00002 /* 00003 * Copyright 2006 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_GRI_AGC_CC_H 00024 #define INCLUDED_GRI_AGC_CC_H 00025 00026 #include <gr_core_api.h> 00027 #include <math.h> 00028 00029 /*! 00030 * \brief high performance Automatic Gain Control class 00031 * 00032 * For Power the absolute value of the complex number is used. 00033 */ 00034 00035 class GR_CORE_API gri_agc_cc { 00036 00037 public: 00038 gri_agc_cc (float rate = 1e-4, float reference = 1.0, 00039 float gain = 1.0, float max_gain = 0.0) 00040 : _rate(rate), _reference(reference), 00041 _gain(gain), _max_gain(max_gain) {}; 00042 00043 float rate () const { return _rate; } 00044 float reference () const { return _reference; } 00045 float gain () const { return _gain; } 00046 float max_gain() const { return _max_gain; } 00047 00048 void set_rate (float rate) { _rate = rate; } 00049 void set_reference (float reference) { _reference = reference; } 00050 void set_gain (float gain) { _gain = gain; } 00051 void set_max_gain(float max_gain) { _max_gain = max_gain; } 00052 00053 gr_complex scale (gr_complex input){ 00054 gr_complex output = input * _gain; 00055 00056 _gain += _rate * (_reference - sqrt(output.real()*output.real() + 00057 output.imag()*output.imag())); 00058 if (_max_gain > 0.0 && _gain > _max_gain) 00059 _gain = _max_gain; 00060 return output; 00061 } 00062 00063 void scaleN (gr_complex output[], const gr_complex input[], unsigned n){ 00064 for (unsigned i = 0; i < n; i++) 00065 output[i] = scale (input[i]); 00066 } 00067 00068 protected: 00069 float _rate; // adjustment rate 00070 float _reference; // reference value 00071 float _gain; // current gain 00072 float _max_gain; // max allowable gain 00073 }; 00074 00075 #endif /* INCLUDED_GRI_AGC_CC_H */