aboutsummaryrefslogtreecommitdiffstats
path: root/op25/gr-op25_repeater/apps/gr_gnuplot.py
diff options
context:
space:
mode:
authorMax <ikj1234i@yahoo.com>2017-05-10 09:45:34 -0400
committerMax <ikj1234i@yahoo.com>2017-05-10 09:45:34 -0400
commit8f7932224451db4e8aeee5291e78c2ffb69cb353 (patch)
treef7e8a9a79d99262b0d86ec2b99f6ba59a3b88b02 /op25/gr-op25_repeater/apps/gr_gnuplot.py
parent8c98a8be5215db0a6e4c7e23059ef76aff8d55ba (diff)
add fft and catch exceptions
Diffstat (limited to 'op25/gr-op25_repeater/apps/gr_gnuplot.py')
-rw-r--r--op25/gr-op25_repeater/apps/gr_gnuplot.py50
1 files changed, 42 insertions, 8 deletions
diff --git a/op25/gr-op25_repeater/apps/gr_gnuplot.py b/op25/gr-op25_repeater/apps/gr_gnuplot.py
index 168941e..f4e4942 100644
--- a/op25/gr-op25_repeater/apps/gr_gnuplot.py
+++ b/op25/gr-op25_repeater/apps/gr_gnuplot.py
@@ -36,9 +36,11 @@ GNUPLOT = '/usr/bin/gnuplot'
class wrap_gp(object):
def __init__(self, sps=_def_sps):
self.sps = sps
+ self.center_freq = None
+ self.width = None
+ self.buf = []
self.attach_gp()
- self.buf = []
def attach_gp(self):
args = (GNUPLOT, '-noraise')
@@ -80,29 +82,51 @@ class wrap_gp(object):
self.buf = []
plots.append('"-" with dots')
elif mode == 'fft':
- ffbuf = np.fft.fft(self.buf)
- for b in ffbuf:
- s += '%f\n' % (b.real**2 + b.imag**2)
+ ffbuf = np.fft.fft(self.buf * np.blackman(BUFSZ)) / (0.42 * BUFSZ)
+ ffbuf = np.fft.fftshift(ffbuf)
+ for i in xrange(len(ffbuf)):
+ if self.center_freq and self.width:
+ f = (self.center_freq - self.width / 2.0) / 1e6
+ w = self.width / 1e6
+ s += '%f\t%f\n' % (f + i*(w/BUFSZ), 20 * np.log10(np.abs(ffbuf[i])))
+ else:
+ s += '%f\n' % (20 * np.log10(np.abs(ffbuf[i])))
s += 'e\n'
self.buf = []
plots.append('"-" with lines')
self.buf = []
h= 'set terminal x11 noraise\n'
- h+= 'set size square\n'
- h += 'set object 1 rectangle from screen 0,0 to screen 1,1 fillcolor rgb"black"\n'
+ background = 'set object 1 circle from screen 0,0 to screen 1,1 fillcolor rgb"black"\n'
h+= 'set key off\n'
if mode == 'constellation':
+ h += background
+ h+= 'set size square\n'
h+= 'set xrange [-1:1]\n'
h+= 'set yrange [-1:1]\n'
elif mode == 'eye':
+ h += background
h+= 'set yrange [-4:4]\n'
elif mode == 'symbol':
+ h += background
h+= 'set yrange [-4:4]\n'
+ elif mode == 'fft':
+ h+= 'set yrange [-100:0]\n'
+ h+= 'set grid\n'
+ if self.center_freq:
+ h += 'set title "%f"\n' % (self.center_freq / 1e6)
dat = '%splot %s\n%s' % (h, ','.join(plots), s)
self.gp.stdin.write(dat)
return consumed
+ def set_center_freq(self, f):
+ sys.stderr.write('set_center_freq: %s\n' % f)
+ self.center_freq = f
+
+ def set_width(self, w):
+ sys.stderr.write('set_width: %f\n' % w)
+ self.width = w
+
class eye_sink_f(gr.sync_block):
"""
"""
@@ -152,15 +176,25 @@ class fft_sink_c(gr.sync_block):
out_sig=None)
self.debug = debug
self.gnuplot = wrap_gp()
+ self.skip = 0
def work(self, input_items, output_items):
- in0 = input_items[0]
- self.gnuplot.plot(in0, 512, mode='fft')
+ self.skip += 1
+ if self.skip == 50:
+ self.skip = 0
+ in0 = input_items[0]
+ self.gnuplot.plot(in0, 512, mode='fft')
return len(input_items[0])
def kill(self):
self.gnuplot.kill()
+ def set_center_freq(self, f):
+ self.gnuplot.set_center_freq(f)
+
+ def set_width(self, w):
+ self.gnuplot.set_width(w)
+
class symbol_sink_f(gr.sync_block):
"""
"""