Exemplo n.º 1
0
    def __init__(self,
                 cp_len=32,
                 fft_len=64,
                 max_fft_shift=4,
                 occupied_carriers=48,
                 ports=2):
        gr.hier_block2.__init__(
            self,
            "OFDM Mutichannel Recover",
            gr.io_signaturev(
                2, 2, [gr.sizeof_gr_complex * 1, gr.sizeof_gr_complex * 1]),
            gr.io_signaturev(2, 2, [
                gr.sizeof_gr_complex * occupied_carriers,
                gr.sizeof_gr_complex * occupied_carriers
            ]),
        )
        self.message_port_register_hier_out("packet")
        self.message_port_register_hier_out("header_dfe")

        ##################################################
        # Parameters
        ##################################################
        self.cp_len = cp_len
        self.fft_len = fft_len
        self.max_fft_shift = max_fft_shift
        self.occupied_carriers = occupied_carriers
        self.ports = ports

        ##################################################
        # Variables
        ##################################################
        self.rcvd_pktq = rcvd_pktq = gr.msg_queue()
        self.modulation = modulation = 'bpsk'
        self.mods = mods = {
            "bpsk": 2,
            "qpsk": 4,
            "8psk": 8,
            "qam8": 8,
            "qam16": 16,
            "qam64": 64,
            "qam256": 256
        }
        self.bw = bw = (float(occupied_carriers) / float(fft_len)) / 2.0
        self.watcher = watcher = pp._queue_watcher_thread(rcvd_pktq)
        self.tb = tb = bw * 0.08
        self.samp_rate = samp_rate = 32000
        self.rotated_const = rotated_const = gp.gen_framer_info(modulation)
        self.phgain = phgain = 0.25
        self.arity = arity = mods[modulation]

        ##################################################
        # Blocks
        ##################################################
        self.ofdm_sync_channel_0 = ofdm_sync_channel(
            cp_len=cp_len,
            fftlen=fft_len,
            max_fft_shift=max_fft_shift,
            occupied_carriers=occupied_carriers,
        )
        self.ofdm_packet_sync_0 = ofdm_packet_sync(
            cp_len=cp_len,
            fft_len=fft_len,
        )

        self.fft_filter_xxx_0 = filter.fft_filter_ccc(
            1, (filter.firdes.low_pass(1.0, 1.0, bw + tb, tb,
                                       filter.firdes.WIN_HAMMING)), 1)
        self.fft_filter_xxx_0.declare_sample_delay(0)
        self.ofdm_ofdm_mrx_frame_sink_0 = ofdm.ofdm_mrx_frame_sink(
            rotated_const, range(arity), rcvd_pktq, occupied_carriers, phgain,
            phgain * phgain / 4.0, ports)

        for p in range(ports - 1):
            # Add OFDM Sync Channel
            object_name_osc = 'ofdm_sync_channel_' + str(p + 1)
            setattr(
                self, object_name_osc,
                ofdm_sync_channel(
                    cp_len=cp_len,
                    fftlen=fft_len,
                    max_fft_shift=max_fft_shift,
                    occupied_carriers=occupied_carriers,
                ))

            # Add FFT Filter
            object_name_ft = 'fft_filter_ccc_' + str(p + 1)
            setattr(
                self, object_name_ft,
                filter.fft_filter_ccc(1, (filter.firdes.low_pass(
                    1.0, 1.0, bw + tb, tb, filter.firdes.WIN_HAMMING)), 1))
            # self.fft_filter_xxx_0_0.declare_sample_delay(0)
            setattr(getattr(self, object_name_ft), 'declare_sample_delay', 0)

            # Add null sink
            object_name_ns = 'blocks_null_sink_' + str(p + 1)
            setattr(self, object_name_ns, blocks.null_sink(gr.sizeof_char * 1))

            ### Connections
            # Pad to FFT Filter
            self.connect((self, p + 1), (getattr(self, object_name_ft), 0))

            # FFT Filt to OFS
            self.connect((getattr(self, object_name_ft), 0),
                         (getattr(self, object_name_osc), 0))

            # PS To OFDM SC
            self.connect((self.ofdm_packet_sync_0, 0),
                         (getattr(self, object_name_osc), 2))
            self.connect((self.ofdm_packet_sync_0, 1),
                         (getattr(self, object_name_osc), 1))

            # OSC To OFDM Frame Sink
            self.connect((getattr(self, object_name_osc), 1),
                         (self.ofdm_sync_channel_0, p + 2))

            # OSC To Null Sink
            self.connect((getattr(self, object_name_osc), 0),
                         (self.blocks_null_sink_0, 0))

            # OFDM Frame Sink to Pad
            self.connect((self.ofdm_ofdm_mrx_frame_sink_0, p), (self, p))

        ##################################################
        # Connections
        ##################################################
        self.connect((self, 0), (self.fft_filter_xxx_0, 0))
        self.connect((self.fft_filter_xxx_0, 0), (self.ofdm_packet_sync_0, 0))

        self.connect((self.ofdm_packet_sync_0, 0),
                     (self.ofdm_sync_channel_0, 2))
        self.connect((self.ofdm_packet_sync_0, 1),
                     (self.ofdm_sync_channel_0, 1))
        self.connect((self.ofdm_packet_sync_0, 2),
                     (self.ofdm_sync_channel_0, 0))

        self.connect((self.ofdm_sync_channel_0, 0),
                     (self.ofdm_ofdm_mrx_frame_sink_0, 0))  # Flag
        self.connect((self.ofdm_sync_channel_0, 1),
                     (self.ofdm_ofdm_mrx_frame_sink_0, 1))

        self.msg_connect((self.ofdm_ofdm_mrx_frame_sink_0, 'packet'),
                         (self, 'packet'))
        self.msg_connect((self.ofdm_ofdm_mrx_frame_sink_0, 'header_dfe'),
                         (self, 'header_dfe'))
