commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r8761 - gnuradio/branches/developers/jblum/gr-wxglgui/


From: jblum
Subject: [Commit-gnuradio] r8761 - gnuradio/branches/developers/jblum/gr-wxglgui/src/python
Date: Mon, 30 Jun 2008 19:19:12 -0600 (MDT)

Author: jblum
Date: 2008-06-30 19:19:12 -0600 (Mon, 30 Jun 2008)
New Revision: 8761

Modified:
   gnuradio/branches/developers/jblum/gr-wxglgui/src/python/common.py
   gnuradio/branches/developers/jblum/gr-wxglgui/src/python/constsink.py
   gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py
   gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py
Log:
work on autoranging

Modified: gnuradio/branches/developers/jblum/gr-wxglgui/src/python/common.py
===================================================================
--- gnuradio/branches/developers/jblum/gr-wxglgui/src/python/common.py  
2008-07-01 01:18:48 UTC (rev 8760)
+++ gnuradio/branches/developers/jblum/gr-wxglgui/src/python/common.py  
2008-07-01 01:19:12 UTC (rev 8761)
@@ -228,3 +228,16 @@
                2: 1,
                5: 2,
        }[base]*(10**exp)
+
+def get_min_max(samples):
+       """!
+       Get the minimum and maximum bounds for an array of samples.
+       @param samples the array of real values
+       @return a tuple of min, max
+       """
+       scale_factor = 2
+       mean = numpy.average(samples)
+       rms = scale_factor*((numpy.sum((samples-mean)**2)/len(samples))**.5)
+       min = mean - rms
+       max = mean + rms
+       return min, max

Modified: gnuradio/branches/developers/jblum/gr-wxglgui/src/python/constsink.py
===================================================================
--- gnuradio/branches/developers/jblum/gr-wxglgui/src/python/constsink.py       
2008-07-01 01:18:48 UTC (rev 8760)
+++ gnuradio/branches/developers/jblum/gr-wxglgui/src/python/constsink.py       
2008-07-01 01:19:12 UTC (rev 8761)
@@ -33,9 +33,10 @@
 # Constants
 ##################################################
 DEFAULT_FRAME_RATE = 30
-DEFAULT_WIN_SIZE = (400, 400)
+DEFAULT_WIN_SIZE = (500, 400)
 DEFAULT_CONST_SIZE = 1024
 CONST_PLOT_COLOR_SPEC = (0, 0, 1) 
+AUTORANGE_UPDATE_RATE = 0.5 #sec
 
 ##################################################
 # Constellation window control panel
@@ -96,6 +97,7 @@
                self.y_divs = 8
                self.y_per_div = 1
                self.y_off = 0
+               self.autorange_ts = 0
                #init panel and plot 
                wx.Panel.__init__(self, parent, -1, style=wx.SIMPLE_BORDER)
                self.plotter = plotter.grid_plotter(self)  
@@ -120,15 +122,43 @@
                if not self.running: return
                real = numpy.real(samples)
                imag = numpy.imag(samples)
-               samples = zip((real, imag))
+               #update autorange
+               if time.time() - self.autorange_ts > AUTORANGE_UPDATE_RATE:
+                       #adjust the x per div
+                       min, max = common.get_min_max(real)
+                       x_per_div = 
common.get_clean_num(1.5*(max-min)/self.x_divs)                                 
    
+                       if self.x_per_div != x_per_div: 
self.set_x_per_div(x_per_div)
+                       #adjust the x offset
+                       x_off = self.x_per_div*round((max+min)/2/self.x_per_div)
+                       if self.x_off != x_off: self.set_x_off(x_off)   
+                       #adjust the y per div           
+                       min, max = common.get_min_max(imag)
+                       y_per_div = 
common.get_clean_num(1.5*(max-min)/self.y_divs)                                 
    
+                       if self.y_per_div != y_per_div: 
self.set_y_per_div(y_per_div)
+                       #adjust the y offset
+                       y_off = self.y_per_div*round((max+min)/2/self.y_per_div)
+                       if self.y_off != y_off: self.set_y_off(y_off)           
                        
