Esempio n. 1
0
 def set_bits_per_symbol(self, bits_per_symbol):
     self.bits_per_symbol = bits_per_symbol
     self.set_payload_mod(
         digital.qam_constellation(
             constellation_points=2**self.bits_per_symbol))
     self.analog_noise_source_x_0.set_amplitude(
         np.sqrt(10**(np.log10(1 / self.bits_per_symbol) -
                      (self.mag / 10.0))) * 1)
     self.blocks_repack_bits_bb_0_0_1.set_k_and_l(self.bits_per_symbol, 1)
     self.blocks_repack_bits_bb_0_0_1_1.set_k_and_l(self.bits_per_symbol, 1)
Esempio n. 2
0
def make_constellation_object(params):
    gr_params = {}
    constellation_str = params['constellation']
    gr_params['m'] = params['order']
    gr_params['differential'] = params.get('differential',
                                           False)  # give it a default
    mod_code_str = params.get('mod_code', 'GRAY')
    if mod_code_str == 'GRAY' or mod_code_str == 'gray':
        gr_params['mod_code'] = digital.mod_codes.GRAY_CODE
    elif mod_code_str == 'no_code' or mod_code_str == 'NO_CODE':
        gr_params['mod_code'] = digital.mod_codes.NO_CODE
    else:
        logger.error(
            'The provided mod code for the generic modulator is not recognized'
        )
        raise AttributeError('I do not recognize this mod_code')
    logger.debug('these are the params %s', gr_params)
    if constellation_str == 'psk':
        return digital.psk_constellation(**gr_params)
    elif constellation_str == 'qam':
        return digital.qam_constellation(**gr_params)
    else:
        logger.error('The provided constellation is not supported')
        raise AttributeError('I do not recognize this constellation')
Esempio n. 3
0
    def __init__(self):
        gr.top_block.__init__(self, "BER Simulation")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("BER Simulation")
        qtgui.util.check_set_qss()
        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", "ber_sim")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(
                    self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Variables
        ##################################################
        self.constellation = constellation = digital.qam_constellation(
            64, True, digital.mod_codes.GRAY_CODE, True)
        self.bits_per_symbol = bits_per_symbol = constellation.bits_per_symbol(
        )
        self.EbN0 = EbN0 = 15
        self.sym_map = sym_map = [
            0, 1, 2, 3, 6, 7, 4, 5, 25, 24, 27, 26, 31, 30, 29, 28, 18, 19, 16,
            17, 20, 21, 22, 23, 11, 10, 9, 8, 13, 12, 15, 14
        ]
        self.samp_rate = samp_rate = 100000
        self.const_points = const_points = [(-7 + 7j), (-3 + 7j), (1 + 7j),
                                            (5 + 7j), (-5 + 5j), (-1 + 5j),
                                            (3 + 5j), (7 + 5j), (-7 + 3j),
                                            (-3 + 3j), (1 + 3j), (5 + 3j),
                                            (-5 + 1j), (-1 + 1j), (3 + 1j),
                                            (7 + 1j), (-7 - 1j), (-3 - 1j),
                                            (1 - 1j), (5 - 1j), (-5 - 3j),
                                            (-1 - 3j), (3 - 3j), (7 - 3j),
                                            (-7 - 5j), (-3 - 5j), (1 - 5j),
                                            (5 - 5j), (-5 - 7j), (-1 - 7j),
                                            (3 - 7j), (7 - 7j)]
        self.EsN0 = EsN0 = EbN0 + 10 * math.log10(bits_per_symbol)

        ##################################################
        # Blocks
        ##################################################
        self.qtgui_number_sink_0 = qtgui.number_sink(gr.sizeof_float, 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 range(1):
            self.qtgui_number_sink_0.set_min(i, 0)
            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_grid_layout.addWidget(self._qtgui_number_sink_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(False)
        self.qtgui_const_sink_x_0.enable_grid(False)
        self.qtgui_const_sink_x_0.enable_axis_labels(True)

        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 range(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_grid_layout.addWidget(self._qtgui_const_sink_x_0_win)
        self.fec_ber_bf_0 = fec.ber_bf(False, 100, -7.0)
        self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(
            constellation.base())
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc(
            constellation.points(), 1)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char * 1, samp_rate,
                                                 True)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.analog_random_source_x_0 = blocks.vector_source_b(
            list(
                map(int,
                    numpy.random.randint(0, constellation.arity(), 10000000))),
            True)
        self.analog_noise_source_x_0 = analog.noise_source_c(
            analog.GR_GAUSSIAN, 1.0 / math.sqrt(10**(EsN0 / 10)), 42)
        self._EbN0_range = Range(-2, 30, 1, 15, 200)
        self._EbN0_win = RangeWidget(self._EbN0_range, self.set_EbN0,
                                     'Eb / N0 (dB)', "counter_slider", float)
        self.top_grid_layout.addWidget(self._EbN0_win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_noise_source_x_0, 0),
                     (self.blocks_add_xx_0, 1))
        self.connect((self.analog_random_source_x_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_add_xx_0, 0),
                     (self.digital_constellation_decoder_cb_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.qtgui_const_sink_x_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.digital_chunks_to_symbols_xx_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.fec_ber_bf_0, 0))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0),
                     (self.blocks_add_xx_0, 0))
        self.connect((self.digital_constellation_decoder_cb_0, 0),
                     (self.fec_ber_bf_0, 1))
        self.connect((self.fec_ber_bf_0, 0), (self.qtgui_number_sink_0, 0))
