Imported Upstream version 3.0
[debian/gnuradio] / gnuradio-examples / python / apps / hf_radio / ssbagc.py
1 # post detection agc processing
2 #
3 # Imagine that the usual gnuradio copyright stuff is right here.
4 #
5 # This agc strategy is copied more or less verbatim from
6 # weaver_isb_am1_usrp3.py by cswiger.
7 #
8 # Thanks.
9 #
10 # Then modified in a variety of ways.
11 #
12 # There doesn't appear to be a way to hook multiple blocks to the
13 # input port when building a hier block like this. Thus the
14 # split below.
15 #
16 # Basic operation.
17 # Power is estimated by squaring the input.
18 # Low pass filter using a 1 pole iir.
19 # The time constant can be tweaked by changing the taps.
20 # Currently there is no implementation to change this while operating
21 #   a potentially useful addition.
22 # The log block turns this into dB
23 # gain adjusts the agc authority.
24 #
25 # M. Revnell 2006-Jan
26
27 from gnuradio import gr, gru
28
29 class agc( gr.hier_block ):
30     def __init__( self, fg ):
31         self.split = gr.multiply_const_ff( 1 )
32         self.sqr   = gr.multiply_ff( )
33         self.int0  = gr.iir_filter_ffd( [.004, 0], [0, .999] )
34         self.offs  = gr.add_const_ff( -30 )
35         self.gain  = gr.multiply_const_ff( 70 )
36         self.log   = gr.nlog10_ff( 10, 1 )
37         self.agc   = gr.divide_ff( )
38
39         fg.connect(   self.split,        ( self.agc,   0 ) )
40         fg.connect(   self.split,        ( self.sqr,   0 ) )
41         fg.connect(   self.split,        ( self.sqr,   1 ) )
42         fg.connect(   self.sqr,            self.int0       )
43         fg.connect(   self.int0,           self.log        )
44         fg.connect(   self.log,            self.offs       )
45         fg.connect(   self.offs,           self.gain       )
46         fg.connect(   self.gain,         ( self.agc,   1 ) )
47
48         gr.hier_block.__init__( self, fg, self.split, self.agc )