commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r5622 - gnuradio/branches/features/ofdm/receiver/gnura


From: trondeau
Subject: [Commit-gnuradio] r5622 - gnuradio/branches/features/ofdm/receiver/gnuradio-examples/python/ofdm
Date: Sat, 2 Jun 2007 18:24:38 -0600 (MDT)

Author: trondeau
Date: 2007-06-02 18:24:37 -0600 (Sat, 02 Jun 2007)
New Revision: 5622

Modified:
   
gnuradio/branches/features/ofdm/receiver/gnuradio-examples/python/ofdm/benchmark_ofdm.py
   
gnuradio/branches/features/ofdm/receiver/gnuradio-examples/python/ofdm/receive_path.py
Log:
restructured ofdm example code for clarity

Modified: 
gnuradio/branches/features/ofdm/receiver/gnuradio-examples/python/ofdm/benchmark_ofdm.py
===================================================================
--- 
gnuradio/branches/features/ofdm/receiver/gnuradio-examples/python/ofdm/benchmark_ofdm.py
    2007-06-03 00:23:40 UTC (rev 5621)
+++ 
gnuradio/branches/features/ofdm/receiver/gnuradio-examples/python/ofdm/benchmark_ofdm.py
    2007-06-03 00:24:37 UTC (rev 5622)
@@ -33,88 +33,76 @@
 from transmit_path import transmit_path
 from receive_path import receive_path
 
-class awgn_channel(gr.hier_block):
-    def __init__(self, fg, sample_rate, noise_voltage, frequency_offset):
+class channel_model(gr.hier_block):
+    def __init__(self, fg, sample_rate, noise_voltage, frequency_offset, taps):
 
-        self.input = gr.add_const_cc(0)
+        self.multipath = gr.fir_filter_ccc(1, taps)
 
         self.noise_adder = gr.add_cc()
         self.noise = gr.noise_source_c(gr.GR_GAUSSIAN,noise_voltage)
-        self.offset = gr.sig_source_c(1, gr.GR_SIN_WAVE, frequency_offset, 
1.0, 0.0)
+        self.freq_offset = gr.sig_source_c(1, gr.GR_SIN_WAVE, 
frequency_offset, 1.0, 0.0)
         self.mixer_offset = gr.multiply_cc()
 
-        fg.connect(self.input, (self.mixer_offset,0))
-        fg.connect(self.offset,(self.mixer_offset,1))
+        fg.connect(self.multipath, (self.mixer_offset,0))
+        fg.connect(self.freq_offset,(self.mixer_offset,1))
         fg.connect(self.mixer_offset, (self.noise_adder,1))
         fg.connect(self.noise, (self.noise_adder,0))
 
-        gr.hier_block.__init__(self, fg, self.input, self.noise_adder)
 
-class multipath_channel(gr.hier_block):
-    def __init__(self, fg):
+        gr.hier_block.__init__(self, fg, self.multipath, self.noise_adder)
 
-        self.taps = [1.0, .2, 0.0, .1, .08, -.4, .12, -.2, 0, 0, 0, .3]
-        self.chan = gr.fir_filter_ccc(1, self.taps)
-        
-        gr.hier_block.__init__(self, fg, self.chan, self.chan)
-
 class my_graph(gr.flow_graph):
     def __init__(self, callback, options):
         gr.flow_graph.__init__(self)
 
-        channel_on = True
+        if options.channel_on:
+            SNR = 10.0**(options.snr/10.0)
+            power_in_signal = 1.0
+            noise_power_in_channel = power_in_signal/SNR
+            noise_voltage = math.sqrt(noise_power_in_channel/2.0)
+            print "Noise voltage: ", noise_voltage
 
-        SNR = 10.0**(options.snr/10.0)
-        frequency_offset = options.frequency_offset / options.fft_length
+            frequency_offset = options.frequency_offset / options.fft_length
 
