Index: usrp_fft.py
===================================================================
--- usrp_fft.py	(Revision 227)
+++ usrp_fft.py	(Revision 228)
@@ -1,24 +1,24 @@
 #!/usr/bin/env python
 #
 # Copyright 2004,2005 Free Software Foundation, Inc.
-# 
+#
 # This file is part of GNU Radio
-# 
+#
 # GNU Radio is free software; you can redistribute it and/or modify
 # it under the terms of the GNU General Public License as published by
 # the Free Software Foundation; either version 3, or (at your option)
 # any later version.
-# 
+#
 # GNU Radio is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 # GNU General Public License for more details.
-# 
+#
 # You should have received a copy of the GNU General Public License
 # along with GNU Radio; see the file COPYING.  If not, write to
 # the Free Software Foundation, Inc., 51 Franklin Street,
 # Boston, MA 02110-1301, USA.
-# 
+#
 
 from gnuradio import gr, gru
 from gnuradio import usrp
@@ -29,7 +29,9 @@
 import wx
 import sys
 
+from gnuradio import optfir
 
+
 def pick_subdevice(u):
     """
     The user didn't specify a subdevice on the command line.
@@ -50,11 +52,11 @@
 
         self.frame = frame
         self.panel = panel
-        
+
         parser = OptionParser(option_class=eng_option)
         parser.add_option("-R", "--rx-subdev-spec", type="subdev", default=None,
                           help="select USRP Rx side A or B (default=first one with a daughterboard)")
-        parser.add_option("-d", "--decim", type="int", default=16,
+        parser.add_option("-d", "--decim", type="int", default=32,
                           help="set fgpa decimation rate to DECIM [default=%default]")
         parser.add_option("-f", "--freq", type="eng_float", default=None,
                           help="set frequency to FREQ", metavar="FREQ")
@@ -66,16 +68,35 @@
                           help="Enable 8-bit samples across USB")
         parser.add_option("-S", "--oscilloscope", action="store_true", default=False,
                           help="Enable oscilloscope display")
+        parser.add_option("", "--fft-size", type="int", default=1024,
+                          help="set fft size [default=%default]")
+
         (options, args) = parser.parse_args()
         if len(args) != 0:
             parser.print_help()
             sys.exit(1)
 
         self.show_debug_info = True
-        
+
         # build the graph
 
-        self.u = usrp.source_c(decim_rate=options.decim)
+        self.decimation = 2
+        bw = 0.5/self.decimation * 1.4
+        tb = bw/5
+#        filt_coeff = \
+#          gr.firdes.low_pass (self.decimation, # gain
+#                              1.0,             # sampling rate
+#                              bw+tb/2,         # low pass cutoff freq
+#                              tb,              # width of trans. band
+#                              gr.firdes.WIN_HAMMING)
+        # gain, sampling rate, passband cutoff, stopband cutoff
+        # passband ripple in dB, stopband attenuation in dB
+        # extra taps
+        filt_coeff = optfir.low_pass(1.0, 1.0, bw, bw+tb, 0.1, 60.0, 1)
+        print "Software decimation filter length: %d" % (len(filt_coeff))
+        self.filter = gr.fir_filter_ccf(self.decimation,filt_coeff)
+
+        self.u = usrp.source_c(decim_rate=options.decim/self.decimation)
         if options.rx_subdev_spec is None:
             options.rx_subdev_spec = pick_subdevice(self.u)
         self.u.set_mux(usrp.determine_rx_mux_value(self.u, options.rx_subdev_spec))
@@ -87,21 +108,23 @@
             print "format =", hex(format)
             r = self.u.set_format(format)
             print "set_format =", r
-            
+
         # determine the daughterboard subdevice we're using
         self.subdev = usrp.selected_subdev(self.u, options.rx_subdev_spec)
 
-        input_rate = self.u.adc_freq() / self.u.decim_rate()
+        input_rate = self.u.adc_freq() / self.u.decim_rate() / self.decimation
 
         if options.waterfall:
             self.scope = \
-              waterfallsink.waterfall_sink_c (self, panel, fft_size=1024, sample_rate=input_rate)
+              waterfallsink.waterfall_sink_c (self, panel, fft_size=options.fft_size,
+                                              sample_rate=input_rate)
         elif options.oscilloscope:
             self.scope = scopesink.scope_sink_c(self, panel, sample_rate=input_rate)
         else:
-            self.scope = fftsink.fft_sink_c (self, panel, fft_size=1024, sample_rate=input_rate)
+            self.scope = fftsink.fft_sink_c (self, panel, fft_size=options.fft_size,
+                                             sample_rate=input_rate)
 
-        self.connect(self.u, self.scope)
+        self.connect(self.u, self.filter, self.scope)
 
         self._build_gui(vbox)
 
@@ -120,7 +143,7 @@
         self.set_gain(options.gain)
 
         if self.show_debug_info:
-            self.myform['decim'].set_value(self.u.decim_rate())
+            self.myform['decim'].set_value(self.u.decim_rate()*self.decimation)
             self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate())
             self.myform['dbname'].set_value(self.subdev.name())
             self.myform['baseband'].set_value(0)
@@ -136,9 +159,9 @@
 
         def _form_set_freq(kv):
             return self.set_freq(kv['freq'])
-            
+
         vbox.Add(self.scope.win, 10, wx.EXPAND)
-        
+
         # add control area at the bottom
         self.myform = myform = form.form()
         hbox = wx.BoxSizer(wx.HORIZONTAL)
@@ -164,7 +187,7 @@
 
         # FIXME figure out how to have this be a subpanel that is always
         # created, but has its visibility controlled by foo.Show(True/False)
-        
+
         def _form_set_decim(kv):
             return self.set_decim(kv['decim'])
 
@@ -204,7 +227,7 @@
         hbox.Add((5,0), 0)
         vbox.Add(hbox, 0, wx.EXPAND)
 
-        
+
     def set_freq(self, target_freq):
         """
         Set the center frequency we're interested in.
@@ -218,7 +241,7 @@
         determine the value for the digital down converter.
         """
         r = self.u.tune(0, self.subdev, target_freq)
-        
+
         if r:
             self.myform['freq'].set_value(target_freq)     # update displayed value
             if self.show_debug_info:
@@ -233,13 +256,13 @@
         self.subdev.set_gain(gain)
 
     def set_decim(self, decim):
-        ok = self.u.set_decim_rate(decim)
+        ok = self.u.set_decim_rate(decim/self.decimation)
         if not ok:
             print "set_decim failed"
-        input_rate = self.u.adc_freq() / self.u.decim_rate()
-        self.scope.set_sample_rate(input_rate)
+        self.input_rate = self.u.adc_freq() / self.u.decim_rate() / self.decimation
+        self.scope.set_sample_rate(self.input_rate)
         if self.show_debug_info:  # update displayed values
-            self.myform['decim'].set_value(self.u.decim_rate())
+            self.myform['decim'].set_value(self.u.decim_rate()*self.decimation)
             self.myform['fs@usb'].set_value(self.u.adc_freq() / self.u.decim_rate())
         return ok
 
