Changeset 7528

Show
Ignore:
Timestamp:
01/30/08 04:36:39
Author:
trondeau
Message:

Updating and cleaning up plotting code. When plotting char/int/short/float you can now specify multiple input files on the command line and each are plotted in a different color. Useful when comparing two outputs.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • gnuradio/trunk/gnuradio-core/src/utils/gr_plot_char.py

    r7324 r7528  
    11#!/usr/bin/env python 
    22# 
    3 # Copyright 2007 Free Software Foundation, Inc. 
     3# Copyright 2007,2008 Free Software Foundation, Inc. 
    44#  
    55# This file is part of GNU Radio 
     
    2222 
    2323import scipy 
    24 from pylab import * 
    2524from optparse import OptionParser 
    26  
    27 matplotlib.interactive(True) 
    28 matplotlib.use('TkAgg') 
    29  
    30 class draw_fft_c: 
    31     def __init__(self, filename, options): 
    32         self.hfile = open(filename, "r") 
    33         self.block_length = options.block 
    34         self.start = options.start 
    35         self.sample_rate = options.sample_rate 
    36  
    37         self.axis_font_size = 16 
    38         self.label_font_size = 18 
    39         self.title_font_size = 20 
    40         self.text_size = 22 
    41  
    42         # Setup PLOT 
    43         self.fig = figure(1, figsize=(16, 9), facecolor='w') 
    44         rcParams['xtick.labelsize'] = self.axis_font_size 
    45         rcParams['ytick.labelsize'] = self.axis_font_size 
    46          
    47         self.text_file     = figtext(0.10, 0.94, ("File: %s" % filename), weight="heavy", size=self.text_size) 
    48         self.text_file_pos = figtext(0.10, 0.88, "File Position: ", weight="heavy", size=self.text_size) 
    49         self.text_block    = figtext(0.40, 0.88, ("Block Size: %d" % self.block_length), 
    50                                      weight="heavy", size=self.text_size) 
    51         self.text_sr       = figtext(0.60, 0.88, ("Sample Rate: %.2f" % self.sample_rate), 
    52                                      weight="heavy", size=self.text_size) 
    53         self.make_plots() 
    54  
    55         self.button_left_axes = self.fig.add_axes([0.45, 0.01, 0.05, 0.05], frameon=True) 
    56         self.button_left = Button(self.button_left_axes, "<") 
    57         self.button_left_callback = self.button_left.on_clicked(self.button_left_click) 
    58  
    59         self.button_right_axes = self.fig.add_axes([0.50, 0.01, 0.05, 0.05], frameon=True) 
    60         self.button_right = Button(self.button_right_axes, ">") 
    61         self.button_right_callback = self.button_right.on_clicked(self.button_right_click) 
    62  
    63         self.xlim = self.sp_f.get_xlim() 
    64  
    65         self.manager = get_current_fig_manager() 
    66         connect('key_press_event', self.click) 
    67         show() 
    68          
    69     def get_data(self): 
    70         self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell())) 
    71         f = scipy.fromfile(self.hfile, dtype=scipy.int8, count=self.block_length) 
    72         #print "Read in %d items" % len(self.f) 
    73         if(len(f) == 0): 
    74             print "End of File" 
    75         else: 
    76             self.f = f 
    77             self.time = [i*(1/self.sample_rate) for i in range(len(self.f))] 
    78          
    79     def make_plots(self): 
    80         # if specified on the command-line, set file pointer 
    81         self.hfile.seek(8*self.start, 1) 
    82  
    83         self.get_data() 
    84          
    85         # Subplot for real and imaginary parts of signal 
    86         self.sp_f = self.fig.add_subplot(2,1,1, position=[0.075, 0.2, 0.875, 0.6]) 
    87         self.sp_f.set_title(("Amplitude"), fontsize=self.title_font_size, fontweight="bold") 
    88         self.sp_f.set_xlabel("Time (s)", fontsize=self.label_font_size, fontweight="bold") 
    89         self.sp_f.set_ylabel("Amplitude (V)", fontsize=self.label_font_size, fontweight="bold") 
    90         self.plot_f = plot(self.time, self.f, 'bo-') 
    91         self.sp_f.set_ylim([1.5*min(self.f), 
    92                             1.5*max(self.f)]) 
    93  
    94         draw() 
    95  
    96     def update_plots(self): 
    97         self.plot_f[0].set_data([self.time, self.f]) 
    98         self.sp_f.set_ylim([1.5*min(self.f), 
    99                             1.5*max(self.f)]) 
    100         draw() 
    101          
    102     def click(self, event): 
    103         forward_valid_keys = [" ", "down", "right"] 
    104         backward_valid_keys = ["up", "left"] 
    105  
    106         if(find(event.key, forward_valid_keys)): 
    107             self.step_forward() 
    108              
    109         elif(find(event.key, backward_valid_keys)): 
    110             self.step_backward() 
    111  
    112     def button_left_click(self, event): 
    113         self.step_backward() 
    114  
    115     def button_right_click(self, event): 
    116         self.step_forward() 
    117  
    118     def step_forward(self): 
    119         self.get_data() 
    120         self.update_plots() 
    121  
    122     def step_backward(self): 
    123         # Step back in file position 
    124         if(self.hfile.tell() >= 2*self.block_length ): 
    125             self.hfile.seek(-2*self.block_length, 1) 
    126         else: 
    127             self.hfile.seek(-self.hfile.tell(),1) 
    128         self.get_data() 
    129         self.update_plots() 
    130          
    131              
    132  
    133 #FIXME: there must be a way to do this with a Python builtin 
    134 def find(item_in, list_search): 
    135     for l in list_search: 
    136         if item_in == l: 
    137             return True 
    138     return False 
     25from gr_plot_data import plot_data 
    13926 
    14027def main(): 
    141     usage="%prog: [options] input_filename
    142     description = "Takes a GNU Radio floating point binary file and displays the samples versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." 
     28    usage="%prog: [options] input_filenames
     29    description = "Takes a GNU Radio byte/char binary file and displays the samples versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." 
    14330 
    14431    parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) 
     
    15138     
    15239    (options, args) = parser.parse_args () 
    153     if len(args) != 1: 
     40    if len(args) < 1: 
    15441        parser.print_help() 
    15542        raise SystemExit, 1 
    156     filename = args[0] 
     43    filenames = args 
    15744 
    158     dc = draw_fft_c(filename, options) 
     45    datatype=scipy.int8 
     46    dc = plot_data(datatype, filenames, options) 
    15947 
    16048if __name__ == "__main__": 
  • gnuradio/trunk/gnuradio-core/src/utils/gr_plot_const.py

    r7324 r7528  
    3636        self.sample_rate = options.sample_rate 
    3737 
     38        self.datatype = scipy.complex64 
     39        self.sizeof_data = self.datatype().nbytes    # number of bytes per sample in file 
     40 
    3841        self.axis_font_size = 16 
    3942        self.label_font_size = 18 
     
    6972 
    7073    def get_data(self): 
    71         self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//8)) 
    72         iq = scipy.fromfile(self.hfile, dtype=scipy.complex64, count=self.block_length) 
     74        self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//self.sizeof_data)) 
     75        iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) 
    7376        #print "Read in %d items" % len(iq) 
    7477        if(len(iq) == 0): 
     
    8285    def make_plots(self): 
    8386        # if specified on the command-line, set file pointer 
    84         self.hfile.seek(16*self.start, 1) 
     87        self.hfile.seek(self.sizeof_data*self.start, 1) 
    8588 
    8689        self.get_data() 
     
    151154    def step_backward(self): 
    152155        # Step back in file position 
    153         if(self.hfile.tell() >= 16*self.block_length ): 
    154             self.hfile.seek(-16*self.block_length, 1) 
     156        if(self.hfile.tell() >= 2*self.sizeof_data*self.block_length ): 
     157            self.hfile.seek(-2*self.sizeof_data*self.block_length, 1) 
    155158        else: 
    156159            self.hfile.seek(-self.hfile.tell(),1) 
  • gnuradio/trunk/gnuradio-core/src/utils/gr_plot_fft_c.py

    r7324 r7528  
    3636        self.start = options.start 
    3737        self.sample_rate = options.sample_rate 
     38 
     39        self.datatype = scipy.complex64 
     40        self.sizeof_data = self.datatype().nbytes    # number of bytes per sample in file 
    3841 
    3942        self.axis_font_size = 16 
     
    7174         
    7275    def get_data(self): 
    73         self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//8)) 
    74         self.iq = scipy.fromfile(self.hfile, dtype=scipy.complex64, count=self.block_length) 
     76        self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//self.sizeof_data)) 
     77        self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) 
    7578        #print "Read in %d items" % len(self.iq) 
    7679        if(len(self.iq) == 0): 
     
    101104    def make_plots(self): 
    102105        # if specified on the command-line, set file pointer 
    103         self.hfile.seek(16*self.start, 1) 
     106        self.hfile.seek(self.sizeof_data*self.start, 1) 
    104107 
    105108        self.get_data() 
     
    176179    def step_backward(self): 
    177180        # Step back in file position 
    178         if(self.hfile.tell() >= 16*self.block_length ): 
    179             self.hfile.seek(-16*self.block_length, 1) 
     181        if(self.hfile.tell() >= 2*self.sizeof_data*self.block_length ): 
     182            self.hfile.seek(-2*self.sizeof_data*self.block_length, 1) 
    180183        else: 
    181184            self.hfile.seek(-self.hfile.tell(),1) 
  • gnuradio/trunk/gnuradio-core/src/utils/gr_plot_fft_f.py

    r7324 r7528  
    3636        self.start = options.start 
    3737        self.sample_rate = options.sample_rate 
     38 
     39        self.datatype = scipy.float32 
     40        self.sizeof_data = self.datatype().nbytes    # number of bytes per sample in file 
    3841 
    3942        self.axis_font_size = 16 
     
    7174         
    7275    def get_data(self): 
    73         self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//4)) 
    74         self.floats = scipy.fromfile(self.hfile, dtype=scipy.float32, count=self.block_length) 
     76        self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//self.sizeof_data)) 
     77        self.floats = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) 
    7578        #print "Read in %d items" % len(self.floats) 
    7679        if(len(self.floats) == 0): 
     
    104107    def make_plots(self): 
    105108        # if specified on the command-line, set file pointer 
    106         self.hfile.seek(16*self.start, 1) 
     109        self.hfile.seek(self.sizeof_data*self.start, 1) 
    107110 
    108111        self.get_data() 
     
    178181    def step_backward(self): 
    179182        # Step back in file position 
    180         if(self.hfile.tell() >= 8*self.block_length ): 
    181             self.hfile.seek(-8*self.block_length, 1) 
     183        if(self.hfile.tell() >= 2*self.sizeof_data*self.block_length ): 
     184            self.hfile.seek(-2*self.sizeof_data*self.block_length, 1) 
    182185        else: 
    183186            self.hfile.seek(-self.hfile.tell(),1) 
  • gnuradio/trunk/gnuradio-core/src/utils/gr_plot_float.py

    r7324 r7528  
    11#!/usr/bin/env python 
    22# 
    3 # Copyright 2007 Free Software Foundation, Inc. 
     3# Copyright 2007,2008 Free Software Foundation, Inc. 
    44#  
    55# This file is part of GNU Radio 
     
    2222 
    2323import scipy 
    24 from pylab import * 
    2524from optparse import OptionParser 
    26  
    27 matplotlib.interactive(True) 
    28 matplotlib.use('TkAgg') 
    29  
    30 class draw_fft_c: 
    31     def __init__(self, filename, options): 
    32         self.hfile = open(filename, "r") 
    33         self.block_length = options.block 
    34         self.start = options.start 
    35         self.sample_rate = options.sample_rate 
    36  
    37         self.axis_font_size = 16 
    38         self.label_font_size = 18 
    39         self.title_font_size = 20 
    40         self.text_size = 22 
    41  
    42         # Setup PLOT 
    43         self.fig = figure(1, figsize=(16, 9), facecolor='w') 
    44         rcParams['xtick.labelsize'] = self.axis_font_size 
    45         rcParams['ytick.labelsize'] = self.axis_font_size 
    46          
    47         self.text_file     = figtext(0.10, 0.94, ("File: %s" % filename), weight="heavy", size=self.text_size) 
    48         self.text_file_pos = figtext(0.10, 0.88, "File Position: ", weight="heavy", size=self.text_size) 
    49         self.text_block    = figtext(0.40, 0.88, ("Block Size: %d" % self.block_length), 
    50                                      weight="heavy", size=self.text_size) 
    51         self.text_sr       = figtext(0.60, 0.88, ("Sample Rate: %.2f" % self.sample_rate), 
    52                                      weight="heavy", size=self.text_size) 
    53         self.make_plots() 
    54  
    55         self.button_left_axes = self.fig.add_axes([0.45, 0.01, 0.05, 0.05], frameon=True) 
    56         self.button_left = Button(self.button_left_axes, "<") 
    57         self.button_left_callback = self.button_left.on_clicked(self.button_left_click) 
    58  
    59         self.button_right_axes = self.fig.add_axes([0.50, 0.01, 0.05, 0.05], frameon=True) 
    60         self.button_right = Button(self.button_right_axes, ">") 
    61         self.button_right_callback = self.button_right.on_clicked(self.button_right_click) 
    62  
    63         self.xlim = self.sp_f.get_xlim() 
    64  
    65         self.manager = get_current_fig_manager() 
    66         connect('key_press_event', self.click) 
    67         show() 
    68          
    69     def get_data(self): 
    70         self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//4)) 
    71         f = scipy.fromfile(self.hfile, dtype=scipy.float32, count=self.block_length) 
    72         #print "Read in %d items" % len(self.f) 
    73         if(len(f) == 0): 
    74             print "End of File" 
    75         else: 
    76             self.f = f 
    77             self.time = [i*(1/self.sample_rate) for i in range(len(self.f))] 
    78          
    79     def make_plots(self): 
    80         # if specified on the command-line, set file pointer 
    81         self.hfile.seek(8*self.start, 1) 
    82  
    83         self.get_data() 
    84          
    85         # Subplot for real and imaginary parts of signal 
    86         self.sp_f = self.fig.add_subplot(2,1,1, position=[0.075, 0.2, 0.875, 0.6]) 
    87         self.sp_f.set_title(("Amplitude"), fontsize=self.title_font_size, fontweight="bold") 
    88         self.sp_f.set_xlabel("Time (s)", fontsize=self.label_font_size, fontweight="bold") 
    89         self.sp_f.set_ylabel("Amplitude (V)", fontsize=self.label_font_size, fontweight="bold") 
    90         self.plot_f = plot(self.time, self.f, 'bo-') 
    91         self.sp_f.set_ylim([1.5*min(self.f), 
    92                             1.5*max(self.f)]) 
    93  
    94         draw() 
    95  
    96     def update_plots(self): 
    97         self.plot_f[0].set_data([self.time, self.f]) 
    98         self.sp_f.set_ylim([1.5*min(self.f), 
    99                             1.5*max(self.f)]) 
    100         draw() 
    101          
    102     def click(self, event): 
    103         forward_valid_keys = [" ", "down", "right"] 
    104         backward_valid_keys = ["up", "left"] 
    105  
    106         if(find(event.key, forward_valid_keys)): 
    107             self.step_forward() 
    108              
    109         elif(find(event.key, backward_valid_keys)): 
    110             self.step_backward() 
    111  
    112     def button_left_click(self, event): 
    113         self.step_backward() 
    114  
    115     def button_right_click(self, event): 
    116         self.step_forward() 
    117  
    118     def step_forward(self): 
    119         self.get_data() 
    120         self.update_plots() 
    121  
    122     def step_backward(self): 
    123         # Step back in file position 
    124         if(self.hfile.tell() >= 8*self.block_length ): 
    125             self.hfile.seek(-8*self.block_length, 1) 
    126         else: 
    127             self.hfile.seek(-self.hfile.tell(),1) 
    128         self.get_data() 
    129         self.update_plots() 
    130          
    131              
    132  
    133 #FIXME: there must be a way to do this with a Python builtin 
    134 def find(item_in, list_search): 
    135     for l in list_search: 
    136         if item_in == l: 
    137             return True 
    138     return False 
     25from gr_plot_data import plot_data 
    13926 
    14027def main(): 
    141     usage="%prog: [options] input_filename
     28    usage="%prog: [options] input_filenames
    14229    description = "Takes a GNU Radio floating point binary file and displays the samples versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." 
    14330 
     
    15138     
    15239    (options, args) = parser.parse_args () 
    153     if len(args) != 1: 
     40    if len(args) < 1: 
    15441        parser.print_help() 
    15542        raise SystemExit, 1 
    156     filename = args[0] 
     43    filenames = args 
    15744 
    158     dc = draw_fft_c(filename, options) 
     45    datatype=scipy.float32 
     46    dc = plot_data(datatype, filenames, options) 
    15947 
    16048if __name__ == "__main__": 
  • gnuradio/trunk/gnuradio-core/src/utils/gr_plot_int.py

    r7324 r7528  
    11#!/usr/bin/env python 
    22# 
    3 # Copyright 2007 Free Software Foundation, Inc. 
     3# Copyright 2007,2008 Free Software Foundation, Inc. 
    44#  
    55# This file is part of GNU Radio 
     
    2222 
    2323import scipy 
    24 from pylab import * 
    2524from optparse import OptionParser 
    26  
    27 matplotlib.interactive(True) 
    28 matplotlib.use('TkAgg') 
    29  
    30 class draw_fft_c: 
    31     def __init__(self, filename, options): 
    32         self.hfile = open(filename, "r") 
    33         self.block_length = options.block 
    34         self.start = options.start 
    35         self.sample_rate = options.sample_rate 
    36  
    37         self.axis_font_size = 16 
    38         self.label_font_size = 18 
    39         self.title_font_size = 20 
    40         self.text_size = 22 
    41  
    42         # Setup PLOT 
    43         self.fig = figure(1, figsize=(16, 9), facecolor='w') 
    44         rcParams['xtick.labelsize'] = self.axis_font_size 
    45         rcParams['ytick.labelsize'] = self.axis_font_size 
    46          
    47         self.text_file     = figtext(0.10, 0.94, ("File: %s" % filename), weight="heavy", size=self.text_size) 
    48         self.text_file_pos = figtext(0.10, 0.88, "File Position: ", weight="heavy", size=self.text_size) 
    49         self.text_block    = figtext(0.40, 0.88, ("Block Size: %d" % self.block_length), 
    50                                      weight="heavy", size=self.text_size) 
    51         self.text_sr       = figtext(0.60, 0.88, ("Sample Rate: %.2f" % self.sample_rate), 
    52                                      weight="heavy", size=self.text_size) 
    53         self.make_plots() 
    54  
    55         self.button_left_axes = self.fig.add_axes([0.45, 0.01, 0.05, 0.05], frameon=True) 
    56         self.button_left = Button(self.button_left_axes, "<") 
    57         self.button_left_callback = self.button_left.on_clicked(self.button_left_click) 
    58  
    59         self.button_right_axes = self.fig.add_axes([0.50, 0.01, 0.05, 0.05], frameon=True) 
    60         self.button_right = Button(self.button_right_axes, ">") 
    61         self.button_right_callback = self.button_right.on_clicked(self.button_right_click) 
    62  
    63         self.xlim = self.sp_f.get_xlim() 
    64  
    65         self.manager = get_current_fig_manager() 
    66         connect('key_press_event', self.click) 
    67         show() 
    68          
    69     def get_data(self): 
    70         self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//4)) 
    71         f = scipy.fromfile(self.hfile, dtype=scipy.int32, count=self.block_length) 
    72         #print "Read in %d items" % len(self.f) 
    73         if(len(f) == 0): 
    74             print "End of File" 
    75         else: 
    76             self.f = f 
    77             self.time = [i*(1/self.sample_rate) for i in range(len(self.f))] 
    78          
    79     def make_plots(self): 
    80         # if specified on the command-line, set file pointer 
    81         self.hfile.seek(8*self.start, 1) 
    82  
    83         self.get_data() 
    84          
    85         # Subplot for real and imaginary parts of signal 
    86         self.sp_f = self.fig.add_subplot(2,1,1, position=[0.075, 0.2, 0.875, 0.6]) 
    87         self.sp_f.set_title(("Amplitude"), fontsize=self.title_font_size, fontweight="bold") 
    88         self.sp_f.set_xlabel("Time (s)", fontsize=self.label_font_size, fontweight="bold") 
    89         self.sp_f.set_ylabel("Amplitude (V)", fontsize=self.label_font_size, fontweight="bold") 
    90         self.plot_f = plot(self.time, self.f, 'bo-') 
    91         self.sp_f.set_ylim([1.5*min(self.f), 
    92                             1.5*max(self.f)]) 
    93  
    94         draw() 
    95  
    96     def update_plots(self): 
    97         self.plot_f[0].set_data([self.time, self.f]) 
    98         self.sp_f.set_ylim([1.5*min(self.f), 
    99                             1.5*max(self.f)]) 
    100         draw() 
    101          
    102     def click(self, event): 
    103         forward_valid_keys = [" ", "down", "right"] 
    104         backward_valid_keys = ["up", "left"] 
    105  
    106         if(find(event.key, forward_valid_keys)): 
    107             self.step_forward() 
    108              
    109         elif(find(event.key, backward_valid_keys)): 
    110             self.step_backward() 
    111  
    112     def button_left_click(self, event): 
    113         self.step_backward() 
    114  
    115     def button_right_click(self, event): 
    116         self.step_forward() 
    117  
    118     def step_forward(self): 
    119         self.get_data() 
    120         self.update_plots() 
    121  
    122     def step_backward(self): 
    123         # Step back in file position 
    124         if(self.hfile.tell() >= 8*self.block_length ): 
    125             self.hfile.seek(-8*self.block_length, 1) 
    126         else: 
    127             self.hfile.seek(-self.hfile.tell(),1) 
    128         self.get_data() 
    129         self.update_plots() 
    130          
    131              
    132  
    133 #FIXME: there must be a way to do this with a Python builtin 
    134 def find(item_in, list_search): 
    135     for l in list_search: 
    136         if item_in == l: 
    137             return True 
    138     return False 
     25from gr_plot_data import plot_data 
    13926 
    14027def main(): 
    141     usage="%prog: [options] input_filename
    142     description = "Takes a GNU Radio floating point binary file and displays the samples versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." 
     28    usage="%prog: [options] input_filenames
     29    description = "Takes a GNU Radio integer binary file and displays the samples versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." 
    14330 
    14431    parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) 
     
    15138     
    15239    (options, args) = parser.parse_args () 
    153     if len(args) != 1: 
     40    if len(args) < 1: 
    15441        parser.print_help() 
    15542        raise SystemExit, 1 
    156     filename = args[0] 
     43    filenames = args 
    15744 
    158     dc = draw_fft_c(filename, options) 
     45    datatype=scipy.int32 
     46    dc = plot_data(datatype, filenames, options) 
    15947 
    16048if __name__ == "__main__": 
  • gnuradio/trunk/gnuradio-core/src/utils/gr_plot_iq.py

    r7324 r7528  
    3535        self.sample_rate = options.sample_rate 
    3636 
     37        self.datatype = scipy.complex64 
     38        self.sizeof_data = self.datatype().nbytes    # number of bytes per sample in file 
     39 
    3740        self.axis_font_size = 16 
    3841        self.label_font_size = 18 
     
    6871 
    6972    def get_data(self): 
    70         self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//8)) 
    71         self.iq = scipy.fromfile(self.hfile, dtype=scipy.complex64, count=self.block_length) 
     73        self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//self.sizeof_data)) 
     74        self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length) 
    7275        #print "Read in %d items" % len(self.iq) 
    7376        if(len(self.iq) == 0): 
     
    8083    def make_plots(self): 
    8184        # if specified on the command-line, set file pointer 
    82         self.hfile.seek(16*self.start, 1) 
     85        self.hfile.seek(self.sizeof_data*self.start, 1) 
    8386 
    8487        self.get_data() 
     
    124127    def step_backward(self): 
    125128        # Step back in file position 
    126         if(self.hfile.tell() >= 16*self.block_length ): 
    127             self.hfile.seek(-16*self.block_length, 1) 
     129        if(self.hfile.tell() >= 2*self.sizeof_data*self.block_length ): 
     130            self.hfile.seek(-2*self.sizeof_data*self.block_length, 1) 
    128131        else: 
    129132            self.hfile.seek(-self.hfile.tell(),1) 
  • gnuradio/trunk/gnuradio-core/src/utils/gr_plot_short.py

    r7324 r7528  
    11#!/usr/bin/env python 
    22# 
    3 # Copyright 2007 Free Software Foundation, Inc. 
     3# Copyright 2007,2008 Free Software Foundation, Inc. 
    44#  
    55# This file is part of GNU Radio 
     
    2222 
    2323import scipy 
    24 from pylab import * 
    2524from optparse import OptionParser 
    26  
    27 matplotlib.interactive(True) 
    28 matplotlib.use('TkAgg') 
    29  
    30 class draw_fft_c: 
    31     def __init__(self, filename, options): 
    32         self.hfile = open(filename, "r") 
    33         self.block_length = options.block 
    34         self.start = options.start 
    35         self.sample_rate = options.sample_rate 
    36  
    37         self.axis_font_size = 16 
    38         self.label_font_size = 18 
    39         self.title_font_size = 20 
    40         self.text_size = 22 
    41  
    42         # Setup PLOT 
    43         self.fig = figure(1, figsize=(16, 9), facecolor='w') 
    44         rcParams['xtick.labelsize'] = self.axis_font_size 
    45         rcParams['ytick.labelsize'] = self.axis_font_size 
    46          
    47         self.text_file     = figtext(0.10, 0.94, ("File: %s" % filename), weight="heavy", size=self.text_size) 
    48         self.text_file_pos = figtext(0.10, 0.88, "File Position: ", weight="heavy", size=self.text_size) 
    49         self.text_block    = figtext(0.40, 0.88, ("Block Size: %d" % self.block_length), 
    50                                      weight="heavy", size=self.text_size) 
    51         self.text_sr       = figtext(0.60, 0.88, ("Sample Rate: %.2f" % self.sample_rate), 
    52                                      weight="heavy", size=self.text_size) 
    53         self.make_plots() 
    54  
    55         self.button_left_axes = self.fig.add_axes([0.45, 0.01, 0.05, 0.05], frameon=True) 
    56         self.button_left = Button(self.button_left_axes, "<") 
    57         self.button_left_callback = self.button_left.on_clicked(self.button_left_click) 
    58  
    59         self.button_right_axes = self.fig.add_axes([0.50, 0.01, 0.05, 0.05], frameon=True) 
    60         self.button_right = Button(self.button_right_axes, ">") 
    61         self.button_right_callback = self.button_right.on_clicked(self.button_right_click) 
    62  
    63         self.xlim = self.sp_f.get_xlim() 
    64  
    65         self.manager = get_current_fig_manager() 
    66         connect('key_press_event', self.click) 
    67         show() 
    68          
    69     def get_data(self): 
    70         self.text_file_pos.set_text("File Position: %d" % (self.hfile.tell()//2)) 
    71         f = scipy.fromfile(self.hfile, dtype=scipy.int16, count=self.block_length) 
    72         #print "Read in %d items" % len(self.f) 
    73         if(len(f) == 0): 
    74             print "End of File" 
    75         else: 
    76             self.f = f 
    77             self.time = [i*(1/self.sample_rate) for i in range(len(self.f))] 
    78          
    79     def make_plots(self): 
    80         # if specified on the command-line, set file pointer 
    81         self.hfile.seek(8*self.start, 1) 
    82  
    83         self.get_data() 
    84          
    85         # Subplot for real and imaginary parts of signal 
    86         self.sp_f = self.fig.add_subplot(2,1,1, position=[0.075, 0.2, 0.875, 0.6]) 
    87         self.sp_f.set_title(("Amplitude"), fontsize=self.title_font_size, fontweight="bold") 
    88         self.sp_f.set_xlabel("Time (s)", fontsize=self.label_font_size, fontweight="bold") 
    89         self.sp_f.set_ylabel("Amplitude (V)", fontsize=self.label_font_size, fontweight="bold") 
    90         self.plot_f = plot(self.time, self.f, 'bo-') 
    91         self.sp_f.set_ylim([1.5*min(self.f), 
    92                             1.5*max(self.f)]) 
    93  
    94         draw() 
    95  
    96     def update_plots(self): 
    97         self.plot_f[0].set_data([self.time, self.f]) 
    98         self.sp_f.set_ylim([1.5*min(self.f), 
    99                             1.5*max(self.f)]) 
    100         draw() 
    101          
    102     def click(self, event): 
    103         forward_valid_keys = [" ", "down", "right"] 
    104         backward_valid_keys = ["up", "left"] 
    105  
    106         if(find(event.key, forward_valid_keys)): 
    107             self.step_forward() 
    108              
    109         elif(find(event.key, backward_valid_keys)): 
    110             self.step_backward() 
    111  
    112     def button_left_click(self, event): 
    113         self.step_backward() 
    114  
    115     def button_right_click(self, event): 
    116         self.step_forward() 
    117  
    118     def step_forward(self): 
    119         self.get_data() 
    120         self.update_plots() 
    121  
    122     def step_backward(self): 
    123         # Step back in file position 
    124         if(self.hfile.tell() >= 4*self.block_length ): 
    125             self.hfile.seek(-4*self.block_length, 1) 
    126         else: 
    127             self.hfile.seek(-self.hfile.tell(),1) 
    128         self.get_data() 
    129         self.update_plots() 
    130          
    131              
    132  
    133 #FIXME: there must be a way to do this with a Python builtin 
    134 def find(item_in, list_search): 
    135     for l in list_search: 
    136         if item_in == l: 
    137             return True 
    138     return False 
     25from gr_plot_data import plot_data 
    13926 
    14027def main(): 
    141     usage="%prog: [options] input_filename
    142     description = "Takes a GNU Radio floating point binary file and displays the samples versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." 
     28    usage="%prog: [options] input_filenames
     29    description = "Takes a GNU Radio short integer binary file and displays the samples versus time. You can set the block size to specify how many points to read in at a time and the start position in the file. By default, the system assumes a sample rate of 1, so in time, each sample is plotted versus the sample number. To set a true time axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples." 
    14330 
    14431    parser = OptionParser(conflict_handler="resolve", usage=usage, description=description) 
     
    15138     
    15239    (options, args) = parser.parse_args () 
    153     if len(args) != 1: 
     40    if len(args) < 1: 
    15441        parser.print_help() 
    15542        raise SystemExit, 1 
    156     filename = args[0] 
     43    filenames = args 
    15744 
    158     dc = draw_fft_c(filename, options) 
     45    datatype=scipy.int16 
     46    dc = plot_data(datatype, filenames, options) 
    15947 
    16048if __name__ == "__main__":