discuss-gnuradio
[Top][All Lists]
Advanced

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

[Discuss-gnuradio] FFT in gr-wxgui changes


From: Toby Oliver
Subject: [Discuss-gnuradio] FFT in gr-wxgui changes
Date: Fri, 29 Oct 2004 09:39:51 +0200
User-agent: Mozilla Thunderbird 0.8 (X11/20040913)

Hi,

I thought I would have a go at adding in a couple of features to the fftsink so I have created a run/stop button, as well as the ability to set the db/div, the center frequency and the span. I have set it up so you enter integer numbers to control the output, but I could change this if people preferred another way (i.e. click on the plot to choose a frequency).

Just out of curiousity what needs to be done to gr-wxgui for it to be released as part of the tarball?

The code is attached as a diff against fftsink.py in cvs, if you have any problems or feedback, please let me know.

Cheers,
Toby




Index: fftsink.py
===================================================================
RCS file: /cvsroot/gnuradio/gr-wxgui/src/python/gnuradio/wxgui/fftsink.py,v
retrieving revision 1.3
diff -r1.3 fftsink.py
24a25
> 
25a27
> import wx.lib.intctrl as int_input
27a30
> 
102c105,109
< class fft_info:
---
> class fft_info (object):
>     __slots__ = ['file_descriptor', 'fft_size', 'sample_rate', 
> 'input_is_real',
>                  'title', 'running', 'db_div', 'cent_freq', 'cent_freq_scale',
>                'span_freq', 'span_freq_scale']
> 
109c116,122
<         
---
>       self.running = True
>       self.db_div=0
>       self.cent_freq = 0
>       self.cent_freq_scale = 1
>         self.span_freq = 0
>       self.span_freq_scale = 1
> 
133d145
<     
135c147,151
< class fft_window (plot.PlotCanvas):
---
> # =====================================================================
> # Creates the fft window as a wx.Panel in two parts, graph_window
> # and make_control_box
> 
> class fft_window (wx.Panel):
139c155,219
<         plot.PlotCanvas.__init__ (self, parent, id, pos, size, style, name)
---
>         wx.Panel.__init__ (self, parent, -1)
> 
>         self.info = info
> 
>         vbox = wx.BoxSizer (wx.VERTICAL)
> 
>         self.graph = graph_window (info, self, -1)
> 
>         vbox.Add (self.graph, 1, wx.EXPAND)
>         vbox.Add (self.make_control_box (), 0, wx.EXPAND)
>       vbox.SetMinSize((400,400))
> 
>         self.sizer = vbox
>         self.SetSizer (self.sizer)
> 
> 
> # ===================================================================
> # Creates the controls for the fft
> 
>     def make_control_box (self):
>         ctrlbox = wx.BoxSizer (wx.HORIZONTAL)
> 
>         run_stop = wx.Button (self, 1001, "Run/Stop")
>         run_stop.SetToolTipString ("Toggle Run/Stop mode")
>         wx.EVT_BUTTON (self, 1001, self.run_stop)
> 
>         db_div = int_input.IntCtrl (self, 1002)
>         db_div.SetToolTipString ("Set db per div")
>         int_input.EVT_INT (self, 1002, self.db_div_int)
> 
>         cent_freq = int_input.IntCtrl (self, 1003)
>         cent_freq.SetToolTipString ("Set Center Frequency")
>         int_input.EVT_INT (self, 1003, self.cent_freq_int)
> 
>         span_freq = int_input.IntCtrl (self, 1005)
>         span_freq.SetToolTipString ("Set Span Frequency")
>         int_input.EVT_INT (self, 1005, self.span_freq_int)
> 
>         ctrlbox.Add (run_stop, 0, wx.EXPAND)
>       ctrlbox.Add ((10,0) ,0)
>         ctrlbox.Add (wx.StaticText (self, -1, "Approx dB/div: "), 0, 
> wx.ALIGN_CENTER)
>         ctrlbox.Add (db_div, 0, wx.EXPAND)
> 
>       ctrlbox.Add ((100,0) ,0)
> 
>         ctrlbox.Add (wx.StaticText (self, -1, "Center Freq: "), 0, 
> wx.ALIGN_CENTER)
>         ctrlbox.Add (cent_freq, 0, wx.EXPAND)
> 
>         self.cent_freq_scale_choice = wx.Choice (self, 1007,
>                                            choices = ['Hz', 'kHz', 'Mhz'])
>         self.cent_freq_scale_choice.SetToolTipString ("Select scale for 
> center frequency")
>         wx.EVT_CHOICE (self, 1007, self.cent_freq_scale_choice_event)
>         ctrlbox.Add (self.cent_freq_scale_choice, 0, wx.ALIGN_CENTER)
> 
>       ctrlbox.Add ((100,0) ,0)
> 
>         ctrlbox.Add (wx.StaticText (self, -1, "Span Freq: "), 0, 
> wx.ALIGN_CENTER)
>         ctrlbox.Add (span_freq, 0, wx.EXPAND)
>         self.span_freq_scale_choice = wx.Choice (self, 1008,
>                                            choices = ['Hz', 'kHz', 'Mhz'])
>         self.cent_freq_scale_choice.SetToolTipString ("Select scale for span 
> frequency")
>         wx.EVT_CHOICE (self, 1008, self.span_freq_scale_choice_event)
>         ctrlbox.Add (self.span_freq_scale_choice, 0, wx.ALIGN_CENTER)
> 
>       return ctrlbox
140a221,270
> # ===================================================================
> # Defines the methods for the control widgets events
> 
>     def run_stop (self, evt):
>         self.info.running = not self.info.running
> 
>     def db_div_int (self, evt):
>         v = evt.GetValue ()
>         self.info.db_div = v
> 
>     def cent_freq_int (self, evt):
>         v = evt.GetValue ()
>         self.info.cent_freq = v
> 
>     def cent_freq_scale_choice_event (self, evt):
>         s = evt.GetString ()
>         if s == 'Hz':
>             self.info.cent_freq_scale = 1
>         elif s == 'kHz':
>             self.info.cent_freq_scale = 1e3
>         elif s == 'Mhz':
>             self.info.cent_freq_scale = 1e6
>         else:
>             assert 0, "Bad cent_freq_scale_choice string"
> 
>     def span_freq_scale_choice_event (self, evt):
>         s = evt.GetString ()
>         if s == 'Hz':
>             self.info.span_freq_scale = 1
>         elif s == 'kHz':
>             self.info.span_freq_scale = 1e3
>         elif s == 'Mhz':
>             self.info.span_freq_scale = 1e6
>         else:
>             assert 0, "Bad span_freq_scale_choice string"
> 
>     def span_freq_int (self, evt):
>         v = evt.GetValue ()
>         self.info.span_freq = v
> 
> # ============================================================
> # Draw the graph window
> 
> class graph_window (plot.PlotCanvas):
> 
>     def __init__ (self, info, parent, id = -1,
>                   pos = wx.DefaultPosition, size = wx.DefaultSize,
>                   style = wx.DEFAULT_FRAME_STYLE, name = ""):
>         plot.PlotCanvas.__init__ (self, parent, id, pos, size, style, name)
>        
143,144c273
<         # self.SetBackgroundColour ('black')
<         
---
> 
146a276
>       self.x_range = None
148a279,280
>       self.avg_x_min = None
>       self.avg_x_max = None
150,151c282
<         EVT_DATA_EVENT (self, self.set_data)
<         wx.EVT_CLOSE (self, self.on_close_window)
---
>         EVT_DATA_EVENT (self, self.format_data)
154,155c285,286
<                                             info.fft_size,
<                                             self)
---
>                                            info.fft_size,
>                                            self)
157,160c288,293
<     def on_close_window (self, event):
<         print "fft_window:on_close_window"
<         self.keep_running = False
<         
---
> # ================================================================
> # Scale and range the data
> 
>     def format_data (self, evt):
>       if not self.info.running:
>           return
162d294
<     def set_data (self, evt):
186,187c318,319
<                                       title=self.info.title,
<                                       xLabel = units, yLabel = "dB")
---
>                                      title=self.info.title,
>                                      xLabel = units, yLabel = "dB")
189c321
<         self.Draw (graphics, xAxis=None, yAxis=self.y_range)
---
>         self.Draw (graphics, xAxis=self.x_range, yAxis=self.y_range)
190a323
>       self.update_x_range ()
202a336,347
>       
>       if self.info.db_div != 0:
>           self.y_range = self._axisInterval ('auto', 
>                                               self.avg_y_min, 
>                                               
> self.avg_y_min+(10*self.info.db_div))
>       else:
>           self.y_range = self._axisInterval ('auto', self.avg_y_min, 
> self.avg_y_max)
>               
>     def update_x_range (self):
>       alpha = 1.0/25
>         graphics = self.last_draw[0]
>         p1, p2 = graphics.boundingBox ()     # min, max points of graphics
204c349,359
<         self.y_range = self._axisInterval ('auto', self.avg_y_min, 
self.avg_y_max)
---
>         if self.avg_x_min:
>             self.avg_x_min = p1[0] * alpha + self.avg_x_min * (1 - alpha)
>             self.avg_x_max = p2[0] * alpha + self.avg_x_max * (1 - alpha)
>         else:
>             self.avg_x_min = p1[0]
>             self.avg_x_max = p2[0]
> 
>         if self.info.sample_rate >= 1e6:
>             sf = 1e-6
>         else:
>             sf = 1e-3
205a361,373
>       if self.info.span_freq != 0:
>           fft_span = self.info.span_freq*sf*self.info.span_freq_scale
>       else:
>           fft_span = self.avg_x_max - self.avg_x_min
> 
>       if self.info.cent_freq != 0:
>             cent_freq = self.info.cent_freq*sf*self.info.cent_freq_scale
>       else:
>           cent_freq = (self.avg_x_max + self.avg_x_min)/2
>           
>         self.x_range = self._axisInterval ('auto', 
>                                             cent_freq - (fft_span/2), 
>                                             cent_freq + (fft_span/2))
221a390,391
>       
>         vbox.Fit (frame)

reply via email to

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