Exemplo n.º 2
0
    def __init__(self, options, num_channels, callback=None):
        """
	Hierarchical block for demodulating and deframing packets.

	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)
	"""

        self.rx_channels = num_channels#len(options.args.split(','))

	gr.hier_block2.__init__(self, "ofdm_demod",
				gr.io_signaturev(self.rx_channels, self.rx_channels, gen_multiple_ios(self.rx_channels,1) ), # Input signature
				gr.io_signaturev(self.rx_channels, self.rx_channels, gen_multiple_ios(self.rx_channels,options.occupied_tones) ))
                #[gr.sizeof_gr_complex*options.occupied_tones, gr.sizeof_gr_complex*options.occupied_tones])) # Output signature


        self._rcvd_pktq = gr.msg_queue()          # holds packets from the PHY from all receive channels

        self._modulation = options.modulation
        self._fft_length = options.fft_length
        self._occupied_tones = options.occupied_tones
        self._cp_length = options.cp_length
        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))
        ksfreq = known_symbols_4512_3[0:self._occupied_tones]
        for i in range(len(ksfreq)):
            if((zeros_on_left + i) & 1):
                ksfreq[i] = 0

        # hard-coded known symbols
        preambles = (ksfreq,)

        symbol_length = self._fft_length + self._cp_length
        self.ofdm_recv = ofdm_receiver(self.rx_channels, self._fft_length,
                                       self._cp_length,
                                       self._occupied_tones,
                                       self._snr, preambles,
                                       options.log)

        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())
        elif(self._modulation.find("qam") >= 0):
            constel = qam.qam_constellation(arity)
            rotated_const = map(lambda pt: pt * rot, constel.points())
        #print rotated_const

        phgain = 0.25
        frgain = phgain*phgain / 4.0
        # self.ofdm_demod = ofdm.ofdm_frame_sink(rotated_const, range(arity),self._rcvd_pktq,self._occupied_tones,phgain, frgain, 3)
        self.ofdm_demod = ofdm.ofdm_mrx_frame_sink(rotated_const, range(arity),self._rcvd_pktq,self._occupied_tones,phgain, frgain, self.rx_channels)

        self.mdb = blocks.message_debug()

        ############# CONNECTIONS ##############

        # Connect ofdm_receiver flag to ofdm framer flag
        self.connect((self.ofdm_recv, 1), (self.ofdm_demod, 0)) # Connect flag from 1st chain only

        # Connect frame sink msg port to debugger
        self.msg_connect((self.ofdm_demod, 'packet'), (self.mdb,'print'))

        # Connect remaining data ports
        port = 0
        for c in range(self.rx_channels):

            # Connect USRP's to channel filters
            self.connect((self,c), (self.ofdm_recv,c))

            # Add null sink
            object_name_ns = 'null_sink_'+str(c)
            setattr(self, object_name_ns, blocks.null_sink(gr.sizeof_char*1))

            # Connect ofdm_receiver to ofdm framer
            self.connect((self.ofdm_recv, port), (self.ofdm_demod, c+1)) # Occupied tones

            # Connect extra port(s) to null since we dont need it now
            self.connect((self.ofdm_recv, port+1), (getattr(self,object_name_ns), 0))
            port = port + 2

            # Connect equalized signals to output
            self.connect((self.ofdm_demod, c), (self, c))

        # added output signature to work around bug, though it might not be a bad
        # thing to export, anyway
        # self.connect(self.ofdm_recv.chan_filt, (self,0))

        ############## ##############

        if options.log:
            self.connect(self.ofdm_demod,
                         blocks.file_sink(gr.sizeof_gr_complex*self._occupied_tones,
                                      "ofdm_frame_sink_c.dat"))
        else:
            self.connect(self.ofdm_demod,
                         blocks.null_sink(gr.sizeof_gr_complex*self._occupied_tones))

        if options.verbose:
            self._print_verbage()

        self._watcher = _queue_watcher_thread(self._rcvd_pktq, callback)
