Merged r4518:5130 from developer branch n4hy/ofdm into trunk, passes distcheck.
[debian/gnuradio] / gnuradio-core / src / utils / gr_plot_iq.py
1 #!/usr/bin/env python
2 #
3 # Copyright 2007 Free Software Foundation, Inc.
4
5 # This file is part of GNU Radio
6
7 # GNU Radio is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2, or (at your option)
10 # any later version.
11
12 # GNU Radio is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with GNU Radio; see the file COPYING.  If not, write to
19 # the Free Software Foundation, Inc., 51 Franklin Street,
20 # Boston, MA 02110-1301, USA.
21
22
23 import pylab, math
24 from pylab import *
25 import struct, sys
26 from optparse import OptionParser
27
28 import gr_read_binary
29
30 def main():
31     usage="%prog: [options] output_filename"
32     parser = OptionParser(conflict_handler="resolve", usage=usage)
33     parser.add_option("-s", "--size", type="int", default=None,
34                       help="Specify the number of points to plot [default=%default]")
35     parser.add_option("", "--skip", type="int", default=None,
36                       help="Specify the number of points to skip [default=%default]")
37
38     (options, args) = parser.parse_args ()
39     if len(args) != 1:
40         parser.print_help()
41         raise SystemExit, 1
42     filename = args[0]
43
44     iq = gr_read_binary.read_complex_binary(filename)
45
46     if(options.skip is None):
47         options.skip = 0
48     
49     if((options.size is None) or ((options.skip+options.size) > len(iq[0]))):
50         options.size = len(iq[0]) - options.skip
51
52     reals = iq[0][options.skip : options.skip + options.size]
53     imags = iq[1][options.skip : options.skip + options.size]
54     x = range(options.skip, options.skip + options.size)
55     
56     # PLOT REAL AND IMAGINARY PARTS
57     
58     f = figure(1, figsize=(16, 12), facecolor='w')
59     rcParams['xtick.labelsize'] = 16
60     rcParams['ytick.labelsize'] = 16
61
62     sp1 = f.add_subplot(1,1,1)
63     sp1.set_title(("I&Q"), fontsize=26, fontweight="bold")
64     sp1.set_xlabel("Time (s)", fontsize=20, fontweight="bold")
65     sp1.set_ylabel("Amplitude (V)", fontsize=20, fontweight="bold")
66     plot(x, reals, 'bo-', x, imags, 'ro-')
67
68     show()
69
70 if __name__ == "__main__":
71     try:
72         main()
73     except KeyboardInterrupt:
74         pass
75     
76
77