Esempio n. 4
0
    def __init__(self, doc, ip="127.0.0.1"):
        gr.top_block.__init__(self, "RL Demod training")
        self.doc = doc
        self.plot_lst = []
        self.widget_lst = []

        ##################################################
        # Parameters
        ##################################################
        self.ip = ip

        ##################################################
        # Variables
        ##################################################
        self.pilot_symbols = pilot_symbols = ((
            1,
            1,
            1,
            -1,
        ), )
        self.pilot_carriers = pilot_carriers = ((
            -21,
            -7,
            7,
            21,
        ), )
        self.packet_length_tag_key = packet_length_tag_key = "packet_length"
        self.occupied_carriers = occupied_carriers = (
            list(range(-22, -21)) + list(range(-20, -7)) + list(range(-6, 0)) +
            list(range(1, 7)) + list(range(8, 21)) + list(range(22, 23)), )
        self.length_tag_key_0 = length_tag_key_0 = "frame_len"
        self.length_tag_key = length_tag_key = "packet_len"
        self.header_mod = header_mod = digital.constellation_bpsk()
        self.fft_len = fft_len = 64
        self.errors = errors = 0
        self.bits_per_symbol = bits_per_symbol = 4
        self.ber = ber = 0
        self.variable_qtgui_label_0_0_val = variable_qtgui_label_0_0 = ber
        self.variable_qtgui_label_0_val = variable_qtgui_label_0 = errors
        self.variable_0 = variable_0 = len(occupied_carriers[0])
        self.training_mod = training_mod = 1
        self.timestamp = timestamp = '1'
        self.t_state = t_state = 1
        self.sync_word2 = sync_word2 = [
            0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1,
            1, 1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 0, 1, -1, 1, 1, 1, -1,
            1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, -1, -1, -1,
            -1, 0, 0, 0, 0, 0
        ]
        self.sync_word1 = sync_word1 = [
            0., 0., 0., 0., 0., 0., 0., 1.41421356, 0., -1.41421356, 0.,
            1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0.,
            1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0.,
            -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., 1.41421356, 0.,
            -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0.,
            -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0.,
            -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0.,
            0., 0., 0., 0., 0.
        ]
        self.snr_stop = snr_stop = 29
        self.snr_step = snr_step = 0.5
        self.snr_start = snr_start = 0
        self.samp_rate = samp_rate = 0.3e6
        self.rx_lr = rx_lr = -2
        self.rolloff = rolloff = 0
        self.puncpat = puncpat = '11'
        self.payload_mod = payload_mod = digital.qam_constellation(
            constellation_points=2**bits_per_symbol)
        self.payload_equalizer = payload_equalizer = digital.ofdm_equalizer_static(
            fft_len, occupied_carriers, pilot_carriers, pilot_symbols, 1)
        self.packet_len = packet_len = 400
        self.mag = mag = 10
        self.ldpc_enc = ldpc_enc = fec.ldpc_encoder_make(
            gr.prefix() + "/share/gnuradio/fec/ldpc/" +
            "n_0100_k_0042_gap_02.alist")
        self.ldpc_dec = ldpc_dec = fec.ldpc_decoder.make(
            gr.prefix() + "/share/gnuradio/fec/ldpc/" +
            "n_0100_k_0042_gap_02.alist", 0.5, 50)
        self.header_formatter = header_formatter = digital.packet_header_ofdm(
            occupied_carriers,
            n_syms=1,
            len_tag_key=packet_length_tag_key,
            frame_len_tag_key=length_tag_key_0,
            bits_per_header_sym=header_mod.bits_per_symbol(),
            bits_per_payload_sym=8,
            scramble_header=False)
        self.header_equalizer = header_equalizer = digital.ofdm_equalizer_simpledfe(
            fft_len, header_mod.base(), occupied_carriers, pilot_carriers,
            pilot_symbols)
        self.hdr_format = hdr_format = digital.header_format_ofdm(
            occupied_carriers,
            1,
            length_tag_key,
        )
        self.gain_rx = gain_rx = 5
        self.freq = freq = 900e6
        self.bits_per_symbol_0 = bits_per_symbol_0 = len(occupied_carriers[0])

        ##################################################
        # Blocks
        ##################################################
        self.training_mod_textbox = bokehgui.textbox(
            self.widget_lst, str(1), 'Alternate training every' + ": ")
        self.training_mod_textbox.add_callback(
            lambda attr, old, new: self.set_training_mod(int(new)))
        self._t_state_options = [
            1,
            0,
        ]
        self._t_state_labels = [
            'On',
            'Off',
        ]

        self.t_state_radiobutton = bokehgui.radiobutton(self.widget_lst,
                                                        None,
                                                        self._t_state_labels,
                                                        inline=True)
        self.t_state_radiobutton.add_callback(
            lambda new: self.set_t_state(int(self._t_state_options[new])))
        self.rx_lr_slider = bokehgui.slider(self.widget_lst,
                                            'RX Learning rate (log)' + ":", -5,
                                            0, 0.1, 1, -2)
        self.rx_lr_slider.add_callback(
            lambda attr, old, new: self.set_rx_lr(new))
        self.mag_slider = bokehgui.slider(self.widget_lst, 'Eb/N0' + ":", 0,
                                          40, 0.1, 1, 10)
        self.mag_slider.add_callback(lambda attr, old, new: self.set_mag(new))
        self.learning_ber_bf_0 = learning.ber_bf(False, 100, -7.0, 1)
        self.gain_rx_slider = bokehgui.slider(self.widget_lst,
                                              'Amplitude Rx' + ":", 0, 90, 0.5,
                                              1, 5)
        self.gain_rx_slider.add_callback(
            lambda attr, old, new: self.set_gain_rx(new))
        self.blocks_probe_signal_x_0 = blocks.probe_signal_f()
        self.zeromq_sub_msg_source_0_0 = zeromq.sub_msg_source(
            "tcp://" + ip + ":50001", 1000)
        self.zeromq_pub_msg_sink_0_0_0 = zeromq.pub_msg_sink(
            'tcp://*:50002', 1000)
        self.variable_qtgui_label_0_0 = bokehgui.label(
            self.widget_lst, str(variable_qtgui_label_0_0), 'BER' + ": ")
        self.variable_qtgui_label_0 = bokehgui.label(
            self.widget_lst, str(variable_qtgui_label_0), 'Error count' + ": ")
        self.uhd_usrp_source_0 = uhd.usrp_source(
            ",".join(("", "")),
            uhd.stream_args(
                cpu_format="fc32",
                args='',
                channels=list(range(0, 1)),
            ),
        )

        self.uhd_usrp_source_0.set_samp_rate(samp_rate)

        self.uhd_usrp_source_0.set_time_now(uhd.time_spec(time.time()),
                                            uhd.ALL_MBOARDS)

        self.uhd_usrp_source_0.set_center_freq(freq, 0)

        self.uhd_usrp_source_0.set_antenna("TX/RX", 0)

        self.uhd_usrp_source_0.set_rx_agc(False, 0)
        self.uhd_usrp_source_0.set_gain(gain_rx, 0)
        self.timestamp_textbox = bokehgui.textbox(self.widget_lst, str('1'),
                                                  'Load timestamp' + ": ")
        self.timestamp_textbox.add_callback(
            lambda attr, old, new: self.set_timestamp(str(new)))
        self.learning_dl_demod_0 = learning.dl_demod(
            'packet_num', False, bits_per_symbol, packet_len, 20, training_mod,
            10**rx_lr, t_state,
            '/home/cyrille/Gnu-Radio/modules/gr-learning/examples/saved_models'
        )
        self.learning_align_0 = learning.align('packet_num', packet_len, 1, 48)
        self.fft_vxx_1 = fft.fft_vcc(fft_len, True, (), True, 1)
        self.fft_vxx_0 = fft.fft_vcc(fft_len, True, (), True, 1)

        def _errors_probe():
            while True:

                val = self.learning_ber_bf_0.total_errors()
                try:
                    self.set_errors(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (0.5))

        _errors_thread = threading.Thread(target=_errors_probe)
        _errors_thread.daemon = True
        _errors_thread.start()

        self.digital_packet_headerparser_b_0 = digital.packet_headerparser_b(
            header_formatter.base())
        self.digital_ofdm_sync_sc_cfb_0 = digital.ofdm_sync_sc_cfb(
            fft_len, fft_len // 4, False, 0.9)
        self.digital_ofdm_serializer_vcc_payload = digital.ofdm_serializer_vcc(
            fft_len, occupied_carriers, length_tag_key_0,
            packet_length_tag_key, 1, '', True)
        self.digital_ofdm_serializer_vcc_header = digital.ofdm_serializer_vcc(
            fft_len, occupied_carriers, length_tag_key_0, '', 0, '', True)
        self.digital_ofdm_frame_equalizer_vcvc_1 = digital.ofdm_frame_equalizer_vcvc(
            payload_equalizer.base(), fft_len // 4, length_tag_key_0, True, 0)
        self.digital_ofdm_frame_equalizer_vcvc_0 = digital.ofdm_frame_equalizer_vcvc(
            header_equalizer.base(), fft_len // 4, length_tag_key_0, True, 1)
        self.digital_ofdm_chanest_vcvc_0 = digital.ofdm_chanest_vcvc(
            sync_word1, sync_word2, 1, 0, 3, False)
        self.digital_header_payload_demux_0 = digital.header_payload_demux(
            3, fft_len, fft_len // 4, length_tag_key_0, "", True,
            gr.sizeof_gr_complex, "rx_time", int(samp_rate), (), 0)
        self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(
            header_mod.base())
        self.bokehgui_time_sink_x_0 = bokehgui.time_sink_f_proc(
            1024, samp_rate, "Decoded minus label", 1)

        self.bokehgui_time_sink_x_0_plot = bokehgui.time_sink_f(
            self.doc,
            self.plot_lst,
            self.bokehgui_time_sink_x_0,
            is_message=False)

        labels = ['', '', '', '', '', '', '', '', '', '']
        legend_list = []
        for i in range(1):
            if len(labels[i]) == 0:
                legend_list.append("Data {0}".format(i))
            else:
                legend_list.append(labels[i])
        self.bokehgui_time_sink_x_0_plot.initialize(log_x=False,
                                                    log_y=False,
                                                    update_time=500,
                                                    legend_list=legend_list)

        self.bokehgui_time_sink_x_0_plot.set_y_axis([-10, 10])
        self.bokehgui_time_sink_x_0_plot.set_y_label('Difference' + '(' + "" +
                                                     ')')
        self.bokehgui_time_sink_x_0_plot.set_x_label('Symbol' + '(' + "" + ')')

        self.bokehgui_time_sink_x_0_plot.enable_tags(-1, True)
        self.bokehgui_time_sink_x_0_plot.set_trigger_mode(
            bokehgui.TRIG_MODE_FREE, bokehgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.bokehgui_time_sink_x_0_plot.enable_grid(False)
        self.bokehgui_time_sink_x_0_plot.enable_axis_labels(True)
        self.bokehgui_time_sink_x_0_plot.disable_legend(not True)
        self.bokehgui_time_sink_x_0_plot.set_layout(*((2, 0, 1, 3)))

        colors = [
            "blue", "red", "green", "black", "cyan", "magenta", "yellow",
            "blue", "blue", "blue"
        ]
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        styles = [
            "solid", "solid", "solid", "solid", "solid", "solid", "solid",
            "solid", "solid", "solid"
        ]
        markers = [None, None, None, None, None, None, None, None, None, None]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        for i in range(1):
            self.bokehgui_time_sink_x_0_plot.format_line(
                i, colors[i], widths[i], styles[i], markers[i], alphas[i])
        self.bokehgui_time_const_x_0 = bokehgui.time_sink_c_proc(
            1024, samp_rate, "Received noisy constellation", 1)

        self.bokehgui_time_const_x_0_plot = bokehgui.const_sink_c(
            self.doc,
            self.plot_lst,
            self.bokehgui_time_const_x_0,
            is_message=False)
        labels = ['', '', '', '', '', '', '', '', '', '']
        legend_list = []
        for i in range(1):
            if len(labels[i]) == 0:
                if (i % 2 == 0):
                    legend_list.append("Re{{Data {0}}}".format(i / 2))
                else:
                    legend_list.append("Im{{Data {0}}}".format(i / 2))
            else:
                legend_list.append(labels[i])

        self.bokehgui_time_const_x_0_plot.initialize(update_time=500,
                                                     legend_list=legend_list)

        self.bokehgui_time_const_x_0_plot.set_y_axis([-2, 2])
        self.bokehgui_time_const_x_0_plot.set_y_label('Q Channel' + '(' + "" +
                                                      ')')

        self.bokehgui_time_const_x_0_plot.set_x_label('I Channel' + '(' + "" +
                                                      ')')
        self.bokehgui_time_const_x_0_plot.enable_tags(-1, False)
        self.bokehgui_time_const_x_0_plot.set_trigger_mode(
            bokehgui.TRIG_MODE_FREE, bokehgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.bokehgui_time_const_x_0_plot.enable_grid(True)
        self.bokehgui_time_const_x_0_plot.enable_axis_labels(True)
        self.bokehgui_time_const_x_0_plot.disable_legend(not True)
        self.bokehgui_time_const_x_0_plot.set_layout(*((0, 1, 2, 2)))
        colors = [
            "blue", "red", "green", "black", "cyan", "magenta", "yellow",
            "blue", "blue", "blue"
        ]
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        markers = ['o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o', 'o']
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]
        for i in range(1):
            self.bokehgui_time_const_x_0_plot.format_line(
                i, colors[i], widths[i], 'None', markers[i], alphas[i])
        self.bokehgui_frequency_sink_x_0 = bokehgui.freq_sink_c_proc(
            1024, firdes.WIN_BLACKMAN_hARRIS, freq, samp_rate, "Rx signal", 1)
        self.bokehgui_frequency_sink_x_0_plot = bokehgui.freq_sink_c(
            self.doc,
            self.plot_lst,
            self.bokehgui_frequency_sink_x_0,
            is_message=False)
        labels = ['', '', '', '', '', '', '', '', '', '']
        legend_list = []

        for i in range(1):
            if len(labels[i]) == 0:
                legend_list.append("Data {0}".format(i))
            else:
                legend_list.append(labels[i])

        self.bokehgui_frequency_sink_x_0_plot.initialize(
            update_time=100, legend_list=legend_list)

        self.bokehgui_frequency_sink_x_0_plot.set_y_axis([-140, 10])
        self.bokehgui_frequency_sink_x_0_plot.set_y_label('Relative Gain' +
                                                          '(' + 'dB' + ')')
        self.bokehgui_frequency_sink_x_0_plot.set_x_label('Frequency' + '(' +
                                                          "Hz" + ')')

        self.bokehgui_frequency_sink_x_0_plot.set_trigger_mode(
            bokehgui.TRIG_MODE_FREE, 0.0, 0, "")

        self.bokehgui_frequency_sink_x_0_plot.enable_grid(False)
        self.bokehgui_frequency_sink_x_0_plot.enable_axis_labels(True)
        self.bokehgui_frequency_sink_x_0_plot.disable_legend(not True)
        self.bokehgui_frequency_sink_x_0_plot.set_layout(*((3, 0, 1, 3)))
        self.bokehgui_frequency_sink_x_0_plot.enable_max_hold()
        colors = [
            "blue", "red", "green", "black", "cyan", "magenta", "yellow",
            "dark red", "dark green", "dark blue"
        ]
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        styles = [
            "solid", "solid", "solid", "solid", "solid", "solid", "solid",
            "solid", "solid", "solid"
        ]
        markers = [None, None, None, None, None, None, None, None, None, None]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

        for i in range(1):
            self.bokehgui_frequency_sink_x_0_plot.format_line(
                i, colors[i], widths[i], styles[i], markers[i], alphas[i])
        self.blocks_sub_xx_0 = blocks.sub_ff(1)
        self.blocks_repack_bits_bb_0_0_1_1 = blocks.repack_bits_bb(
            bits_per_symbol, 1, '', False, gr.GR_LSB_FIRST)
        self.blocks_repack_bits_bb_0_0_1 = blocks.repack_bits_bb(
            bits_per_symbol, 1, '', False, gr.GR_LSB_FIRST)
        self.blocks_pdu_to_tagged_stream_0_0 = blocks.pdu_to_tagged_stream(
            blocks.byte_t, 'packet_len')
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_float *
                                                   bits_per_symbol)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1,
                                           fft_len + 0 * (fft_len // 4) + 10)
        self.blocks_char_to_float_0_0_0 = blocks.char_to_float(1, 1)
        self.blocks_char_to_float_0_0 = blocks.char_to_float(1, 1)
        self.blocks_add_xx_0 = blocks.add_vcc(1)

        def _ber_probe():
            while True:

                val = self.blocks_probe_signal_x_0.level()
                try:
                    self.set_ber(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (0.5))

        _ber_thread = threading.Thread(target=_ber_probe)
        _ber_thread.daemon = True
        _ber_thread.start()

        self.analog_noise_source_x_0 = analog.noise_source_c(
            analog.GR_GAUSSIAN,
            np.sqrt(10**(np.log10(1 / bits_per_symbol) - (mag / 10.0))) * 1,
            -1)
        self.analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(
            -2.0 / fft_len)

        if self.widget_lst:
            input_t = bokehgui.bokeh_layout.widgetbox(self.widget_lst)
            widgetbox = bokehgui.bokeh_layout.WidgetLayout(input_t)
            widgetbox.set_layout(*((0, 0, 2, 1)))
            list_obj = [widgetbox] + self.plot_lst
        else:
            list_obj = self.plot_lst
        layout_t = bokehgui.bokeh_layout.create_layout(list_obj,
                                                       "stretch_both")
        self.doc.add_root(layout_t)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.digital_packet_headerparser_b_0, 'header_data'),
                         (self.digital_header_payload_demux_0, 'header_data'))
        self.msg_connect((self.learning_dl_demod_0, 'losses'),
                         (self.zeromq_pub_msg_sink_0_0_0, 'in'))
        self.msg_connect((self.zeromq_sub_msg_source_0_0, 'out'),
                         (self.blocks_pdu_to_tagged_stream_0_0, 'pdus'))
        self.connect((self.analog_frequency_modulator_fc_0, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.analog_noise_source_x_0, 0),
                     (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_add_xx_0, 0),
                     (self.bokehgui_time_const_x_0, 0))
        self.connect((self.blocks_add_xx_0, 0), (self.learning_align_0, 0))
        self.connect((self.blocks_char_to_float_0_0, 0),
                     (self.blocks_sub_xx_0, 0))
        self.connect((self.blocks_char_to_float_0_0_0, 0),
                     (self.blocks_sub_xx_0, 1))
        self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.digital_header_payload_demux_0, 0))
        self.connect((self.blocks_pdu_to_tagged_stream_0_0, 0),
                     (self.learning_align_0, 1))
        self.connect((self.blocks_repack_bits_bb_0_0_1, 0),
                     (self.learning_ber_bf_0, 1))
        self.connect((self.blocks_repack_bits_bb_0_0_1_1, 0),
                     (self.learning_ber_bf_0, 0))
        self.connect((self.blocks_sub_xx_0, 0),
                     (self.bokehgui_time_sink_x_0, 0))
        self.connect((self.digital_constellation_decoder_cb_0, 0),
                     (self.digital_packet_headerparser_b_0, 0))
        self.connect((self.digital_header_payload_demux_0, 0),
                     (self.fft_vxx_0, 0))
        self.connect((self.digital_header_payload_demux_0, 1),
                     (self.fft_vxx_1, 0))
        self.connect((self.digital_ofdm_chanest_vcvc_0, 0),
                     (self.digital_ofdm_frame_equalizer_vcvc_0, 0))
        self.connect((self.digital_ofdm_frame_equalizer_vcvc_0, 0),
                     (self.digital_ofdm_serializer_vcc_header, 0))
        self.connect((self.digital_ofdm_frame_equalizer_vcvc_1, 0),
                     (self.digital_ofdm_serializer_vcc_payload, 0))
        self.connect((self.digital_ofdm_serializer_vcc_header, 0),
                     (self.digital_constellation_decoder_cb_0, 0))
        self.connect((self.digital_ofdm_serializer_vcc_payload, 0),
                     (self.blocks_add_xx_0, 0))
        self.connect((self.digital_ofdm_sync_sc_cfb_0, 0),
                     (self.analog_frequency_modulator_fc_0, 0))
        self.connect((self.digital_ofdm_sync_sc_cfb_0, 1),
                     (self.digital_header_payload_demux_0, 1))
        self.connect((self.fft_vxx_0, 0),
                     (self.digital_ofdm_chanest_vcvc_0, 0))
        self.connect((self.fft_vxx_1, 0),
                     (self.digital_ofdm_frame_equalizer_vcvc_1, 0))
        self.connect((self.learning_align_0, 1), (self.learning_dl_demod_0, 1))
        self.connect((self.learning_align_0, 0), (self.learning_dl_demod_0, 0))
        self.connect((self.learning_ber_bf_0, 0),
                     (self.blocks_probe_signal_x_0, 0))
        self.connect((self.learning_dl_demod_0, 1),
                     (self.blocks_char_to_float_0_0, 0))
        self.connect((self.learning_dl_demod_0, 2),
                     (self.blocks_char_to_float_0_0_0, 0))
        self.connect((self.learning_dl_demod_0, 0),
                     (self.blocks_null_sink_0, 0))
        self.connect((self.learning_dl_demod_0, 2),
                     (self.blocks_repack_bits_bb_0_0_1, 0))
        self.connect((self.learning_dl_demod_0, 1),
                     (self.blocks_repack_bits_bb_0_0_1_1, 0))
        self.connect((self.uhd_usrp_source_0, 0), (self.blocks_delay_0, 0))
        self.connect((self.uhd_usrp_source_0, 0),
                     (self.bokehgui_frequency_sink_x_0, 0))
        self.connect((self.uhd_usrp_source_0, 0),
                     (self.digital_ofdm_sync_sc_cfb_0, 0))
