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