-        power_in_signal = 1
-        noise_power_in_channel = power_in_signal/SNR
-        noise_voltage = math.sqrt(noise_power_in_channel/2.0)
-        #noise_voltage=0.0
-        print "Power in signal: ", power_in_signal
-        print "Noise power in channel: ", noise_power_in_channel
-        print "Noise voltage: ", noise_voltage
+            if options.multipath_on:
+                taps = [1.0, .2, 0.0, .1, .08, -.4, .12, -.2, 0, 0, 0, .3]
+            else:
+                taps = [1.0, 0.0]
 
+        else:
+            noise_voltage = 0.0
+            frequency_offset = 0.0
+            taps = [1.0, 0.0]
+
         self.txpath = transmit_path(self, options)
         self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
+        self.channel = channel_model(self, options.sample_rate, noise_voltage, 
frequency_offset, taps)
         self.rxpath = receive_path(self, callback, options)
 
-        if channel_on:
-            self.channel = awgn_channel(self, options.sample_rate, 
noise_voltage, frequency_offset)
-            self.multipath = multipath_channel(self)
 
-            if options.discontinuous:
-                z = 20000*[0,]
-                self.zeros = gr.vector_source_c(z, True)
-                packet_size = math.ceil(((4+options.size+4) * 8) / 
options.occupied_tones)
-                sample_size = (packet_size+2) * 
(options.fft_length+options.cp_length)
-                self.mux = gr.stream_mux(gr.sizeof_gr_complex, 
[int(4*sample_size), int(10e4)])
+        z = 20000*[0,]
+        if options.discontinuous:
+            packet_size = math.ceil(((4+options.size+4) * 8) / 
options.occupied_tones)
+            sample_size = (packet_size+2) * 
(options.fft_length+options.cp_length)
+            stream_size = [100000, int(options.discontinuous*sample_size)]
 
-                # Connect components
-                self.connect(self.txpath, (self.mux,0))
-                self.connect(self.zeros, (self.mux,1))
-                self.connect(self.mux, self.throttle, self.channel, 
self.rxpath)
-                self.connect(self.mux, gr.file_sink(gr.sizeof_gr_complex, 
"tx_ofdm.dat"))
-                self.connect(self.channel, gr.file_sink(gr.sizeof_gr_complex, 
"channel.dat"))
+            self.zeros = gr.vector_source_c(z, True)
+            self.mux = gr.stream_mux(gr.sizeof_gr_complex, stream_size)
 
-         
-            else:
-                #self.connect(self.txpath, self.throttle, self.multipath, 
self.channel)
-                self.connect(self.txpath, self.throttle, self.channel)
-                self.connect(self.channel, self.rxpath)
-                self.connect(self.txpath, gr.file_sink(gr.sizeof_gr_complex, 
"tx_ofdm.dat"))
+            self.connect(self.zeros, (self.mux,0))
+            self.connect(self.txpath, (self.mux,1))
+            self.connect(self.mux, self.throttle, self.channel, self.rxpath)
 
-            sig_rms = gr.rms_cf()
-            noise_rms = gr.rms_cf()
-            self.connect(self.txpath, sig_rms, gr.file_sink(gr.sizeof_float, 
"rms_signal.dat"))
-            self.connect(self.channel.noise, noise_rms, 
gr.file_sink(gr.sizeof_float, "rms_noise.dat"))
-            
         else:
-            self.connect(self.txpath, self.throttle, self.rxpath)
-            self.connect(self.txpath, gr.file_sink(gr.sizeof_gr_complex, "tx"))
-            self.connect(self.rxpath.ofdm_demod.ofdm_rx, 
gr.file_sink(options.fft_length*gr.sizeof_gr_complex, "rx"))
+            packet_size = math.ceil(((4+options.size+4) * 8) / 
options.occupied_tones)
+            sample_size = (packet_size+2) * 
(options.fft_length+options.cp_length)
+            stream_size = [0,1]
+            self.connect(self.txpath, self.throttle, self.channel, self.rxpath)
 
-
+        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"))
+         
 # /////////////////////////////////////////////////////////////////////////////
 #                                   main
 # /////////////////////////////////////////////////////////////////////////////