Esempio n. 5
0
try:
    from matplotlib import pyplot
except ImportError:
    print(
        "Error: could not from matplotlib import pyplot (http://matplotlib.sourceforge.net/)"
    )
    sys.exit(1)

m = 64
# constellation = digital.psk_constellation(m, digital.mod_codes.GRAY_CODE, True)
# (const_points, sym_map) = digital.psk_32_0x0_<permutation>()

# sym_map = [0, 1, 2, 3, 6, 7, 4, 5, 25, 24, 27, 26, 31, 30, 29, 28, 18, 19, 16, 17, 20, 21, 22, 23, 11, 10, 9, 8, 13, 12, 15, 14]
# const_points = [(-7+7j), (-3+7j), (1+7j), (5+7j), (-5+5j), (-1+5j), (3+5j), (7+5j), (-7+3j), (-3+3j), (1+3j), (5+3j), (-5+1j), (-1+1j), (3+1j), (7+1j), (-7-1j), (-3-1j), (1-1j), (5-1j), (-5-3j), (-1-3j), (3-3j), (7-3j), (-7-5j), (-3-5j), (1-5j), (5-5j), (-5-7j), (-1-7j), (3-7j), (7-7j)]
rot_sym = 4
dims = 1

differential = True
mod_code = digital.mod_codes.GRAY_CODE
large_ampls_to_corners = True
# constellation = digital.qam_constellation(const_points, differential, mod_code, large_ampls_to_corners)
constellation = digital.qam_constellation(m, differential, mod_code,
                                          large_ampls_to_corners)
