diff options
author | Tom Rondeau <trondeau@vt.edu> | 2012-07-29 14:19:09 -0400 |
---|---|---|
committer | Tom Rondeau <trondeau@vt.edu> | 2012-07-29 14:19:09 -0400 |
commit | eb4305b92f0128c47743b4e2df032a04052ac21d (patch) | |
tree | f89afd36f050587b943839162e65922de4ca86f5 /gr-qtgui | |
parent | 0eea9a33a1a57473973709662eb734d54df647fa (diff) |
qtgui: introduces new static plot tools for different data types.
Time, PSD, and Spectrogram have tools for char, short, int, float, and complex data types. Constellation requires complex inputs.
These tools are now installed into the runtime bin directory.
Diffstat (limited to 'gr-qtgui')
-rw-r--r-- | gr-qtgui/CMakeLists.txt | 1 | ||||
-rw-r--r-- | gr-qtgui/apps/CMakeLists.txt | 49 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_constellation_plot | 5 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_psd_plot_b | 183 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_psd_plot_c (renamed from gr-qtgui/apps/gr_psd_plot) | 13 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_psd_plot_f | 178 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_psd_plot_i | 183 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_psd_plot_s | 183 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_spectrogram_plot_b | 181 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_spectrogram_plot_c (renamed from gr-qtgui/apps/gr_spectrogram_plot) | 7 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_spectrogram_plot_f | 176 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_spectrogram_plot_i | 181 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_spectrogram_plot_s | 181 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_time_plot_b | 168 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_time_plot_c (renamed from gr-qtgui/apps/gr_time_plot) | 7 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_time_plot_f | 162 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_time_plot_i | 168 | ||||
-rwxr-xr-x | gr-qtgui/apps/gr_time_plot_s | 168 |
18 files changed, 2185 insertions, 9 deletions
diff --git a/gr-qtgui/CMakeLists.txt b/gr-qtgui/CMakeLists.txt index ca23aabb77..be35beeec2 100644 --- a/gr-qtgui/CMakeLists.txt +++ b/gr-qtgui/CMakeLists.txt @@ -115,6 +115,7 @@ if(ENABLE_PYTHON) add_subdirectory(swig) add_subdirectory(python) add_subdirectory(examples) + add_subdirectory(apps) endif(ENABLE_PYTHON) ######################################################################## diff --git a/gr-qtgui/apps/CMakeLists.txt b/gr-qtgui/apps/CMakeLists.txt new file mode 100644 index 0000000000..07a8298701 --- /dev/null +++ b/gr-qtgui/apps/CMakeLists.txt @@ -0,0 +1,49 @@ +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. + +include(GrPython) + +GR_PYTHON_INSTALL( + FILES + plot_form.py + DESTINATION ${GR_PYTHON_DIR}/gnuradio/qtgui + COMPONENT "qtgui_python" +) + +GR_PYTHON_INSTALL( + PROGRAMS + gr_time_plot_c + gr_time_plot_f + gr_time_plot_i + gr_time_plot_s + gr_time_plot_b + gr_psd_plot_c + gr_psd_plot_f + gr_psd_plot_i + gr_psd_plot_s + gr_psd_plot_b + gr_spectrogram_plot_c + gr_spectrogram_plot_f + gr_spectrogram_plot_i + gr_spectrogram_plot_s + gr_spectrogram_plot_b + gr_constellation_plot + DESTINATION ${GR_RUNTIME_DIR} + COMPONENT "qtgui_python" +) diff --git a/gr-qtgui/apps/gr_constellation_plot b/gr-qtgui/apps/gr_constellation_plot index 246b54e37b..8595167a74 100755 --- a/gr-qtgui/apps/gr_constellation_plot +++ b/gr-qtgui/apps/gr_constellation_plot @@ -39,7 +39,10 @@ except ImportError: print "Error: Scipy required (www.scipy.org)." sys.exit(1) -from plot_form import * +try: + from gnuradio.qtgui.plot_form import * +except ImportError: + from plot_form import * def read_samples(filename, start, in_size): # Read in_size number of samples from file diff --git a/gr-qtgui/apps/gr_psd_plot_b b/gr-qtgui/apps/gr_psd_plot_b new file mode 100755 index 0000000000..3418d1f3e5 --- /dev/null +++ b/gr-qtgui/apps/gr_psd_plot_b @@ -0,0 +1,183 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import os, sys + +try: + from gnuradio import qtgui + from PyQt4 import QtGui, QtCore + import sip +except ImportError: + print "Error: Program requires PyQt4 and gr-qtgui." + sys.exit(1) + +try: + import scipy +except ImportError: + print "Error: Scipy required (www.scipy.org)." + sys.exit(1) + +try: + from gnuradio.qtgui.plot_form import * +except ImportError: + from plot_form import * + +def read_samples_and_pad(filename, start, in_size, min_size): + # Read in_size number of samples from file + fhandle = open(filename, 'r') + fhandle.seek(start*gr.sizeof_char, 0) + data = scipy.fromfile(fhandle, dtype=scipy.uint8, count=in_size) + data = data.tolist() + fhandle.close() + + # If we have to, append 0's to create min_size samples of data + if(len(data) < min_size): + data += (min_size - len(data)) * [scipy.uint8(0)] + + return data + +class my_top_block(gr.top_block): + def __init__(self, filelist, fc, samp_rate, psdsize, start, + nsamples, max_nsamples, scale, avg=1.0): + gr.top_block.__init__(self) + + self._filelist = filelist + self._center_freq = fc + self._samp_rate = samp_rate + self._psd_size = psdsize + self._start = start + self._max_nsamps = max_nsamples + self._scale = scale + self._nsigs = len(self._filelist) + self._avg = avg + + if(nsamples is None): + self._nsamps = max_nsamples + else: + self._nsamps = nsamples + + self.qapp = QtGui.QApplication(sys.argv) + + self.skip = gr.skiphead(gr.sizeof_float, self._start) + self.gui_snk = qtgui.freq_sink_f(self._psd_size, gr.firdes.WIN_BLACKMAN_hARRIS, + self._center_freq, self._samp_rate, + "GNU Radio PSD Plot", self._nsigs) + n = 0 + self.srcs = list() + self.cnvrt = list() + for f in filelist: + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + self.srcs.append(gr.vector_source_b(data)) + self.cnvrt.append(gr.char_to_float(1, self._scale)) + + # Set default labels based on file names + self.gui_snk.set_title(n, "{0}".format(f)) + n += 1 + + self.connect(self.srcs[0], self.cnvrt[0], self.skip) + self.connect(self.skip, (self.gui_snk, 0)) + + for i,s in enumerate(self.srcs[1:]): + self.connect(s, self.cnvrt[i], (self.gui_snk, i+1)) + + self.gui_snk.set_update_time(0); + self.gui_snk.set_fft_average(self._avg) + + # Get Python Qt references + pyQt = self.gui_snk.pyqwidget() + self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) + + def get_gui(self): + return self.pyWin + + def reset(self, newstart, newnsamps): + self.stop() + self.wait() + + self._start = newstart + self._nsamps = newnsamps + + for s,f in zip(self.srcs, self._filelist): + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + s.set_data(data) + + self.start() + +def main(): + description = "Plots the PSDs of a list of files. Files are a binary list of chars/bytes." + parser = OptionParser(option_class=eng_option, description=description, + conflict_handler="resolve") + parser.add_option("-N", "--nsamples", type="int", default=None, + help="Set the number of samples to display [default=prints entire file]") + parser.add_option("-S", "--start", type="int", default=0, + help="Starting sample number [default=%default]") + parser.add_option("-L", "--psd-size", type="int", default=2048, + help="Set the FFT size of the PSD [default=%default]") + parser.add_option("-f", "--center-frequency", type="eng_float", default=0.0, + help="Set the center frequency of the signal [default=%default]") + parser.add_option("-r", "--sample-rate", type="eng_float", default=1.0, + help="Set the sample rate of the signal [default=%default]") + parser.add_option("-a", "--average", type="float", default=1.0, + help="Set amount of averaging (smaller=more averaging) [default=%default]") + parser.add_option("-s", "--scale", type="eng_float", default=2**(8-1)-1, + help="Set a scaling factor for the char->float conversion [default=%default]") + (options, args) = parser.parse_args() + + if(len(args) < 1): + parser.print_help() + sys.exit(0) + + filelist = list(args) + + nsamples = options.nsamples + + # Find the smallest number of samples in all files and use that as + # a maximum value possible. + filesizes = [] + for f in filelist: + if(os.path.exists(f)): + filesizes.append(os.path.getsize(f) / gr.sizeof_char) + max_nsamples = min(filesizes) + + tb = my_top_block(filelist, + options.center_frequency, options.sample_rate, + options.psd_size, + options.start, nsamples, max_nsamples, + options.scale, options.average) + + main_box = dialog_box(tb, 'GNU Radio PSD Plot') + main_box.show() + + tb.run() + tb.qapp.exec_() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass + diff --git a/gr-qtgui/apps/gr_psd_plot b/gr-qtgui/apps/gr_psd_plot_c index 74c740fc67..d7424d0a28 100755 --- a/gr-qtgui/apps/gr_psd_plot +++ b/gr-qtgui/apps/gr_psd_plot_c @@ -39,8 +39,11 @@ except ImportError: print "Error: Scipy required (www.scipy.org)." sys.exit(1) -from plot_form import * - +try: + from gnuradio.qtgui.plot_form import * +except ImportError: + from plot_form import * + def read_samples_and_pad(filename, start, in_size, min_size): # Read in_size number of samples from file fhandle = open(filename, 'r') @@ -76,6 +79,7 @@ class my_top_block(gr.top_block): self.qapp = QtGui.QApplication(sys.argv) + self.skip = gr.skiphead(gr.sizeof_gr_complex, self._start) self.gui_snk = qtgui.freq_sink_c(self._psd_size, gr.firdes.WIN_BLACKMAN_hARRIS, self._center_freq, self._samp_rate, "GNU Radio PSD Plot", self._nsigs) @@ -90,7 +94,8 @@ class my_top_block(gr.top_block): self.gui_snk.set_title(n, "{0}".format(f)) n += 1 - self.connect(self.srcs[0], (self.gui_snk, 0)) + self.connect(self.srcs[0], self.skip) + self.connect(self.skip, (self.gui_snk, 0)) for i,s in enumerate(self.srcs[1:]): self.connect(s, (self.gui_snk, i+1)) @@ -120,7 +125,7 @@ class my_top_block(gr.top_block): self.start() def main(): - description = "Plots the PSDs of a list of files." + description = "Plots the PSDs of a list of files. Files are a binary list of complex floats." parser = OptionParser(option_class=eng_option, description=description, conflict_handler="resolve") parser.add_option("-N", "--nsamples", type="int", default=None, diff --git a/gr-qtgui/apps/gr_psd_plot_f b/gr-qtgui/apps/gr_psd_plot_f new file mode 100755 index 0000000000..a1a2fad3d3 --- /dev/null +++ b/gr-qtgui/apps/gr_psd_plot_f @@ -0,0 +1,178 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import os, sys + +try: + from gnuradio import qtgui + from PyQt4 import QtGui, QtCore + import sip +except ImportError: + print "Error: Program requires PyQt4 and gr-qtgui." + sys.exit(1) + +try: + import scipy +except ImportError: + print "Error: Scipy required (www.scipy.org)." + sys.exit(1) + +try: + from gnuradio.qtgui.plot_form import * +except ImportError: + from plot_form import * + +def read_samples_and_pad(filename, start, in_size, min_size): + # Read in_size number of samples from file + fhandle = open(filename, 'r') + fhandle.seek(start*gr.sizeof_float, 0) + data = scipy.fromfile(fhandle, dtype=scipy.float32, count=in_size) + data = data.tolist() + fhandle.close() + + # If we have to, append 0's to create min_size samples of data + if(len(data) < min_size): + data += (min_size - len(data)) * [scipy.float32(0.0)] + + return data + +class my_top_block(gr.top_block): + def __init__(self, filelist, fc, samp_rate, psdsize, start, + nsamples, max_nsamples, avg=1.0): + gr.top_block.__init__(self) + + self._filelist = filelist + self._center_freq = fc + self._samp_rate = samp_rate + self._psd_size = psdsize + self._start = start + self._max_nsamps = max_nsamples + self._nsigs = len(self._filelist) + self._avg = avg + + if(nsamples is None): + self._nsamps = max_nsamples + else: + self._nsamps = nsamples + + self.qapp = QtGui.QApplication(sys.argv) + + self.skip = gr.skiphead(gr.sizeof_float, self._start) + self.gui_snk = qtgui.freq_sink_f(self._psd_size, gr.firdes.WIN_BLACKMAN_hARRIS, + self._center_freq, self._samp_rate, + "GNU Radio PSD Plot", self._nsigs) + n = 0 + self.srcs = list() + for f in filelist: + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + self.srcs.append(gr.vector_source_f(data)) + + # Set default labels based on file names + self.gui_snk.set_title(n, "{0}".format(f)) + n += 1 + + self.connect(self.srcs[0], self.skip) + self.connect(self.skip, (self.gui_snk, 0)) + + for i,s in enumerate(self.srcs[1:]): + self.connect(s, (self.gui_snk, i+1)) + + self.gui_snk.set_update_time(0); + self.gui_snk.set_fft_average(self._avg) + + # Get Python Qt references + pyQt = self.gui_snk.pyqwidget() + self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) + + def get_gui(self): + return self.pyWin + + def reset(self, newstart, newnsamps): + self.stop() + self.wait() + + self._start = newstart + self._nsamps = newnsamps + + for s,f in zip(self.srcs, self._filelist): + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + s.set_data(data) + + self.start() + +def main(): + description = "Plots the PSDs of a list of files. Files are a binary list of floats." + parser = OptionParser(option_class=eng_option, description=description, + conflict_handler="resolve") + parser.add_option("-N", "--nsamples", type="int", default=None, + help="Set the number of samples to display [default=prints entire file]") + parser.add_option("-S", "--start", type="int", default=0, + help="Starting sample number [default=%default]") + parser.add_option("-L", "--psd-size", type="int", default=2048, + help="Set the FFT size of the PSD [default=%default]") + parser.add_option("-f", "--center-frequency", type="eng_float", default=0.0, + help="Set the center frequency of the signal [default=%default]") + parser.add_option("-r", "--sample-rate", type="eng_float", default=1.0, + help="Set the sample rate of the signal [default=%default]") + parser.add_option("-a", "--average", type="float", default=1.0, + help="Set amount of averaging (smaller=more averaging) [default=%default]") + (options, args) = parser.parse_args() + + if(len(args) < 1): + parser.print_help() + sys.exit(0) + + filelist = list(args) + + nsamples = options.nsamples + + # Find the smallest number of samples in all files and use that as + # a maximum value possible. + filesizes = [] + for f in filelist: + if(os.path.exists(f)): + filesizes.append(os.path.getsize(f) / gr.sizeof_float) + max_nsamples = min(filesizes) + + tb = my_top_block(filelist, + options.center_frequency, options.sample_rate, + options.psd_size, + options.start, nsamples, max_nsamples, + options.average); + + main_box = dialog_box(tb, 'GNU Radio PSD Plot') + main_box.show() + + tb.run() + tb.qapp.exec_() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass + diff --git a/gr-qtgui/apps/gr_psd_plot_i b/gr-qtgui/apps/gr_psd_plot_i new file mode 100755 index 0000000000..aefccc0f3a --- /dev/null +++ b/gr-qtgui/apps/gr_psd_plot_i @@ -0,0 +1,183 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import os, sys + +try: + from gnuradio import qtgui + from PyQt4 import QtGui, QtCore + import sip +except ImportError: + print "Error: Program requires PyQt4 and gr-qtgui." + sys.exit(1) + +try: + import scipy +except ImportError: + print "Error: Scipy required (www.scipy.org)." + sys.exit(1) + +try: + from gnuradio.qtgui.plot_form import * +except ImportError: + from plot_form import * + +def read_samples_and_pad(filename, start, in_size, min_size): + # Read in_size number of samples from file + fhandle = open(filename, 'r') + fhandle.seek(start*gr.sizeof_int, 0) + data = scipy.fromfile(fhandle, dtype=scipy.int32, count=in_size) + data = data.tolist() + fhandle.close() + + # If we have to, append 0's to create min_size samples of data + if(len(data) < min_size): + data += (min_size - len(data)) * [scipy.int32(0)] + + return data + +class my_top_block(gr.top_block): + def __init__(self, filelist, fc, samp_rate, psdsize, start, + nsamples, max_nsamples, scale, avg=1.0): + gr.top_block.__init__(self) + + self._filelist = filelist + self._center_freq = fc + self._samp_rate = samp_rate + self._psd_size = psdsize + self._start = start + self._max_nsamps = max_nsamples + self._scale = scale + self._nsigs = len(self._filelist) + self._avg = avg + + if(nsamples is None): + self._nsamps = max_nsamples + else: + self._nsamps = nsamples + + self.qapp = QtGui.QApplication(sys.argv) + + self.skip = gr.skiphead(gr.sizeof_float, self._start) + self.gui_snk = qtgui.freq_sink_f(self._psd_size, gr.firdes.WIN_BLACKMAN_hARRIS, + self._center_freq, self._samp_rate, + "GNU Radio PSD Plot", self._nsigs) + n = 0 + self.srcs = list() + self.cnvrt = list() + for f in filelist: + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + self.srcs.append(gr.vector_source_i(data)) + self.cnvrt.append(gr.int_to_float(1, self._scale)) + + # Set default labels based on file names + self.gui_snk.set_title(n, "{0}".format(f)) + n += 1 + + self.connect(self.srcs[0], self.cnvrt[0], self.skip) + self.connect(self.skip, (self.gui_snk, 0)) + + for i,s in enumerate(self.srcs[1:]): + self.connect(s, self.cnvrt[i], (self.gui_snk, i+1)) + + self.gui_snk.set_update_time(0); + self.gui_snk.set_fft_average(self._avg) + + # Get Python Qt references + pyQt = self.gui_snk.pyqwidget() + self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) + + def get_gui(self): + return self.pyWin + + def reset(self, newstart, newnsamps): + self.stop() + self.wait() + + self._start = newstart + self._nsamps = newnsamps + + for s,f in zip(self.srcs, self._filelist): + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + s.set_data(data) + + self.start() + +def main(): + description = "Plots the PSDs of a list of files. Files are a binary list of integers." + parser = OptionParser(option_class=eng_option, description=description, + conflict_handler="resolve") + parser.add_option("-N", "--nsamples", type="int", default=None, + help="Set the number of samples to display [default=prints entire file]") + parser.add_option("-S", "--start", type="int", default=0, + help="Starting sample number [default=%default]") + parser.add_option("-L", "--psd-size", type="int", default=2048, + help="Set the FFT size of the PSD [default=%default]") + parser.add_option("-f", "--center-frequency", type="eng_float", default=0.0, + help="Set the center frequency of the signal [default=%default]") + parser.add_option("-r", "--sample-rate", type="eng_float", default=1.0, + help="Set the sample rate of the signal [default=%default]") + parser.add_option("-a", "--average", type="float", default=1.0, + help="Set amount of averaging (smaller=more averaging) [default=%default]") + parser.add_option("-s", "--scale", type="eng_float", default=2**(32-1)-1, + help="Set a scaling factor for the int->float conversion [default=%default]") + (options, args) = parser.parse_args() + + if(len(args) < 1): + parser.print_help() + sys.exit(0) + + filelist = list(args) + + nsamples = options.nsamples + + # Find the smallest number of samples in all files and use that as + # a maximum value possible. + filesizes = [] + for f in filelist: + if(os.path.exists(f)): + filesizes.append(os.path.getsize(f) / gr.sizeof_int) + max_nsamples = min(filesizes) + + tb = my_top_block(filelist, + options.center_frequency, options.sample_rate, + options.psd_size, + options.start, nsamples, max_nsamples, + options.scale, options.average) + + main_box = dialog_box(tb, 'GNU Radio PSD Plot') + main_box.show() + + tb.run() + tb.qapp.exec_() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass + diff --git a/gr-qtgui/apps/gr_psd_plot_s b/gr-qtgui/apps/gr_psd_plot_s new file mode 100755 index 0000000000..2b810376e2 --- /dev/null +++ b/gr-qtgui/apps/gr_psd_plot_s @@ -0,0 +1,183 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import os, sys + +try: + from gnuradio import qtgui + from PyQt4 import QtGui, QtCore + import sip +except ImportError: + print "Error: Program requires PyQt4 and gr-qtgui." + sys.exit(1) + +try: + import scipy +except ImportError: + print "Error: Scipy required (www.scipy.org)." + sys.exit(1) + +try: + from gnuradio.qtgui.plot_form import * +except ImportError: + from plot_form import * + +def read_samples_and_pad(filename, start, in_size, min_size): + # Read in_size number of samples from file + fhandle = open(filename, 'r') + fhandle.seek(start*gr.sizeof_short, 0) + data = scipy.fromfile(fhandle, dtype=scipy.int16, count=in_size) + data = data.tolist() + fhandle.close() + + # If we have to, append 0's to create min_size samples of data + if(len(data) < min_size): + data += (min_size - len(data)) * [scipy.int16(0)] + + return data + +class my_top_block(gr.top_block): + def __init__(self, filelist, fc, samp_rate, psdsize, start, + nsamples, max_nsamples, scale, avg=1.0): + gr.top_block.__init__(self) + + self._filelist = filelist + self._center_freq = fc + self._samp_rate = samp_rate + self._psd_size = psdsize + self._start = start + self._max_nsamps = max_nsamples + self._scale = scale + self._nsigs = len(self._filelist) + self._avg = avg + + if(nsamples is None): + self._nsamps = max_nsamples + else: + self._nsamps = nsamples + + self.qapp = QtGui.QApplication(sys.argv) + + self.skip = gr.skiphead(gr.sizeof_float, self._start) + self.gui_snk = qtgui.freq_sink_f(self._psd_size, gr.firdes.WIN_BLACKMAN_hARRIS, + self._center_freq, self._samp_rate, + "GNU Radio PSD Plot", self._nsigs) + n = 0 + self.srcs = list() + self.cnvrt = list() + for f in filelist: + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + self.srcs.append(gr.vector_source_s(data)) + self.cnvrt.append(gr.short_to_float(1, self._scale)) + + # Set default labels based on file names + self.gui_snk.set_title(n, "{0}".format(f)) + n += 1 + + self.connect(self.srcs[0], self.cnvrt[0], self.skip) + self.connect(self.skip, (self.gui_snk, 0)) + + for i,s in enumerate(self.srcs[1:]): + self.connect(s, self.cnvrt[i], (self.gui_snk, i+1)) + + self.gui_snk.set_update_time(0); + self.gui_snk.set_fft_average(self._avg) + + # Get Python Qt references + pyQt = self.gui_snk.pyqwidget() + self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) + + def get_gui(self): + return self.pyWin + + def reset(self, newstart, newnsamps): + self.stop() + self.wait() + + self._start = newstart + self._nsamps = newnsamps + + for s,f in zip(self.srcs, self._filelist): + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + s.set_data(data) + + self.start() + +def main(): + description = "Plots the PSDs of a list of files. Files are a binary list of shorts." + parser = OptionParser(option_class=eng_option, description=description, + conflict_handler="resolve") + parser.add_option("-N", "--nsamples", type="int", default=None, + help="Set the number of samples to display [default=prints entire file]") + parser.add_option("-S", "--start", type="int", default=0, + help="Starting sample number [default=%default]") + parser.add_option("-L", "--psd-size", type="int", default=2048, + help="Set the FFT size of the PSD [default=%default]") + parser.add_option("-f", "--center-frequency", type="eng_float", default=0.0, + help="Set the center frequency of the signal [default=%default]") + parser.add_option("-r", "--sample-rate", type="eng_float", default=1.0, + help="Set the sample rate of the signal [default=%default]") + parser.add_option("-a", "--average", type="float", default=1.0, + help="Set amount of averaging (smaller=more averaging) [default=%default]") + parser.add_option("-s", "--scale", type="eng_float", default=2**(16-1)-1, + help="Set a scaling factor for the short->float conversion [default=%default]") + (options, args) = parser.parse_args() + + if(len(args) < 1): + parser.print_help() + sys.exit(0) + + filelist = list(args) + + nsamples = options.nsamples + + # Find the smallest number of samples in all files and use that as + # a maximum value possible. + filesizes = [] + for f in filelist: + if(os.path.exists(f)): + filesizes.append(os.path.getsize(f) / gr.sizeof_short) + max_nsamples = min(filesizes) + + tb = my_top_block(filelist, + options.center_frequency, options.sample_rate, + options.psd_size, + options.start, nsamples, max_nsamples, + options.scale, options.average) + + main_box = dialog_box(tb, 'GNU Radio PSD Plot') + main_box.show() + + tb.run() + tb.qapp.exec_() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass + diff --git a/gr-qtgui/apps/gr_spectrogram_plot_b b/gr-qtgui/apps/gr_spectrogram_plot_b new file mode 100755 index 0000000000..41c1af521a --- /dev/null +++ b/gr-qtgui/apps/gr_spectrogram_plot_b @@ -0,0 +1,181 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import os, sys + +try: + from gnuradio import qtgui + from PyQt4 import QtGui, QtCore + import sip +except ImportError: + print "Error: Program requires PyQt4 and gr-qtgui." + sys.exit(1) + +try: + import scipy +except ImportError: + print "Error: Scipy required (www.scipy.org)." + sys.exit(1) + +try: + from gnuradio.qtgui.plot_form import * +except ImportError: + from plot_form import * + +def read_samples_and_pad(filename, start, in_size, min_size): + # Read in_size number of samples from file + fhandle = open(filename, 'r') + fhandle.seek(start*gr.sizeof_char, 0) + data = scipy.fromfile(fhandle, dtype=scipy.uint8, count=in_size) + data = data.tolist() + fhandle.close() + + # If we have to, append 0's to create min_size samples of data + if(len(data) < min_size): + data += (min_size - len(data)) * [scipy.uint8(0)] + + return data + +class my_top_block(gr.top_block): + def __init__(self, filelist, fc, samp_rate, psdsize, start, + nsamples, max_nsamples, scale, avg=1.0): + gr.top_block.__init__(self) + + self._filelist = filelist + self._center_freq = fc + self._samp_rate = samp_rate + self._psd_size = psdsize + self._start = start + self._max_nsamps = max_nsamples + self._scale = scale + self._nsigs = len(self._filelist) + self._avg = avg + + if(nsamples is None): + self._nsamps = max_nsamples + else: + self._nsamps = nsamples + + self.qapp = QtGui.QApplication(sys.argv) + + self.skip = gr.skiphead(gr.sizeof_float, self._start) + self.add = gr.add_ff() + self.gui_snk = qtgui.waterfall_sink_f(self._psd_size, gr.firdes.WIN_BLACKMAN_hARRIS, + self._center_freq, self._samp_rate, + "GNU Radio Spectrogram Plot") + n = 0 + self.srcs = list() + self.cnvrt = list() + for f in filelist: + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + self.srcs.append(gr.vector_source_b(data)) + self.cnvrt.append(gr.char_to_float(1, self._scale)) + n += 1 + + self.connect(self.add, self.skip) + self.connect(self.skip, (self.gui_snk, 0)) + + for i,s in enumerate(self.srcs): + self.connect(s, self.cnvrt[i], (self.add, i)) + + self.gui_snk.set_update_time(0); + self.gui_snk.set_fft_average(self._avg) + + # Get Python Qt references + pyQt = self.gui_snk.pyqwidget() + self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) + + def get_gui(self): + return self.pyWin + + def reset(self, newstart, newnsamps): + self.stop() + self.wait() + + self._start = newstart + self._nsamps = newnsamps + + for s,f in zip(self.srcs, self._filelist): + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + s.set_data(data) + + self.start() + +def main(): + description = "Plots the spectrogram (waterfall) of a list of files. Files are a binary list of chars/bytes." + parser = OptionParser(option_class=eng_option, description=description, + conflict_handler="resolve") + parser.add_option("-N", "--nsamples", type="int", default=None, + help="Set the number of samples to display [default=prints entire file]") + parser.add_option("-S", "--start", type="int", default=0, + help="Starting sample number [default=%default]") + parser.add_option("-L", "--psd-size", type="int", default=2048, + help="Set the FFT size of the PSD [default=%default]") + parser.add_option("-f", "--center-frequency", type="eng_float", default=0.0, + help="Set the center frequency of the signal [default=%default]") + parser.add_option("-r", "--sample-rate", type="eng_float", default=1.0, + help="Set the sample rate of the signal [default=%default]") + parser.add_option("-a", "--average", type="float", default=1.0, + help="Set amount of averaging (smaller=more averaging) [default=%default]") + parser.add_option("-s", "--scale", type="eng_float", default=2**(8-1)-1, + help="Set a scaling factor for the char->float conversion [default=%default]") + (options, args) = parser.parse_args() + + if(len(args) < 1): + parser.print_help() + sys.exit(0) + + filelist = list(args) + + nsamples = options.nsamples + + # Find the smallest number of samples in all files and use that as + # a maximum value possible. + filesizes = [] + for f in filelist: + if(os.path.exists(f)): + filesizes.append(os.path.getsize(f) / gr.sizeof_char) + max_nsamples = min(filesizes) + + tb = my_top_block(filelist, + options.center_frequency, options.sample_rate, + options.psd_size, + options.start, nsamples, max_nsamples, + options.scale, options.average); + + main_box = dialog_box(tb, 'GNU Radio Spectrogram Plot') + main_box.show() + + tb.run() + tb.qapp.exec_() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass + diff --git a/gr-qtgui/apps/gr_spectrogram_plot b/gr-qtgui/apps/gr_spectrogram_plot_c index 768eba9f29..28fa82f298 100755 --- a/gr-qtgui/apps/gr_spectrogram_plot +++ b/gr-qtgui/apps/gr_spectrogram_plot_c @@ -39,7 +39,10 @@ except ImportError: print "Error: Scipy required (www.scipy.org)." sys.exit(1) -from plot_form import * +try: + from gnuradio.qtgui.plot_form import * +except ImportError: + from plot_form import * def read_samples_and_pad(filename, start, in_size, min_size): # Read in_size number of samples from file @@ -120,7 +123,7 @@ class my_top_block(gr.top_block): self.start() def main(): - description = "Plots the spectrogram (waterfall) of a list of files." + description = "Plots the spectrogram (waterfall) of a list of files. Files are a binary list of complex floats." parser = OptionParser(option_class=eng_option, description=description, conflict_handler="resolve") parser.add_option("-N", "--nsamples", type="int", default=None, diff --git a/gr-qtgui/apps/gr_spectrogram_plot_f b/gr-qtgui/apps/gr_spectrogram_plot_f new file mode 100755 index 0000000000..d1bb73212a --- /dev/null +++ b/gr-qtgui/apps/gr_spectrogram_plot_f @@ -0,0 +1,176 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import os, sys + +try: + from gnuradio import qtgui + from PyQt4 import QtGui, QtCore + import sip +except ImportError: + print "Error: Program requires PyQt4 and gr-qtgui." + sys.exit(1) + +try: + import scipy +except ImportError: + print "Error: Scipy required (www.scipy.org)." + sys.exit(1) + +try: + from gnuradio.qtgui.plot_form import * +except ImportError: + from plot_form import * + +def read_samples_and_pad(filename, start, in_size, min_size): + # Read in_size number of samples from file + fhandle = open(filename, 'r') + fhandle.seek(start*gr.sizeof_float, 0) + data = scipy.fromfile(fhandle, dtype=scipy.float32, count=in_size) + data = data.tolist() + fhandle.close() + + # If we have to, append 0's to create min_size samples of data + if(len(data) < min_size): + data += (min_size - len(data)) * [scipy.float32(0.0)] + + return data + +class my_top_block(gr.top_block): + def __init__(self, filelist, fc, samp_rate, psdsize, start, + nsamples, max_nsamples, avg=1.0): + gr.top_block.__init__(self) + + self._filelist = filelist + self._center_freq = fc + self._samp_rate = samp_rate + self._psd_size = psdsize + self._start = start + self._max_nsamps = max_nsamples + self._nsigs = len(self._filelist) + self._avg = avg + + if(nsamples is None): + self._nsamps = max_nsamples + else: + self._nsamps = nsamples + + self.qapp = QtGui.QApplication(sys.argv) + + self.skip = gr.skiphead(gr.sizeof_float, self._start) + self.add = gr.add_ff() + self.gui_snk = qtgui.waterfall_sink_f(self._psd_size, gr.firdes.WIN_BLACKMAN_hARRIS, + self._center_freq, self._samp_rate, + "GNU Radio Spectrogram Plot") + n = 0 + self.srcs = list() + for f in filelist: + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + self.srcs.append(gr.vector_source_f(data)) + n += 1 + + self.connect(self.add, self.skip) + self.connect(self.skip, (self.gui_snk, 0)) + + for i,s in enumerate(self.srcs): + self.connect(s, (self.add, i)) + + self.gui_snk.set_update_time(0); + self.gui_snk.set_fft_average(self._avg) + + # Get Python Qt references + pyQt = self.gui_snk.pyqwidget() + self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) + + def get_gui(self): + return self.pyWin + + def reset(self, newstart, newnsamps): + self.stop() + self.wait() + + self._start = newstart + self._nsamps = newnsamps + + for s,f in zip(self.srcs, self._filelist): + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + s.set_data(data) + + self.start() + +def main(): + description = "Plots the spectrogram (waterfall) of a list of files. Files are a binary list of floats." + parser = OptionParser(option_class=eng_option, description=description, + conflict_handler="resolve") + parser.add_option("-N", "--nsamples", type="int", default=None, + help="Set the number of samples to display [default=prints entire file]") + parser.add_option("-S", "--start", type="int", default=0, + help="Starting sample number [default=%default]") + parser.add_option("-L", "--psd-size", type="int", default=2048, + help="Set the FFT size of the PSD [default=%default]") + parser.add_option("-f", "--center-frequency", type="eng_float", default=0.0, + help="Set the center frequency of the signal [default=%default]") + parser.add_option("-r", "--sample-rate", type="eng_float", default=1.0, + help="Set the sample rate of the signal [default=%default]") + parser.add_option("-a", "--average", type="float", default=1.0, + help="Set amount of averaging (smaller=more averaging) [default=%default]") + (options, args) = parser.parse_args() + + if(len(args) < 1): + parser.print_help() + sys.exit(0) + + filelist = list(args) + + nsamples = options.nsamples + + # Find the smallest number of samples in all files and use that as + # a maximum value possible. + filesizes = [] + for f in filelist: + if(os.path.exists(f)): + filesizes.append(os.path.getsize(f) / gr.sizeof_float) + max_nsamples = min(filesizes) + + tb = my_top_block(filelist, + options.center_frequency, options.sample_rate, + options.psd_size, + options.start, nsamples, max_nsamples, + options.average); + + main_box = dialog_box(tb, 'GNU Radio Spectrogram Plot') + main_box.show() + + tb.run() + tb.qapp.exec_() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass + diff --git a/gr-qtgui/apps/gr_spectrogram_plot_i b/gr-qtgui/apps/gr_spectrogram_plot_i new file mode 100755 index 0000000000..a617f9087d --- /dev/null +++ b/gr-qtgui/apps/gr_spectrogram_plot_i @@ -0,0 +1,181 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import os, sys + +try: + from gnuradio import qtgui + from PyQt4 import QtGui, QtCore + import sip +except ImportError: + print "Error: Program requires PyQt4 and gr-qtgui." + sys.exit(1) + +try: + import scipy +except ImportError: + print "Error: Scipy required (www.scipy.org)." + sys.exit(1) + +try: + from gnuradio.qtgui.plot_form import * +except ImportError: + from plot_form import * + +def read_samples_and_pad(filename, start, in_size, min_size): + # Read in_size number of samples from file + fhandle = open(filename, 'r') + fhandle.seek(start*gr.sizeof_int, 0) + data = scipy.fromfile(fhandle, dtype=scipy.int32, count=in_size) + data = data.tolist() + fhandle.close() + + # If we have to, append 0's to create min_size samples of data + if(len(data) < min_size): + data += (min_size - len(data)) * [scipy.int32(0)] + + return data + +class my_top_block(gr.top_block): + def __init__(self, filelist, fc, samp_rate, psdsize, start, + nsamples, max_nsamples, scale, avg=1.0): + gr.top_block.__init__(self) + + self._filelist = filelist + self._center_freq = fc + self._samp_rate = samp_rate + self._psd_size = psdsize + self._start = start + self._max_nsamps = max_nsamples + self._scale = scale + self._nsigs = len(self._filelist) + self._avg = avg + + if(nsamples is None): + self._nsamps = max_nsamples + else: + self._nsamps = nsamples + + self.qapp = QtGui.QApplication(sys.argv) + + self.skip = gr.skiphead(gr.sizeof_float, self._start) + self.add = gr.add_ff() + self.gui_snk = qtgui.waterfall_sink_f(self._psd_size, gr.firdes.WIN_BLACKMAN_hARRIS, + self._center_freq, self._samp_rate, + "GNU Radio Spectrogram Plot") + n = 0 + self.srcs = list() + self.cnvrt = list() + for f in filelist: + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + self.srcs.append(gr.vector_source_i(data)) + self.cnvrt.append(gr.int_to_float(1, self._scale)) + n += 1 + + self.connect(self.add, self.skip) + self.connect(self.skip, (self.gui_snk, 0)) + + for i,s in enumerate(self.srcs): + self.connect(s, self.cnvrt[i], (self.add, i)) + + self.gui_snk.set_update_time(0); + self.gui_snk.set_fft_average(self._avg) + + # Get Python Qt references + pyQt = self.gui_snk.pyqwidget() + self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) + + def get_gui(self): + return self.pyWin + + def reset(self, newstart, newnsamps): + self.stop() + self.wait() + + self._start = newstart + self._nsamps = newnsamps + + for s,f in zip(self.srcs, self._filelist): + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + s.set_data(data) + + self.start() + +def main(): + description = "Plots the spectrogram (waterfall) of a list of files. Files are a binary list of integers." + parser = OptionParser(option_class=eng_option, description=description, + conflict_handler="resolve") + parser.add_option("-N", "--nsamples", type="int", default=None, + help="Set the number of samples to display [default=prints entire file]") + parser.add_option("-S", "--start", type="int", default=0, + help="Starting sample number [default=%default]") + parser.add_option("-L", "--psd-size", type="int", default=2048, + help="Set the FFT size of the PSD [default=%default]") + parser.add_option("-f", "--center-frequency", type="eng_float", default=0.0, + help="Set the center frequency of the signal [default=%default]") + parser.add_option("-r", "--sample-rate", type="eng_float", default=1.0, + help="Set the sample rate of the signal [default=%default]") + parser.add_option("-a", "--average", type="float", default=1.0, + help="Set amount of averaging (smaller=more averaging) [default=%default]") + parser.add_option("-s", "--scale", type="eng_float", default=2**(32-1)-1, + help="Set a scaling factor for the int->float conversion [default=%default]") + (options, args) = parser.parse_args() + + if(len(args) < 1): + parser.print_help() + sys.exit(0) + + filelist = list(args) + + nsamples = options.nsamples + + # Find the smallest number of samples in all files and use that as + # a maximum value possible. + filesizes = [] + for f in filelist: + if(os.path.exists(f)): + filesizes.append(os.path.getsize(f) / gr.sizeof_int) + max_nsamples = min(filesizes) + + tb = my_top_block(filelist, + options.center_frequency, options.sample_rate, + options.psd_size, + options.start, nsamples, max_nsamples, + options.scale, options.average); + + main_box = dialog_box(tb, 'GNU Radio Spectrogram Plot') + main_box.show() + + tb.run() + tb.qapp.exec_() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass + diff --git a/gr-qtgui/apps/gr_spectrogram_plot_s b/gr-qtgui/apps/gr_spectrogram_plot_s new file mode 100755 index 0000000000..29f3d3df77 --- /dev/null +++ b/gr-qtgui/apps/gr_spectrogram_plot_s @@ -0,0 +1,181 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import os, sys + +try: + from gnuradio import qtgui + from PyQt4 import QtGui, QtCore + import sip +except ImportError: + print "Error: Program requires PyQt4 and gr-qtgui." + sys.exit(1) + +try: + import scipy +except ImportError: + print "Error: Scipy required (www.scipy.org)." + sys.exit(1) + +try: + from gnuradio.qtgui.plot_form import * +except ImportError: + from plot_form import * + +def read_samples_and_pad(filename, start, in_size, min_size): + # Read in_size number of samples from file + fhandle = open(filename, 'r') + fhandle.seek(start*gr.sizeof_short, 0) + data = scipy.fromfile(fhandle, dtype=scipy.int16, count=in_size) + data = data.tolist() + fhandle.close() + + # If we have to, append 0's to create min_size samples of data + if(len(data) < min_size): + data += (min_size - len(data)) * [scipy.int16(0)] + + return data + +class my_top_block(gr.top_block): + def __init__(self, filelist, fc, samp_rate, psdsize, start, + nsamples, max_nsamples, scale, avg=1.0): + gr.top_block.__init__(self) + + self._filelist = filelist + self._center_freq = fc + self._samp_rate = samp_rate + self._psd_size = psdsize + self._start = start + self._max_nsamps = max_nsamples + self._scale = scale + self._nsigs = len(self._filelist) + self._avg = avg + + if(nsamples is None): + self._nsamps = max_nsamples + else: + self._nsamps = nsamples + + self.qapp = QtGui.QApplication(sys.argv) + + self.skip = gr.skiphead(gr.sizeof_float, self._start) + self.add = gr.add_ff() + self.gui_snk = qtgui.waterfall_sink_f(self._psd_size, gr.firdes.WIN_BLACKMAN_hARRIS, + self._center_freq, self._samp_rate, + "GNU Radio Spectrogram Plot") + n = 0 + self.srcs = list() + self.cnvrt = list() + for f in filelist: + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + self.srcs.append(gr.vector_source_s(data)) + self.cnvrt.append(gr.short_to_float(1, self._scale)) + n += 1 + + self.connect(self.add, self.skip) + self.connect(self.skip, (self.gui_snk, 0)) + + for i,s in enumerate(self.srcs): + self.connect(s, self.cnvrt[i], (self.add, i)) + + self.gui_snk.set_update_time(0); + self.gui_snk.set_fft_average(self._avg) + + # Get Python Qt references + pyQt = self.gui_snk.pyqwidget() + self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) + + def get_gui(self): + return self.pyWin + + def reset(self, newstart, newnsamps): + self.stop() + self.wait() + + self._start = newstart + self._nsamps = newnsamps + + for s,f in zip(self.srcs, self._filelist): + data = read_samples_and_pad(f, self._start, + self._nsamps, self._psd_size) + s.set_data(data) + + self.start() + +def main(): + description = "Plots the spectrogram (waterfall) of a list of files. Files are a binary list of shorts." + parser = OptionParser(option_class=eng_option, description=description, + conflict_handler="resolve") + parser.add_option("-N", "--nsamples", type="int", default=None, + help="Set the number of samples to display [default=prints entire file]") + parser.add_option("-S", "--start", type="int", default=0, + help="Starting sample number [default=%default]") + parser.add_option("-L", "--psd-size", type="int", default=2048, + help="Set the FFT size of the PSD [default=%default]") + parser.add_option("-f", "--center-frequency", type="eng_float", default=0.0, + help="Set the center frequency of the signal [default=%default]") + parser.add_option("-r", "--sample-rate", type="eng_float", default=1.0, + help="Set the sample rate of the signal [default=%default]") + parser.add_option("-a", "--average", type="float", default=1.0, + help="Set amount of averaging (smaller=more averaging) [default=%default]") + parser.add_option("-s", "--scale", type="eng_float", default=2**(16-1)-1, + help="Set a scaling factor for the short->float conversion [default=%default]") + (options, args) = parser.parse_args() + + if(len(args) < 1): + parser.print_help() + sys.exit(0) + + filelist = list(args) + + nsamples = options.nsamples + + # Find the smallest number of samples in all files and use that as + # a maximum value possible. + filesizes = [] + for f in filelist: + if(os.path.exists(f)): + filesizes.append(os.path.getsize(f) / gr.sizeof_short) + max_nsamples = min(filesizes) + + tb = my_top_block(filelist, + options.center_frequency, options.sample_rate, + options.psd_size, + options.start, nsamples, max_nsamples, + options.scale, options.average); + + main_box = dialog_box(tb, 'GNU Radio Spectrogram Plot') + main_box.show() + + tb.run() + tb.qapp.exec_() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass + diff --git a/gr-qtgui/apps/gr_time_plot_b b/gr-qtgui/apps/gr_time_plot_b new file mode 100755 index 0000000000..5b5977b61d --- /dev/null +++ b/gr-qtgui/apps/gr_time_plot_b @@ -0,0 +1,168 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import os, sys + +try: + from gnuradio import qtgui + from PyQt4 import QtGui, QtCore + import sip +except ImportError: + print "Error: Program requires PyQt4 and gr-qtgui." + sys.exit(1) + +try: + import scipy +except ImportError: + print "Error: Scipy required (www.scipy.org)." + sys.exit(1) + +from plot_form import * + +def read_samples(filename, start, in_size): + # Read in_size number of samples from file + fhandle = open(filename, 'r') + fhandle.seek(start*gr.sizeof_char, 0) + data = scipy.fromfile(fhandle, dtype=scipy.uint8, count=in_size) + data = data.tolist() + fhandle.close() + + if(len(data) < in_size): + print "Warning: read in {0} samples but asked for {1} samples.".format( + len(data), in_size) + + return data + +class gr_time_plot_f(gr.top_block): + def __init__(self, filelist, samp_rate, start, nsamples, max_nsamples, scale): + gr.top_block.__init__(self) + + self._filelist = filelist + self._samp_rate = samp_rate + self._start = start + self._max_nsamps = max_nsamples + self._scale = scale + self._nsigs = len(self._filelist) + + if(nsamples is None): + self._nsamps = max_nsamples + else: + self._nsamps = nsamples + + self.qapp = QtGui.QApplication(sys.argv) + + self.skip = gr.skiphead(gr.sizeof_float, self._start) + self.gui_snk = qtgui.time_sink_f(self._nsamps, self._samp_rate, + "GNU Radio Time Plot", self._nsigs) + n = 0 + self.srcs = list() + self.cnvrt = list() + for f in filelist: + data = read_samples(f, self._start, self._nsamps) + self.srcs.append(gr.vector_source_b(data)) + self.cnvrt.append(gr.char_to_float(1, self._scale)) + + # Set default labels based on file names + self.gui_snk.set_title(n, "{0}".format(f)) + n += 1 + + self.connect(self.srcs[0], self.cnvrt[0], self.skip) + self.connect(self.skip, (self.gui_snk, 0)) + + for i,s in enumerate(self.srcs[1:]): + self.connect(s, self.cnvrt[i], (self.gui_snk, i+1)) + + self.gui_snk.set_update_time(0); + + # Get Python Qt references + pyQt = self.gui_snk.pyqwidget() + self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) + + def get_gui(self): + return self.pyWin + + def reset(self, newstart, newnsamps): + self.stop() + self.wait() + + self._start = newstart + + for s,f in zip(self.srcs, self._filelist): + data = read_samples(f, self._start, newnsamps) + s.set_data(data) + if(len(data) < newnsamps): + newnsamps = len(data) + + self._nsamps = newnsamps + self.gui_snk.set_nsamps(self._nsamps) + + self.start() + +def main(): + description = "Plots a list of files on a scope plot. Files are a binary list of chars/bytes." + parser = OptionParser(option_class=eng_option, description=description, + conflict_handler="resolve") + parser.add_option("-N", "--nsamples", type="int", default=None, + help="Set the number of samples to display [default=prints entire file]") + parser.add_option("-S", "--start", type="int", default=0, + help="Starting sample number [default=%default]") + parser.add_option("-r", "--sample-rate", type="eng_float", default=1.0, + help="Set the sample rate of the signal [default=%default]") + parser.add_option("-s", "--scale", type="eng_float", default=2**(8-1)-1, + help="Set a scaling factor for the char->float conversion [default=%default]") + (options, args) = parser.parse_args() + + if(len(args) < 1): + parser.print_help() + sys.exit(0) + + filelist = list(args) + + nsamples = options.nsamples + + # Find the smallest number of samples in all files and use that as + # a maximum value possible. + filesizes = [] + for f in filelist: + if(os.path.exists(f)): + filesizes.append(os.path.getsize(f) / gr.sizeof_char) + max_nsamples = min(filesizes) + + tb = gr_time_plot_f(filelist, options.sample_rate, + options.start, nsamples, max_nsamples, + options.scale); + + main_box = dialog_box(tb, 'GNU Radio Time Plot') + main_box.show() + + tb.run() + tb.qapp.exec_() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass + diff --git a/gr-qtgui/apps/gr_time_plot b/gr-qtgui/apps/gr_time_plot_c index 39db050718..13240ebfb3 100755 --- a/gr-qtgui/apps/gr_time_plot +++ b/gr-qtgui/apps/gr_time_plot_c @@ -39,7 +39,10 @@ except ImportError: print "Error: Scipy required (www.scipy.org)." sys.exit(1) -from plot_form import * +try: + from gnuradio.qtgui.plot_form import * +except ImportError: + from plot_form import * def read_samples(filename, start, in_size): # Read in_size number of samples from file @@ -119,7 +122,7 @@ class my_top_block(gr.top_block): self.start() def main(): - description = "Plots a list of files on a scope plot." + description = "Plots a list of files on a scope plot. Files are a binary list of complex floats." parser = OptionParser(option_class=eng_option, description=description, conflict_handler="resolve") parser.add_option("-N", "--nsamples", type="int", default=None, diff --git a/gr-qtgui/apps/gr_time_plot_f b/gr-qtgui/apps/gr_time_plot_f new file mode 100755 index 0000000000..cc14e0510c --- /dev/null +++ b/gr-qtgui/apps/gr_time_plot_f @@ -0,0 +1,162 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import os, sys + +try: + from gnuradio import qtgui + from PyQt4 import QtGui, QtCore + import sip +except ImportError: + print "Error: Program requires PyQt4 and gr-qtgui." + sys.exit(1) + +try: + import scipy +except ImportError: + print "Error: Scipy required (www.scipy.org)." + sys.exit(1) + +from plot_form import * + +def read_samples(filename, start, in_size): + # Read in_size number of samples from file + fhandle = open(filename, 'r') + fhandle.seek(start*gr.sizeof_float, 0) + data = scipy.fromfile(fhandle, dtype=scipy.float32, count=in_size) + data = data.tolist() + fhandle.close() + + if(len(data) < in_size): + print "Warning: read in {0} samples but asked for {1} samples.".format( + len(data), in_size) + + return data + +class gr_time_plot_f(gr.top_block): + def __init__(self, filelist, samp_rate, start, nsamples, max_nsamples): + gr.top_block.__init__(self) + + self._filelist = filelist + self._samp_rate = samp_rate + self._start = start + self._max_nsamps = max_nsamples + self._nsigs = len(self._filelist) + + if(nsamples is None): + self._nsamps = max_nsamples + else: + self._nsamps = nsamples + + self.qapp = QtGui.QApplication(sys.argv) + + self.skip = gr.skiphead(gr.sizeof_float, self._start) + self.gui_snk = qtgui.time_sink_f(self._nsamps, self._samp_rate, + "GNU Radio Time Plot", self._nsigs) + n = 0 + self.srcs = list() + for f in filelist: + data = read_samples(f, self._start, self._nsamps) + self.srcs.append(gr.vector_source_f(data)) + + # Set default labels based on file names + self.gui_snk.set_title(n, "{0}".format(f)) + n += 1 + + self.connect(self.srcs[0], self.skip) + self.connect(self.skip, (self.gui_snk, 0)) + + for i,s in enumerate(self.srcs[1:]): + self.connect(s, (self.gui_snk, i+1)) + + self.gui_snk.set_update_time(0); + + # Get Python Qt references + pyQt = self.gui_snk.pyqwidget() + self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) + + def get_gui(self): + return self.pyWin + + def reset(self, newstart, newnsamps): + self.stop() + self.wait() + + self._start = newstart + + for s,f in zip(self.srcs, self._filelist): + data = read_samples(f, self._start, newnsamps) + s.set_data(data) + if(len(data) < newnsamps): + newnsamps = len(data) + + self._nsamps = newnsamps + self.gui_snk.set_nsamps(self._nsamps) + + self.start() + +def main(): + description = "Plots a list of files on a scope plot. Files are a binary list of floats." + parser = OptionParser(option_class=eng_option, description=description, + conflict_handler="resolve") + parser.add_option("-N", "--nsamples", type="int", default=None, + help="Set the number of samples to display [default=prints entire file]") + parser.add_option("-S", "--start", type="int", default=0, + help="Starting sample number [default=%default]") + parser.add_option("-r", "--sample-rate", type="eng_float", default=1.0, + help="Set the sample rate of the signal [default=%default]") + (options, args) = parser.parse_args() + + if(len(args) < 1): + parser.print_help() + sys.exit(0) + + filelist = list(args) + + nsamples = options.nsamples + + # Find the smallest number of samples in all files and use that as + # a maximum value possible. + filesizes = [] + for f in filelist: + if(os.path.exists(f)): + filesizes.append(os.path.getsize(f) / gr.sizeof_float) + max_nsamples = min(filesizes) + + tb = gr_time_plot_f(filelist, options.sample_rate, + options.start, nsamples, max_nsamples); + + main_box = dialog_box(tb, 'GNU Radio Time Plot') + main_box.show() + + tb.run() + tb.qapp.exec_() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass + diff --git a/gr-qtgui/apps/gr_time_plot_i b/gr-qtgui/apps/gr_time_plot_i new file mode 100755 index 0000000000..65a8556552 --- /dev/null +++ b/gr-qtgui/apps/gr_time_plot_i @@ -0,0 +1,168 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import os, sys + +try: + from gnuradio import qtgui + from PyQt4 import QtGui, QtCore + import sip +except ImportError: + print "Error: Program requires PyQt4 and gr-qtgui." + sys.exit(1) + +try: + import scipy +except ImportError: + print "Error: Scipy required (www.scipy.org)." + sys.exit(1) + +from plot_form import * + +def read_samples(filename, start, in_size): + # Read in_size number of samples from file + fhandle = open(filename, 'r') + fhandle.seek(start*gr.sizeof_int, 0) + data = scipy.fromfile(fhandle, dtype=scipy.int32, count=in_size) + data = data.tolist() + fhandle.close() + + if(len(data) < in_size): + print "Warning: read in {0} samples but asked for {1} samples.".format( + len(data), in_size) + + return data + +class gr_time_plot_f(gr.top_block): + def __init__(self, filelist, samp_rate, start, nsamples, max_nsamples, scale): + gr.top_block.__init__(self) + + self._filelist = filelist + self._samp_rate = samp_rate + self._start = start + self._max_nsamps = max_nsamples + self._scale = scale + self._nsigs = len(self._filelist) + + if(nsamples is None): + self._nsamps = max_nsamples + else: + self._nsamps = nsamples + + self.qapp = QtGui.QApplication(sys.argv) + + self.skip = gr.skiphead(gr.sizeof_float, self._start) + self.gui_snk = qtgui.time_sink_f(self._nsamps, self._samp_rate, + "GNU Radio Time Plot", self._nsigs) + n = 0 + self.srcs = list() + self.cnvrt = list() + for f in filelist: + data = read_samples(f, self._start, self._nsamps) + self.srcs.append(gr.vector_source_i(data)) + self.cnvrt.append(gr.int_to_float(1, self._scale)) + + # Set default labels based on file names + self.gui_snk.set_title(n, "{0}".format(f)) + n += 1 + + self.connect(self.srcs[0], self.cnvrt[0], self.skip) + self.connect(self.skip, (self.gui_snk, 0)) + + for i,s in enumerate(self.srcs[1:]): + self.connect(s, self.cnvrt[i], (self.gui_snk, i+1)) + + self.gui_snk.set_update_time(0); + + # Get Python Qt references + pyQt = self.gui_snk.pyqwidget() + self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) + + def get_gui(self): + return self.pyWin + + def reset(self, newstart, newnsamps): + self.stop() + self.wait() + + self._start = newstart + + for s,f in zip(self.srcs, self._filelist): + data = read_samples(f, self._start, newnsamps) + s.set_data(data) + if(len(data) < newnsamps): + newnsamps = len(data) + + self._nsamps = newnsamps + self.gui_snk.set_nsamps(self._nsamps) + + self.start() + +def main(): + description = "Plots a list of files on a scope plot. Files are a binary list of integers." + parser = OptionParser(option_class=eng_option, description=description, + conflict_handler="resolve") + parser.add_option("-N", "--nsamples", type="int", default=None, + help="Set the number of samples to display [default=prints entire file]") + parser.add_option("-S", "--start", type="int", default=0, + help="Starting sample number [default=%default]") + parser.add_option("-r", "--sample-rate", type="eng_float", default=1.0, + help="Set the sample rate of the signal [default=%default]") + parser.add_option("-s", "--scale", type="eng_float", default=2**(32-1)-1, + help="Set a scaling factor for the int->float conversion [default=%default]") + (options, args) = parser.parse_args() + + if(len(args) < 1): + parser.print_help() + sys.exit(0) + + filelist = list(args) + + nsamples = options.nsamples + + # Find the smallest number of samples in all files and use that as + # a maximum value possible. + filesizes = [] + for f in filelist: + if(os.path.exists(f)): + filesizes.append(os.path.getsize(f) / gr.sizeof_int) + max_nsamples = min(filesizes) + + tb = gr_time_plot_f(filelist, options.sample_rate, + options.start, nsamples, max_nsamples, + options.scale); + + main_box = dialog_box(tb, 'GNU Radio Time Plot') + main_box.show() + + tb.run() + tb.qapp.exec_() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass + diff --git a/gr-qtgui/apps/gr_time_plot_s b/gr-qtgui/apps/gr_time_plot_s new file mode 100755 index 0000000000..ef490be382 --- /dev/null +++ b/gr-qtgui/apps/gr_time_plot_s @@ -0,0 +1,168 @@ +#!/usr/bin/env python +# +# Copyright 2012 Free Software Foundation, Inc. +# +# This file is part of GNU Radio +# +# GNU Radio is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3, or (at your option) +# any later version. +# +# GNU Radio is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with GNU Radio; see the file COPYING. If not, write to +# the Free Software Foundation, Inc., 51 Franklin Street, +# Boston, MA 02110-1301, USA. +# + +from gnuradio import gr +from gnuradio.eng_option import eng_option +from optparse import OptionParser +import os, sys + +try: + from gnuradio import qtgui + from PyQt4 import QtGui, QtCore + import sip +except ImportError: + print "Error: Program requires PyQt4 and gr-qtgui." + sys.exit(1) + +try: + import scipy +except ImportError: + print "Error: Scipy required (www.scipy.org)." + sys.exit(1) + +from plot_form import * + +def read_samples(filename, start, in_size): + # Read in_size number of samples from file + fhandle = open(filename, 'r') + fhandle.seek(start*gr.sizeof_short, 0) + data = scipy.fromfile(fhandle, dtype=scipy.int16, count=in_size) + data = data.tolist() + fhandle.close() + + if(len(data) < in_size): + print "Warning: read in {0} samples but asked for {1} samples.".format( + len(data), in_size) + + return data + +class gr_time_plot_f(gr.top_block): + def __init__(self, filelist, samp_rate, start, nsamples, max_nsamples, scale): + gr.top_block.__init__(self) + + self._filelist = filelist + self._samp_rate = samp_rate + self._start = start + self._max_nsamps = max_nsamples + self._scale = scale + self._nsigs = len(self._filelist) + + if(nsamples is None): + self._nsamps = max_nsamples + else: + self._nsamps = nsamples + + self.qapp = QtGui.QApplication(sys.argv) + + self.skip = gr.skiphead(gr.sizeof_float, self._start) + self.gui_snk = qtgui.time_sink_f(self._nsamps, self._samp_rate, + "GNU Radio Time Plot", self._nsigs) + n = 0 + self.srcs = list() + self.cnvrt = list() + for f in filelist: + data = read_samples(f, self._start, self._nsamps) + self.srcs.append(gr.vector_source_s(data)) + self.cnvrt.append(gr.short_to_float(1, self._scale)) + + # Set default labels based on file names + self.gui_snk.set_title(n, "{0}".format(f)) + n += 1 + + self.connect(self.srcs[0], self.cnvrt[0], self.skip) + self.connect(self.skip, (self.gui_snk, 0)) + + for i,s in enumerate(self.srcs[1:]): + self.connect(s, self.cnvrt[i], (self.gui_snk, i+1)) + + self.gui_snk.set_update_time(0); + + # Get Python Qt references + pyQt = self.gui_snk.pyqwidget() + self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget) + + def get_gui(self): + return self.pyWin + + def reset(self, newstart, newnsamps): + self.stop() + self.wait() + + self._start = newstart + + for s,f in zip(self.srcs, self._filelist): + data = read_samples(f, self._start, newnsamps) + s.set_data(data) + if(len(data) < newnsamps): + newnsamps = len(data) + + self._nsamps = newnsamps + self.gui_snk.set_nsamps(self._nsamps) + + self.start() + +def main(): + description = "Plots a list of files on a scope plot. Files are a binary list of shorts." + parser = OptionParser(option_class=eng_option, description=description, + conflict_handler="resolve") + parser.add_option("-N", "--nsamples", type="int", default=None, + help="Set the number of samples to display [default=prints entire file]") + parser.add_option("-S", "--start", type="int", default=0, + help="Starting sample number [default=%default]") + parser.add_option("-r", "--sample-rate", type="eng_float", default=1.0, + help="Set the sample rate of the signal [default=%default]") + parser.add_option("-s", "--scale", type="eng_float", default=2**(16-1)-1, + help="Set a scaling factor for the short->float conversion [default=%default]") + (options, args) = parser.parse_args() + + if(len(args) < 1): + parser.print_help() + sys.exit(0) + + filelist = list(args) + + nsamples = options.nsamples + + # Find the smallest number of samples in all files and use that as + # a maximum value possible. + filesizes = [] + for f in filelist: + if(os.path.exists(f)): + filesizes.append(os.path.getsize(f) / gr.sizeof_short) + max_nsamples = min(filesizes) + + tb = gr_time_plot_f(filelist, options.sample_rate, + options.start, nsamples, max_nsamples, + options.scale); + + main_box = dialog_box(tb, 'GNU Radio Time Plot') + main_box.show() + + tb.run() + tb.qapp.exec_() + +if __name__ == "__main__": + try: + main() + except KeyboardInterrupt: + pass + |