commit-gnuradio
[Top][All Lists]
Advanced

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

[Commit-gnuradio] r4173 - gnuradio/branches/developers/n4hy/ofdm/gnuradi


From: trondeau
Subject: [Commit-gnuradio] r4173 - gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm
Date: Wed, 20 Dec 2006 18:27:42 -0700 (MST)

Author: trondeau
Date: 2006-12-20 18:27:41 -0700 (Wed, 20 Dec 2006)
New Revision: 4173

Added:
   
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/benchmark_ofdm.py
   gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/ofdm.py
   
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/receive_path_simple.py
   
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/transmit_path_simple.py
Log:
loopback test flowgraph for OFDM (working and ready to test sampler)

Added: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/benchmark_ofdm.py
===================================================================
--- 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/benchmark_ofdm.py
                              (rev 0)
+++ 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/benchmark_ofdm.py
      2006-12-21 01:27:41 UTC (rev 4173)
@@ -0,0 +1,157 @@
+#!/usr/bin/env python
+#
+# Copyright 2005, 2006 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)
+# 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, modulation_utils
+from gnuradio import usrp
+from gnuradio import eng_notation
+from gnuradio.eng_option import eng_option
+from optparse import OptionParser
+
+import random, time, struct, sys, math
+
+# from current dir
+from transmit_path_simple import transmit_path
+from receive_path_simple import receive_path
+import ofdm
+
+class awgn_channel(gr.hier_block):
+    def __init__(self, fg, sample_rate, noise_voltage, frequency_offset):
+
+        self.input = gr.add_const_cc(0)
+        
+        self.noise_adder = gr.add_cc()
+        self.noise = gr.noise_source_c(gr.GR_GAUSSIAN,noise_voltage,1)
+        self.offset = gr.sig_source_c((sample_rate*1.0), 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.noise,(self.noise_adder,0))
+
+        if 0:
+            self.throttle = gr.throttle(gr.sizeof_gr_complex, 1e5)
+            fg.connect(self.mixer_offset, self.throttle, (self.noise_adder,1))
+        else:
+            fg.connect(self.mixer_offset, (self.noise_adder,1))
+
+        gr.hier_block.__init__(self, fg, self.input, self.noise_adder)
+
+class my_graph(gr.flow_graph):
+    def __init__(self, callback, options):
+        gr.flow_graph.__init__(self)
+
+        channel_on = False
+
+        SNR = 10.0**(options.snr/10.0)
+        frequency_offset = options.frequency_offset / options.fft_length
+
+#        print "SNR:              %f" % options.snr
+#        print "Frequency offset: %f" % options.frequency_offset
+        
+        power_in_signal = options.occupied_tones
+        noise_power_in_channel = power_in_signal/SNR
+        noise_power_required = noise_power_in_channel * options.fft_length / 
options.occupied_tones
+        noise_voltage = math.sqrt(noise_power_required)
+        
+        self.txpath = transmit_path(self, options)
+        self.rxpath = receive_path(self, callback, options)
+
+        if channel_on:
+            self.channel = awgn_channel(self, options.sample_rate, 
noise_voltage, frequency_offset)
+            self.connect(self.txpath, self.channel)
+            self.connect(self.channel, self.rxpath)
+        else:
+            self.connect(self.txpath, 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"))
+
+
+# /////////////////////////////////////////////////////////////////////////////
+#                                   main
+# /////////////////////////////////////////////////////////////////////////////
+
+def main():
+    global n_rcvd, n_right
+        
+    n_rcvd = 0
+    n_right = 0
+        
+    def send_pkt(payload='', eof=False):
+        return fg.txpath.send_pkt(payload, eof)
+        
+    def rx_callback(ok, payload):
+        global n_rcvd, n_right
+        n_rcvd += 1
+        if ok:
+            n_right += 1
+        print "ok: %r \t n_rcvd: %d \t n_right: %d" % (ok, n_rcvd, n_right)
+                
+    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=1500,
+                      help="set packet size [default=%default]")
+    parser.add_option("-M", "--megabytes", type="eng_float", default=1.0,
+                      help="set megabytes to transmit [default=%default]")
+    parser.add_option("-r", "--sample-rate", type="eng_float", default=48000,
+                      help="set sample rate to RATE (%default)") 
+    parser.add_option("", "--snr", type="eng_float", default=30,
+                      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]")
+    transmit_path.add_options(parser, expert_grp)
+    ofdm.ofdm_mod.add_options(parser, expert_grp)
+    ofdm.ofdm_demod.add_options(parser, expert_grp)
+    
+    (options, args) = parser.parse_args ()
+        
+    # build the graph
+    fg = my_graph(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
+        
+    # generate and send packets
+    nbytes = int(1e6 * options.megabytes)
+    n = 0
+    pktno = 0
+    pkt_size = int(options.size)
+    
+    while n < nbytes:
+        pkt_contents = struct.pack('!H', pktno) + (pkt_size - 2) * chr(pktno & 
0xff)
+        send_pkt(pkt_contents)
+        n += pkt_size
+        #sys.stderr.write('.')
+        #if options.discontinuous and pktno % 5 == 4:
+        #    time.sleep(1)
+        pktno += 1
+        
+    send_pkt(eof=True)
+    fg.wait()                       # wait for it to finish
+
+if __name__ == '__main__':
+    try:
+        main()
+    except KeyboardInterrupt:
+        pass


Property changes on: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/benchmark_ofdm.py
___________________________________________________________________
Name: svn:executable
   + *

Added: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/ofdm.py
===================================================================
--- 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/ofdm.py    
                            (rev 0)
+++ 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/ofdm.py    
    2006-12-21 01:27:41 UTC (rev 4173)
@@ -0,0 +1,134 @@
+#!/usr/bin/env python
+#
+# Copyright 2004,2005,2006 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)
+# 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
+from optparse import OptionParser
+from ofdm_receiver import ofdm_receiver
+
+class ofdm_mod(gr.hier_block):
+    def __init__(self, fg, options):
+        self.fg = fg
+        self._occupied_tones = options.occupied_tones
+        self._fft_length = options.fft_length
+        self._cp_length = options.cp_length
+
+        symbol_length = self._fft_length + self._cp_length
+
+        if self._fft_length < self._occupied_tones:
+            sys.stderr.write("occupied tones must be less than FFT length\n")
+            raise SystemExit
+        if self._fft_length < self._cp_length:
+            sys.stderr.write("cyclic prefix length  must be less than FFT 
length\n")
+            raise SystemExit
+
+        win = [] #[1 for i in range(self._fft_length)]
+
+        self.ofdm = gr.ofdm_bpsk_mapper(1500, self._occupied_tones, 
self._fft_length)
+        self.ifft = gr.fft_vcc(self._fft_length, False, win, True)
+        self.cp_adder = gr.ofdm_cyclic_prefixer(self._fft_length, 
symbol_length)
+
+        if options.verbose:
+            self._print_verbage()
+
+        self.fg.connect(self.ofdm, self.ifft, self.cp_adder)
+        gr.hier_block.__init__(self, self.fg, self.ofdm, self.cp_adder)
+
+    def samples_per_symbol(self):
+        return 2
+
+    def bits_per_symbol(self=None):   # staticmethod that's also callable on 
an instance
+        return 1
+    bits_per_symbol = staticmethod(bits_per_symbol)      # make it a static 
method.  RTFM
+
+    def add_options(normal, expert):
+        """
+        Adds OFDM-specific options to the Options Parser
+        """
+        expert.add_option("", "--fft-length", type="intx", default=512,
+                          help="set the number of FFT bins [default=%default]")
+        expert.add_option("", "--occupied-tones", type="intx", default=480,
+                          help="set the number of occupied FFT bins 
[default=%default]")
+        expert.add_option("", "--cp-length", type="intx", default=32,
+                          help="set the number of bits in the cyclic prefix 
[default=%default]")
+    # Make a static method to call before instantiation
+    add_options = staticmethod(add_options)
+
+    def _print_verbage(self):
+        """
+        Prints information about the OFDM modulator
+        """
+        print "\nOFDM Modulator:"
+        print "FFT length:      %3d"   % (self._fft_length)
+        print "Occupied Tones:  %3d"   % (self._occupied_tones)
+        print "CP length:       %3d"   % (self._cp_length)
+
+
+class ofdm_demod(gr.hier_block):
+    def __init__(self, fg, options):
+        self.fg = fg
+        self._occupied_tones = options.occupied_tones
+        self._fft_length = options.fft_length
+        self._cp_length = options.cp_length
+        self._snr = options.snr
+
+        symbol_length = self._fft_length + self._cp_length
+
+        win = [1 for i in range(self._fft_length)]
+
+        # ML Sync
+        self.ofdm_rx = ofdm_receiver(self.fg, self._fft_length, symbol_length, 
self._snr)
+        
+        # OFDM Demod
+        self.fftdemod = gr.fft_vcc(self._fft_length, True, win, True)
+        self.ofdm = gr.ofdm_bpsk_demapper(self._occupied_tones, 
self._fft_length)
+
+        if options.verbose:
+            self._print_verbage()
+
+        self.fg.connect(self.ofdm_rx, self.fftdemod, self.ofdm)
+        gr.hier_block.__init__(self, self.fg, self.ofdm_rx, self.ofdm)
+
+    def bits_per_symbol(self=None):   # staticmethod that's also callable on 
an instance
+        return 1
+    bits_per_symbol = staticmethod(bits_per_symbol)      # make it a static 
method.  RTFM
+
+    def add_options(normal, expert):
+        """
+        Adds OFDM-specific options to the Options Parser
+        """
+        expert.add_option("", "--fft-length", type="intx", default=512,
+                          help="set the number of FFT bins [default=%default]")
+        expert.add_option("", "--occupied-tones", type="intx", default=480,
+                          help="set the number of occupied FFT bins 
[default=%default]")
+        expert.add_option("", "--cp-length", type="intx", default=32,
+                          help="set the number of bits in the cyclic prefix 
[default=%default]")
+    # Make a static method to call before instantiation
+    add_options = staticmethod(add_options)
+
+    def _print_verbage(self):
+        """
+        Prints information about the OFDM demodulator
+        """
+        print "\nOFDM Demodulator:"
+        print "FFT length:      %3d"   % (self._fft_length)
+        print "Occupied Tones:  %3d"   % (self._occupied_tones)
+        print "CP length:       %3d"   % (self._cp_length)

Added: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/receive_path_simple.py
===================================================================
--- 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/receive_path_simple.py
                         (rev 0)
+++ 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/receive_path_simple.py
 2006-12-21 01:27:41 UTC (rev 4173)
@@ -0,0 +1,93 @@
+#!/usr/bin/env python
+#
+# Copyright 2005,2006 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)
+# 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, blks
+from gnuradio import usrp
+from gnuradio import eng_notation
+import copy
+import sys
+
+import ofdm
+
+# /////////////////////////////////////////////////////////////////////////////
+#                              receive path
+# /////////////////////////////////////////////////////////////////////////////
+
+class receive_path(gr.hier_block):
+    def __init__(self, fg, rx_callback, options):
+
+        options = copy.copy(options)    # make a copy so we can destructively 
modify
+
+        self._verbose            = options.verbose
+        self._samples_per_symbol = options.samples_per_symbol  # desired 
samples/symbol
+
+        self._rx_callback   = rx_callback      # this callback is fired when 
there's a packet available
+         
+        # Design filter to get actual channel we want
+        sw_decim = 1
+        bw = float(options.occupied_tones+25) / float(options.fft_length)
+        print options.occupied_tones
+        print options.fft_length
+        print bw
+        chan_coeffs = gr.firdes.low_pass (1.0,                  # gain
+                                          2.0,                  # sampling rate
+                                          bw,                   # midpoint of 
trans. band
+                                          1*bw,               # width of 
trans. band
+                                          gr.firdes.WIN_KAISER)   # filter 
type 
+
+        # Decimating channel filter
+        self.chan_filt = gr.fft_filter_ccc(sw_decim, chan_coeffs)
+        
+        self.ofdm_demod = ofdm.ofdm_demod(fg, options)
+
+        # receiver
+        self.packet_receiver = \
+            blks.demod_ofdm_pkts(fg,
+                                 self.ofdm_demod,
+                                 access_code=None,
+                                 callback=self._rx_callback,
+                                 threshold=-1)
+
+        if 0:
+            fg.connect(self.chan_filt, self.packet_receiver)
+            gr.hier_block.__init__(self, fg, self.chan_filt, None)
+        else:
+            gr.hier_block.__init__(self, fg, self.packet_receiver, None)
+            
+    def add_options(normal, expert):
+        """
+        Adds receiver-specific options to the Options Parser
+        """
+        normal.add_option("-v", "--verbose", action="store_true", 
default=False)
+        expert.add_option("", "--log", action="store_true", default=False,
+                          help="Log all parts of flow graph to files (CAUTION: 
lots of data)")
+        expert.add_option("-S", "--samples-per-symbol", type="int", default=2,
+                          help="set samples/symbol [default=%default]")
+
+    # Make a static method to call before instantiation
+    add_options = staticmethod(add_options)
+
+    def _print_verbage(self):
+        """
+        Prints information about the receive path
+        """
+        pass

Added: 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/transmit_path_simple.py
===================================================================
--- 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/transmit_path_simple.py
                                (rev 0)
+++ 
gnuradio/branches/developers/n4hy/ofdm/gnuradio-examples/python/ofdm/transmit_path_simple.py
        2006-12-21 01:27:41 UTC (rev 4173)
@@ -0,0 +1,80 @@
+#
+# Copyright 2005,2006 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)
+# 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, blks
+from gnuradio import usrp
+from gnuradio import eng_notation
+
+import copy
+import sys
+
+import ofdm
+
+# /////////////////////////////////////////////////////////////////////////////
+#                              transmit path
+# /////////////////////////////////////////////////////////////////////////////
+
+class transmit_path(gr.hier_block): 
+    def __init__(self, fg, options):
+        '''
+        See below for what options should hold
+        '''
+        options = copy.copy(options)    # make a copy so we can destructively 
modify
+
+        self._verbose            = options.verbose
+        self._samples_per_symbol = options.samples_per_symbol  # desired 
samples/baud
+        
+        self.ofdm_mod = ofdm.ofdm_mod(fg, options)
+        self.packet_transmitter = \
+            blks.mod_ofdm_pkts(fg,
+                               self.ofdm_mod,
+                               mtu=1500,
+                               access_code=None,
+                               msgq_limit=4,
+                               pad_for_usrp=False)
+
+        gr.hier_block.__init__(self, fg, None, self.packet_transmitter)
+
+    def send_pkt(self, payload='', eof=False):
+        """
+        Calls the transmitter method to send a packet
+        """
+        return self.packet_transmitter.send_pkt(payload, eof)
+        
+    def add_options(normal, expert):
+        """
+        Adds transmitter-specific options to the Options Parser
+        """
+        normal.add_option("-v", "--verbose", action="store_true", 
default=False)
+
+        expert.add_option("-S", "--samples-per-symbol", type="int", default=2,
+                          help="set samples/symbol [default=%default]")
+        expert.add_option("", "--log", action="store_true", default=False,
+                          help="Log all parts of flow graph to file (CAUTION: 
lots of data)")
+
+    # Make a static method to call before instantiation
+    add_options = staticmethod(add_options)
+
+    def _print_verbage(self):
+        """
+        Prints information about the transmit path
+        """
+        pass





reply via email to

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