switch source package format to 3.0 quilt
[debian/gnuradio] / gnuradio-examples / python / ofdm / benchmark_ofdm.py
index 3c4f172c2e6daba62e9cbd1b6adb4c62e865bbba..6d6ca9f2aeb43a5a652acdde79ec0d84232803c9 100755 (executable)
@@ -1,12 +1,12 @@
 #!/usr/bin/env python
 #
-# Copyright 2006, 2007 Free Software Foundation, Inc.
+# Copyright 2006, 2007, 2009 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 2, or (at your option)
+# 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,
@@ -20,7 +20,7 @@
 # Boston, MA 02110-1301, USA.
 # 
 
-from gnuradio import gr, blks
+from gnuradio import gr, blks2
 from gnuradio import eng_notation
 from gnuradio.eng_option import eng_option
 from optparse import OptionParser
@@ -32,18 +32,19 @@ from transmit_path import transmit_path
 from receive_path import receive_path
 
 
-class my_graph(gr.flow_graph):
+class my_top_block(gr.top_block):
     def __init__(self, callback, options):
-        gr.flow_graph.__init__(self)
+        gr.top_block.__init__(self)
 
-        if options.channel_on:
+        if not options.channel_off:
             SNR = 10.0**(options.snr/10.0)
-            power_in_signal = 1.0
+            power_in_signal = abs(options.tx_amplitude)**2.0
             noise_power_in_channel = power_in_signal/SNR
             noise_voltage = math.sqrt(noise_power_in_channel/2.0)
             print "Noise voltage: ", noise_voltage
 
             frequency_offset = options.frequency_offset / options.fft_length
+            print "Frequency offset: ", frequency_offset
 
             if options.multipath_on:
                 taps = [1.0, .2, 0.0, .1, .08, -.4, .12, -.2, 0, 0, 0, .3]
@@ -66,21 +67,24 @@ class my_graph(gr.flow_graph):
 
         z = [0,]
         self.zeros = gr.vector_source_c(z, True)
-        self.txpath = transmit_path(self, options)
+        self.txpath = transmit_path(options)
 
-        self.mux = gr.stream_mux(gr.sizeof_gr_complex, stream_size)
+        #self.mux = gr.stream_mux(gr.sizeof_gr_complex, stream_size)
         self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
-        self.channel = blks.channel_model(self, noise_voltage, frequency_offset, options.clockrate_ratio, taps)
-        self.rxpath = receive_path(self, callback, options)
+        self.channel = gr.channel_model(noise_voltage, frequency_offset,
+                                        options.clockrate_ratio, taps)
+        self.rxpath = receive_path(callback, options)
                 
-        self.connect(self.zeros, (self.mux,0))
-        self.connect(self.txpath, (self.mux,1))
-        self.connect(self.mux, self.throttle, self.channel, self.rxpath)
-
+        #self.connect(self.zeros, (self.mux,0))
+        #self.connect(self.txpath, (self.mux,1))
+        #self.connect(self.mux, self.throttle, self.channel, self.rxpath)
+        #self.connect(self.mux, self.throttle, self.rxpath)
+        self.connect(self.txpath, self.throttle, self.channel, self.rxpath)
+        
         if options.log:
             self.connect(self.txpath, gr.file_sink(gr.sizeof_gr_complex, "txpath.dat"))
-            self.connect(self.mux, gr.file_sink(gr.sizeof_gr_complex, "mux.dat"))
-            self.connect(self.channel, gr.file_sink(gr.sizeof_gr_complex, "channel.dat"))
+            #self.connect(self.mux, gr.file_sink(gr.sizeof_gr_complex, "mux.dat"))
+            #self.connect(self.channel, gr.file_sink(gr.sizeof_gr_complex, "channel.dat"))
             
 # /////////////////////////////////////////////////////////////////////////////
 #                                   main
@@ -93,7 +97,7 @@ def main():
     n_right = 0
         
     def send_pkt(payload='', eof=False):
-        return fg.txpath.send_pkt(payload, eof)
+        return tb.txpath.send_pkt(payload, eof)
         
     def rx_callback(ok, payload):
         global n_rcvd, n_right
@@ -116,7 +120,7 @@ def main():
                 
     parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
     expert_grp = parser.add_option_group("Expert")
-    parser.add_option("-s", "--size", type="eng_float", default=1450,
+    parser.add_option("-s", "--size", type="eng_float", default=400,
                       help="set packet size [default=%default]")
     parser.add_option("-M", "--megabytes", type="eng_float", default=1.0,
                       help="set megabytes to transmit [default=%default]")
@@ -130,26 +134,26 @@ def main():
                       help="set clock rate ratio (sample rate difference) between two systems [default=%default]")
     parser.add_option("","--discontinuous", type="int", default=0,
                       help="enable discontinous transmission, burst of N packets [Default is continuous]")
-    parser.add_option("","--channel-on", action="store_true", default=True,
-                      help="Enables AWGN, freq offset")
+    parser.add_option("","--channel-off", action="store_true", default=False,
+                      help="Turns AWGN, freq offset channel off")
     parser.add_option("","--multipath-on", action="store_true", default=False,
                       help="enable multipath")
 
     transmit_path.add_options(parser, expert_grp)
     receive_path.add_options(parser, expert_grp)
-    blks.ofdm_mod.add_options(parser, expert_grp)
-    blks.ofdm_demod.add_options(parser, expert_grp)
+    blks2.ofdm_mod.add_options(parser, expert_grp)
+    blks2.ofdm_demod.add_options(parser, expert_grp)
     
     (options, args) = parser.parse_args ()
        
     # build the graph
-    fg = my_graph(rx_callback, options)
+    tb = my_top_block(rx_callback, options)
     
     r = gr.enable_realtime_scheduling()
     #    if r != gr.RT_OK:
     #        print "Warning: failed to enable realtime scheduling"
-        
-    fg.start()                       # start flow graph
+    
+    tb.start()                       # start flow graph
     
     # generate and send packets
     nbytes = int(1e6 * options.megabytes)
@@ -171,7 +175,7 @@ def main():
         pktno += 1
         
     send_pkt(eof=True)
-    fg.wait()                       # wait for it to finish
+    tb.wait()                       # wait for it to finish
 
 
 if __name__ == '__main__':