@@ -135,6 +123,17 @@
         if ok:
             n_right += 1
         print "ok: %r \t pktno: %d \t n_rcvd: %d \t n_right: %d" % (ok, pktno, 
n_rcvd, n_right)
+
+        printlst = list()
+        for x in payload[2:]:
+            t = hex(ord(x)).replace('0x', '')
+            if(len(t) == 1):
+                t = '0' + t
+            printlst.append(t)
+        printable = ''.join(printlst)
+
+        print printable
+        print "\n"
                 
     parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
     expert_grp = parser.add_option_group("Expert")
@@ -148,8 +147,12 @@
                       help="set the SNR of the channel in dB 
[default=%default]")
     parser.add_option("", "--frequency-offset", type="eng_float", default=0,
                       help="set frequency offset introduced by channel 
[default=%default]")
-    parser.add_option("","--discontinuous", action="store_true", default=False,
-                      help="enable discontinous transmission (bursts of 5 
packets)")
+    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("","--multipath_on", action="store_true", default=False,
+                      help="enable multipath")
 
     transmit_path.add_options(parser, expert_grp)
     receive_path.add_options(parser, expert_grp)
@@ -175,7 +178,7 @@
     # generate and send packets
     nbytes = int(1e6 * options.megabytes)
     n = 0
-    pktno = 10
+    pktno = 0
     pkt_size = int(options.size)
 
     while n < nbytes:

Modified: 
gnuradio/branches/features/ofdm/receiver/gnuradio-examples/python/ofdm/receive_path.py
===================================================================
--- 
gnuradio/branches/features/ofdm/receiver/gnuradio-examples/python/ofdm/receive_path.py
      2007-06-03 00:23:40 UTC (rev 5621)
+++ 
gnuradio/branches/features/ofdm/receiver/gnuradio-examples/python/ofdm/receive_path.py
      2007-06-03 00:24:37 UTC (rev 5622)
@@ -28,7 +28,6 @@
 
 # from current dir
 from pick_bitrate import pick_rx_bitrate
-import ofdm
 
 # /////////////////////////////////////////////////////////////////////////////
 #                              receive path
@@ -43,46 +42,22 @@
         self._log         = options.log
         self._rx_callback = rx_callback      # this callback is fired when 
there's a packet available
 
-        if 1:
-            bw = (float(options.occupied_tones) / float(options.fft_length)) / 
2.0
-            tb = bw*0.08
-
-            print "BW: ", bw
-            print "TB: ", tb
-            
-            chan_coeffs = gr.firdes.low_pass (1.0,                  # gain
-                                              1.0,                  # sampling 
rate
-                                              bw+tb,                   # 
midpoint of trans. band
-                                              tb,               # width of 
trans. band
-                                              gr.firdes.WIN_HAMMING)   # 
filter type
-            print chan_coeffs
-            f = open("channel_filter_taps.txt", 'w')
-            for x in chan_coeffs:
-                f.write("%e\n" % x)
-            f.close()
-                        
-        else:
-            chan_coeffs = [ 1.0, 0.0, 0 ] 
-        self.chan_filt = gr.fft_filter_ccc(1, chan_coeffs)
-
         # receiver
-        self.packet_receiver = \
+        self.ofdm_receiver = \
             blks.demod_ofdm_pkts(fg, options,
                                  callback=self._rx_callback)
 
         # Carrier Sensing Blocks
-        alpha = 0.001
-        thresh = 30   # in dB, will have to adjust
-        self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha)
-        fg.connect(self.chan_filt, self.probe)
+        #alpha = 0.001
+        #thresh = 30   # in dB, will have to adjust
+        #self.probe = gr.probe_avg_mag_sqrd_c(thresh,alpha)
+        #fg.connect(self.chan_filt, self.probe)
 
         # Display some information about the setup
         if self._verbose:
             self._print_verbage()
         
-        fg.connect(self.chan_filt, self.packet_receiver)
-        #fg.connect(self.chan_filt, gr.file_sink(gr.sizeof_gr_complex, 
"ofdmrx_chflt.dat"))
-        gr.hier_block.__init__(self, fg, self.chan_filt, None)
+        gr.hier_block.__init__(self, fg, self.ofdm_receiver, None)
 
     def carrier_sensed(self):
         """





reply via email to

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