const_points = constellation.points()

# print(len(sym_map))

print(len(const_points))

# print(digital.constellation_calcdist(const_points, sym_map, rot_sym, dims))
    def __init__(self):
        gr.top_block.__init__(self, "SER Simulation", catch_exceptions=True)
        Qt.QWidget.__init__(self)
        self.setWindowTitle("SER Simulation")
        qtgui.util.check_set_qss()
        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", "ser_simulation")

        try:
            if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
                self.restoreGeometry(
                    self.settings.value("geometry").toByteArray())
            else:
                self.restoreGeometry(self.settings.value("geometry"))
        except:
            pass

        ##################################################
        # Variables
        ##################################################
        self.const3 = const3 = digital.qam_constellation(16).points()
        self.const2 = const2 = digital.constellation_8psk().points()
        self.const1 = const1 = digital.constellation_qpsk().points()
        self.const0 = const0 = digital.constellation_bpsk().points()
        self.samp_rate = samp_rate = 100e3
        self.Sps = Sps = 1
        self.M3 = M3 = len(const3)
        self.M2 = M2 = len(const2)
        self.M1 = M1 = len(const1)
        self.M0 = M0 = len(const0)
        self.run_stop = run_stop = True
        self.Rs = Rs = samp_rate / Sps
        self.N_snr = N_snr = 128
        self.MiconstellationObject3 = MiconstellationObject3 = digital.constellation_calcdist(
            const3, np.arange(M3), 4, 1,
            digital.constellation.AMPLITUDE_NORMALIZATION).base()
        self.MiconstellationObject2 = MiconstellationObject2 = digital.constellation_calcdist(
            const2, np.arange(M2), 4, 1,
            digital.constellation.AMPLITUDE_NORMALIZATION).base()
        self.MiconstellationObject1 = MiconstellationObject1 = digital.constellation_calcdist(
            const1, np.arange(M1), 4, 1,
            digital.constellation.AMPLITUDE_NORMALIZATION).base()
        self.MiconstellationObject0 = MiconstellationObject0 = digital.constellation_calcdist(
            const0, np.arange(M0), 4, 1,
            digital.constellation.AMPLITUDE_NORMALIZATION).base()
        self.MaxErrors = MaxErrors = 1000
        self.MaxCount = MaxCount = int(1e7)
        self.EsN0min = EsN0min = -5.
        self.EsN0max = EsN0max = 25.

        ##################################################
        # Blocks
        ##################################################
        _run_stop_check_box = Qt.QCheckBox('Inicial/Parar')
        self._run_stop_choices = {True: True, False: False}
        self._run_stop_choices_inv = dict(
            (v, k) for k, v in self._run_stop_choices.items())
        self._run_stop_callback = lambda i: Qt.QMetaObject.invokeMethod(
            _run_stop_check_box, "setChecked",
            Qt.Q_ARG("bool", self._run_stop_choices_inv[i]))
        self._run_stop_callback(self.run_stop)
        _run_stop_check_box.stateChanged.connect(
            lambda i: self.set_run_stop(self._run_stop_choices[bool(i)]))
        self.top_grid_layout.addWidget(_run_stop_check_box, 0, 0, 1, 1)
        for r in range(0, 1):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.qtgui_vector_sink_f_0 = qtgui.vector_sink_f(
            N_snr,
            EsN0min,
            (EsN0max - EsN0min) / float(N_snr),
            "Es/N0 [dB]",
            "logPe",
            "Curva de BER",
            4,  # Number of inputs
            None  # parent
        )
        self.qtgui_vector_sink_f_0.set_update_time(0.10)
        self.qtgui_vector_sink_f_0.set_y_axis(-8, 0)
        self.qtgui_vector_sink_f_0.enable_autoscale(False)
        self.qtgui_vector_sink_f_0.enable_grid(False)
        self.qtgui_vector_sink_f_0.set_x_axis_units("dB")
        self.qtgui_vector_sink_f_0.set_y_axis_units("")
        self.qtgui_vector_sink_f_0.set_ref_level(0)

        labels = ["BPSK", "QPSK", '8PSK', "16QAM", '', '', '', '', '', '']
        widths = [4, 4, 4, 4, 1, 1, 1, 1, 1, 1]
        colors = [
            "blue", "red", "green", "black", "cyan", "magenta", "yellow",
            "dark red", "dark green", "dark blue"
        ]
        alphas = [1, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

        for i in range(4):
            if len(labels[i]) == 0:
                self.qtgui_vector_sink_f_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_vector_sink_f_0.set_line_label(i, labels[i])
            self.qtgui_vector_sink_f_0.set_line_width(i, widths[i])
            self.qtgui_vector_sink_f_0.set_line_color(i, colors[i])
            self.qtgui_vector_sink_f_0.set_line_alpha(i, alphas[i])

        self._qtgui_vector_sink_f_0_win = sip.wrapinstance(
            self.qtgui_vector_sink_f_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_vector_sink_f_0_win, 2, 0,
                                       1, 1)
        for r in range(2, 3):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.digital_constellation_decoder_cb_0_1 = digital.constellation_decoder_cb(
            MiconstellationObject1)
        self.digital_constellation_decoder_cb_0_0_0 = digital.constellation_decoder_cb(
            MiconstellationObject0)
        self.digital_constellation_decoder_cb_0_0 = digital.constellation_decoder_cb(
            MiconstellationObject2)
        self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(
            MiconstellationObject3)
        self.digital_chunks_to_symbols_xx_1 = digital.chunks_to_symbols_bc(
            const0, 1)
        self.digital_chunks_to_symbols_xx_0_0 = digital.chunks_to_symbols_bc(
            const1, 1)
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc(
            const3, 1)
        self.digital_chunks_to_symbols_xx = digital.chunks_to_symbols_bc(
            const2, 1)
        self.b_BERTool_0_1 = b_BERTool(
            EsN0max=EsN0max,
            EsN0min=EsN0min,
            N_snr=N_snr,
            Rs=Rs,
        )
        self.b_BERTool_0_0_0 = b_BERTool(
            EsN0max=EsN0max,
            EsN0min=EsN0min,
            N_snr=N_snr,
            Rs=Rs,
        )
        self.b_BERTool_0_0 = b_BERTool(
            EsN0max=EsN0max,
            EsN0min=EsN0min,
            N_snr=N_snr,
            Rs=Rs,
        )
        self.b_BERTool_0 = b_BERTool(
            EsN0max=EsN0max,
            EsN0min=EsN0min,
            N_snr=N_snr,
            Rs=Rs,
        )
        self.analog_random_source_x_1 = blocks.vector_source_b(
            list(map(int, numpy.random.randint(0, M0, 10000000))), True)
        self.analog_random_source_x_0_0 = blocks.vector_source_b(
            list(map(int, numpy.random.randint(0, M1, 10000000))), True)
        self.analog_random_source_x_0 = blocks.vector_source_b(
            list(map(int, numpy.random.randint(0, M3, 10000000))), True)
        self.analog_random_source_x = blocks.vector_source_b(
            list(map(int, numpy.random.randint(0, M2, 10000000))), True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_random_source_x, 0), (self.b_BERTool_0_0, 2))
        self.connect((self.analog_random_source_x, 0),
                     (self.digital_chunks_to_symbols_xx, 0))
        self.connect((self.analog_random_source_x_0, 0), (self.b_BERTool_0, 1))
        self.connect((self.analog_random_source_x_0, 0),
                     (self.digital_chunks_to_symbols_xx_0, 0))
        self.connect((self.analog_random_source_x_0_0, 0),
                     (self.b_BERTool_0_1, 2))
        self.connect((self.analog_random_source_x_0_0, 0),
                     (self.digital_chunks_to_symbols_xx_0_0, 0))
        self.connect((self.analog_random_source_x_1, 0),
                     (self.b_BERTool_0_0_0, 2))
        self.connect((self.analog_random_source_x_1, 0),
                     (self.digital_chunks_to_symbols_xx_1, 0))
        self.connect((self.b_BERTool_0, 0),
                     (self.digital_constellation_decoder_cb_0, 0))
        self.connect((self.b_BERTool_0, 1), (self.qtgui_vector_sink_f_0, 3))
        self.connect((self.b_BERTool_0_0, 0),
                     (self.digital_constellation_decoder_cb_0_0, 0))
        self.connect((self.b_BERTool_0_0, 1), (self.qtgui_vector_sink_f_0, 2))
        self.connect((self.b_BERTool_0_0_0, 0),
                     (self.digital_constellation_decoder_cb_0_0_0, 0))
        self.connect((self.b_BERTool_0_0_0, 1),
                     (self.qtgui_vector_sink_f_0, 0))
        self.connect((self.b_BERTool_0_1, 0),
                     (self.digital_constellation_decoder_cb_0_1, 0))
        self.connect((self.b_BERTool_0_1, 1), (self.qtgui_vector_sink_f_0, 1))
        self.connect((self.digital_chunks_to_symbols_xx, 0),
                     (self.b_BERTool_0_0, 0))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0),
                     (self.b_BERTool_0, 0))
        self.connect((self.digital_chunks_to_symbols_xx_0_0, 0),
                     (self.b_BERTool_0_1, 0))
        self.connect((self.digital_chunks_to_symbols_xx_1, 0),
                     (self.b_BERTool_0_0_0, 0))
        self.connect((self.digital_constellation_decoder_cb_0, 0),
                     (self.b_BERTool_0, 2))
        self.connect((self.digital_constellation_decoder_cb_0_0, 0),
                     (self.b_BERTool_0_0, 1))
        self.connect((self.digital_constellation_decoder_cb_0_0_0, 0),
                     (self.b_BERTool_0_0_0, 1))
        self.connect((self.digital_constellation_decoder_cb_0_1, 0),
                     (self.b_BERTool_0_1, 1))
