diff options
-rwxr-xr-x | gr-utils/src/python/gr_plot_const.py | 28 | ||||
-rwxr-xr-x | gr-utils/src/python/gr_plot_fft.py | 37 | ||||
-rwxr-xr-x | gr-utils/src/python/gr_plot_iq.py | 25 | ||||
-rwxr-xr-x | gr-utils/src/python/gr_plot_psd.py | 83 | ||||
-rw-r--r-- | gr-utils/src/python/plot_data.py | 20 |
5 files changed, 101 insertions, 92 deletions
diff --git a/gr-utils/src/python/gr_plot_const.py b/gr-utils/src/python/gr_plot_const.py index ec2272c74..5dd08c9a0 100755 --- a/gr-utils/src/python/gr_plot_const.py +++ b/gr-utils/src/python/gr_plot_const.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2007,2008 Free Software Foundation, Inc. +# Copyright 2007,2008,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -80,15 +80,15 @@ class draw_constellation: def get_data(self): self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//self.sizeof_data)) - iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) - #print "Read in %d items" % len(iq) - if(len(iq) == 0): + try: + iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) + except MemoryError: print "End of File" else: - self.reals = [r.real for r in iq] - self.imags = [i.imag for i in iq] + self.reals = scipy.array([r.real for r in iq]) + self.imags = scipy.array([i.imag for i in iq]) - self.time = [i*(1/self.sample_rate) for i in range(len(self.reals))] + self.time = scipy.array([i*(1/self.sample_rate) for i in range(len(self.reals))]) def make_plots(self): # if specified on the command-line, set file pointer @@ -117,9 +117,9 @@ class draw_constellation: self.plot_const += self.sp_const.plot([self.reals[self.indx],], [self.imags[self.indx],], 'mo', ms=12) # Adjust axis - self.sp_iq.axis([min(self.time), max(self.time), - 1.5*min([min(self.reals), min(self.imags)]), - 1.5*max([max(self.reals), max(self.imags)])]) + self.sp_iq.axis([self.time.min(), self.time.max(), + 1.5*min([self.reals.min(), self.imags.min()]), + 1.5*max([self.reals.max(), self.imags.max()])]) self.sp_const.axis([-2, 2, -2, 2]) draw() @@ -127,9 +127,9 @@ class draw_constellation: def update_plots(self): self.plot_iq[0].set_data([self.time, self.reals]) self.plot_iq[1].set_data([self.time, self.imags]) - self.sp_iq.axis([min(self.time), max(self.time), - 1.5*min([min(self.reals), min(self.imags)]), - 1.5*max([max(self.reals), max(self.imags)])]) + self.sp_iq.axis([self.time.min(), self.time.max(), + 1.5*min([self.reals.min(), self.imags.min()]), + 1.5*max([self.reals.max(), self.imags.max()])]) self.plot_const[0].set_data([self.reals, self.imags]) self.sp_const.axis([-2, 2, -2, 2]) @@ -138,7 +138,7 @@ class draw_constellation: def zoom(self, event): newxlim = scipy.array(self.sp_iq.get_xlim()) curxlim = scipy.array(self.xlim) - if(newxlim.all() != curxlim.all()): + if(newxlim[0] != curxlim[0] or newxlim[1] != curxlim[1]): self.xlim = newxlim r = self.reals[int(ceil(self.xlim[0])) : int(ceil(self.xlim[1]))] i = self.imags[int(ceil(self.xlim[0])) : int(ceil(self.xlim[1]))] diff --git a/gr-utils/src/python/gr_plot_fft.py b/gr-utils/src/python/gr_plot_fft.py index a9c1417f9..ba3901e03 100755 --- a/gr-utils/src/python/gr_plot_fft.py +++ b/gr-utils/src/python/gr_plot_fft.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2007,2008 Free Software Foundation, Inc. +# Copyright 2007,2008,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -81,15 +81,16 @@ class gr_plot_fft: def get_data(self): self.position = self.hfile.tell()/self.sizeof_data self.text_file_pos.set_text("File Position: %d" % (self.position)) - self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) - #print "Read in %d items" % len(self.iq) - if(len(self.iq) == 0): + try: + self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) + except MemoryError: print "End of File" else: self.iq_fft = self.dofft(self.iq) tstep = 1.0 / self.sample_rate - self.time = [tstep*(self.position + i) for i in xrange(len(self.iq))] + #self.time = scipy.array([tstep*(self.position + i) for i in xrange(len(self.iq))]) + self.time = scipy.array([tstep*(i) for i in xrange(len(self.iq))]) self.freq = self.calc_freq(self.time, self.sample_rate) @@ -102,9 +103,9 @@ class gr_plot_fft: def calc_freq(self, time, sample_rate): N = len(time) - Fs = 1.0 / (max(time) - min(time)) + Fs = 1.0 / (time.max() - time.min()) Fn = 0.5 * sample_rate - freq = [-Fn + i*Fs for i in xrange(N)] + freq = scipy.array([-Fn + i*Fs for i in xrange(N)]) return freq def make_plots(self): @@ -139,14 +140,14 @@ class gr_plot_fft: imags = self.iq.imag self.plot_iq[0].set_data([self.time, reals]) self.plot_iq[1].set_data([self.time, imags]) - self.sp_iq.set_xlim(min(self.time), max(self.time)) - self.sp_iq.set_ylim([1.5*min([min(reals), min(imags)]), - 1.5*max([max(reals), max(imags)])]) + self.sp_iq.set_xlim(self.time.min(), self.time.max()) + self.sp_iq.set_ylim([1.5*min([reals.min(), imags.min()]), + 1.5*max([reals.max(), imags.max()])]) def draw_fft(self): self.plot_fft[0].set_data([self.freq, self.iq_fft]) - self.sp_fft.set_xlim(min(self.freq), max(self.freq)) - self.sp_fft.set_ylim([min(self.iq_fft)-10, max(self.iq_fft)+10]) + self.sp_fft.set_xlim(self.freq.min(), self.freq.max()) + self.sp_fft.set_ylim([self.iq_fft.min()-10, self.iq_fft.max()+10]) def update_plots(self): self.draw_time() @@ -158,10 +159,12 @@ class gr_plot_fft: def zoom(self, event): newxlim = scipy.array(self.sp_iq.get_xlim()) curxlim = scipy.array(self.xlim) - if(newxlim.all() != curxlim.all()): + if(newxlim[0] != curxlim[0] or newxlim[1] != curxlim[1]): self.xlim = newxlim - xmin = max(0, int(ceil(self.sample_rate*(self.xlim[0] - self.position)))) - xmax = min(int(ceil(self.sample_rate*(self.xlim[1] - self.position))), len(self.iq)) + #xmin = max(0, int(ceil(self.sample_rate*(self.xlim[0] - self.position)))) + #xmax = min(int(ceil(self.sample_rate*(self.xlim[1] - self.position))), len(self.iq)) + xmin = max(0, int(ceil(self.sample_rate*(self.xlim[0])))) + xmax = min(int(ceil(self.sample_rate*(self.xlim[1]))), len(self.iq)) iq = self.iq[xmin : xmax] time = self.time[xmin : xmax] @@ -170,8 +173,8 @@ class gr_plot_fft: freq = self.calc_freq(time, self.sample_rate) self.plot_fft[0].set_data(freq, iq_fft) - self.sp_fft.axis([min(freq), max(freq), - min(iq_fft)-10, max(iq_fft)+10]) + self.sp_fft.axis([freq.min(), freq.max(), + iq_fft.min()-10, iq_fft.max()+10]) draw() diff --git a/gr-utils/src/python/gr_plot_iq.py b/gr-utils/src/python/gr_plot_iq.py index 371ce3b79..316e60a75 100755 --- a/gr-utils/src/python/gr_plot_iq.py +++ b/gr-utils/src/python/gr_plot_iq.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2007,2008 Free Software Foundation, Inc. +# Copyright 2007,2008,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -78,14 +78,14 @@ class draw_iq: def get_data(self): self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//self.sizeof_data)) - self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) - #print "Read in %d items" % len(self.iq) - if(len(self.iq) == 0): + try: + self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) + except MemoryError: print "End of File" else: - self.reals = [r.real for r in self.iq] - self.imags = [i.imag for i in self.iq] - self.time = [i*(1/self.sample_rate) for i in range(len(self.reals))] + self.reals = scipy.array([r.real for r in self.iq]) + self.imags = scipy.array([i.imag for i in self.iq]) + self.time = scipy.array([i*(1/self.sample_rate) for i in range(len(self.reals))]) def make_plots(self): # if specified on the command-line, set file pointer @@ -99,16 +99,17 @@ class draw_iq: self.sp_iq.set_xlabel("Time (s)", fontsize=self.label_font_size, fontweight="bold") self.sp_iq.set_ylabel("Amplitude (V)", fontsize=self.label_font_size, fontweight="bold") self.plot_iq = plot(self.time, self.reals, 'bo-', self.time, self.imags, 'ro-') - self.sp_iq.set_ylim([1.5*min([min(self.reals), min(self.imags)]), - 1.5*max([max(self.reals), max(self.imags)])]) - + self.sp_iq.set_ylim([1.5*min([self.reals.min(), self.imags.min()]), + 1.5*max([self.reals.max(), self.imags.max()])]) + self.sp_iq.set_xlim(self.time.min(), self.time.max()) draw() def update_plots(self): self.plot_iq[0].set_data([self.time, self.reals]) self.plot_iq[1].set_data([self.time, self.imags]) - self.sp_iq.set_ylim([1.5*min([min(self.reals), min(self.imags)]), - 1.5*max([max(self.reals), max(self.imags)])]) + self.sp_iq.set_ylim([1.5*min([self.reals.min(), self.imags.min()]), + 1.5*max([self.reals.max(), self.imags.max()])]) + self.sp_iq.set_xlim(self.time.min(), self.time.max()) draw() def click(self, event): diff --git a/gr-utils/src/python/gr_plot_psd.py b/gr-utils/src/python/gr_plot_psd.py index 0e3dbecd9..e88995b72 100755 --- a/gr-utils/src/python/gr_plot_psd.py +++ b/gr-utils/src/python/gr_plot_psd.py @@ -1,6 +1,6 @@ #!/usr/bin/env python # -# Copyright 2007,2008 Free Software Foundation, Inc. +# Copyright 2007,2008,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -60,8 +60,10 @@ class gr_plot_psd: rcParams['xtick.labelsize'] = self.axis_font_size rcParams['ytick.labelsize'] = self.axis_font_size - self.text_file = figtext(0.10, 0.95, ("File: %s" % filename), weight="heavy", size=self.text_size) - self.text_file_pos = figtext(0.10, 0.92, "File Position: ", weight="heavy", size=self.text_size) + self.text_file = figtext(0.10, 0.95, ("File: %s" % filename), + weight="heavy", size=self.text_size) + self.text_file_pos = figtext(0.10, 0.92, "File Position: ", + weight="heavy", size=self.text_size) self.text_block = figtext(0.35, 0.92, ("Block Size: %d" % self.block_length), weight="heavy", size=self.text_size) self.text_sr = figtext(0.60, 0.915, ("Sample Rate: %.2f" % self.sample_rate), @@ -76,7 +78,7 @@ class gr_plot_psd: self.button_right = Button(self.button_right_axes, ">") self.button_right_callback = self.button_right.on_clicked(self.button_right_click) - self.xlim = self.sp_iq.get_xlim() + self.xlim = scipy.array(self.sp_iq.get_xlim()) self.manager = get_current_fig_manager() connect('draw_event', self.zoom) @@ -86,16 +88,17 @@ class gr_plot_psd: def get_data(self): self.position = self.hfile.tell()/self.sizeof_data self.text_file_pos.set_text("File Position: %d" % self.position) - self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) - #print "Read in %d items" % len(self.iq) - if(len(self.iq) == 0): + try: + self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) + except MemoryError: print "End of File" else: tstep = 1.0 / self.sample_rate - self.time = [tstep*(self.position + i) for i in xrange(len(self.iq))] + #self.time = scipy.array([tstep*(self.position + i) for i in xrange(len(self.iq))]) + self.time = scipy.array([tstep*(i) for i in xrange(len(self.iq))]) self.iq_psd, self.freq = self.dopsd(self.iq) - + def dopsd(self, iq): ''' Need to do this here and plot later so we can do the fftshift ''' overlap = self.psdfftsize/4 @@ -130,10 +133,10 @@ class gr_plot_psd: self.plot_iq = self.sp_iq.plot([], 'bo-') # make plot for reals self.plot_iq += self.sp_iq.plot([], 'ro-') # make plot for imags - self.draw_time() # draw the plot + self.draw_time(self.time, self.iq) # draw the plot self.plot_psd = self.sp_psd.plot([], 'b') # make plot for PSD - self.draw_psd() # draw the plot + self.draw_psd(self.freq, self.iq_psd) # draw the plot if self.dospec: @@ -143,57 +146,59 @@ class gr_plot_psd: self.sp_spec.set_xlabel("Time (s)", fontsize=self.label_font_size, fontweight="bold") self.sp_spec.set_ylabel("Frequency (Hz)", fontsize=self.label_font_size, fontweight="bold") - self.draw_spec() + self.draw_spec(self.time, self.iq) draw() - def draw_time(self): - reals = self.iq.real - imags = self.iq.imag - self.plot_iq[0].set_data([self.time, reals]) - self.plot_iq[1].set_data([self.time, imags]) - self.sp_iq.set_xlim(min(self.time), max(self.time)) - self.sp_iq.set_ylim([1.5*min([min(reals), min(imags)]), - 1.5*max([max(reals), max(imags)])]) - - def draw_psd(self): - self.plot_psd[0].set_data([self.freq, self.iq_psd]) - self.sp_psd.set_ylim([min(self.iq_psd)-10, max(self.iq_psd)+10]) - - def draw_spec(self): + def draw_time(self, t, iq): + reals = iq.real + imags = iq.imag + self.plot_iq[0].set_data([t, reals]) + self.plot_iq[1].set_data([t, imags]) + self.sp_iq.set_xlim(t.min(), t.max()) + self.sp_iq.set_ylim([1.5*min([reals.min(), imags.min()]), + 1.5*max([reals.max(), imags.max()])]) + + def draw_psd(self, f, p): + self.plot_psd[0].set_data([f, p]) + self.sp_psd.set_ylim([p.min()-10, p.max()+10]) + self.sp_psd.set_xlim([f.min(), f.max()]) + + def draw_spec(self, t, s): overlap = self.specfftsize/4 winfunc = scipy.blackman self.sp_spec.clear() - self.sp_spec.specgram(self.iq, self.specfftsize, self.sample_rate, + self.sp_spec.specgram(s, self.specfftsize, self.sample_rate, window = lambda d: d*winfunc(self.specfftsize), - noverlap = overlap, xextent=[min(self.time), max(self.time)]) + noverlap = overlap, xextent=[t.min(), t.max()]) def update_plots(self): - self.draw_time() - self.draw_psd() + self.draw_time(self.time, self.iq) + self.draw_psd(self.freq, self.iq_psd) if self.dospec: - self.draw_spec() + self.draw_spec(self.time, self.iq) - self.xlim = self.sp_iq.get_xlim() # so zoom doesn't get called + self.xlim = scipy.array(self.sp_iq.get_xlim()) # so zoom doesn't get called + draw() def zoom(self, event): newxlim = scipy.array(self.sp_iq.get_xlim()) curxlim = scipy.array(self.xlim) - if(newxlim.all() != curxlim.all()): - self.xlim = newxlim - xmin = max(0, int(ceil(self.sample_rate*(self.xlim[0] - self.position)))) - xmax = min(int(ceil(self.sample_rate*(self.xlim[1] - self.position))), len(self.iq)) + if(newxlim[0] != curxlim[0] or newxlim[1] != curxlim[1]): + #xmin = max(0, int(ceil(self.sample_rate*(newxlim[0] - self.position)))) + #xmax = min(int(ceil(self.sample_rate*(newxlim[1] - self.position))), len(self.iq)) + xmin = max(0, int(ceil(self.sample_rate*(newxlim[0])))) + xmax = min(int(ceil(self.sample_rate*(newxlim[1]))), len(self.iq)) iq = self.iq[xmin : xmax] time = self.time[xmin : xmax] iq_psd, freq = self.dopsd(iq) - self.plot_psd[0].set_data(freq, iq_psd) - self.sp_psd.axis([min(freq), max(freq), - min(iq_psd)-10, max(iq_psd)+10]) + self.draw_psd(freq, iq_psd) + self.xlim = scipy.array(self.sp_iq.get_xlim()) draw() diff --git a/gr-utils/src/python/plot_data.py b/gr-utils/src/python/plot_data.py index 08cdd6030..15012e589 100644 --- a/gr-utils/src/python/plot_data.py +++ b/gr-utils/src/python/plot_data.py @@ -1,5 +1,5 @@ # -# Copyright 2007,2008 Free Software Foundation, Inc. +# Copyright 2007,2008,2011 Free Software Foundation, Inc. # # This file is part of GNU Radio # @@ -81,13 +81,13 @@ class plot_data: def get_data(self, hfile): self.text_file_pos.set_text("File Position: %d" % (hfile.tell()//self.sizeof_data)) - f = scipy.fromfile(hfile, dtype=self.datatype, count=self.block_length) - #print "Read in %d items" % len(self.f) - if(len(f) == 0): + try: + f = scipy.fromfile(hfile, dtype=self.datatype, count=self.block_length) + except MemoryError: print "End of File" else: - self.f = f - self.time = [i*(1/self.sample_rate) for i in range(len(self.f))] + self.f = scipy.array(f) + self.time = scipy.array([i*(1/self.sample_rate) for i in range(len(self.f))]) def make_plots(self): self.sp_f = self.fig.add_subplot(2,1,1, position=[0.075, 0.2, 0.875, 0.6]) @@ -107,8 +107,8 @@ class plot_data: # Subplot for real and imaginary parts of signal self.plot_f += plot(self.time, self.f, 'o-') - maxval = max(maxval, max(self.f)) - minval = min(minval, min(self.f)) + maxval = max(maxval, self.f.max()) + minval = min(minval, self.f.min()) self.sp_f.set_ylim([1.5*minval, 1.5*maxval]) @@ -122,8 +122,8 @@ class plot_data: for hf,p in zip(self.hfile,self.plot_f): self.get_data(hf) p.set_data([self.time, self.f]) - maxval = max(maxval, max(self.f)) - minval = min(minval, min(self.f)) + maxval = max(maxval, self.f.max()) + minval = min(minval, self.f.min()) self.sp_f.set_ylim([1.5*minval, 1.5*maxval]) |