Exemplo n.º 3
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block2")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block2")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "top_block2")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.occupied_carriers = occupied_carriers = 200
        self.fft_len = fft_len = 512
        self.rcvd_pktq = rcvd_pktq = gr.msg_queue()
        self.modulation = modulation = 'bpsk'
        self.mods = mods = {"bpsk": 2, "qpsk": 4, "8psk": 8, "qam8": 8, "qam16": 16, "qam64": 64, "qam256": 256}
        self.bw = bw = (float(occupied_carriers) / float(fft_len)) / 2.0
        self.zeros_on_left = zeros_on_left = int(math.ceil((fft_len - occupied_carriers)/2.0))
        self.win = win = [1 for i in range(fft_len )]
        self.watcher = watcher = pp._queue_watcher_thread(rcvd_pktq)
        self.tb = tb = bw*0.08
        self.samp_rate = samp_rate = 100000000/16
        self.rotated_const = rotated_const = gp.gen_framer_info(modulation)
        self.phgain = phgain = 0.25
        self.max_fft_shift = max_fft_shift = 4
        self.ks0 = ks0 = gp.gen_preamble_data(fft_len , occupied_carriers)
        self.cp_len = cp_len = 128
        self.arity = arity = mods[modulation]

        ##################################################
        # Blocks
        ##################################################
        self.qtgui_time_sink_x_0 = qtgui.time_sink_c(
        	1024, #size
        	samp_rate, #samp_rate
        	"", #name
        	1 #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-1, 1)
        
        self.qtgui_time_sink_x_0.set_y_label("Amplitude", "")
        
        self.qtgui_time_sink_x_0.enable_tags(-1, True)
        self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.qtgui_time_sink_x_0.enable_autoscale(False)
        self.qtgui_time_sink_x_0.enable_grid(False)
        self.qtgui_time_sink_x_0.enable_control_panel(False)
        
        if not True:
          self.qtgui_time_sink_x_0.disable_legend()
        
        labels = ["", "", "", "", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "blue"]
        styles = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1,
                   -1, -1, -1, -1, -1]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        
        for i in xrange(2*1):
            if len(labels[i]) == 0:
                if(i % 2 == 0):
                    self.qtgui_time_sink_x_0.set_line_label(i, "Re{{Data {0}}}".format(i/2))
                else:
                    self.qtgui_time_sink_x_0.set_line_label(i, "Im{{Data {0}}}".format(i/2))
            else:
                self.qtgui_time_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.qtgui_number_sink_0 = qtgui.number_sink(
            gr.sizeof_char,
            0,
            qtgui.NUM_GRAPH_HORIZ,
            1
        )
        self.qtgui_number_sink_0.set_update_time(0.10)
        self.qtgui_number_sink_0.set_title("")
        
        labels = ["", "", "", "", "",
                  "", "", "", "", ""]
        units = ["", "", "", "", "",
                 "", "", "", "", ""]
        colors = [("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"),
                  ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black"), ("black", "black")]
        factor = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        for i in xrange(1):
            self.qtgui_number_sink_0.set_min(i, -1)
            self.qtgui_number_sink_0.set_max(i, 1)
            self.qtgui_number_sink_0.set_color(i, colors[i][0], colors[i][1])
            if len(labels[i]) == 0:
                self.qtgui_number_sink_0.set_label(i, "Data {0}".format(i))
            else:
                self.qtgui_number_sink_0.set_label(i, labels[i])
            self.qtgui_number_sink_0.set_unit(i, units[i])
            self.qtgui_number_sink_0.set_factor(i, factor[i])
        
        self.qtgui_number_sink_0.enable_autoscale(False)
        self._qtgui_number_sink_0_win = sip.wrapinstance(self.qtgui_number_sink_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_number_sink_0_win)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	samp_rate, #bw
        	"", #name
        	1 #number of inputs
        )
        self.qtgui_freq_sink_x_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0.set_y_axis(-140, 10)
        self.qtgui_freq_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0, 0, "")
        self.qtgui_freq_sink_x_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0.enable_grid(False)
        self.qtgui_freq_sink_x_0.set_fft_average(1.0)
        self.qtgui_freq_sink_x_0.enable_control_panel(False)
        
        if not True:
          self.qtgui_freq_sink_x_0.disable_legend()
        
        if "complex" == "float" or "complex" == "msg_float":
          self.qtgui_freq_sink_x_0.set_plot_pos_half(not True)
        
        labels = ["", "", "", "", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "dark blue"]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_freq_sink_x_0_win = sip.wrapinstance(self.qtgui_freq_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_freq_sink_x_0_win)
        self.qtgui_const_sink_x_0 = qtgui.const_sink_c(
        	1024, #size
        	"", #name
        	1 #number of inputs
        )
        self.qtgui_const_sink_x_0.set_update_time(0.10)
        self.qtgui_const_sink_x_0.set_y_axis(-2, 2)
        self.qtgui_const_sink_x_0.set_x_axis(-2, 2)
        self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "")
        self.qtgui_const_sink_x_0.enable_autoscale(True)
        self.qtgui_const_sink_x_0.enable_grid(True)
        
        if not True:
          self.qtgui_const_sink_x_0.disable_legend()
        
        labels = ["", "", "", "", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "red", "red", "red",
                  "red", "red", "red", "red", "red"]
        styles = [0, 0, 0, 0, 0,
                  0, 0, 0, 0, 0]
        markers = [0, 0, 0, 0, 0,
                   0, 0, 0, 0, 0]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_const_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_const_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_const_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_const_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_const_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_const_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_const_sink_x_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_const_sink_x_0_win)
        self.ofdm_packet_sync_0 = ofdm_packet_sync(
            fft_len=fft_len,
            cp_len=cp_len,
        )
        self.ofdm_ofdm_mrx_frame_sink_0 = ofdm.ofdm_mrx_frame_sink(rotated_const, range(arity), rcvd_pktq, occupied_carriers, phgain, phgain*phgain /4.0, 1)
        self.fft_vxx_0 = fft.fft_vcc(fft_len, True, (win), True, 1)
        self.fft_filter_xxx_0 = filter.fft_filter_ccc(1, (filter.firdes.low_pass (1.0, 1.0, bw+tb, tb, filter.firdes.WIN_HAMMING)), 1)
        self.fft_filter_xxx_0.declare_sample_delay(0)
        self.digital_ofdm_sampler_0 = digital.ofdm_sampler(fft_len, cp_len+fft_len, 1000000)
        self.digital_ofdm_frame_acquisition_0 = digital.ofdm_frame_acquisition(occupied_carriers, fft_len, cp_len, (ks0), max_fft_shift)
        self.blocks_vector_to_stream_0_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, occupied_carriers)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_message_debug_0_0 = blocks.message_debug()
        self.blocks_message_debug_0 = blocks.message_debug()
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_gr_complex*1, "/tmp/data.txt", False)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.ofdm_ofdm_mrx_frame_sink_0, 'packet'), (self.blocks_message_debug_0, 'store'))    
        self.msg_connect((self.ofdm_ofdm_mrx_frame_sink_0, 'header_dfe'), (self.blocks_message_debug_0_0, 'store'))    
        self.connect((self.blocks_file_source_0, 0), (self.blocks_throttle_0, 0))    
        self.connect((self.blocks_multiply_xx_0, 0), (self.digital_ofdm_sampler_0, 0))    
        self.connect((self.blocks_throttle_0, 0), (self.fft_filter_xxx_0, 0))    
        self.connect((self.blocks_vector_to_stream_0_0, 0), (self.qtgui_const_sink_x_0, 0))    
        self.connect((self.digital_ofdm_frame_acquisition_0, 1), (self.ofdm_ofdm_mrx_frame_sink_0, 0))    
        self.connect((self.digital_ofdm_frame_acquisition_0, 0), (self.ofdm_ofdm_mrx_frame_sink_0, 1))    
        self.connect((self.digital_ofdm_sampler_0, 1), (self.digital_ofdm_frame_acquisition_0, 1))    
        self.connect((self.digital_ofdm_sampler_0, 0), (self.fft_vxx_0, 0))    
        self.connect((self.fft_filter_xxx_0, 0), (self.ofdm_packet_sync_0, 0))    
        self.connect((self.fft_filter_xxx_0, 0), (self.qtgui_time_sink_x_0, 0))    
        self.connect((self.fft_vxx_0, 0), (self.digital_ofdm_frame_acquisition_0, 0))    
        self.connect((self.ofdm_ofdm_mrx_frame_sink_0, 0), (self.blocks_vector_to_stream_0_0, 0))    
        self.connect((self.ofdm_packet_sync_0, 1), (self.blocks_multiply_xx_0, 0))    
        self.connect((self.ofdm_packet_sync_0, 2), (self.blocks_multiply_xx_0, 1))    
        self.connect((self.ofdm_packet_sync_0, 0), (self.digital_ofdm_sampler_0, 1))    
        self.connect((self.ofdm_packet_sync_0, 2), (self.qtgui_freq_sink_x_0, 0))    
        self.connect((self.ofdm_packet_sync_0, 0), (self.qtgui_number_sink_0, 0))    