Esempio n. 7
0
    def __init__(self, doc, ip="127.0.0.1"):
        gr.top_block.__init__(self, "RL Mod training")
        self.doc = doc
        self.plot_lst = []
        self.widget_lst = []

        ##################################################
        # Parameters
        ##################################################
        self.ip = ip

        ##################################################
        # Variables
        ##################################################
        self.pilot_symbols = pilot_symbols = ((1, 1, 1, -1,),)
        self.pilot_carriers = pilot_carriers = ((-21, -7, 7, 21,),)
        self.packet_length_tag_key = packet_length_tag_key = "packet_length"
        self.occupied_carriers = occupied_carriers = (list(range(-22, -21)) + list(range(-20, -7)) + list(range(-6, 0)) + list(range(1, 7)) + list(range(8, 21)) + list(range(22, 23)),)
        self.length_tag_key_0 = length_tag_key_0 = "frame_len"
        self.length_tag_key = length_tag_key = "packet_len"
        self.header_mod = header_mod = digital.constellation_bpsk()
        self.fft_len = fft_len = 64
        self.bits_per_symbol = bits_per_symbol = 4
        self.variable_0 = variable_0 = len(occupied_carriers[0])
        self.tx_lr = tx_lr = -3
        self.tx_explo = tx_explo = 0.15
        self.training_mod = training_mod = 1
        self.timestamp = timestamp = '1'
        self.t_state = t_state = 1
        self.sync_word2 = sync_word2 = [0, 0, 0, 0, 0, 0, -1, -1, -1, -1, 1, 1, -1, -1, -1, 1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, 1, -1, -1, 1, -1, 0, 1, -1, 1, 1, 1, -1, 1, 1, 1, -1, 1, 1, 1, 1, -1, 1, -1, -1, -1, 1, -1, 1, -1, -1, -1, -1, 0, 0, 0, 0, 0]
        self.sync_word1 = sync_word1 = [0., 0., 0., 0., 0., 0., 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., -1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., -1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 1.41421356, 0., 0., 0., 0., 0., 0.]
        self.samp_rate = samp_rate = 0.3e6
        self.rolloff = rolloff = 0
        self.puncpat = puncpat = '11'
        self.payload_mod = payload_mod = digital.qam_constellation(constellation_points=2**bits_per_symbol)
        self.payload_equalizer = payload_equalizer = digital.ofdm_equalizer_static(fft_len,  occupied_carriers, pilot_carriers, pilot_symbols, 1)
        self.packet_len = packet_len = 400
        self.ldpc_enc = ldpc_enc = fec.ldpc_encoder_make(gr.prefix() + "/share/gnuradio/fec/ldpc/" + "n_0100_k_0042_gap_02.alist")
        self.header_formatter = header_formatter = digital.packet_header_ofdm(occupied_carriers, n_syms=1, len_tag_key=packet_length_tag_key, frame_len_tag_key=length_tag_key_0, bits_per_header_sym=header_mod.bits_per_symbol(), bits_per_payload_sym=8, scramble_header=False)
        self.header_equalizer = header_equalizer = digital.ofdm_equalizer_simpledfe(fft_len, header_mod.base(), occupied_carriers, pilot_carriers, pilot_symbols)
        self.hdr_format = hdr_format = digital.header_format_ofdm(occupied_carriers, 1, length_tag_key,)
        self.gain = gain = 10
        self.freq = freq = 900e6
        self.bits_per_symbol_0 = bits_per_symbol_0 = len(occupied_carriers[0])

        ##################################################
        # Blocks
        ##################################################
        self.tx_lr_slider = bokehgui.slider(self.widget_lst, 'TX Learning rate (log)' +":", -5, 0, 0.1, 1, -3)
        self.tx_lr_slider.add_callback(lambda attr, old, new: self.set_tx_lr(new))
        self.tx_explo_slider = bokehgui.slider(self.widget_lst, 'TX Exploration noise' +":", 0.001, 0.5, 0.001, 1, 0.15)
        self.tx_explo_slider.add_callback(lambda attr, old, new: self.set_tx_explo(new))
        self.training_mod_textbox = bokehgui.textbox(self.widget_lst, str(1), 'Alternate training every' +": ")
        self.training_mod_textbox.add_callback(
          lambda attr, old, new: self.set_training_mod(int(new)))
        self._t_state_options = [    1,     0,   ]
        self._t_state_labels = [      'On',      'Off',  ]

        self.t_state_radiobutton = bokehgui.radiobutton(self.widget_lst, None, self._t_state_labels, inline = True)
        self.t_state_radiobutton.add_callback(
                  lambda new: self.set_t_state(int(self._t_state_options[new])))
        self.gain_slider = bokehgui.slider(self.widget_lst, 'Amplitude' +":", 0, 90, 0.5, 1, 10)
        self.gain_slider.add_callback(lambda attr, old, new: self.set_gain(new))
        self.zeromq_sub_msg_source_0_1 = zeromq.sub_msg_source("tcp://"+ip+":50002", 100)
        self.zeromq_pub_msg_sink_0_0 = zeromq.pub_msg_sink('tcp://*:50001', 100)
        self.uhd_usrp_sink_0 = uhd.usrp_sink(
            ",".join(("", "")),
            uhd.stream_args(
                cpu_format="fc32",
                args='',
                channels=list(range(0,1)),
            ),
            length_tag_key,
        )


        self.uhd_usrp_sink_0.set_samp_rate(samp_rate)

        self.uhd_usrp_sink_0.set_time_now(uhd.time_spec(time.time()), uhd.ALL_MBOARDS)

        self.uhd_usrp_sink_0.set_center_freq(freq, 0)

        self.uhd_usrp_sink_0.set_antenna('TX/RX', 0)

        self.uhd_usrp_sink_0.set_gain(gain, 0)
        self.timestamp_textbox = bokehgui.textbox(self.widget_lst, str('1'), 'Load timestamp' +": ")
        self.timestamp_textbox.add_callback(
          lambda attr, old, new: self.set_timestamp(str(new)))
        self.learning_tag_numerotation_0 = learning.tag_numerotation('packet_num', packet_len, 4096, "bb")
        self.learning_rl_mod_0 = learning.rl_mod('packet_num', bits_per_symbol, packet_len, 1, training_mod, 10**tx_lr , tx_explo, t_state , '/home/cyrille/Gnu-Radio/modules/gr-learning/examples/saved_models')
        self.fft_vxx_0_0 = fft.fft_vcc(fft_len, False, (), True, 1)
        self.fec_extended_encoder_1_0_0 = fec.extended_encoder(encoder_obj_list=ldpc_enc, threading= None, puncpat=puncpat)
        self.digital_protocol_formatter_bb_0 = digital.protocol_formatter_bb(hdr_format, length_tag_key)
        self.digital_ofdm_cyclic_prefixer_0 = digital.ofdm_cyclic_prefixer(
            fft_len,
            fft_len + fft_len//4,
            rolloff,
            length_tag_key)
        self.digital_ofdm_carrier_allocator_cvc_0 = digital.ofdm_carrier_allocator_cvc( fft_len, occupied_carriers, pilot_carriers, pilot_symbols, (sync_word1, sync_word2), length_tag_key, True)
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc(header_mod.points(), 1)
        self.bokehgui_time_const_x_0 = bokehgui.time_sink_c_proc(1024, samp_rate, "Transmitted noiseless constellation",  1)

        self.bokehgui_time_const_x_0_plot = bokehgui.const_sink_c(self.doc, self.plot_lst, self.bokehgui_time_const_x_0, is_message = False)
        labels = ['', '', '', '', '',
                  '', '', '', '', '']
        legend_list = []
        for i in range(  1 ):
          if len(labels[i]) == 0:
              if(i % 2 == 0):
                  legend_list.append("Re{{Data {0}}}".format(i/2))
              else:
                  legend_list.append("Im{{Data {0}}}".format(i/2))
          else:
              legend_list.append(labels[i])

        self.bokehgui_time_const_x_0_plot.initialize(update_time = 500,
                                    legend_list = legend_list)

        self.bokehgui_time_const_x_0_plot.set_y_axis([-2, 2])
        self.bokehgui_time_const_x_0_plot.set_y_label('Q Channel' + '(' +""+')')

        self.bokehgui_time_const_x_0_plot.set_x_label('I Channel' + '(' +""+')')
        self.bokehgui_time_const_x_0_plot.enable_tags(-1, False)
        self.bokehgui_time_const_x_0_plot.set_trigger_mode(bokehgui.TRIG_MODE_FREE, bokehgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.bokehgui_time_const_x_0_plot.enable_grid(False)
        self.bokehgui_time_const_x_0_plot.enable_axis_labels(True)
        self.bokehgui_time_const_x_0_plot.disable_legend(not True)
        self.bokehgui_time_const_x_0_plot.set_layout(*((0,1,2,2)))
        colors = ["blue", "red", "green", "black", "cyan",
                  "magenta", "yellow", "blue", "blue", "blue"]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        markers = ['o', 'o', 'o', 'o', 'o',
                   'o', 'o', 'o', 'o', 'o']
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in range(    1  ):
          self.bokehgui_time_const_x_0_plot.format_line(i, colors[i], widths[i], 'None', markers[i], alphas[i])
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate/6,True)
        self.blocks_tagged_stream_to_pdu_0_0_0 = blocks.tagged_stream_to_pdu(blocks.byte_t, 'packet_len')
        self.blocks_tagged_stream_mux_0 = blocks.tagged_stream_mux(gr.sizeof_gr_complex*1, length_tag_key, 0)
        self.blocks_stream_to_tagged_stream_0_0 = blocks.stream_to_tagged_stream(gr.sizeof_char, 1, packet_len, length_tag_key)
        self.blocks_repack_bits_bb_0_0_0 = blocks.repack_bits_bb(8, 1, length_tag_key, False, gr.GR_LSB_FIRST)
        self.blocks_repack_bits_bb_0_0 = blocks.repack_bits_bb(1, bits_per_symbol, '', False, gr.GR_LSB_FIRST)
        self.blocks_multiply_const_xx_0 = blocks.multiply_const_cc(0.01, 1)
        self.analog_random_source_x_0_0 = blocks.vector_source_b(list(map(int, numpy.random.randint(0, 2, 1000))), True)

        if self.widget_lst:
            input_t = bokehgui.bokeh_layout.widgetbox(self.widget_lst)
            widgetbox = bokehgui.bokeh_layout.WidgetLayout(input_t)
            widgetbox.set_layout(*((0, 0, 2, 1)))
            list_obj = [widgetbox] + self.plot_lst
        else:
            list_obj = self.plot_lst
        layout_t = bokehgui.bokeh_layout.create_layout(list_obj, "fixed")
        self.doc.add_root(layout_t)


        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.blocks_tagged_stream_to_pdu_0_0_0, 'pdus'), (self.zeromq_pub_msg_sink_0_0, 'in'))
        self.msg_connect((self.zeromq_sub_msg_source_0_1, 'out'), (self.learning_rl_mod_0, 'losses'))
        self.connect((self.analog_random_source_x_0_0, 0), (self.fec_extended_encoder_1_0_0, 0))
        self.connect((self.blocks_multiply_const_xx_0, 0), (self.uhd_usrp_sink_0, 0))
        self.connect((self.blocks_repack_bits_bb_0_0, 0), (self.blocks_stream_to_tagged_stream_0_0, 0))
        self.connect((self.blocks_repack_bits_bb_0_0_0, 0), (self.digital_chunks_to_symbols_xx_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0_0, 0), (self.digital_protocol_formatter_bb_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0_0, 0), (self.learning_tag_numerotation_0, 0))
        self.connect((self.blocks_tagged_stream_mux_0, 0), (self.digital_ofdm_carrier_allocator_cvc_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.blocks_tagged_stream_to_pdu_0_0_0, 0))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.blocks_tagged_stream_mux_0, 0))
        self.connect((self.digital_ofdm_carrier_allocator_cvc_0, 0), (self.fft_vxx_0_0, 0))
        self.connect((self.digital_ofdm_cyclic_prefixer_0, 0), (self.blocks_multiply_const_xx_0, 0))
        self.connect((self.digital_protocol_formatter_bb_0, 0), (self.blocks_repack_bits_bb_0_0_0, 0))
        self.connect((self.fec_extended_encoder_1_0_0, 0), (self.blocks_repack_bits_bb_0_0, 0))
        self.connect((self.fft_vxx_0_0, 0), (self.digital_ofdm_cyclic_prefixer_0, 0))
        self.connect((self.learning_rl_mod_0, 0), (self.blocks_tagged_stream_mux_0, 1))
        self.connect((self.learning_rl_mod_0, 1), (self.bokehgui_time_const_x_0, 0))
        self.connect((self.learning_tag_numerotation_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.learning_tag_numerotation_0, 0), (self.learning_rl_mod_0, 0))
Esempio n. 8
0
 def set_bits_per_symbol(self, bits_per_symbol):
     self.bits_per_symbol = bits_per_symbol
     self.set_payload_mod(digital.qam_constellation(constellation_points=2**self.bits_per_symbol))
     self.blocks_repack_bits_bb_0_0.set_k_and_l(1,self.bits_per_symbol)