summaryrefslogtreecommitdiff
path: root/gr-utils/src/python/gr_plot_psd.py
diff options
context:
space:
mode:
authorTom Rondeau2011-06-05 15:36:47 -0400
committerTom Rondeau2011-06-05 15:36:47 -0400
commit233f960474f86bc8cc519ce7257b29d8615c4000 (patch)
tree1a4c846119a01a5a195a9e9ee5b854384b0b6535 /gr-utils/src/python/gr_plot_psd.py
parent024c79a7fb13c08bae7b97079a245f711ecf12a7 (diff)
parenta23a0a46c3bf446cbe09d71bc8e10b061256ef56 (diff)
downloadgnuradio-233f960474f86bc8cc519ce7257b29d8615c4000.tar.gz
gnuradio-233f960474f86bc8cc519ce7257b29d8615c4000.tar.bz2
gnuradio-233f960474f86bc8cc519ce7257b29d8615c4000.zip
Merge branch 'master' into turbo
Diffstat (limited to 'gr-utils/src/python/gr_plot_psd.py')
-rwxr-xr-xgr-utils/src/python/gr_plot_psd.py50
1 files changed, 31 insertions, 19 deletions
diff --git a/gr-utils/src/python/gr_plot_psd.py b/gr-utils/src/python/gr_plot_psd.py
index e88995b72..3dab0535a 100755
--- a/gr-utils/src/python/gr_plot_psd.py
+++ b/gr-utils/src/python/gr_plot_psd.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python
#
-# Copyright 2007,2008,2011 Free Software Foundation, Inc.
+# Copyright 2007,2008,2010,2011 Free Software Foundation, Inc.
#
# This file is part of GNU Radio
#
@@ -35,6 +35,7 @@ except ImportError:
from optparse import OptionParser
from scipy import log10
+from gnuradio.eng_option import eng_option
class gr_plot_psd:
def __init__(self, datatype, filename, options):
@@ -92,21 +93,29 @@ class gr_plot_psd:
self.iq = scipy.fromfile(self.hfile, dtype=self.datatype, count=self.block_length)
except MemoryError:
print "End of File"
+ return False
else:
- tstep = 1.0 / self.sample_rate
- #self.time = scipy.array([tstep*(self.position + i) for i in xrange(len(self.iq))])
- self.time = scipy.array([tstep*(i) for i in xrange(len(self.iq))])
-
- self.iq_psd, self.freq = self.dopsd(self.iq)
+ # retesting length here as newer version of scipy does not throw a MemoryError, just
+ # returns a zero-length array
+ if(len(self.iq) > 0):
+ tstep = 1.0 / self.sample_rate
+ #self.time = scipy.array([tstep*(self.position + i) for i in xrange(len(self.iq))])
+ self.time = scipy.array([tstep*(i) for i in xrange(len(self.iq))])
+
+ self.iq_psd, self.freq = self.dopsd(self.iq)
+ return True
+ else:
+ print "End of File"
+ return False
def dopsd(self, iq):
''' Need to do this here and plot later so we can do the fftshift '''
overlap = self.psdfftsize/4
winfunc = scipy.blackman
- psd,freq = self.sp_psd.psd(iq, self.psdfftsize, self.sample_rate,
- window = lambda d: d*winfunc(self.psdfftsize),
- noverlap = overlap, visible=False)
- psd = 10.0*log10(abs(fftpack.fftshift(psd)))
+ psd,freq = mlab.psd(iq, self.psdfftsize, self.sample_rate,
+ window = lambda d: d*winfunc(self.psdfftsize),
+ noverlap = overlap)
+ psd = 10.0*log10(abs(psd))
return (psd, freq)
def make_plots(self):
@@ -129,7 +138,7 @@ class gr_plot_psd:
self.sp_psd.set_xlabel("Frequency (Hz)", fontsize=self.label_font_size, fontweight="bold")
self.sp_psd.set_ylabel("Power Spectrum (dBm)", fontsize=self.label_font_size, fontweight="bold")
- self.get_data()
+ r = self.get_data()
self.plot_iq = self.sp_iq.plot([], 'bo-') # make plot for reals
self.plot_iq += self.sp_iq.plot([], 'ro-') # make plot for imags
@@ -192,8 +201,8 @@ class gr_plot_psd:
xmin = max(0, int(ceil(self.sample_rate*(newxlim[0]))))
xmax = min(int(ceil(self.sample_rate*(newxlim[1]))), len(self.iq))
- iq = self.iq[xmin : xmax]
- time = self.time[xmin : xmax]
+ iq = scipy.array(self.iq[xmin : xmax])
+ time = scipy.array(self.time[xmin : xmax])
iq_psd, freq = self.dopsd(iq)
@@ -219,8 +228,9 @@ class gr_plot_psd:
self.step_forward()
def step_forward(self):
- self.get_data()
- self.update_plots()
+ r = self.get_data()
+ if(r):
+ self.update_plots()
def step_backward(self):
# Step back in file position
@@ -228,8 +238,9 @@ class gr_plot_psd:
self.hfile.seek(-2*self.sizeof_data*self.block_length, 1)
else:
self.hfile.seek(-self.hfile.tell(),1)
- self.get_data()
- self.update_plots()
+ r = self.get_data()
+ if(r):
+ self.update_plots()
def find(item_in, list_search):
try:
@@ -241,14 +252,15 @@ def setup_options():
usage="%prog: [options] input_filename"
description = "Takes a GNU Radio binary file (with specified data type using --data-type) and displays the I&Q data versus time as well as the power spectral density (PSD) plot. The y-axis values are plotted assuming volts as the amplitude of the I&Q streams and converted into dBm in the frequency domain (the 1/N power adjustment out of the FFT is performed internally). The script plots a certain block of data at a time, specified on the command line as -B or --block. The start position in the file can be set by specifying -s or --start and defaults to 0 (the start of 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 and frequency axis, set the sample rate (-R or --sample-rate) to the sample rate used when capturing the samples. Finally, the size of the FFT to use for the PSD and spectrogram plots can be set independently with --psd-size and --spec-size, respectively. The spectrogram plot does not display by default and is turned on with -S or --enable-spec."
- parser = OptionParser(conflict_handler="resolve", usage=usage, description=description)
+ parser = OptionParser(option_class=eng_option, conflict_handler="resolve",
+ usage=usage, description=description)
parser.add_option("-d", "--data-type", type="string", default="complex64",
help="Specify the data type (complex64, float32, (u)int32, (u)int16, (u)int8) [default=%default]")
parser.add_option("-B", "--block", type="int", default=8192,
help="Specify the block size [default=%default]")
parser.add_option("-s", "--start", type="int", default=0,
help="Specify where to start in the file [default=%default]")
- parser.add_option("-R", "--sample-rate", type="float", default=1.0,
+ parser.add_option("-R", "--sample-rate", type="eng_float", default=1.0,
help="Set the sampler rate of the data [default=%default]")
parser.add_option("", "--psd-size", type="int", default=1024,
help="Set the size of the PSD FFT [default=%default]")