+                       self.autorange_ts = time.time()
+               #plot
                self.plotter.set_waveform(
                        channel=0, 
-                       samples=samples,
+                       samples=(real, imag),
                        color_spec=CONST_PLOT_COLOR_SPEC,
                )
 
        def update(self): 
-               #update the grid
+               #update the x axis
+               self.plotter.set_x_grid(
+                       -1*self.x_per_div*self.x_divs/2.0 + self.x_off, 
+                       self.x_per_div*self.x_divs/2.0 + self.x_off, 
+                       self.x_per_div,
+               )
+               #update the y axis
+               self.plotter.set_y_grid(
+                       -1*self.y_per_div*self.y_divs/2.0 + self.y_off, 
+                       self.y_per_div*self.y_divs/2.0 + self.y_off, 
+                       self.y_per_div,
+               )
                #update control panel and plotter
                self.control_panel.update()
                self.plotter.update()
@@ -136,6 +166,18 @@
        ##################################################
        # Set parameters on-the-fly
        ##################################################
+       def set_x_per_div(self, x_per_div):
+               self.x_per_div = x_per_div
+               self.update()
+       def set_x_off(self, x_off):
+               self.x_off = x_off
+               self.update()
+       def set_y_per_div(self, y_per_div):
+               self.y_per_div = y_per_div
+               self.update()
+       def set_y_off(self, y_off):
+               self.y_off = y_off
+               self.update()
        def set_run(self, running):
                self.running = running
                self.update()

Modified: gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py
===================================================================
--- gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py 
2008-07-01 01:18:48 UTC (rev 8760)
+++ gnuradio/branches/developers/jblum/gr-wxglgui/src/python/plotter.py 
2008-07-01 01:19:12 UTC (rev 8761)
@@ -212,11 +212,17 @@
                for channel in reversed(sorted(self.channels.keys())):
                        samples, color_spec = self.channels[channel]
                        glColor3f(*color_spec)
-                       glBegin(GL_LINE_STRIP)
+                       if isinstance(samples, tuple): glBegin(GL_POINTS)
+                       else: glBegin(GL_LINE_STRIP)
                        num_samps = len(samples)
                        #use numpy to scale the waveform
-                       x_scalar = 
(self.width-self.padding_left-self.padding_right)
-                       x_arr = x_scalar*numpy.arange(0, 
num_samps)/float(num_samps-1) + self.padding_left
+                       if isinstance(samples, tuple):
+                               x_scalar = 
(self.width-self.padding_left-self.padding_right)
+                               x_arr = x_scalar*(samples[0] - 
self.x_min)/(self.x_max-self.x_min) + self.padding_left
+                               samples = samples[1]
+                       else:
+                               x_scalar = 
(self.width-self.padding_left-self.padding_right)
+                               x_arr = x_scalar*numpy.arange(0, 
num_samps)/float(num_samps-1) + self.padding_left
                        y_scalar = 
(self.height-self.padding_top-self.padding_bottom)
                        y_arr = y_scalar*(1 - (numpy.array(samples) - 
self.y_min)/(self.y_max-self.y_min)) + self.padding_top
                        #draw the lines

Modified: gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py
===================================================================
--- gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py       
2008-07-01 01:18:48 UTC (rev 8760)
+++ gnuradio/branches/developers/jblum/gr-wxglgui/src/python/scopesink.py       
2008-07-01 01:19:12 UTC (rev 8761)
@@ -297,10 +297,9 @@
                                #autorange
                                if self.autorange_index == i and \
                                        time.time() - self.autorange_ts > 
AUTORANGE_UPDATE_RATE:
-                                       min = numpy.min(samples)
-                                       max = numpy.max(samples)
+                                       min, max = common.get_min_max(samples)
                                        #adjust the y per div
-                                       y_per_div = 
common.get_clean_num(1.5*(max-min)/self.y_divs)                                 
    
+                                       y_per_div = 
common.get_clean_num((max-min)/self.y_divs)                                 
                                        if self.y_per_div != y_per_div: 
self.set_y_per_div(y_per_div)
                                        #adjust the y offset
                                        y_off = 
self.y_per_div*round((max+min)/2/self.y_per_div)





reply via email to

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