diff options
Diffstat (limited to 'gr-digital/python/digital/ofdm.py')
-rw-r--r-- | gr-digital/python/digital/ofdm.py | 109 |
1 files changed, 57 insertions, 52 deletions
diff --git a/gr-digital/python/digital/ofdm.py b/gr-digital/python/digital/ofdm.py index 563b70ad00..db15a4d3f1 100644 --- a/gr-digital/python/digital/ofdm.py +++ b/gr-digital/python/digital/ofdm.py @@ -1,33 +1,38 @@ #!/usr/bin/env python # # Copyright 2006-2008,2013 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 __future__ import print_function +from __future__ import absolute_import +from __future__ import division +from __future__ import unicode_literals import math from gnuradio import gr, fft from gnuradio import blocks -import digital_swig as digital -import ofdm_packet_utils -from ofdm_receiver import ofdm_receiver +from . import digital_swig as digital +from . import ofdm_packet_utils +from .ofdm_receiver import ofdm_receiver import gnuradio.gr.gr_threading as _threading -import psk, qam +from . import psk, qam # ///////////////////////////////////////////////////////////////////////////// # mod/demod with packets as i/o @@ -37,12 +42,12 @@ class ofdm_mod(gr.hier_block2): """ Modulates an OFDM stream. Based on the options fft_length, occupied_tones, and cp_length, this block creates OFDM symbols using a specified modulation option. - + Send packets by calling send_pkt """ def __init__(self, options, msgq_limit=2, pad_for_usrp=True): """ - Hierarchical block for sending packets + Hierarchical block for sending packets Packets to be sent are enqueued by calling send_pkt. The output is the complex modulated signal at baseband. @@ -53,9 +58,9 @@ class ofdm_mod(gr.hier_block2): pad_for_usrp: If true, packets are padded such that they end up a multiple of 128 samples """ - gr.hier_block2.__init__(self, "ofdm_mod", - gr.io_signature(0, 0, 0), # Input signature - gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature + gr.hier_block2.__init__(self, "ofdm_mod", + gr.io_signature(0, 0, 0), # Input signature + gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._pad_for_usrp = pad_for_usrp self._modulation = options.modulation @@ -66,7 +71,7 @@ class ofdm_mod(gr.hier_block2): win = [] #[1 for i in range(self._fft_length)] # Use freq domain to get doubled-up known symbol for correlation in time domain - zeros_on_left = int(math.ceil((self._fft_length - self._occupied_tones)/2.0)) + zeros_on_left = int(math.ceil((self._fft_length - self._occupied_tones) / 2.0)) ksfreq = known_symbols_4512_3[0:self._occupied_tones] for i in range(len(ksfreq)): if((zeros_on_left + i) & 1): @@ -74,46 +79,46 @@ class ofdm_mod(gr.hier_block2): # hard-coded known symbols preambles = (ksfreq,) - + padded_preambles = list() for pre in preambles: padded = self._fft_length*[0,] padded[zeros_on_left : zeros_on_left + self._occupied_tones] = pre padded_preambles.append(padded) - + symbol_length = options.fft_length + options.cp_length - + mods = {"bpsk": 2, "qpsk": 4, "8psk": 8, "qam8": 8, "qam16": 16, "qam64": 64, "qam256": 256} arity = mods[self._modulation] - + rot = 1 if self._modulation == "qpsk": rot = (0.707+0.707j) - + # FIXME: pass the constellation objects instead of just the points if(self._modulation.find("psk") >= 0): constel = psk.psk_constellation(arity) - rotated_const = map(lambda pt: pt * rot, constel.points()) + rotated_const = [pt * rot for pt in constel.points()] elif(self._modulation.find("qam") >= 0): constel = qam.qam_constellation(arity) - rotated_const = map(lambda pt: pt * rot, constel.points()) - #print rotated_const + rotated_const = [pt * rot for pt in constel.points()] + #print(rotated_const) self._pkt_input = digital.ofdm_mapper_bcv(rotated_const, msgq_limit, options.occupied_tones, options.fft_length) - + self.preambles = digital.ofdm_insert_preamble(self._fft_length, padded_preambles) self.ifft = fft.fft_vcc(self._fft_length, False, win, True) self.cp_adder = digital.ofdm_cyclic_prefixer(self._fft_length, symbol_length) self.scale = blocks.multiply_const_cc(1.0 / math.sqrt(self._fft_length)) - + self.connect((self._pkt_input, 0), (self.preambles, 0)) self.connect((self._pkt_input, 1), (self.preambles, 1)) self.connect(self.preambles, self.ifft, self.cp_adder, self.scale, self) - + if options.verbose: self._print_verbage() @@ -137,12 +142,12 @@ class ofdm_mod(gr.hier_block2): if eof: msg = gr.message(1) # tell self._pkt_input we're not sending any more packets else: - # print "original_payload =", string_to_hex_list(payload) + # print("original_payload =", string_to_hex_list(payload)) pkt = ofdm_packet_utils.make_packet(payload, 1, 1, self._pad_for_usrp, whitening=True) - - #print "pkt =", string_to_hex_list(pkt) + + #print("pkt =", string_to_hex_list(pkt)) msg = gr.message_from_string(pkt) self._pkt_input.msgq().insert_tail(msg) @@ -164,11 +169,11 @@ class ofdm_mod(gr.hier_block2): """ Prints information about the OFDM modulator """ - print "\nOFDM Modulator:" - print "Modulation Type: %s" % (self._modulation) - print "FFT length: %3d" % (self._fft_length) - print "Occupied Tones: %3d" % (self._occupied_tones) - print "CP length: %3d" % (self._cp_length) + print("\nOFDM Modulator:") + print("Modulation Type: %s" % (self._modulation)) + 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_block2): @@ -183,18 +188,18 @@ class ofdm_demod(gr.hier_block2): def __init__(self, options, callback=None): """ - Hierarchical block for demodulating and deframing packets. + Hierarchical block for demodulating and deframing packets. - The input is the complex modulated signal at baseband. + The input is the complex modulated signal at baseband. Demodulated packets are sent to the handler. Args: options: pass modulation options from higher layers (fft length, occupied tones, etc.) callback: function of two args: ok, payload (ok: bool; payload: string) - """ - gr.hier_block2.__init__(self, "ofdm_demod", - gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature - gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature + """ + gr.hier_block2.__init__(self, "ofdm_demod", + gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature + gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature self._rcvd_pktq = gr.msg_queue() # holds packets from the PHY @@ -206,7 +211,7 @@ class ofdm_demod(gr.hier_block2): self._snr = options.snr # Use freq domain to get doubled-up known symbol for correlation in time domain - zeros_on_left = int(math.ceil((self._fft_length - self._occupied_tones)/2.0)) + zeros_on_left = int(math.ceil((self._fft_length - self._occupied_tones) / 2.0)) ksfreq = known_symbols_4512_3[0:self._occupied_tones] for i in range(len(ksfreq)): if((zeros_on_left + i) & 1): @@ -224,7 +229,7 @@ class ofdm_demod(gr.hier_block2): mods = {"bpsk": 2, "qpsk": 4, "8psk": 8, "qam8": 8, "qam16": 16, "qam64": 64, "qam256": 256} arity = mods[self._modulation] - + rot = 1 if self._modulation == "qpsk": rot = (0.707+0.707j) @@ -232,15 +237,15 @@ class ofdm_demod(gr.hier_block2): # FIXME: pass the constellation objects instead of just the points if(self._modulation.find("psk") >= 0): constel = psk.psk_constellation(arity) - rotated_const = map(lambda pt: pt * rot, constel.points()) + rotated_const = [pt * rot for pt in constel.points()] elif(self._modulation.find("qam") >= 0): constel = qam.qam_constellation(arity) - rotated_const = map(lambda pt: pt * rot, constel.points()) - #print rotated_const + rotated_const = [pt * rot for pt in constel.points()] + #print(rotated_const) phgain = 0.25 frgain = phgain*phgain / 4.0 - self.ofdm_demod = digital.ofdm_frame_sink(rotated_const, range(arity), + self.ofdm_demod = digital.ofdm_frame_sink(rotated_const, list(range(arity)), self._rcvd_pktq, self._occupied_tones, phgain, frgain) @@ -263,7 +268,7 @@ class ofdm_demod(gr.hier_block2): if options.verbose: self._print_verbage() - + self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback) @staticmethod @@ -286,11 +291,11 @@ class ofdm_demod(gr.hier_block2): """ Prints information about the OFDM demodulator """ - print "\nOFDM Demodulator:" - print "Modulation Type: %s" % (self._modulation) - print "FFT length: %3d" % (self._fft_length) - print "Occupied Tones: %3d" % (self._occupied_tones) - print "CP length: %3d" % (self._cp_length) + print("\nOFDM Demodulator:") + print("Modulation Type: %s" % (self._modulation)) + print("FFT length: %3d" % (self._fft_length)) + print("Occupied Tones: %3d" % (self._occupied_tones)) + print("CP length: %3d" % (self._cp_length)) |