summaryrefslogtreecommitdiff
path: root/gnuradio-examples
diff options
context:
space:
mode:
authorEric Blossom2010-12-06 23:16:25 -0800
committerEric Blossom2010-12-06 23:16:25 -0800
commit55685f7a8ac97186de05a9e806824fa48e327d47 (patch)
treeadfb51f196eeff692182ff6e8fad2b2b5ac8713d /gnuradio-examples
parent59a1eeb1b18483ec716afde24df3f0593ed5085c (diff)
parente13783aeb84a2c3656c3344a8d52fa2c9ee38a00 (diff)
downloadgnuradio-55685f7a8ac97186de05a9e806824fa48e327d47.tar.gz
gnuradio-55685f7a8ac97186de05a9e806824fa48e327d47.tar.bz2
gnuradio-55685f7a8ac97186de05a9e806824fa48e327d47.zip
Merge branch 'next' into guile-next
* next: (116 commits) Adding new example script for using the new PFB arbitrary resampler interface. One resampler takes user-generated taps and another resampler just takes the resampling rate. Both input and output signals are plotted. Modifying blsk2 wrapper for PFB arbitrary resampler to allow the user to just specify the requested resampling rate without providing their own filter taps. uhd: reverting tag changes on uhd single usrp source, there seems to be issues with the work() logic uhd: removed default value chan=0 in the cc files WITH_INCLUDES _must_ be last uhd: replaced CFLAGS with CPPFLAGS variable, and fixed swig args FIXME uhd: default channel params to zero for single source and sink blocks Revert "Removed usrp2-firmware from being automatically built." Remove generated file from repo Removed usrp2-firmware from being automatically built. uhd: added libdir to UHD CFLAGS (shared by lib and swig) Swapping out preset keys until I work out some of their issues. Modifying QA tests for the sample tags. By default, it only checks the sizes of the tags since order is not specified or guarenteed. Block is a gr_block, so this sets its relative rate. Was required for using in the QA of the sample tags code. Removing global pmt constants. Were causing segfaults during make check. Must fix this later. Fixing up the UHD sample tag example to take command line options. Swapping order of testing rrate. Changing propagation policy enum type name and making a few other minor edits. Changing API for gr_skiphead to use uint64_t for the offset instead of size_t (still unsigned). Fixes issue #304. Adding typedef for uint64_t and int64_t so we can use them through SWIG. ... Passes make distcheck.
Diffstat (limited to 'gnuradio-examples')
-rwxr-xr-xgnuradio-examples/python/pfb/resampler.py95
-rwxr-xr-xgnuradio-examples/python/tags/test_file_tags.py29
-rwxr-xr-xgnuradio-examples/python/tags/uhd_burst_detector.py98
3 files changed, 222 insertions, 0 deletions
diff --git a/gnuradio-examples/python/pfb/resampler.py b/gnuradio-examples/python/pfb/resampler.py
new file mode 100755
index 000000000..6be7cf14e
--- /dev/null
+++ b/gnuradio-examples/python/pfb/resampler.py
@@ -0,0 +1,95 @@
+#!/usr/bin/env python
+
+from gnuradio import gr, blks2
+import scipy, pylab
+
+class mytb(gr.top_block):
+ def __init__(self, fs_in, fs_out, fc, N=10000):
+ gr.top_block.__init__(self)
+
+ rerate = float(fs_out) / float(fs_in)
+ print "Resampling from %f to %f by %f " %(fs_in, fs_out, rerate)
+
+ # Creating our own taps
+ taps = gr.firdes.low_pass_2(32, 32, 0.25, 0.1, 80)
+
+ self.src = gr.sig_source_c(fs_in, gr.GR_SIN_WAVE, fc, 1)
+ #self.src = gr.noise_source_c(gr.GR_GAUSSIAN, 1)
+ self.head = gr.head(gr.sizeof_gr_complex, N)
+
+ # A resampler with our taps
+ self.resamp_0 = blks2.pfb_arb_resampler_ccf(rerate, taps,
+ flt_size=32)
+
+ # A resampler that just needs a resampling rate.
+ # Filter is created for us and designed to cover
+ # entire bandwidth of the input signal.
+ # An optional atten=XX rate can be used here to
+ # specify the out-of-band rejection (default=80).
+ self.resamp_1 = blks2.pfb_arb_resampler_ccf(rerate)
+
+ self.snk_in = gr.vector_sink_c()
+ self.snk_0 = gr.vector_sink_c()
+ self.snk_1 = gr.vector_sink_c()
+
+ self.connect(self.src, self.head, self.snk_in)
+ self.connect(self.head, self.resamp_0, self.snk_0)
+ self.connect(self.head, self.resamp_1, self.snk_1)
+
+def main():
+ fs_in = 8000
+ fs_out = 20000
+ fc = 1000
+ N = 10000
+
+ tb = mytb(fs_in, fs_out, fc, N)
+ tb.run()
+
+
+ # Plot PSD of signals
+ nfftsize = 2048
+ fig1 = pylab.figure(1, figsize=(10,10), facecolor="w")
+ sp1 = fig1.add_subplot(2,1,1)
+ sp1.psd(tb.snk_in.data(), NFFT=nfftsize,
+ noverlap=nfftsize/4, Fs = fs_in)
+ sp1.set_title(("Input Signal at f_s=%.2f kHz" % (fs_in/1000.0)))
+ sp1.set_xlim([-fs_in/2, fs_in/2])
+
+ sp2 = fig1.add_subplot(2,1,2)
+ sp2.psd(tb.snk_0.data(), NFFT=nfftsize,
+ noverlap=nfftsize/4, Fs = fs_out,
+ label="With our filter")
+ sp2.psd(tb.snk_1.data(), NFFT=nfftsize,
+ noverlap=nfftsize/4, Fs = fs_out,
+ label="With auto-generated filter")
+ sp2.set_title(("Output Signals at f_s=%.2f kHz" % (fs_out/1000.0)))
+ sp2.set_xlim([-fs_out/2, fs_out/2])
+ sp2.legend()
+
+ # Plot signals in time
+ Ts_in = 1.0/fs_in
+ Ts_out = 1.0/fs_out
+ t_in = scipy.arange(0, len(tb.snk_in.data())*Ts_in, Ts_in)
+ t_out = scipy.arange(0, len(tb.snk_0.data())*Ts_out, Ts_out)
+
+ fig2 = pylab.figure(2, figsize=(10,10), facecolor="w")
+ sp21 = fig2.add_subplot(2,1,1)
+ sp21.plot(t_in, tb.snk_in.data())
+ sp21.set_title(("Input Signal at f_s=%.2f kHz" % (fs_in/1000.0)))
+ sp21.set_xlim([t_in[100], t_in[200]])
+
+ sp22 = fig2.add_subplot(2,1,2)
+ sp22.plot(t_out, tb.snk_0.data(),
+ label="With our filter")
+ sp22.plot(t_out, tb.snk_1.data(),
+ label="With auto-generated filter")
+ sp22.set_title(("Output Signals at f_s=%.2f kHz" % (fs_out/1000.0)))
+ r = float(fs_out)/float(fs_in)
+ sp22.set_xlim([t_out[r * 100], t_out[r * 200]])
+ sp22.legend()
+
+ pylab.show()
+
+if __name__ == "__main__":
+ main()
+
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..4ff4549ef
--- /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, 1)
+
+ 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()
+
+
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..f8ebbe66a
--- /dev/null
+++ b/gnuradio-examples/python/tags/uhd_burst_detector.py
@@ -0,0 +1,98 @@
+#!/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", trigger=False):
+
+ 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.uhd_src = uhd.single_usrp_source(
+ device_addr=self.uhd_addr,
+ io_type=uhd.io_type_t.COMPLEX_FLOAT32,
+ num_channels=1,
+ )
+
+ 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)
+ self.tagger = gr.burst_tagger(gr.sizeof_gr_complex)
+
+ # Dummy signaler to collect a burst on known periods
+ data = 1000*[0,] + 1000*[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, self.samp_rate)
+
+
+ ##################################################
+ # Connections
+ ##################################################
+ self.connect((self.uhd_src, 0), (self.tagger, 0))
+ self.connect((self.tagger, 0), (self.fsnk, 0))
+
+ if self.trigger:
+ # Connect a dummy signaler to the burst tagger
+ self.connect((self.signal, 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
+ self.wxgui_fftsink2_0.set_sample_rate(self.samp_rate/10)
+ self.uhd_src_0.set_samp_rate(self.samp_rate)
+
+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 = 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.run()