Exemplo n.º 4
0
    def __init__(self, cp_len=32, fft_len=64, max_fft_shift=4, occupied_carriers=48, ports=2):
        gr.hier_block2.__init__(
            self, "OFDM Mutichannel Recover",
            gr.io_signaturev(2, 2, [gr.sizeof_gr_complex*1, gr.sizeof_gr_complex*1]),
            gr.io_signaturev(2, 2, [gr.sizeof_gr_complex*occupied_carriers, gr.sizeof_gr_complex*occupied_carriers]),
        )
        self.message_port_register_hier_out("packet")
        self.message_port_register_hier_out("header_dfe")

        ##################################################
        # Parameters
        ##################################################
        self.cp_len = cp_len
        self.fft_len = fft_len
        self.max_fft_shift = max_fft_shift
        self.occupied_carriers = occupied_carriers
        self.ports = ports

        ##################################################
        # Variables
        ##################################################
        self.rcvd_pktq = rcvd_pktq = gr.msg_queue()
        self.modulation = modulation = 'bpsk'
        self.mods = mods = {"bpsk": 2, "qpsk": 4, "8psk": 8, "qam8": 8, "qam16": 16, "qam64": 64, "qam256": 256}
        self.bw = bw = (float(occupied_carriers) / float(fft_len)) / 2.0
        self.watcher = watcher = pp._queue_watcher_thread(rcvd_pktq)
        self.tb = tb = bw*0.08
        self.samp_rate = samp_rate = 32000
        self.rotated_const = rotated_const = gp.gen_framer_info(modulation)
        self.phgain = phgain = 0.25
        self.arity = arity = mods[modulation]

        ##################################################
        # Blocks
        ##################################################
        self.ofdm_sync_channel_0 = ofdm_sync_channel(
            cp_len=cp_len,
            fftlen=fft_len,
            max_fft_shift=max_fft_shift,
            occupied_carriers=occupied_carriers,
        )
        self.ofdm_packet_sync_0 = ofdm_packet_sync(
            cp_len=cp_len,
            fft_len=fft_len,
        )

        self.fft_filter_xxx_0 = filter.fft_filter_ccc(1, (filter.firdes.low_pass (1.0, 1.0, bw+tb, tb, filter.firdes.WIN_HAMMING)), 1)
        self.fft_filter_xxx_0.declare_sample_delay(0)
        self.ofdm_ofdm_mrx_frame_sink_0 = ofdm.ofdm_mrx_frame_sink(rotated_const, range(arity), rcvd_pktq, occupied_carriers, phgain, phgain*phgain /4.0, ports)

        for p in range(ports-1):
            # Add OFDM Sync Channel
            object_name_osc = 'ofdm_sync_channel_'+str(p+1)
            setattr(self, object_name_osc, ofdm_sync_channel(
                    cp_len=cp_len,
                    fftlen=fft_len,
                    max_fft_shift=max_fft_shift,
                    occupied_carriers=occupied_carriers,
                ))

            # Add FFT Filter
            object_name_ft = 'fft_filter_ccc_'+str(p+1)
            setattr(self, object_name_ft, filter.fft_filter_ccc(1, (filter.firdes.low_pass (1.0, 1.0, bw+tb, tb, filter.firdes.WIN_HAMMING)), 1) )
            # self.fft_filter_xxx_0_0.declare_sample_delay(0)
            setattr(getattr(self,object_name_ft),'declare_sample_delay',0)

            # Add null sink
            object_name_ns = 'blocks_null_sink_'+str(p+1)
            setattr(self, object_name_ns, blocks.null_sink(gr.sizeof_char*1) )

            ### Connections
            # Pad to FFT Filter
            self.connect( (self, p+1), (getattr(self,object_name_ft), 0))

            # FFT Filt to OFS
            self.connect( (getattr(self,object_name_ft), 0), (getattr(self,object_name_osc), 0) )

            # PS To OFDM SC
            self.connect( (self.ofdm_packet_sync_0, 0), (getattr(self,object_name_osc), 2))
            self.connect( (self.ofdm_packet_sync_0, 1), (getattr(self,object_name_osc), 1))

            # OSC To OFDM Frame Sink
            self.connect((getattr(self,object_name_osc), 1), (self.ofdm_sync_channel_0, p+2))

            # OSC To Null Sink
            self.connect((getattr(self,object_name_osc), 0), (self.blocks_null_sink_0, 0))

            # OFDM Frame Sink to Pad
            self.connect((self.ofdm_ofdm_mrx_frame_sink_0, p), (self, p))


        ##################################################
        # Connections
        ##################################################
        self.connect((self, 0), (self.fft_filter_xxx_0, 0))
        self.connect((self.fft_filter_xxx_0, 0), (self.ofdm_packet_sync_0, 0))

        self.connect((self.ofdm_packet_sync_0, 0), (self.ofdm_sync_channel_0, 2))
        self.connect((self.ofdm_packet_sync_0, 1), (self.ofdm_sync_channel_0, 1))
        self.connect((self.ofdm_packet_sync_0, 2), (self.ofdm_sync_channel_0, 0))

        self.connect((self.ofdm_sync_channel_0, 0), (self.ofdm_ofdm_mrx_frame_sink_0, 0)) # Flag
        self.connect((self.ofdm_sync_channel_0, 1), (self.ofdm_ofdm_mrx_frame_sink_0, 1))

        self.msg_connect((self.ofdm_ofdm_mrx_frame_sink_0, 'packet'), (self, 'packet'))
        self.msg_connect((self.ofdm_ofdm_mrx_frame_sink_0, 'header_dfe'), (self, 'header_dfe'))
