2 # Copyright 2005,2007 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
23 from gnuradio import gr, optfir
25 class standard_squelch(gr.hier_block2):
26 def __init__(self, audio_rate):
27 gr.hier_block2.__init__(self, "standard_squelch",
28 gr.io_signature(1, 1, gr.sizeof_float), # Input signature
29 gr.io_signature(1, 1, gr.sizeof_float)) # Output signature
31 self.input_node = gr.add_const_ff(0) # FIXME kludge
33 self.low_iir = gr.iir_filter_ffd((0.0193,0,-0.0193),(1,1.9524,-0.9615))
34 self.low_square = gr.multiply_ff()
35 self.low_smooth = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) # 100ms time constant
37 self.hi_iir = gr.iir_filter_ffd((0.0193,0,-0.0193),(1,1.3597,-0.9615))
38 self.hi_square = gr.multiply_ff()
39 self.hi_smooth = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate))
41 self.sub = gr.sub_ff();
42 self.add = gr.add_ff();
43 self.gate = gr.threshold_ff(0.3,0.43,0)
44 self.squelch_lpf = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate))
46 self.div = gr.divide_ff()
47 self.squelch_mult = gr.multiply_ff()
49 self.connect (self, self.input_node)
50 self.connect (self.input_node, (self.squelch_mult, 0))
52 self.connect (self.input_node,self.low_iir)
53 self.connect (self.low_iir,(self.low_square,0))
54 self.connect (self.low_iir,(self.low_square,1))
55 self.connect (self.low_square,self.low_smooth,(self.sub,0))
56 self.connect (self.low_smooth, (self.add,0))
58 self.connect (self.input_node,self.hi_iir)
59 self.connect (self.hi_iir,(self.hi_square,0))
60 self.connect (self.hi_iir,(self.hi_square,1))
61 self.connect (self.hi_square,self.hi_smooth,(self.sub,1))
62 self.connect (self.hi_smooth, (self.add,1))
64 self.connect (self.sub, (self.div, 0))
65 self.connect (self.add, (self.div, 1))
66 self.connect (self.div, self.gate, self.squelch_lpf, (self.squelch_mult,1))
67 self.connect (self.squelch_mult, self)
69 def set_threshold(self, threshold):
70 self.gate.set_hi(threshold)
75 def squelch_range(self):
76 return (0.0, 1.0, 1.0/100)