From 7930b1ebbb7328b69d78ac4dc3ea919e0d00c2ae Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Tue, 16 Nov 2010 22:34:38 -0800 Subject: Adding a simple example of using the tagger and tagging file. --- gnuradio-examples/python/tags/test_file_tags.py | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100755 gnuradio-examples/python/tags/test_file_tags.py (limited to 'gnuradio-examples/python') diff --git a/gnuradio-examples/python/tags/test_file_tags.py b/gnuradio-examples/python/tags/test_file_tags.py new file mode 100755 index 000000000..a658256c7 --- /dev/null +++ b/gnuradio-examples/python/tags/test_file_tags.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python + +from gnuradio import gr +import scipy + +def main(): + data = scipy.arange(0, 32000, 1).tolist() + trig = 100*[0,] + 100*[1,] + + src = gr.vector_source_s(data, True) + trigger = gr.vector_source_s(trig, True) + + thr = gr.throttle(gr.sizeof_short, 10e3) + ann = gr.annotator_alltoall(1000000, gr.sizeof_short) + tagger = gr.burst_tagger(gr.sizeof_short) + + fsnk = gr.tagged_file_sink(gr.sizeof_short) + + tb = gr.top_block() + tb.connect(src, thr, (tagger, 0)) + tb.connect(trigger, (tagger, 1)) + tb.connect(tagger, fsnk) + + tb.run() + +if __name__ == "__main__": + main() + + -- cgit From 911533c659389d565a9c230c8318a5f57070b656 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 17 Nov 2010 12:04:14 -0800 Subject: Adding an example that uses gr_uhd sources to generate tags and collects bursts of energy. --- .../python/tags/uhd_burst_detector.py | 82 ++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 gnuradio-examples/python/tags/uhd_burst_detector.py (limited to 'gnuradio-examples/python') diff --git a/gnuradio-examples/python/tags/uhd_burst_detector.py b/gnuradio-examples/python/tags/uhd_burst_detector.py new file mode 100755 index 000000000..2d4ca9b9a --- /dev/null +++ b/gnuradio-examples/python/tags/uhd_burst_detector.py @@ -0,0 +1,82 @@ +#!/usr/bin/env python + +from gnuradio import eng_notation +from gnuradio import gr +from gnuradio import uhd +from gnuradio import window +from gnuradio.eng_option import eng_option +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"): + + gr.top_block.__init__(self) + + self.freq = frequency + self.samp_rate = sample_rate + self.uhd_addr = uhd_address + + self.uhd_src = uhd.single_usrp_source( + device_addr="addr="+self.uhd_addr, + io_type=uhd.io_type_t.COMPLEX_FLOAT32, + num_channels=1, + ) + + self.uhd_src.set_samp_rate(samp_rate) + self.uhd_src.set_center_freq(freq, 0) + self.uhd_src.set_gain(32, 0) + + 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 + data = 10000*[0,] + 500*[1,] + self.signal = gr.vector_source_s(data, True) + + # Energy detector to get signal burst + 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) + self.f2s = gr.float_to_short() + self.fsnk = gr.tagged_file_sink(gr.sizeof_gr_complex) + + + ################################################## + # Connections + ################################################## + self.connect((self.uhd_src_0, 0), (self.tagger, 0)) + self.connect((self.tagger, 0), (self.fsnk, 0)) + + # Connect a dummy signaler to the burst tagger + #self.connect((self.signal, 0), (self.tagger, 1)) + + # Connect an energy detector signaler to the burst tagger + self.connect((self.uhd_src_0, 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)) + + 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__': + a = 1 + parser = OptionParser(option_class=eng_option, usage="%prog: [options]") + (options, args) = parser.parse_args() + + frequency = 418e6 + samp_rate = samp_rate = 200000 + uhd_addr = "192.168.10.2" + + tb = uhd_burst_detector(frequency, samp_rate, uhd_addr) + tb.run() -- cgit From 01a054be12bdef4d8c17d6134275ede9d9997c3d Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 17 Nov 2010 16:48:06 -0800 Subject: Removing vestigial line. --- gnuradio-examples/python/tags/uhd_burst_detector.py | 1 - 1 file changed, 1 deletion(-) (limited to 'gnuradio-examples/python') diff --git a/gnuradio-examples/python/tags/uhd_burst_detector.py b/gnuradio-examples/python/tags/uhd_burst_detector.py index 2d4ca9b9a..432698225 100755 --- a/gnuradio-examples/python/tags/uhd_burst_detector.py +++ b/gnuradio-examples/python/tags/uhd_burst_detector.py @@ -70,7 +70,6 @@ class uhd_burst_detector(gr.top_block): self.uhd_src_0.set_samp_rate(self.samp_rate) if __name__ == '__main__': - a = 1 parser = OptionParser(option_class=eng_option, usage="%prog: [options]") (options, args) = parser.parse_args() -- cgit From 49fa0877d64d06eb5dfd2b530d3efc9ea9529851 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Wed, 17 Nov 2010 19:43:02 -0800 Subject: Fixing uhd test app. --- gnuradio-examples/python/tags/uhd_burst_detector.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) (limited to 'gnuradio-examples/python') diff --git a/gnuradio-examples/python/tags/uhd_burst_detector.py b/gnuradio-examples/python/tags/uhd_burst_detector.py index 432698225..fb140704e 100755 --- a/gnuradio-examples/python/tags/uhd_burst_detector.py +++ b/gnuradio-examples/python/tags/uhd_burst_detector.py @@ -17,6 +17,7 @@ class uhd_burst_detector(gr.top_block): self.freq = frequency self.samp_rate = sample_rate self.uhd_addr = uhd_address + self.gain = 32 self.uhd_src = uhd.single_usrp_source( device_addr="addr="+self.uhd_addr, @@ -24,10 +25,10 @@ class uhd_burst_detector(gr.top_block): num_channels=1, ) - self.uhd_src.set_samp_rate(samp_rate) - self.uhd_src.set_center_freq(freq, 0) - self.uhd_src.set_gain(32, 0) - + self.uhd_src.set_samp_rate(self.samp_rate) + self.uhd_src.set_center_freq(self.freq, 0) + self.uhd_src.set_gain(self.gain, 0) + 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) @@ -49,14 +50,14 @@ class uhd_burst_detector(gr.top_block): ################################################## # Connections ################################################## - self.connect((self.uhd_src_0, 0), (self.tagger, 0)) + self.connect((self.uhd_src, 0), (self.tagger, 0)) self.connect((self.tagger, 0), (self.fsnk, 0)) # Connect a dummy signaler to the burst tagger #self.connect((self.signal, 0), (self.tagger, 1)) # Connect an energy detector signaler to the burst tagger - self.connect((self.uhd_src_0, 0), (self.c2m, 0)) + 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)) -- cgit From 716e497547b5e0f3e19481e4ca129bae114935f8 Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 19:43:13 -0500 Subject: Updating example to pass file tagger the sample rate and changed some values for my testing. --- .../python/tags/uhd_burst_detector.py | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'gnuradio-examples/python') diff --git a/gnuradio-examples/python/tags/uhd_burst_detector.py b/gnuradio-examples/python/tags/uhd_burst_detector.py index fb140704e..17e71cb29 100755 --- a/gnuradio-examples/python/tags/uhd_burst_detector.py +++ b/gnuradio-examples/python/tags/uhd_burst_detector.py @@ -35,7 +35,7 @@ class uhd_burst_detector(gr.top_block): self.tagger = gr.burst_tagger(gr.sizeof_gr_complex) # Dummy signaler to collect a burst on known periods - data = 10000*[0,] + 500*[1,] + data = 1000*[0,] + 1000*[1,] self.signal = gr.vector_source_s(data, True) # Energy detector to get signal burst @@ -44,7 +44,7 @@ class uhd_burst_detector(gr.top_block): self.sub = gr.sub_ff() self.mult = gr.multiply_const_ff(32768) self.f2s = gr.float_to_short() - self.fsnk = gr.tagged_file_sink(gr.sizeof_gr_complex) + self.fsnk = gr.tagged_file_sink(gr.sizeof_gr_complex, self.samp_rate) ################################################## @@ -54,16 +54,16 @@ class uhd_burst_detector(gr.top_block): self.connect((self.tagger, 0), (self.fsnk, 0)) # Connect a dummy signaler to the burst tagger - #self.connect((self.signal, 0), (self.tagger, 1)) + self.connect((self.signal, 0), (self.tagger, 1)) # 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, 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)) def set_samp_rate(self, samp_rate): self.samp_rate = samp_rate @@ -74,7 +74,7 @@ if __name__ == '__main__': parser = OptionParser(option_class=eng_option, usage="%prog: [options]") (options, args) = parser.parse_args() - frequency = 418e6 + frequency = 450e6 samp_rate = samp_rate = 200000 uhd_addr = "192.168.10.2" -- cgit From 7ecc767e8fe6248d5e9372da8c7cfb9aacbd790b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 19:44:47 -0500 Subject: Updating test_file_tags.py to use new file tagger interface (sample rate of 1 means time stamp on files is based solely on the item time). --- gnuradio-examples/python/tags/test_file_tags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'gnuradio-examples/python') diff --git a/gnuradio-examples/python/tags/test_file_tags.py b/gnuradio-examples/python/tags/test_file_tags.py index a658256c7..4ff4549ef 100755 --- a/gnuradio-examples/python/tags/test_file_tags.py +++ b/gnuradio-examples/python/tags/test_file_tags.py @@ -14,7 +14,7 @@ def main(): ann = gr.annotator_alltoall(1000000, gr.sizeof_short) tagger = gr.burst_tagger(gr.sizeof_short) - fsnk = gr.tagged_file_sink(gr.sizeof_short) + fsnk = gr.tagged_file_sink(gr.sizeof_short, 1) tb = gr.top_block() tb.connect(src, thr, (tagger, 0)) -- cgit From 7c5dc0920240f566ad4482f47ca8b9095479f04e Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Sun, 21 Nov 2010 21:23:31 -0500 Subject: Removed comments to stdout from file tagger; made it easir to go from internally generated bursts to detected bursts (which needs work). --- .../python/tags/uhd_burst_detector.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'gnuradio-examples/python') diff --git a/gnuradio-examples/python/tags/uhd_burst_detector.py b/gnuradio-examples/python/tags/uhd_burst_detector.py index 17e71cb29..993c6807d 100755 --- a/gnuradio-examples/python/tags/uhd_burst_detector.py +++ b/gnuradio-examples/python/tags/uhd_burst_detector.py @@ -53,17 +53,19 @@ class uhd_burst_detector(gr.top_block): self.connect((self.uhd_src, 0), (self.tagger, 0)) self.connect((self.tagger, 0), (self.fsnk, 0)) - # Connect a dummy signaler to the burst tagger - self.connect((self.signal, 0), (self.tagger, 1)) + if 0: + # Connect a dummy signaler to the burst tagger + self.connect((self.signal, 0), (self.tagger, 1)) - # 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)) + 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)) def set_samp_rate(self, samp_rate): self.samp_rate = samp_rate -- cgit From 4d3bbb036cc4b910e5165c8a5dc7261ef4ebc43b Mon Sep 17 00:00:00 2001 From: Tom Rondeau Date: Mon, 29 Nov 2010 12:57:07 -0500 Subject: Fixing up the UHD sample tag example to take command line options. --- .../python/tags/uhd_burst_detector.py | 28 ++++++++++++++++------ 1 file changed, 21 insertions(+), 7 deletions(-) (limited to 'gnuradio-examples/python') diff --git a/gnuradio-examples/python/tags/uhd_burst_detector.py b/gnuradio-examples/python/tags/uhd_burst_detector.py index 993c6807d..f8ebbe66a 100755 --- a/gnuradio-examples/python/tags/uhd_burst_detector.py +++ b/gnuradio-examples/python/tags/uhd_burst_detector.py @@ -10,7 +10,7 @@ from optparse import OptionParser class uhd_burst_detector(gr.top_block): def __init__(self, frequency, sample_rate, - uhd_address="192.168.10.2"): + uhd_address="192.168.10.2", trigger=False): gr.top_block.__init__(self) @@ -18,9 +18,10 @@ class uhd_burst_detector(gr.top_block): self.samp_rate = sample_rate self.uhd_addr = uhd_address self.gain = 32 + self.trigger = trigger self.uhd_src = uhd.single_usrp_source( - device_addr="addr="+self.uhd_addr, + device_addr=self.uhd_addr, io_type=uhd.io_type_t.COMPLEX_FLOAT32, num_channels=1, ) @@ -53,7 +54,7 @@ class uhd_burst_detector(gr.top_block): self.connect((self.uhd_src, 0), (self.tagger, 0)) self.connect((self.tagger, 0), (self.fsnk, 0)) - if 0: + if self.trigger: # Connect a dummy signaler to the burst tagger self.connect((self.signal, 0), (self.tagger, 1)) @@ -74,11 +75,24 @@ class uhd_burst_detector(gr.top_block): if __name__ == '__main__': parser = OptionParser(option_class=eng_option, usage="%prog: [options]") + parser.add_option("-a", "--address", type="string", default="addr=192.168.10.2", + help="select address of the device [default=%default]") + #parser.add_option("-A", "--antenna", default=None, + # help="select Rx Antenna (only on RFX-series boards)") + parser.add_option("-f", "--freq", type="eng_float", default=450e6, + 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, + help="set USRP sample rate [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 = 450e6 - samp_rate = samp_rate = 200000 - uhd_addr = "192.168.10.2" + 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) + tb = uhd_burst_detector(frequency, samp_rate, uhd_addr, trigger) tb.run() -- cgit