waterfall and fft use a common autoscale function
authorJosh Blum <josh@joshknows.com>
Wed, 2 Sep 2009 21:18:28 +0000 (14:18 -0700)
committerJosh Blum <josh@joshknows.com>
Wed, 2 Sep 2009 21:18:28 +0000 (14:18 -0700)
gr-wxgui/src/python/common.py
gr-wxgui/src/python/fft_window.py
gr-wxgui/src/python/waterfall_window.py

index d555a1f055a9c3b824e2b71cb0c793c0ec562fcb..9c97ce1ecad898a32e1871f9445c42713db7fd9e 100644 (file)
@@ -137,6 +137,25 @@ def get_min_max(samples):
        scale_factor = 3
        mean = numpy.average(samples)
        rms = numpy.max([scale_factor*((numpy.sum((samples-mean)**2)/len(samples))**.5), .1])
-       min = mean - rms
-       max = mean + rms
-       return min, max
+       min_val = mean - rms
+       max_val = mean + rms
+       return min_val, max_val
+
+def get_min_max_fft(fft_samps):
+       """
+       Get the minimum and maximum bounds for an array of fft samples.
+       @param samples the array of real values
+       @return a tuple of min, max
+       """
+       #get the peak level (max of the samples)
+       peak_level = numpy.max(fft_samps)
+       #separate noise samples
+       noise_samps = numpy.sort(fft_samps)[:len(fft_samps)/2]
+       #get the noise floor
+       noise_floor = numpy.average(noise_samps)
+       #get the noise deviation
+       noise_dev = numpy.std(noise_samps)
+       #determine the maximum and minimum levels
+       max_level = peak_level
+       min_level = noise_floor - abs(2*noise_dev)
+       return min_level, max_level
index 4c575f1a62cd29aa302b57a954a71748bf6138a5..237c8940c2bc389b293637d3d64a23fa0d257f69 100644 (file)
@@ -254,17 +254,7 @@ class fft_window(wx.Panel, pubsub.pubsub):
                Set the dynamic range and reference level.
                """
                if not len(self.samples): return
-               #get the peak level (max of the samples)
-               peak_level = numpy.max(self.samples)
-               #separate noise samples
-               noise_samps = numpy.sort(self.samples)[:len(self.samples)/2]
-               #get the noise floor
-               noise_floor = numpy.average(noise_samps)
-               #get the noise deviation
-               noise_dev = numpy.std(noise_samps)
-               #determine the maximum and minimum levels
-               max_level = peak_level
-               min_level = noise_floor - abs(2*noise_dev)
+               min_level, max_level = common.get_min_max_fft(self.samples)
                #set the range to a clean number of the dynamic range
                self[Y_PER_DIV_KEY] = common.get_clean_num(1+(max_level - min_level)/self[Y_DIVS_KEY])
                #set the reference level to a multiple of y per div
index c00992e14fee13598112a12beeb8411852daaa60..28e67a83006aa6af3123107fe4d3f79db06062d6 100644 (file)
@@ -237,16 +237,10 @@ class waterfall_window(wx.Panel, pubsub.pubsub):
                Does not affect the current data in the waterfall.
                """
                if not len(self.samples): return
-               #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)/4])
-               #padding
-               noise_floor -= abs(noise_floor)*.5
-               peak_level += abs(peak_level)*.1
+               min_level, max_level = common.get_min_max_fft(self.samples)
                #set the range and level
-               self[REF_LEVEL_KEY] = peak_level
-               self[DYNAMIC_RANGE_KEY] = peak_level - noise_floor
+               self[REF_LEVEL_KEY] = max_level
+               self[DYNAMIC_RANGE_KEY] = max_level - min_level
 
        def handle_msg(self, msg):
                """