[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Commit-gnuradio] r9270 - in gnuradio/branches/developers/jblum/glwxgui/
From: |
jblum |
Subject: |
[Commit-gnuradio] r9270 - in gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python: . plotter |
Date: |
Wed, 13 Aug 2008 19:27:15 -0600 (MDT) |
Author: jblum
Date: 2008-08-13 19:27:15 -0600 (Wed, 13 Aug 2008)
New Revision: 9270
Modified:
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/common.py
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/fft_window.py
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/plotter/channel_plotter.py
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/plotter/plotter_base.py
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/plotter/waterfall_plotter.py
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/scope_window.py
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/waterfall_window.py
Log:
common format functions, fft autoscale
Modified:
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/common.py
===================================================================
--- gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/common.py
2008-08-13 22:46:54 UTC (rev 9269)
+++ gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/common.py
2008-08-14 01:27:15 UTC (rev 9270)
@@ -254,3 +254,48 @@
min = mean - rms
max = mean + rms
return min, max
+
+def get_time_units(num):
+ """!
+ Get the best time units for the given number.
+ @param num a floating point number
+ @return a tuple of unit string, scalar
+ """
+ exp = get_exp(num)
+ if exp > -2: return 's', 1e0
+ elif exp > -5: return 'ms', 1e3
+ elif exp > -8: return 'us', 1e6
+ return 'ns', 1e9
+
+def get_freq_units(num):
+ """!
+ Get the best frequency units for the given number.
+ @param num a floating point number
+ @return a tuple of unit string, scalar
+ """
+ exp = get_exp(num)
+ if exp > 7: return 'GHz', 1e-9
+ elif exp > 4: return 'MHz', 1e-6
+ elif exp > 1: return 'KHz', 1e-3
+ return 'Hz', 1e-0
+
+def label_format(num):
+ """!
+ Format a floating point number into a presentable string.
+ Exponents should be a multiple of 3.
+ The base should be between 999 and -999.
+ @param num the number to format
+ @return a label string
+ """
+ if num == 0: return '0'
+ else: exp = get_exp(num)
+ exp_mod = exp%3
+ exp_dif = exp - exp_mod
+ base = num/10**exp_dif
+ if abs(exp) >= 3:
+ formatter = '%.3f'
+ num_str = '%se%d'%(formatter%base, exp_dif)
+ else: num_str = '%g'%num
+ return num_str
+
+if __name__ == '__main__': pass
Modified:
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/fft_window.py
===================================================================
---
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/fft_window.py
2008-08-13 22:46:54 UTC (rev 9269)
+++
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/fft_window.py
2008-08-14 01:27:15 UTC (rev 9270)
@@ -92,8 +92,12 @@
control_box.AddSpacer(2)
self._ref_lvl_buttons = common.IncrDecrButtons(self,
self._on_incr_ref_level, self._on_decr_ref_level)
control_box.Add(self._ref_lvl_buttons, 0, wx.ALIGN_CENTER)
+ #autoscale
+ control_box.AddStretchSpacer()
+ self.autoscale_button = wx.Button(self, label='Autoscale',
style=wx.BU_EXACTFIT)
+ self.autoscale_button.Bind(wx.EVT_BUTTON, self.parent.autoscale)
+ control_box.Add(self.autoscale_button, 0, wx.EXPAND)
#run/stop
- control_box.AddStretchSpacer()
self.run_button = common.ToggleButtonController(self, parent,
RUNNING_KEY, 'Stop', 'Run')
control_box.Add(self.run_button, 0, wx.EXPAND)
#set sizer
@@ -187,6 +191,23 @@
self.plotter.enable_legend(self[PEAK_HOLD_KEY])
self.update_grid()
+ def autoscale(self, *args):
+ """!
+ Autoscale the fft plot to the last frame.
+ Set the dynamic range and reference level.
+ """
+ #get the peak level (max of the samples)
+ peak_level = numpy.max(self.samples)
+ #get the noise floor (averge the smallest samples)
+ noise_floor =
numpy.average(numpy.sort(self.samples)[:len(self.samples)/2])
+ #padding
+ noise_floor -= abs(noise_floor)*.5
+ peak_level += abs(peak_level)*.1
+ #set the reference level to a multiple of y divs
+
self.set_ref_level(self[Y_DIVS_KEY]*math.ceil(peak_level/self[Y_DIVS_KEY]))
+ #set the range to a clean number of the dynamic range
+ self.set_y_per_div(common.get_clean_num((peak_level -
noise_floor)/self[Y_DIVS_KEY]))
+
def _reset_peak_vals(self): self.peak_vals = NO_PEAK_VALS
def handle_msg(self, msg):
@@ -205,6 +226,7 @@
#reorder fft
if self.real: samples = samples[:num_samps/2]
else: samples = numpy.concatenate((samples[num_samps/2:],
samples[:num_samps/2]))
+ self.samples = samples
#peak hold calculation
if self[PEAK_HOLD_KEY]:
if len(self.peak_vals) != len(samples): self.peak_vals
= samples
@@ -244,12 +266,7 @@
if self.real: x_width = sample_rate/2.0
else: x_width = sample_rate/1.0
x_per_div = common.get_clean_num(x_width/x_divs)
- exp = common.get_exp(x_per_div)
- #calculate units and scalar
- if exp > 7: x_units, scalar = 'GHz', 1e-9
- elif exp > 4: x_units, scalar = 'MHz', 1e-6
- elif exp > 1: x_units, scalar = 'KHz', 1e-3
- else: x_units, scalar = 'Hz', 1e-0
+ x_units, scalar = common.get_freq_units(x_per_div)
#update the x grid
if self.real:
self.plotter.set_x_grid(
Modified:
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/plotter/channel_plotter.py
===================================================================
---
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/plotter/channel_plotter.py
2008-08-13 22:46:54 UTC (rev 9269)
+++
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/plotter/channel_plotter.py
2008-08-14 01:27:15 UTC (rev 9270)
@@ -22,6 +22,7 @@
import wx
from plotter_base import grid_plotter_base
from OpenGL.GL import *
+from gnuradio.wxgui import common
import numpy
import gltext
import math
@@ -141,7 +142,13 @@
@return a string with newlines
"""
#create text
- label_str = '%s: %g %s\n%s: %g %s'%(self.x_label, x_val,
self.x_units, self.y_label, y_val, self.y_units)
+ label_str = '%s: %s %s\n%s: %s %s'%(
+ self.x_label,
+ common.label_format(x_val),
+ self.x_units, self.y_label,
+ common.label_format(y_val),
+ self.y_units,
+ )
for channel in sorted(self._channels.keys()):
samples = self._channels[channel][SAMPLES_KEY]
num_samps = len(samples)
@@ -152,7 +159,7 @@
x_index_low = int(math.floor(x_index))
x_index_high = int(math.ceil(x_index))
y_value = (samples[x_index_high] -
samples[x_index_low])*(x_index - x_index_low) + samples[x_index_low]
- label_str += '\n%s: %g %s'%(channel, y_value,
self.y_units)
+ label_str += '\n%s: %s %s'%(channel,
common.label_format(y_value), self.y_units)
return label_str
def _draw_legend(self):
Modified:
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/plotter/plotter_base.py
===================================================================
---
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/plotter/plotter_base.py
2008-08-13 22:46:54 UTC (rev 9269)
+++
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/plotter/plotter_base.py
2008-08-14 01:27:15 UTC (rev 9270)
@@ -22,6 +22,7 @@
import wx
import wx.glcanvas
from OpenGL.GL import *
+from gnuradio.wxgui import common
import threading
import gltext
import math
@@ -303,22 +304,11 @@
def _get_tick_label(self, tick):
"""!
- Format the tick value greate a gl text.
- Intelligently switch between decimal representations.
+ Format the tick value and create a gl text.
@param tick the floating point tick value
@return the tick label text
"""
- #format
- if tick == 0: exp = 0
- else: exp = int(math.floor(math.log10(abs(tick))))
- exp_mod = exp%3
- exp_dif = exp - exp_mod
- base = tick/10**exp_dif
- if abs(exp) >= 3:
- formatter = '%%.%df'%(2-exp_mod)
- tick_str = '%se%d'%(formatter%base, exp_dif)
- else: tick_str = '%g'%tick
- #text
+ tick_str = common.label_format(tick)
return gltext.Text(tick_str, font_size=TICK_TEXT_FONT_SIZE)
def _get_ticks(self, min, max, step, scalar):
@@ -395,5 +385,6 @@
w, h = txt.get_size()
#draw rect + text
glColor3f(*POINT_LABEL_COLOR_SPEC)
+ if x > self.width/2: x -= w+2*POINT_LABEL_PADDING
self._draw_rect(x, y-h-2*POINT_LABEL_PADDING,
w+2*POINT_LABEL_PADDING, h+2*POINT_LABEL_PADDING)
txt.draw_text(wx.Point(x+POINT_LABEL_PADDING,
y-h-POINT_LABEL_PADDING))
Modified:
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/plotter/waterfall_plotter.py
===================================================================
---
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/plotter/waterfall_plotter.py
2008-08-13 22:46:54 UTC (rev 9269)
+++
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/plotter/waterfall_plotter.py
2008-08-14 01:27:15 UTC (rev 9270)
@@ -22,6 +22,7 @@
import wx
from plotter_base import grid_plotter_base
from OpenGL.GL import *
+from gnuradio.wxgui import common
import numpy
import gltext
@@ -178,7 +179,7 @@
@param y_val the current y value
@return a value string with units
"""
- return '%s: %g %s'%(self.x_label, x_val, self.x_units)
+ return '%s: %s %s'%(self.x_label, common.label_format(x_val),
self.x_units)
def _draw_legend(self):
"""!
Modified:
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/scope_window.py
===================================================================
---
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/scope_window.py
2008-08-13 22:46:54 UTC (rev 9269)
+++
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/scope_window.py
2008-08-14 01:27:15 UTC (rev 9270)
@@ -464,10 +464,7 @@
else:
#update the t axis
exp = common.get_exp(t_per_div)
- if exp > -2: units, scalar = 's', 1e0
- elif exp > -5: units, scalar = 'ms', 1e3
- elif exp > -8: units, scalar = 'us', 1e6
- else: units, scalar = 'ns', 1e9
+ units, scalar = common.get_time_units(t_per_div)
self.plotter.set_x_label('Time', units)
self.plotter.set_x_grid(
t_off,
Modified:
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/waterfall_window.py
===================================================================
---
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/waterfall_window.py
2008-08-13 22:46:54 UTC (rev 9269)
+++
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/waterfall_window.py
2008-08-14 01:27:15 UTC (rev 9270)
@@ -227,7 +227,7 @@
noise_floor -= abs(noise_floor)*.5
peak_level += abs(peak_level)*.1
#set the range and level
- self.set_ref_level(noise_floor)
+ self.set_ref_level(peak_level)
self.set_dynamic_range(peak_level - noise_floor)
def handle_msg(self, msg):
@@ -248,8 +248,8 @@
#plot the fft
self.plotter.set_samples(
samples=samples,
- minimum=self[REF_LEVEL_KEY],
- maximum=self[DYNAMIC_RANGE_KEY] + self[REF_LEVEL_KEY],
+ minimum=self[REF_LEVEL_KEY] - self[DYNAMIC_RANGE_KEY],
+ maximum=self[REF_LEVEL_KEY],
)
#update the plotter
self.plotter.update()
@@ -273,12 +273,7 @@
if self.real: x_width = sample_rate/2.0
else: x_width = sample_rate/1.0
x_per_div = common.get_clean_num(x_width/x_divs)
- exp = common.get_exp(x_per_div)
- #calculate units and scalar
- if exp > 7: x_units, scalar = 'GHz', 1e-9
- elif exp > 4: x_units, scalar = 'MHz', 1e-6
- elif exp > 1: x_units, scalar = 'KHz', 1e-3
- else: x_units, scalar = 'Hz', 1e-0
+ x_units, scalar = common.get_freq_units(x_per_div)
#update the x grid
if self.real:
self.plotter.set_x_grid(
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Commit-gnuradio] r9270 - in gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python: . plotter,
jblum <=