Main Page | Modules | Namespace List | Class Hierarchy | Class List | Directories | File List | Class Members | File Members

gr_agc.h

Go to the documentation of this file.
00001 /* -*- c++ -*- */
00002 /*
00003  * Copyright 2002 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 2, 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., 59 Temple Place - Suite 330,
00020  * Boston, MA 02111-1307, USA.
00021  */
00022 
00023 #ifndef _GR_AGC_H_
00024 #define _GR_AGC_H_
00025 
00026 #include <math.h>
00027 
00034 class gr_agc {
00035 
00036  public:
00037   gr_agc (float rate = 1e-4, float reference = 1.0, float gain = 1.0)
00038     : _rate(rate), _reference(reference), _gain(gain) {};
00039 
00040   float rate () const      { return _rate; }
00041   float reference () const { return _reference; }
00042   float gain () const      { return _gain;  }
00043 
00044   void set_rate (float rate) { _rate = rate; }
00045   void set_reference (float reference) { _reference = reference; }
00046   void set_gain (float gain) { _gain = gain; }
00047 
00048   float scale (float input){
00049     float output = input * _gain;
00050     _gain += (_reference - fabsf (output)) * _rate;
00051     return output;
00052   }
00053 
00054   void scaleN (float output[], const float input[], unsigned n){
00055     for (unsigned i = 0; i < n; i++)
00056       output[i] = scale (input[i]);
00057   }
00058   
00059  protected:
00060   float _rate;                  // adjustment rate
00061   float _reference;             // reference value
00062   float _gain;                  // current gain
00063 };
00064 
00065 #endif /* _GR_AGC_H_ */

Generated on Tue Mar 29 19:14:33 2005 for GNU Radio 2.x by  doxygen 1.4.2