commit-gnuradio
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Commit-gnuradio] r9207 - gnuradio/branches/features/experimental-gui


From: jblum
Subject: [Commit-gnuradio] r9207 - gnuradio/branches/features/experimental-gui
Date: Thu, 7 Aug 2008 18:11:47 -0600 (MDT)

Author: jblum
Date: 2008-08-07 18:11:45 -0600 (Thu, 07 Aug 2008)
New Revision: 9207

Modified:
   gnuradio/branches/features/experimental-gui/common.py
   gnuradio/branches/features/experimental-gui/waterfall_window.py
Log:
waterfall autoscale

Modified: gnuradio/branches/features/experimental-gui/common.py
===================================================================
--- gnuradio/branches/features/experimental-gui/common.py       2008-08-07 
21:15:37 UTC (rev 9206)
+++ gnuradio/branches/features/experimental-gui/common.py       2008-08-08 
00:11:45 UTC (rev 9207)
@@ -199,9 +199,12 @@
        @param num the number
        @return the closest number
        """
+       if num == 0: return 0
+       if num > 0: sign = 1
+       else: sign = -1
        exp = get_exp(num)
        nums = numpy.array((1, 2, 5, 10))*(10**exp)
-       return nums[numpy.argmin(numpy.abs(nums - num))]
+       return sign*nums[numpy.argmin(numpy.abs(nums - abs(num)))]
 
 def get_clean_incr(num):
        """!
@@ -211,8 +214,11 @@
        """
        num = get_clean_num(num)
        exp = get_exp(num)
-       base = int(num/10**exp)
+       base = int(round(num/10**exp))
        return {
+               -5: -2,
+               -2: -1,
+               -1: -.5,
                1: 2,
                2: 5,
                5: 10,
@@ -226,8 +232,11 @@
        """
        num = get_clean_num(num)
        exp = get_exp(num)
-       base = int(num/10**exp)
+       base = int(round(num/10**exp))
        return {
+               -5: -10,
+               -2: -5,
+               -1: -2,
                1: .5,
                2: 1,
                5: 2,

Modified: gnuradio/branches/features/experimental-gui/waterfall_window.py
===================================================================
--- gnuradio/branches/features/experimental-gui/waterfall_window.py     
2008-08-07 21:15:37 UTC (rev 9206)
+++ gnuradio/branches/features/experimental-gui/waterfall_window.py     
2008-08-08 00:11:45 UTC (rev 9207)
@@ -98,8 +98,12 @@
                control_box.AddSpacer(2)
                self._num_lines_buttons = common.IncrDecrButtons(self, 
self._on_incr_num_lines, self._on_decr_num_lines)
                control_box.Add(self._num_lines_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)
                #clear
-               control_box.AddStretchSpacer()
                self.clear_button = wx.Button(self, label='Clear', 
style=wx.BU_EXACTFIT)
                self.clear_button.Bind(wx.EVT_BUTTON, self._on_clear_button)
                control_box.Add(self.clear_button, 0, wx.EXPAND)
@@ -115,11 +119,11 @@
        def _on_clear_button(self, event):
                self.parent.set_num_lines(self.parent[NUM_LINES_KEY])
        def _on_incr_dynamic_range(self, event):
-               self.parent.set_dynamic_range(common.get_clean_incr(
-                       min(self.parent[DYNAMIC_RANGE_KEY], MAX_DYNAMIC_RANGE)))
+               self.parent.set_dynamic_range(
+                       min(self.parent[DYNAMIC_RANGE_KEY] + 10, 
MAX_DYNAMIC_RANGE))
        def _on_decr_dynamic_range(self, event):
-               self.parent.set_dynamic_range(common.get_clean_decr(
-                       max(self.parent[DYNAMIC_RANGE_KEY], MIN_DYNAMIC_RANGE)))
+               self.parent.set_dynamic_range(
+                       max(self.parent[DYNAMIC_RANGE_KEY] - 10, 
MIN_DYNAMIC_RANGE))
        def _on_incr_ref_level(self, event):
                self.parent.set_ref_level(
                        self.parent[REF_LEVEL_KEY] + 
self.parent[DYNAMIC_RANGE_KEY]/10)
@@ -200,6 +204,23 @@
                #initial update
                self.update_grid()
 
+       def autoscale(self, *args):
+               """!
+               Autoscale the waterfall plot to the last frame.
+               Set the dynamic range and reference level.
+               Does not affect the current data in the waterfall.
+               """
+               #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)/2
+               peak_level += abs(peak_level)*.1
+               #set the range and level
+               self.set_ref_level(noise_floor)
+               self.set_dynamic_range(peak_level - noise_floor)
+
        def handle_msg(self, msg):
                """!
                Handle the message from the fft sink message queue.
@@ -210,7 +231,7 @@
                """
                if not self[RUNNING_KEY]: return
                #convert to floating point numbers
-               samples = numpy.fromstring(msg, numpy.float32)[:self.fft_size] 
#only take first frame
+               self.samples = samples = numpy.fromstring(msg, 
numpy.float32)[:self.fft_size] #only take first frame
                num_samps = len(samples)
                #reorder fft
                if self.real: samples = samples[:num_samps/2]





reply via email to

[Prev in Thread] Current Thread [Next in Thread]