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