2 # Copyright 2005 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 2, 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_block):
26 def __init__(self, fg, audio_rate):
28 self.input_node = gr.add_const_ff(0) # FIXME kludge
30 self.low_iir = gr.iir_filter_ffd((0.0193,0,-0.0193),(1,1.9524,-0.9615))
31 self.low_square = gr.multiply_ff()
32 self.low_smooth = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate)) # 100ms time constant
34 self.hi_iir = gr.iir_filter_ffd((0.0193,0,-0.0193),(1,1.3597,-0.9615))
35 self.hi_square = gr.multiply_ff()
36 self.hi_smooth = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate))
38 self.sub = gr.sub_ff();
39 self.add = gr.add_ff();
40 self.gate = gr.threshold_ff(0.3,0.43,0)
41 self.squelch_lpf = gr.single_pole_iir_filter_ff(1/(0.01*audio_rate))
43 self.div = gr.divide_ff()
44 self.squelch_mult = gr.multiply_ff()
46 fg.connect (self.input_node, (self.squelch_mult, 0))
48 fg.connect (self.input_node,self.low_iir)
49 fg.connect (self.low_iir,(self.low_square,0))
50 fg.connect (self.low_iir,(self.low_square,1))
51 fg.connect (self.low_square,self.low_smooth,(self.sub,0))
52 fg.connect (self.low_smooth, (self.add,0))
54 fg.connect (self.input_node,self.hi_iir)
55 fg.connect (self.hi_iir,(self.hi_square,0))
56 fg.connect (self.hi_iir,(self.hi_square,1))
57 fg.connect (self.hi_square,self.hi_smooth,(self.sub,1))
58 fg.connect (self.hi_smooth, (self.add,1))
60 fg.connect (self.sub, (self.div, 0))
61 fg.connect (self.add, (self.div, 1))
62 fg.connect (self.div, self.gate, self.squelch_lpf, (self.squelch_mult,1))
64 gr.hier_block.__init__(self, fg, self.input_node, self.squelch_mult)
66 def set_threshold(self, threshold):
67 self.gate.set_hi(threshold)
72 def squelch_range(self):
73 return (0.0, 1.0, 1.0/100)