commit-gnuradio
[Top][All Lists]
Advanced

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

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


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

Author: trondeau
Date: 2009-06-29 20:33:37 -0600 (Mon, 29 Jun 2009)
New Revision: 11315

Added:
   
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/decimate.py
Log:
Example use of PFB decimator.

Added: 
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/decimate.py
===================================================================
--- 
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/decimate.py
                          (rev 0)
+++ 
gnuradio/branches/developers/trondeau/pfb/gnuradio-examples/python/pfb/decimate.py
  2009-06-30 02:33:37 UTC (rev 11315)
@@ -0,0 +1,117 @@
+#!/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)
+
+        self._N = 10000000
+        self._fs = 10000
+        self._Tmax = self._N * (1.0/self._fs)
+        self._decim = 20
+        self._taps = gr.firdes.low_pass(1, self._fs, 100, 10)
+
+        tpc = math.ceil(float(len(self._taps)) /  float(self._decim))
+
+        print "Number of taps:     ", len(self._taps)
+        print "Number of filters:  ", self._decim
+        print "Taps per channel:   ", tpc
+        
+        self.signals = list()
+        self.add = gr.add_cc()
+        freqs = [10, 2040]
+        for i in xrange(len(freqs)):
+            self.signals.append(gr.sig_source_c(self._fs, gr.GR_SIN_WAVE, 
freqs[i], 1))
+            self.connect(self.signals[i], (self.add,i))
+
+        self.head = gr.head(gr.sizeof_gr_complex, self._N)
+        #self.pfb = blks2.pfb_decimator_ccf(self._decim, self._taps, 0)
+        self.pfb = gr.fir_filter_ccf(self._decim, self._taps)
+        self.snk_i = gr.vector_sink_c()
+
+        # Connect the blocks
+        self.connect(self.add, self.head, self.pfb)
+        self.connect(self.add, self.snk_i)
+
+        # Create the sink for the decimated siganl
+        self.snk = gr.vector_sink_c()
+        self.connect(self.pfb, self.snk)
+                             
+
+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=(16,9))
+        fig2 = pylab.figure(2, figsize=(16,9))
+        
+        Ns = 10000
+        Ne = 10000
+        d = tb.snk_i.data()[Ns:Ns+Ne]
+        f_in = scipy.arange(-tb._fs/2.0, tb._fs/2.0, tb._fs/float(len(d)))
+        X_in = 10.0*scipy.log10(fftpack.fftshift(fftpack.fft(d, f_in.size)))
+        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)")
+        
+        t_in = scipy.arange(0, tb._Tmax, tb._Tmax/float(len(d)))
+        x_in = scipy.array(d)
+        sp1_t = fig1.add_subplot(2, 1, 2)
+        p1_t = sp1_t.plot(t_in, x_in.real, "b")
+        p1_t = sp1_t.plot(t_in, x_in.imag, "r")
+        sp1_t.set_ylim([-tb._decim*1.1, tb._decim*1.1])
+
+        sp1_t.set_xlabel("Time (s)")
+        sp1_t.set_ylabel("Amplitude")
+
+        fs_o = tb._fs / tb._decim
+
+        d = tb.snk.data()[Ns:Ns+Ne]
+        f_o = scipy.arange(-fs_o/2.0, fs_o/2.0, fs_o/float(len(d)))
+        x_o = 10.0*scipy.log10(fftpack.fftshift(fftpack.fft(d)))
+        sp2_f = fig2.add_subplot(2, 1, 1)
+        p2_f = sp2_f.plot(f_o, x_o)
+        sp2_f.set_ylim([-50.0, 50.0])
+
+        sp2_f.set_title("PFB Decimated Signal", weight="bold")
+        sp2_f.set_xlabel("Frequency (Hz)")
+        sp2_f.set_ylabel("Power (dBW)")
+        
+
+        x_o = scipy.array(d)
+        t_o = scipy.arange(0, tb._Tmax, tb._Tmax/float(x_o.size))
+        sp2_t = fig2.add_subplot(2, 1, 2)
+        p2_t = sp2_t.plot(t_o, x_o.real, "b")
+        p2_t = sp2_t.plot(t_o, x_o.imag, "r")
+        sp2_t.set_ylim([-1.5, 1.5])
+
+        sp2_t.set_xlabel("Time (s)")
+        sp2_t.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]