commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r5121 - gnuradio/branches/developers/n4hy/ofdm/gnuradi


From: trondeau
Subject: [Commit-gnuradio] r5121 - gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils
Date: Thu, 26 Apr 2007 12:59:49 -0600 (MDT)

Author: trondeau
Date: 2007-04-26 12:59:48 -0600 (Thu, 26 Apr 2007)
New Revision: 5121

Added:
   
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_const.py
   
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_float.py
   gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_iq.py
   
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_read_binary.py
Log:
adding useful (I think) scripts for plotting with Python's Matplotlib (and 
getting me permanently away from Matlab)

Added: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_const.py
===================================================================
--- 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_const.py 
                            (rev 0)
+++ 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_const.py 
    2007-04-26 18:59:48 UTC (rev 5121)
@@ -0,0 +1,93 @@
+#!/usr/bin/env python
+
+import pylab, math
+from pylab import *
+import struct, sys
+from optparse import OptionParser
+
+import gr_read_binary
+
+class zoom:
+    def __init__(self, xdata, reals, imags, sp_iq, sp_const, plot_const, 
manager):
+        self.sp_iq = sp_iq
+        self.sp_const = sp_const
+        self.xaxis = xdata
+        self.reals = reals
+        self.imags = imags
+        self.plot_const = plot_const
+        self.manager = manager
+
+        self.xlim = self.sp_iq.get_xlim()
+           
+    def __call__(self, event):
+        newxlim = self.sp_iq.get_xlim()
+
+        if(newxlim != self.xlim):
+            self.xlim = newxlim
+            r = self.reals[int(self.xlim[0]) : int(self.xlim[1])]
+            i = self.imags[int(self.xlim[0]) : int(self.xlim[1])]
+
+            self.plot_const[0].set_data(r, i)
+            self.sp_const.axis([-2, 2, -2, 2])
+            self.manager.canvas.draw()
+            
+def main():
+    usage="%prog: [options] output_filename"
+    parser = OptionParser(conflict_handler="resolve", usage=usage)
+    parser.add_option("-s", "--size", type="int", default=None,
+                      help="Specify the number of points to plot 
[default=%default]")
+    parser.add_option("", "--skip", type="int", default=None,
+                      help="Specify the number of points to skip 
[default=%default]")
+
+    (options, args) = parser.parse_args ()
+    if len(args) != 1:
+        parser.print_help()
+        raise SystemExit, 1
+    filename = args[0]
+
+    iq = gr_read_binary.read_complex_binary(filename)
+
+    if(options.skip is None):
+        options.skip = 0
+    
+    if((options.size is None) or ((options.skip+options.size) > len(iq[0]))):
+        options.size = len(iq[0]) - options.skip
+
+    reals = iq[0][options.skip : options.skip + options.size]
+    imags = iq[1][options.skip : options.skip + options.size]
+    x = range(options.skip, options.skip + options.size)
+    
+    # PLOT
+    f = figure(1, figsize=(16, 12), facecolor='w')
+    rcParams['xtick.labelsize'] = 16
+    rcParams['ytick.labelsize'] = 16
+
+    # Subplot for real and imaginary parts of signal
+    sp1 = f.add_subplot(2,1,1)
+    sp1.set_title(("I&Q"), fontsize=26, fontweight="bold")
+    sp1.set_xlabel("Time (s)", fontsize=20, fontweight="bold")
+    sp1.set_ylabel("Amplitude (V)", fontsize=20, fontweight="bold")
+    plot(x, reals, 'bo-', x, imags, 'ro-')
+
+    # Subplot for constellation plot
+    sp2 = f.add_subplot(2,1,2)
+    sp2.set_title(("Constellation"), fontsize=26, fontweight="bold")
+    sp2.set_xlabel("Inphase", fontsize=20, fontweight="bold")
+    sp2.set_ylabel("Qaudrature", fontsize=20, fontweight="bold")
+    p2 = plot(reals, imags, 'bo')
+    sp2.axis([-2, 2, -2, 2])
+    
+    manager = get_current_fig_manager()
+    zm = zoom(x, reals, imags, sp1, sp2, p2, manager)
+    connect('draw_event', zm)
+    
+    show()
+
+if __name__ == "__main__":
+    try:
+        main()
+    except KeyboardInterrupt:
+        pass
+    
+
+


Property changes on: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_const.py
___________________________________________________________________
Name: svn:executable
   + *

Added: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_float.py
===================================================================
--- 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_float.py 
                            (rev 0)
+++ 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_float.py 
    2007-04-26 18:59:48 UTC (rev 5121)
@@ -0,0 +1,55 @@
+#!/usr/bin/env python
+
+import pylab, math
+from pylab import *
+import struct, sys
+from optparse import OptionParser
+
+import gr_read_binary
+
+def main():
+    usage="%prog: [options] output_filename"
+    parser = OptionParser(conflict_handler="resolve", usage=usage)
+    parser.add_option("-s", "--size", type="int", default=None,
+                      help="Specify the number of points to plot 
[default=%default]")
+    parser.add_option("", "--skip", type="int", default=None,
+                      help="Specify the number of points to skip 
[default=%default]")
+
+    (options, args) = parser.parse_args ()
+    if len(args) != 1:
+        parser.print_help()
+        raise SystemExit, 1
+    filename = args[0]
+
+    fl = gr_read_binary.read_float_binary(filename)
+
+    if(options.skip is None):
+        options.skip = 0
+    
+    if((options.size is None) or ((options.skip+options.size) > len(iq[0]))):
+        options.size = len(fl) - options.skip
+
+    x = range(options.skip, options.skip + options.size)
+    
+    # PLOT REAL AND IMAGINARY PARTS
+    
+    f = figure(1, figsize=(16, 12), facecolor='w')
+    rcParams['xtick.labelsize'] = 16
+    rcParams['ytick.labelsize'] = 16
+
+    sp1 = f.add_subplot(1,1,1)
+    sp1.set_title(("GNU Radio Float"), fontsize=26, fontweight="bold")
+    sp1.set_xlabel("Time (s)", fontsize=20, fontweight="bold")
+    sp1.set_ylabel("Amplitude (V)", fontsize=20, fontweight="bold")
+    plot(x, fl, 'bo-')
+
+    show()
+
+if __name__ == "__main__":
+    try:
+        main()
+    except KeyboardInterrupt:
+        pass
+    
+
+


Property changes on: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_float.py
___________________________________________________________________
Name: svn:executable
   + *

Added: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_iq.py
===================================================================
--- 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_iq.py    
                            (rev 0)
+++ 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_iq.py    
    2007-04-26 18:59:48 UTC (rev 5121)
@@ -0,0 +1,57 @@
+#!/usr/bin/env python
+
+import pylab, math
+from pylab import *
+import struct, sys
+from optparse import OptionParser
+
+import gr_read_binary
+
+def main():
+    usage="%prog: [options] output_filename"
+    parser = OptionParser(conflict_handler="resolve", usage=usage)
+    parser.add_option("-s", "--size", type="int", default=None,
+                      help="Specify the number of points to plot 
[default=%default]")
+    parser.add_option("", "--skip", type="int", default=None,
+                      help="Specify the number of points to skip 
[default=%default]")
+
+    (options, args) = parser.parse_args ()
+    if len(args) != 1:
+        parser.print_help()
+        raise SystemExit, 1
+    filename = args[0]
+
+    iq = gr_read_binary.read_complex_binary(filename)
+
+    if(options.skip is None):
+        options.skip = 0
+    
+    if((options.size is None) or ((options.skip+options.size) > len(iq[0]))):
+        options.size = len(iq[0]) - options.skip
+
+    reals = iq[0][options.skip : options.skip + options.size]
+    imags = iq[1][options.skip : options.skip + options.size]
+    x = range(options.skip, options.skip + options.size)
+    
+    # PLOT REAL AND IMAGINARY PARTS
+    
+    f = figure(1, figsize=(16, 12), facecolor='w')
+    rcParams['xtick.labelsize'] = 16
+    rcParams['ytick.labelsize'] = 16
+
+    sp1 = f.add_subplot(1,1,1)
+    sp1.set_title(("I&Q"), fontsize=26, fontweight="bold")
+    sp1.set_xlabel("Time (s)", fontsize=20, fontweight="bold")
+    sp1.set_ylabel("Amplitude (V)", fontsize=20, fontweight="bold")
+    plot(x, reals, 'bo-', x, imags, 'ro-')
+
+    show()
+
+if __name__ == "__main__":
+    try:
+        main()
+    except KeyboardInterrupt:
+        pass
+    
+
+


Property changes on: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_plot_iq.py
___________________________________________________________________
Name: svn:executable
   + *

Added: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_read_binary.py
===================================================================
--- 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_read_binary.py
                            (rev 0)
+++ 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-core/src/utils/gr_read_binary.py
    2007-04-26 18:59:48 UTC (rev 5121)
@@ -0,0 +1,41 @@
+#!/usr/bin/env python
+
+import struct
+
+def read_binary(filename, type):
+    n = struct.calcsize(type)
+    f = open(filename, 'rb')
+    out = list()
+    lin = f.read(n)
+    while(len(lin) == n):
+        cp = struct.unpack(type, lin)
+        out.append(cp)
+        lin = f.read(n)
+    return out
+
+def read_char_binary(filename):
+    return read_binary(filename, 'c')
+
+def read_float_binary(filename):
+    return read_binary(filename, 'f')
+
+def read_int_binary(filename):
+    return read_binary(filename, 'i')
+
+def read_short_binary(filename):
+    return read_binary(filename, 'h')
+
+def read_complex_binary(filename):
+    n = struct.calcsize('ff')
+    f = open(filename, 'rb')
+    re = list()
+    im = list()
+    lin = f.read(n)
+    while(len(lin) == n):
+        cp = struct.unpack('ff', lin)
+        re.append(cp[0])
+        im.append(cp[1])
+        lin = f.read(n)
+    return (re, im)
+
+





reply via email to

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