2 # Copyright 2007,2008 Free Software Foundation, Inc.
4 # This file is part of GNU Radio
6 # GNU Radio is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 3, or (at your option)
11 # GNU Radio is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with GNU Radio; see the file COPYING. If not, write to
18 # the Free Software Foundation, Inc., 51 Franklin Street,
19 # Boston, MA 02110-1301, USA.
25 print "Please install SciPy to run this script (http://www.scipy.org/)"
31 print "Please install Matplotlib to run this script (http://matplotlib.sourceforge.net/)"
34 from optparse import OptionParser
36 matplotlib.interactive(True)
37 matplotlib.use('TkAgg')
40 def __init__(self, datatype, filenames, options):
42 self.legend_text = list()
44 self.hfile.append(open(f, "r"))
45 self.legend_text.append(f)
47 self.block_length = options.block
48 self.start = options.start
49 self.sample_rate = options.sample_rate
51 self.datatype = datatype
52 self.sizeof_data = datatype().nbytes # number of bytes per sample in file
54 self.axis_font_size = 16
55 self.label_font_size = 18
56 self.title_font_size = 20
60 self.fig = figure(1, figsize=(16, 9), facecolor='w')
61 rcParams['xtick.labelsize'] = self.axis_font_size
62 rcParams['ytick.labelsize'] = self.axis_font_size
64 self.text_file_pos = figtext(0.10, 0.88, "File Position: ", weight="heavy", size=self.text_size)
65 self.text_block = figtext(0.40, 0.88, ("Block Size: %d" % self.block_length),
66 weight="heavy", size=self.text_size)
67 self.text_sr = figtext(0.60, 0.88, ("Sample Rate: %.2f" % self.sample_rate),
68 weight="heavy", size=self.text_size)
71 self.button_left_axes = self.fig.add_axes([0.45, 0.01, 0.05, 0.05], frameon=True)
72 self.button_left = Button(self.button_left_axes, "<")
73 self.button_left_callback = self.button_left.on_clicked(self.button_left_click)
75 self.button_right_axes = self.fig.add_axes([0.50, 0.01, 0.05, 0.05], frameon=True)
76 self.button_right = Button(self.button_right_axes, ">")
77 self.button_right_callback = self.button_right.on_clicked(self.button_right_click)
79 self.xlim = self.sp_f.get_xlim()
81 self.manager = get_current_fig_manager()
82 connect('key_press_event', self.click)
85 def get_data(self, hfile):
86 self.text_file_pos.set_text("File Position: %d" % (hfile.tell()//self.sizeof_data))
87 f = scipy.fromfile(hfile, dtype=self.datatype, count=self.block_length)
88 #print "Read in %d items" % len(self.f)
93 self.time = [i*(1/self.sample_rate) for i in range(len(self.f))]
96 self.sp_f = self.fig.add_subplot(2,1,1, position=[0.075, 0.2, 0.875, 0.6])
97 self.sp_f.set_title(("Amplitude"), fontsize=self.title_font_size, fontweight="bold")
98 self.sp_f.set_xlabel("Time (s)", fontsize=self.label_font_size, fontweight="bold")
99 self.sp_f.set_ylabel("Amplitude (V)", fontsize=self.label_font_size, fontweight="bold")
105 for hf in self.hfile:
106 # if specified on the command-line, set file pointer
107 hf.seek(self.sizeof_data*self.start, 1)
111 # Subplot for real and imaginary parts of signal
112 self.plot_f += plot(self.time, self.f, 'o-')
113 maxval = max(maxval, max(self.f))
114 minval = min(minval, min(self.f))
116 self.sp_f.set_ylim([1.5*minval, 1.5*maxval])
118 self.leg = self.sp_f.legend(self.plot_f, self.legend_text)
122 def update_plots(self):
125 for hf,p in zip(self.hfile,self.plot_f):
127 p.set_data([self.time, self.f])
128 maxval = max(maxval, max(self.f))
129 minval = min(minval, min(self.f))
131 self.sp_f.set_ylim([1.5*minval, 1.5*maxval])
135 def click(self, event):
136 forward_valid_keys = [" ", "down", "right"]
137 backward_valid_keys = ["up", "left"]
139 if(find(event.key, forward_valid_keys)):
142 elif(find(event.key, backward_valid_keys)):
145 def button_left_click(self, event):
148 def button_right_click(self, event):
151 def step_forward(self):
154 def step_backward(self):
155 for hf in self.hfile:
156 # Step back in file position
157 if(hf.tell() >= 2*self.sizeof_data*self.block_length ):
158 hf.seek(-2*self.sizeof_data*self.block_length, 1)
160 hf.seek(-hf.tell(),1)
164 def find(item_in, list_search):
166 return list_search.index(item_in) != None