Exemplo n.º 5
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        try:
            self.setWindowIcon(Qt.QIcon.fromTheme('gnuradio-grc'))
        except:
            pass
        self.top_scroll_layout = Qt.QVBoxLayout()
        self.setLayout(self.top_scroll_layout)
        self.top_scroll = Qt.QScrollArea()
        self.top_scroll.setFrameStyle(Qt.QFrame.NoFrame)
        self.top_scroll_layout.addWidget(self.top_scroll)
        self.top_scroll.setWidgetResizable(True)
        self.top_widget = Qt.QWidget()
        self.top_scroll.setWidget(self.top_widget)
        self.top_layout = Qt.QVBoxLayout(self.top_widget)
        self.top_grid_layout = Qt.QGridLayout()
        self.top_layout.addLayout(self.top_grid_layout)

        self.settings = Qt.QSettings("GNU Radio", "top_block")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.occupied_carriers = occupied_carriers = 200
        self.fft_len = fft_len = 512
        self.view = view = False
        self.rcvd_pktq = rcvd_pktq = gr.msg_queue()
        self.modulation = modulation = 'bpsk'
        self.mods = mods = {"bpsk": 2, "qpsk": 4, "8psk": 8, "qam8": 8, "qam16": 16, "qam64": 64, "qam256": 256}
        self.bw = bw = (float(occupied_carriers) / float(fft_len)) / 2.0
        self.zeros_on_left = zeros_on_left = int(math.ceil((fft_len - occupied_carriers)/2.0))
        self.win = win = [1 for i in range(fft_len )]
        self.watcher = watcher = pp._queue_watcher_thread(rcvd_pktq,view)
        self.tb = tb = bw*0.08
        self.samp_rate = samp_rate = 10000000/2
        self.rotated_const = rotated_const = gp.gen_framer_info(modulation)
        self.phgain = phgain = 0.25
        self.max_fft_shift = max_fft_shift = 4
        self.ks0 = ks0 = gp.gen_preamble_data(fft_len , occupied_carriers)
        self.cp_len = cp_len = 128
        self.arity = arity = mods[modulation]

        ##################################################
        # Blocks
        ##################################################
        self.twinrx_usrp_source_0 = doa.twinrx_usrp_source(
            samp_rate=samp_rate,
            center_freq=2.45e9,
            gain=60,
            sources=4,
            addresses="addr=192.168.50.2"
        )
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
        	20, #size
        	samp_rate, #samp_rate
        	"", #name
        	1 #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-1, 1)
        
        self.qtgui_time_sink_x_0.set_y_label('Amplitude', "")
        
        self.qtgui_time_sink_x_0.enable_tags(-1, True)
        self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.qtgui_time_sink_x_0.enable_autoscale(True)
        self.qtgui_time_sink_x_0.enable_grid(True)
        self.qtgui_time_sink_x_0.enable_axis_labels(True)
        self.qtgui_time_sink_x_0.enable_control_panel(True)
        
        if not True:
          self.qtgui_time_sink_x_0.disable_legend()
        
        labels = ['', '', '', '', '',
                  '', '', '', '', '']
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "dark red", "dark green", "blue"]
        styles = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1,
                   -1, -1, -1, -1, -1]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_time_sink_x_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.qtgui_const_sink_x_0 = qtgui.const_sink_c(
        	1024, #size
        	"", #name
        	4 #number of inputs
        )
        self.qtgui_const_sink_x_0.set_update_time(0.10)
        self.qtgui_const_sink_x_0.set_y_axis(-2, 2)
        self.qtgui_const_sink_x_0.set_x_axis(-2, 2)
        self.qtgui_const_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, "")
        self.qtgui_const_sink_x_0.enable_autoscale(True)
        self.qtgui_const_sink_x_0.enable_grid(True)
        self.qtgui_const_sink_x_0.enable_axis_labels(True)
        
        if not True:
          self.qtgui_const_sink_x_0.disable_legend()
        
        labels = ['', '', '', '', '',
                  '', '', '', '', '']
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "red", "red", "red",
                  "red", "red", "red", "red", "red"]
        styles = [0, 0, 0, 0, 0,
                  0, 0, 0, 0, 0]
        markers = [0, 1, 2, 3, 0,
                   0, 0, 0, 0, 0]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(4):
            if len(labels[i]) == 0:
                self.qtgui_const_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_const_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_const_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_const_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_const_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_const_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_const_sink_x_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_const_sink_x_0_win)
        self.phase_correct_hier_1 = doa.phase_correct_hier(
            num_ports=4,
            config_filename='/tmp/measure_X310_TwinRX_phase_offsets_245.cfg',
        )
        self.ofdm_packet_sync_0 = ofdm_packet_sync(
            cp_len=cp_len,
            fft_len=fft_len,
        )
        self.ofdm_ofdm_mrx_frame_sink_0 = ofdm.ofdm_mrx_frame_sink(rotated_const, range(arity), rcvd_pktq, occupied_carriers, phgain, phgain*phgain /4.0, 4)
        self.ofdm_m_channel_sync_0 = ofdm_m_channel_sync(
            cp_len=cp_len,
            fft_len=fft_len,
            max_fft_shift=max_fft_shift,
            occupied_carriers=occupied_carriers,
        )
        self.ofdm_eadf_doa_0 = ofdm.eadf_doa('/home/travis/Dropbox/PHD/WiFiUS/doa/gnuradio/gr-ofdm/matlab_code/data.mat', 4, 256)
        self.fft_filter_xxx_0_0_0_0 = filter.fft_filter_ccc(1, (filter.firdes.low_pass (1.0, 1.0, bw+tb, tb, filter.firdes.WIN_HAMMING)), 1)
        self.fft_filter_xxx_0_0_0_0.declare_sample_delay(0)
        self.fft_filter_xxx_0_0_0 = filter.fft_filter_ccc(1, (filter.firdes.low_pass (1.0, 1.0, bw+tb, tb, filter.firdes.WIN_HAMMING)), 1)
        self.fft_filter_xxx_0_0_0.declare_sample_delay(0)
        self.fft_filter_xxx_0_0 = filter.fft_filter_ccc(1, (filter.firdes.low_pass (1.0, 1.0, bw+tb, tb, filter.firdes.WIN_HAMMING)), 1)
        self.fft_filter_xxx_0_0.declare_sample_delay(0)
        self.fft_filter_xxx_0 = filter.fft_filter_ccc(1, (filter.firdes.low_pass (1.0, 1.0, bw+tb, tb, filter.firdes.WIN_HAMMING)), 1)
        self.fft_filter_xxx_0.declare_sample_delay(0)
        self.equalize_chains_0 = equalize_chains(
            cp_len=cp_len,
            fft_len=fft_len,
            nports=4,
            occupied_carriers=occupied_carriers,
        )
        self.blocks_vector_to_stream_0_0_0_0_0_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, occupied_carriers)
        self.blocks_vector_to_stream_0_0_0_0_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, occupied_carriers)
        self.blocks_vector_to_stream_0_0_0_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, occupied_carriers)
        self.blocks_vector_to_stream_0_0_0 = blocks.vector_to_stream(gr.sizeof_gr_complex*1, occupied_carriers)
        self.blocks_message_debug_0 = blocks.message_debug()

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.ofdm_ofdm_mrx_frame_sink_0, 'packet'), (self.blocks_message_debug_0, 'store'))    
        self.msg_connect((self.ofdm_ofdm_mrx_frame_sink_0, 'header_dfe'), (self.ofdm_eadf_doa_0, 'Chan_Est'))    
        self.connect((self.blocks_vector_to_stream_0_0_0, 0), (self.qtgui_const_sink_x_0, 0))    
        self.connect((self.blocks_vector_to_stream_0_0_0_0, 0), (self.qtgui_const_sink_x_0, 1))    
        self.connect((self.blocks_vector_to_stream_0_0_0_0_0, 0), (self.qtgui_const_sink_x_0, 2))    
        self.connect((self.blocks_vector_to_stream_0_0_0_0_0_0, 0), (self.qtgui_const_sink_x_0, 3))    
        self.connect((self.equalize_chains_0, 0), (self.ofdm_ofdm_mrx_frame_sink_0, 1))    
        self.connect((self.equalize_chains_0, 1), (self.ofdm_ofdm_mrx_frame_sink_0, 2))    
        self.connect((self.equalize_chains_0, 2), (self.ofdm_ofdm_mrx_frame_sink_0, 3))    
        self.connect((self.equalize_chains_0, 3), (self.ofdm_ofdm_mrx_frame_sink_0, 4))    
        self.connect((self.fft_filter_xxx_0, 0), (self.ofdm_packet_sync_0, 0))    
        self.connect((self.fft_filter_xxx_0_0, 0), (self.ofdm_m_channel_sync_0, 3))    
        self.connect((self.fft_filter_xxx_0_0_0, 0), (self.ofdm_m_channel_sync_0, 4))    
        self.connect((self.fft_filter_xxx_0_0_0_0, 0), (self.ofdm_m_channel_sync_0, 5))    
        self.connect((self.ofdm_eadf_doa_0, 0), (self.qtgui_time_sink_x_0, 0))    
        self.connect((self.ofdm_m_channel_sync_0, 5), (self.equalize_chains_0, 5))    
        self.connect((self.ofdm_m_channel_sync_0, 0), (self.equalize_chains_0, 0))    
        self.connect((self.ofdm_m_channel_sync_0, 1), (self.equalize_chains_0, 1))    
        self.connect((self.ofdm_m_channel_sync_0, 2), (self.equalize_chains_0, 2))    
        self.connect((self.ofdm_m_channel_sync_0, 3), (self.equalize_chains_0, 3))    
        self.connect((self.ofdm_m_channel_sync_0, 4), (self.equalize_chains_0, 4))    
        self.connect((self.ofdm_m_channel_sync_0, 6), (self.ofdm_ofdm_mrx_frame_sink_0, 0))    
        self.connect((self.ofdm_ofdm_mrx_frame_sink_0, 0), (self.blocks_vector_to_stream_0_0_0, 0))    
        self.connect((self.ofdm_ofdm_mrx_frame_sink_0, 1), (self.blocks_vector_to_stream_0_0_0_0, 0))    
        self.connect((self.ofdm_ofdm_mrx_frame_sink_0, 2), (self.blocks_vector_to_stream_0_0_0_0_0, 0))    
        self.connect((self.ofdm_ofdm_mrx_frame_sink_0, 3), (self.blocks_vector_to_stream_0_0_0_0_0_0, 0))    
        self.connect((self.ofdm_packet_sync_0, 1), (self.ofdm_m_channel_sync_0, 1))    
        self.connect((self.ofdm_packet_sync_0, 0), (self.ofdm_m_channel_sync_0, 0))    
        self.connect((self.ofdm_packet_sync_0, 2), (self.ofdm_m_channel_sync_0, 2))    
        self.connect((self.phase_correct_hier_1, 0), (self.fft_filter_xxx_0, 0))    
        self.connect((self.phase_correct_hier_1, 1), (self.fft_filter_xxx_0_0, 0))    
        self.connect((self.phase_correct_hier_1, 2), (self.fft_filter_xxx_0_0_0, 0))    
        self.connect((self.phase_correct_hier_1, 3), (self.fft_filter_xxx_0_0_0_0, 0))    
        self.connect((self.twinrx_usrp_source_0, 0), (self.phase_correct_hier_1, 0))    
        self.connect((self.twinrx_usrp_source_0, 1), (self.phase_correct_hier_1, 1))    
        self.connect((self.twinrx_usrp_source_0, 2), (self.phase_correct_hier_1, 2))    
        self.connect((self.twinrx_usrp_source_0, 3), (self.phase_correct_hier_1, 3))