summaryrefslogtreecommitdiff
path: root/gnuradio-examples/python/pfb/resampler.py
diff options
context:
space:
mode:
authorTom Rondeau <trondeau@vt.edu>2010-12-06 20:57:40 -0500
committerTom Rondeau <trondeau@vt.edu>2010-12-06 20:57:40 -0500
commite13783aeb84a2c3656c3344a8d52fa2c9ee38a00 (patch)
tree1c5688dc89173336020d7e8b2083a11e39c48e65 /gnuradio-examples/python/pfb/resampler.py
parentcdca1c917626f7c63f820da921a17187efc92cd5 (diff)
parent7b19372f83fede6a1d55e4b70202aa58b004e9f8 (diff)
Merge branch 'master' into next
* master: 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 blks2 wrapper for PFB arbitrary resampler to allow the user to just specify the requested resampling rate without providing their own filter taps. 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. Removing warnings in portaudio source/sink. Fixing output types from tap_type to o_type in gr_single_pole_iir.h. Doesn't make a difference in the current uses of this class, but could in the future. Thanks to Achilleas Anastasopoulos for pointing this out. first shot at Windows-compatible LIBUSB check Tweak LIBUSB m4 script to not check for 'usb_debug' symbol on Windows, because the symbol does not exist for that platform (only, it seems) Removing autogenerated file. Updated doxygen Doxyfile for newer versions. Adding file operations result checking. Updating audio_jack to new interface for creating a client. Fixes depricated warning. Potential fix to MSDD warnings by setting sequence number from buffer more explicitly. Adding a bit more checking on file operations. Fixing copyright date. Fixed warning re defining GNU_SOURCE. Can probably just remove it since it's defined in config, but this won't hurt anyone. Fixing signed/unsigned warnings. first shot at Windows-compatible LIBUSB check Tweak LIBUSB m4 script to not check for 'usb_debug' symbol on Windows, because the symbol does not exist for that platform (only, it seems) Conflicts: gnuradio-core/src/lib/swig/gnuradio.i
Diffstat (limited to 'gnuradio-examples/python/pfb/resampler.py')
-rwxr-xr-xgnuradio-examples/python/pfb/resampler.py95
1 files changed, 95 insertions, 0 deletions
diff --git a/gnuradio-examples/python/pfb/resampler.py b/gnuradio-examples/python/pfb/resampler.py
new file mode 100755
index 0000000000..6be7cf14e0
--- /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()
+