commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r9277 - in gnuradio/branches/developers/jblum/glwxgui/


From: jblum
Subject: [Commit-gnuradio] r9277 - in gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python: . plotter
Date: Wed, 13 Aug 2008 22:31:14 -0600 (MDT)

Author: jblum
Date: 2008-08-13 22:31:13 -0600 (Wed, 13 Aug 2008)
New Revision: 9277

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/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:
si units

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-14 03:27:17 UTC (rev 9276)
+++ gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/common.py    
2008-08-14 04:31:13 UTC (rev 9277)
@@ -214,7 +214,7 @@
        """
        num = get_clean_num(num)
        exp = get_exp(num)
-       base = int(round(num/10**exp))
+       coeff = int(round(num/10**exp))
        return {
                -5: -2,
                -2: -1,
@@ -222,7 +222,7 @@
                1: 2,
                2: 5,
                5: 10,
-       }[base]*(10**exp)
+       }[coeff]*(10**exp)
 
 def get_clean_decr(num):
        """!
@@ -232,7 +232,7 @@
        """
        num = get_clean_num(num)
        exp = get_exp(num)
-       base = int(round(num/10**exp))
+       coeff = int(round(num/10**exp))
        return {
                -5: -10,
                -2: -5,
@@ -240,7 +240,7 @@
                1: .5,
                2: 1,
                5: 2,
-       }[base]*(10**exp)
+       }[coeff]*(10**exp)
 
 def get_min_max(samples):
        """!
@@ -255,47 +255,44 @@
        max = mean + rms
        return min, max
 
-def get_time_units(num):
+def get_si_components(num):
        """!
-       Get the best time units for the given number.
-       @param num a floating point number
-       @return a tuple of unit string, scalar
+       Get the SI units for the number.
+       Extract the coeff and exponent of the number.
+       The exponent will be a multiple of 3.
+       @param num the floating point number
+       @return the tuple coeff, exp, prefix
        """
        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
+       exp -= exp%3
+       exp = min(max(exp, -24), 24) #bounds on SI table below
+       prefix = {
+               24: 'Y', 21: 'Z',
+               18: 'E', 15: 'P',
+               12: 'T', 9: 'G',
+               6: 'M', 3: 'K',
+               0: '',
+               -3: 'm', -6: 'u',
+               -9: 'n', -12: 'p',
+               -15: 'f', -18: 'a',
+               -21: 'z', -24: 'y',
+       }[exp]
+       coeff = num/10**exp
+       return coeff, exp, prefix
 
-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
+       coeff, exp, prefix = get_si_components(num)
        if abs(exp) >= 3:
-               formatter = '%.3f'
-               num_str = '%se%d'%(formatter%base, exp_dif)
-       else: num_str = '%g'%num
-       return num_str
+               return '%se%d'%('%.3g'%coeff, exp)
+       else: return '%g'%num
 
-if __name__ == '__main__': pass
+if __name__ == '__main__':
+       import random
+       for i in range(-25, 25):
+               num = random.random()*10**i
+               print num, ':', get_si_components(num)

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-14 03:27:17 UTC (rev 9276)
+++ 
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/fft_window.py    
    2008-08-14 04:31:13 UTC (rev 9277)
@@ -199,7 +199,7 @@
                #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])
+               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
@@ -266,24 +266,24 @@
                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)
-               x_units, scalar = common.get_freq_units(x_per_div)
+               coeff, exp, prefix = 
common.get_si_components(x_per_div+baseband_freq)
                #update the x grid
                if self.real:
                        self.plotter.set_x_grid(
                                baseband_freq,
                                baseband_freq + sample_rate/2.0,
                                x_per_div,
-                               scalar,
+                               10**(-exp),
                        )
                else:
                        self.plotter.set_x_grid(
                                baseband_freq - sample_rate/2.0,
                                baseband_freq + sample_rate/2.0,
                                x_per_div,
-                               scalar,
+                               10**(-exp),
                        )
                #update x units
-               self.plotter.set_x_label('Frequency', x_units)
+               self.plotter.set_x_label('Frequency', prefix+'Hz')
                #update y grid
                self.plotter.set_y_grid(ref_level-y_per_div*y_divs, ref_level, 
y_per_div)
                #update y units

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-14 03:27:17 UTC (rev 9276)
+++ 
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/plotter/waterfall_plotter.py
 2008-08-14 04:31:13 UTC (rev 9277)
@@ -95,7 +95,7 @@
                self._resize_texture(False)
                self._minimum = 0
                self._maximum = 0
-               self._fft_size = 0
+               self._fft_size = 1
                self._buffer = list()
                self._pointer = 0
                self._counter = 0

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-14 03:27:17 UTC (rev 9276)
+++ 
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/scope_window.py  
    2008-08-14 04:31:13 UTC (rev 9277)
@@ -463,17 +463,16 @@
                        )
                else:
                        #update the t axis
-                       exp = common.get_exp(t_per_div)
-                       units, scalar = common.get_time_units(t_per_div)
-                       self.plotter.set_x_label('Time', units)
+                       coeff, exp, prefix = common.get_si_components(t_per_div)
+                       self.plotter.set_x_label('Time', prefix+'s')
                        self.plotter.set_x_grid(
                                t_off,
                                t_per_div*t_divs + t_off,
                                t_per_div,
-                               scalar,
+                               10**(-exp),
                        )
                        #update the y axis
-                       self.plotter.set_y_label('Voltage')
+                       self.plotter.set_y_label('Counts')
                        self.plotter.set_y_grid(
                                -1*y_per_div*y_divs/2.0 + y_off,
                                y_per_div*y_divs/2.0 + y_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-14 03:27:17 UTC (rev 9276)
+++ 
gnuradio/branches/developers/jblum/glwxgui/gr-wxgui/src/python/waterfall_window.py
  2008-08-14 04:31:13 UTC (rev 9277)
@@ -222,7 +222,7 @@
                #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])
+               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
@@ -273,24 +273,24 @@
                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)
-               x_units, scalar = common.get_freq_units(x_per_div)
+               coeff, exp, prefix = 
common.get_si_components(x_per_div+baseband_freq)
                #update the x grid
                if self.real:
                        self.plotter.set_x_grid(
                                baseband_freq,
                                baseband_freq + sample_rate/2.0,
                                x_per_div,
-                               scalar,
+                               10**(-exp),
                        )
                else:
                        self.plotter.set_x_grid(
                                baseband_freq - sample_rate/2.0,
                                baseband_freq + sample_rate/2.0,
                                x_per_div,
-                               scalar,
+                               10**(-exp),
                        )
                #update x units
-               self.plotter.set_x_label('Frequency', x_units)
+               self.plotter.set_x_label('Frequency', prefix+'Hz')
                #update y grid
                duration = float(num_lines)/frame_rate
                y_per_div = common.get_clean_num(duration/y_divs)





reply via email to

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