commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r3904 - gnuradio/branches/developers/eb/binstats/gnura


From: eb
Subject: [Commit-gnuradio] r3904 - gnuradio/branches/developers/eb/binstats/gnuradio-examples/python/usrp
Date: Mon, 30 Oct 2006 18:30:05 -0700 (MST)

Author: eb
Date: 2006-10-30 18:30:05 -0700 (Mon, 30 Oct 2006)
New Revision: 3904

Modified:
   
gnuradio/branches/developers/eb/binstats/gnuradio-examples/python/usrp/usrp_spectrum_sense.py
Log:
believed to be working ;)

Modified: 
gnuradio/branches/developers/eb/binstats/gnuradio-examples/python/usrp/usrp_spectrum_sense.py
===================================================================
--- 
gnuradio/branches/developers/eb/binstats/gnuradio-examples/python/usrp/usrp_spectrum_sense.py
       2006-10-31 01:20:30 UTC (rev 3903)
+++ 
gnuradio/branches/developers/eb/binstats/gnuradio-examples/python/usrp/usrp_spectrum_sense.py
       2006-10-31 01:30:05 UTC (rev 3904)
@@ -9,6 +9,7 @@
 import usrp_dbid
 import sys
 import math
+import struct
 
 
 class tune(gr.feval_dd):
@@ -18,20 +19,20 @@
     def __init__(self, fg):
         gr.feval_dd.__init__(self)
         self.fg = fg
-        print "tune: __init__ self =", self
 
     def eval(self, ignore):
         """
-        This method is called from gr.bin_statistics_f when it want to change
+        This method is called from gr.bin_statistics_f when it wants to change
         the center frequency.  This method tunes the front end to the new 
center
         frequency, and returns the new frequency as its result.
         """
-        #print "tune.eval!" >> sys.stderr
-        print "tune: eval self =", self
-        print "tune.eval!"
-        print "self.fg =", self.fg
-        new_freq = self.fg.set_next_frequency()
-        print "new_freq =", new_freq
+
+        #try:
+        #    new_freq = self.fg.set_next_freq()
+        #except Exception, e:
+        #    print "tune: Exception: ", e
+
+        new_freq = self.fg.set_next_freq()
         return new_freq
         
 
@@ -40,10 +41,13 @@
         self.center_freq = msg.arg1()
         self.vlen = int(msg.arg2())
         assert(msg.length() == self.vlen * gr.sizeof_float)
-        # FIXME consider using Numarry vector
-        self.data = struct.unpack('%df' % (self.vlen,), msg.to_string())
 
+        # FIXME consider using Numarray or NumPy vector
+        t = msg.to_string()
+        self.raw_data = t
+        self.data = struct.unpack('%df' % (self.vlen,), t)
 
+
 class my_graph(gr.flow_graph):
 
     def __init__(self):
@@ -59,9 +63,9 @@
                           help="time to delay (in seconds) after changing 
frequency [default=%default]")
         parser.add_option("", "--dwell-delay", type="eng_float", 
default=10e-3, metavar="SECS",
                           help="time to dwell (in seconds) at a given frequncy 
[default=%default]")
-        parser.add_option("-F", "--fft-size", type="int", default=512,
+        parser.add_option("-F", "--fft-size", type="int", default=256,
                           help="specify number of FFT bins [default=%default]")
-        parser.add_option("-d", "--decim", type="intx", default=8,
+        parser.add_option("-d", "--decim", type="intx", default=16,
                           help="set decimation to DECIM [default=%default]")
         parser.add_option("", "--real-time", action="store_true", 
default=False,
                           help="Attempt to enable real-time scheduling")
@@ -98,13 +102,14 @@
         # If the user hasn't set the fusb_* parameters on the command line,
         # pick some values that will reduce latency.
 
-        if options.fusb_block_size == 0 and options.fusb_nblocks == 0:
-            if realtime:                        # be more aggressive
-                options.fusb_block_size = gr.prefs().get_long('fusb', 
'rt_block_size', 1024)
-                options.fusb_nblocks    = gr.prefs().get_long('fusb', 
'rt_nblocks', 16)
-            else:
-                options.fusb_block_size = gr.prefs().get_long('fusb', 
'block_size', 4096)
-                options.fusb_nblocks    = gr.prefs().get_long('fusb', 
'nblocks', 16)
+        if 1:
+            if options.fusb_block_size == 0 and options.fusb_nblocks == 0:
+                if realtime:                        # be more aggressive
+                    options.fusb_block_size = gr.prefs().get_long('fusb', 
'rt_block_size', 1024)
+                    options.fusb_nblocks    = gr.prefs().get_long('fusb', 
'rt_nblocks', 16)
+                else:
+                    options.fusb_block_size = gr.prefs().get_long('fusb', 
'block_size', 4096)
+                    options.fusb_nblocks    = gr.prefs().get_long('fusb', 
'nblocks', 16)
     
         #print "fusb_block_size =", options.fusb_block_size
        #print "fusb_nblocks    =", options.fusb_nblocks
@@ -133,12 +138,15 @@
         for tap in mywindow:
             power += tap*tap
             
-        c2mag = gr.complex_to_mag(self.fft_size)
-        #self.avg = gr.single_pole_iir_filter_ff(1.0, self.fft_size)
+        c2mag = gr.complex_to_mag_squared(self.fft_size)
 
-        log = gr.nlog10_ff(20, self.fft_size,
+        # FIXME the log10 primitive is dog slow
+        log = gr.nlog10_ff(10, self.fft_size,
                            
-20*math.log10(self.fft_size)-10*math.log10(power/self.fft_size))
                
+        # Set the freq_step to 75% of the actual data throughput.
+        # This allows us to discard the bins on both ends of the spectrum.
+
         self.freq_step = 0.75 * usrp_rate
         self.min_center_freq = self.min_freq + self.freq_step/2
         self.max_center_freq = self.max_freq - self.freq_step/2
@@ -153,7 +161,9 @@
         stats = gr.bin_statistics_f(self.fft_size, self.msgq,
                                     self._tune_callback, tune_delay, 
dwell_delay)
 
-       self.connect(self.u, s2v, fft, c2mag, log, stats)
+        # FIXME leave out the log10 until we speed it up
+       #self.connect(self.u, s2v, fft, c2mag, log, stats)
+       self.connect(self.u, s2v, fft, c2mag, stats)
 
         if options.gain is None:
             # if no gain was specified, use the mid-point in dB
@@ -165,14 +175,11 @@
 
 
     def set_next_freq(self):
-        print "set_next_freq"
         target_freq = self.next_freq
         self.next_freq = self.next_freq + self.freq_step
         if self.next_freq > self.max_center_freq:
             self.next_freq = self.min_center_freq
 
-        print "target_freq =", target_freq
-
         if not self.set_freq(target_freq):
             print "Failed to set frequency to", target_freq
 
@@ -200,9 +207,22 @@
 
 def main_loop(fg):
     while 1:
+
+        # Get the next message sent from the C++ code (blocking call).
+        # It contains the center frequency and the mag squared of the fft
         m = parse_msg(fg.msgq.delete_head())
-        # do something with the data
+
+        # Print center freq so we know that something is happening...
         print m.center_freq
+
+        # FIXME do something useful with the data...
+        
+        # m.data are the mag_squared of the fft output (they are in the
+        # standard order.  I.e., bin 0 == DC.)
+        # You'll probably want to do the equivalent of "fftshift" on them
+        # m.raw_data is a string that contains the binary floats.
+        # You could write this as binary to a file.
+
     
 if __name__ == '__main__':
     fg = my_graph()





reply via email to

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