Updated FSF address in all files. Fixes ticket:51
[debian/gnuradio] / gr-atsc / src / lib / atsci_slicer_agc.h
1 /* -*- c++ -*- */
2 /*
3  * Copyright 2002 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 2, 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 _ATSC_SLICER_AGC_H_
24 #define _ATSC_SLICER_AGC_H_
25
26 #include <math.h>
27 #include <gr_single_pole_iir.h>
28
29 /*!
30  * \brief Automatic Gain Control class for atsc slicer
31  *
32  * Given perfect data, output values will be +/- {7, 5, 3, 1}
33  */
34
35 class atsci_slicer_agc {
36
37  public:
38   atsci_slicer_agc () : _gain(1), dc(0.0025) {};
39
40   
41   float gain () { return _gain; }
42
43 #if 1
44   float scale (float input){
45     float t = input * _gain;
46     float output = t - REFERENCE;
47     float error = REFERENCE - dc.filter (t);
48     _gain += error * RATE;
49     return output;
50   }
51 #else
52   float scale(float input){
53     float avg = dc.filter(input);
54     if(fabs(avg)<.1)avg=.1;
55     _gain += _gain*.99 + .01* REFERENCE/avg;
56     return input*_gain - REFERENCE;
57   }
58 #endif
59
60  protected:
61   
62   static const float                    REFERENCE = 1.25;       // pilot reference value
63   static const float                    RATE = 1.0e-5;          // adjustment rate
64   float                                 _gain;                  // current gain
65   gr_single_pole_iir<float,float,float> dc;
66 };
67
68 #endif /* _ATSC_SLICER_AGC_H_ */