commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r11314 - gnuradio/branches/developers/trondeau/pfb/gnu


From: trondeau
Subject: [Commit-gnuradio] r11314 - gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb
Date: Mon, 29 Jun 2009 20:29:07 -0600 (MDT)

Author: trondeau
Date: 2009-06-29 20:29:07 -0600 (Mon, 29 Jun 2009)
New Revision: 11314

Added:
   
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/interpolate.py
Log:
Example use of PFB interpolator and arbitrary resampler.

Added: 
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/interpolate.py
===================================================================
--- 
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/interpolate.py
                               (rev 0)
+++ 
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/interpolate.py
       2009-06-30 02:29:07 UTC (rev 11314)
@@ -0,0 +1,171 @@
+#!/usr/bin/env python
+
+from gnuradio import gr, blks2
+import math
+import os
+import scipy, pylab
+from scipy import fftpack
+import time
+
+#print os.getpid()
+#raw_input()
+
+class pfb_top_block(gr.top_block):
+    def __init__(self):
+        gr.top_block.__init__(self)
+
+        freq1 = 100
+        freq2 = 500
+
+        self._N = 100000
+        self._fs = 2000
+        self._Tmax = self._N * (1.0/self._fs)
+        self._interp = 8
+        self._ainterp = 8
+
+        self._taps = gr.firdes.low_pass(self._interp, self._interp*self._fs, 
freq2+50, 50)
+        self._taps2 = gr.firdes.low_pass(32.0, 1,
+                                         0.4 / (32.0), 0.1/(32.0))
+
+        tpc = math.ceil(float(len(self._taps)) /  float(self._interp))
+
+        print "Number of taps:     ", len(self._taps)
+        print "Number of filters:  ", self._interp
+        print "Taps per channel:   ", tpc
+        
+        self.signal1 = gr.sig_source_c(self._fs, gr.GR_SIN_WAVE, freq1, 0.5)
+        self.signal2 = gr.sig_source_c(self._fs, gr.GR_SIN_WAVE, freq2, 0.5)
+        self.signal = gr.add_cc()
+        
+        self.head = gr.head(gr.sizeof_gr_complex, self._N)
+        self.pfb = blks2.pfb_interpolator_ccf(self._interp, self._taps)
+        self.pfb_ar = blks2.pfb_arb_resampler_ccf(self._ainterp, self._taps2)
+        self.snk_i = gr.vector_sink_c()
+
+        #self.pfb_ar.pfb.print_taps()
+
+        # Connect the blocks
+        self.connect(self.signal1, self.head, (self.signal,0))
+        self.connect(self.signal2, (self.signal,1))
+        self.connect(self.signal, self.pfb)
+        self.connect(self.signal, self.pfb_ar)
+        self.connect(self.signal, self.snk_i)
+
+        # Create the sink for the interpolated siganl
+        self.snk1 = gr.vector_sink_c()
+        self.snk2 = gr.vector_sink_c()
+        self.connect(self.pfb, self.snk1)
+        self.connect(self.pfb_ar, self.snk2)
+                             
+
+def main():
+    tb = pfb_top_block()
+
+    tstart = time.time()
+    tb.run()
+    tend = time.time()
+    print "Run time: %f" % (tend - tstart)
+
+
+    if 1:
+        fig1 = pylab.figure(1, figsize=(12,10), facecolor="w")
+        fig2 = pylab.figure(2, figsize=(12,10), facecolor="w")
+        fig3 = pylab.figure(3, figsize=(12,10), facecolor="w")
+        
+        Ns = 10000
+        Ne = 10000
+
+        # Plot input signal
+        fs = tb._fs
+
+        d = tb.snk_i.data()[Ns:Ns+Ne]
+        f_in = scipy.arange(-fs/2.0, fs/2.0, fs/float(len(d)))
+        X_in = 10.0*scipy.log10(fftpack.fftshift(fftpack.fft(d)))
+        sp1_f = fig1.add_subplot(2, 1, 1)
+        p1_f = sp1_f.plot(f_in, X_in)
+        sp1_f.set_ylim([-50.0, 50.0])
+
+        sp1_f.set_title("Input Signal", weight="bold")
+        sp1_f.set_xlabel("Frequency (Hz)")
+        sp1_f.set_ylabel("Power (dBW)")
+
+        Ts = 1.0/fs
+        Tmax = len(d)*Ts
+        
+        t_in = scipy.arange(0, Tmax, Ts)
+        x_in = scipy.array(d)
+        sp1_t = fig1.add_subplot(2, 1, 2)
+        p1_t = sp1_t.plot(t_in, x_in.real, "b-o")
+        #p1_t = sp1_t.plot(t_in, x_in.imag, "r-o")
+        sp1_t.set_ylim([-2.5, 2.5])
+
+        sp1_t.set_title("Input Signal", weight="bold")
+        sp1_t.set_xlabel("Time (s)")
+        sp1_t.set_ylabel("Amplitude")
+
+
+        # Plot output of PFB interpolator
+        fs_int = tb._fs*tb._interp
+
+        d = tb.snk1.data()[Ns:Ns+(tb._interp*Ne)]
+        f_o = scipy.arange(-fs_int/2.0, fs_int/2.0, fs_int/float(len(d)))
+        X_o = 10.0*scipy.log10(fftpack.fftshift(fftpack.fft(d)))
+        sp2_f = fig2.add_subplot(2, 1, 1)
+        p2_o = sp2_f.plot(f_o, X_o)
+        sp2_f.set_ylim([-50.0, 50.0])
+
+        sp2_f.set_title("Output Signal from PFB Interpolator", weight="bold")
+        sp2_f.set_xlabel("Frequency (Hz)")
+        sp2_f.set_ylabel("Power (dBW)")
+
+        Ts_int = 1.0/fs_int
+        Tmax = len(d)*Ts_int
+
+        t_o = scipy.arange(0, Tmax, Ts_int)
+        x_o1 = scipy.array(d)
+        sp2_t = fig2.add_subplot(2, 1, 2)
+        p2_t = sp2_t.plot(t_o, x_o1.real, "b-o")
+        #p2_t = sp2_t.plot(t_o, x_o.imag, "r-o")
+        sp2_t.set_ylim([-2.5, 2.5])
+
+        sp2_t.set_title("Output Signal from PFB Interpolator", weight="bold")
+        sp2_t.set_xlabel("Time (s)")
+        sp2_t.set_ylabel("Amplitude")
+
+        # Plot output of PFB arbitrary resampler
+        fs_aint = tb._fs * tb._ainterp
+
+        d = tb.snk2.data()[Ns:Ns+(tb._interp*Ne)]
+        f_o = scipy.arange(-fs_int/2.0, fs_int/2.0, fs_int/float(len(d)))
+        X_o = 10.0*scipy.log10(fftpack.fftshift(fftpack.fft(d)))
+        sp3_f = fig3.add_subplot(2, 1, 1)
+        p3_f = sp3_f.plot(f_o, X_o)
+        sp3_f.set_ylim([-50.0, 50.0])
+
+        sp3_f.set_title("Output Signal from PFB Arbitrary Resampler", 
weight="bold")
+        sp3_f.set_xlabel("Frequency (Hz)")
+        sp3_f.set_ylabel("Power (dBW)")
+
+        Ts_aint = 1.0/fs_aint
+        Tmax = len(d)*Ts_aint
+
+        t_o = scipy.arange(0, Tmax, Ts_aint)
+        x_o1 = scipy.array(d)
+        sp3_f = fig3.add_subplot(2, 1, 2)
+        p3_f = sp3_f.plot(t_o, x_o1.real, "b-o")
+        #p3_f = sp3_f.plot(t_o, x_o.imag, "r-o")
+        sp3_f.set_ylim([-2.5, 2.5])
+        
+        sp3_f.set_title("Output Signal from PFB Arbitrary Resampler", 
weight="bold")
+        sp3_f.set_xlabel("Time (s)")
+        sp3_f.set_ylabel("Amplitude")
+
+        pylab.show()
+
+
+if __name__ == "__main__":
+    try:
+        main()
+    except KeyboardInterrupt:
+        pass
+    





reply via email to

[Prev in Thread] Current Thread [Next in Thread]