diff options
author | Tom Rondeau | 2011-09-09 16:34:49 -0400 |
---|---|---|
committer | Tom Rondeau | 2011-09-09 16:34:49 -0400 |
commit | 0e86a5f357d40de759c804cc704dd907c50b02d7 (patch) | |
tree | 7839af901c451487ac0109a37c692a2995810886 | |
parent | 2c0a3dc882306e772ede8a69925c23227bfcaf96 (diff) | |
download | gnuradio-0e86a5f357d40de759c804cc704dd907c50b02d7.tar.gz gnuradio-0e86a5f357d40de759c804cc704dd907c50b02d7.tar.bz2 gnuradio-0e86a5f357d40de759c804cc704dd907c50b02d7.zip |
tags: updated uhd_burst_detector with a better energy detector. Works well when receiving bursty NBFM signals.
-rwxr-xr-x | gnuradio-examples/python/tags/uhd_burst_detector.py | 66 |
1 files changed, 43 insertions, 23 deletions
diff --git a/gnuradio-examples/python/tags/uhd_burst_detector.py b/gnuradio-examples/python/tags/uhd_burst_detector.py index f8ebbe66a..ffa419562 100755 --- a/gnuradio-examples/python/tags/uhd_burst_detector.py +++ b/gnuradio-examples/python/tags/uhd_burst_detector.py @@ -1,4 +1,24 @@ #!/usr/bin/env python +# +# Copyright 2011 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# from gnuradio import eng_notation from gnuradio import gr @@ -9,16 +29,16 @@ from gnuradio.gr import firdes from optparse import OptionParser class uhd_burst_detector(gr.top_block): - def __init__(self, frequency, sample_rate, - uhd_address="192.168.10.2", trigger=False): + def __init__(self, uhd_address, options): gr.top_block.__init__(self) - self.freq = frequency - self.samp_rate = sample_rate self.uhd_addr = uhd_address - self.gain = 32 - self.trigger = trigger + self.freq = options.freq + self.samp_rate = options.samp_rate + self.gain = options.gain + self.threshold = options.threshold + self.trigger = options.trigger self.uhd_src = uhd.single_usrp_source( device_addr=self.uhd_addr, @@ -32,7 +52,6 @@ class uhd_burst_detector(gr.top_block): taps = firdes.low_pass_2(1, 1, 0.4, 0.1, 60) self.chanfilt = gr.fir_filter_ccc(10, taps) - self.ann0 = gr.annotator_alltoall(100000, gr.sizeof_gr_complex) self.tagger = gr.burst_tagger(gr.sizeof_gr_complex) # Dummy signaler to collect a burst on known periods @@ -40,11 +59,18 @@ class uhd_burst_detector(gr.top_block): self.signal = gr.vector_source_s(data, True) # Energy detector to get signal burst + ## use squelch to detect energy + self.det = gr.simple_squelch_cc(self.threshold, 0.01) + ## convert to mag squared (float) self.c2m = gr.complex_to_mag_squared() - self.iir = gr.single_pole_iir_filter_ff(0.0001) - self.sub = gr.sub_ff() - self.mult = gr.multiply_const_ff(32768) + ## average to debounce + self.avg = gr.single_pole_iir_filter_ff(0.01) + ## rescale signal for conversion to short + self.scale = gr.multiply_const_ff(2**16) + ## signal input uses shorts self.f2s = gr.float_to_short() + + # Use file sink burst tagger to capture bursts self.fsnk = gr.tagged_file_sink(gr.sizeof_gr_complex, self.samp_rate) @@ -60,17 +86,12 @@ class uhd_burst_detector(gr.top_block): else: # Connect an energy detector signaler to the burst tagger - self.connect((self.uhd_src, 0), (self.c2m, 0)) - self.connect((self.c2m, 0), (self.sub, 0)) - self.connect((self.c2m, 0), (self.iir, 0)) - self.connect((self.iir, 0), (self.sub, 1)) - self.connect((self.sub, 0), (self.mult,0)) - self.connect((self.mult, 0), (self.f2s, 0)) - self.connect((self.f2s, 0), (self.tagger, 1)) + self.connect(self.uhd_src, self.det) + self.connect(self.det, self.c2m, self.avg, self.scale, self.f2s) + self.connect(self.f2s, (self.tagger, 1)) def set_samp_rate(self, samp_rate): self.samp_rate = samp_rate - self.wxgui_fftsink2_0.set_sample_rate(self.samp_rate/10) self.uhd_src_0.set_samp_rate(self.samp_rate) if __name__ == '__main__': @@ -83,16 +104,15 @@ if __name__ == '__main__': help="set frequency to FREQ", metavar="FREQ") parser.add_option("-g", "--gain", type="eng_float", default=0, help="set gain in dB [default=%default]") - parser.add_option("-R", "--rate", type="eng_float", default=200000, + parser.add_option("-R", "--samp-rate", type="eng_float", default=200000, help="set USRP sample rate [default=%default]") + parser.add_option("-t", "--threshold", type="float", default=-60, + help="Set the detection power threshold (dBm) [default=%default") parser.add_option("-T", "--trigger", action="store_true", default=False, help="Use internal trigger instead of detector [default=%default]") (options, args) = parser.parse_args() - frequency = options.freq - samp_rate = samp_rate = options.rate uhd_addr = options.address - trigger = options.trigger - tb = uhd_burst_detector(frequency, samp_rate, uhd_addr, trigger) + tb = uhd_burst_detector(uhd_addr, options) tb.run() |