Exemplo n.º 1
0
    def test_vector_complex(self):
        tb = self.tb

        vlen = 5
        N = 10 * vlen
        data = make_random_complex_tuple(N, 2**10)
        src = blocks.vector_source_c(data, False)
        one_to_many = blocks.stream_to_streams(gr.sizeof_gr_complex, vlen)
        one_to_vector = blocks.stream_to_vector(gr.sizeof_gr_complex, vlen)
        many_to_vector = blocks.streams_to_vector(gr.sizeof_gr_complex, vlen)
        isolated = [blocks.moving_average_cc(100, 1) for i in range(vlen)]
        dut = blocks.moving_average_cc(100, 1, vlen=vlen)
        dut_dst = blocks.vector_sink_c(vlen=vlen)
        ref_dst = blocks.vector_sink_c(vlen=vlen)

        tb.connect(src, one_to_many)
        tb.connect(src, one_to_vector, dut, dut_dst)
        tb.connect(many_to_vector, ref_dst)
        for idx, single in enumerate(isolated):
            tb.connect((one_to_many, idx), single, (many_to_vector, idx))

        tb.run()

        dut_data = dut_dst.data()
        ref_data = ref_dst.data()

        # make sure result is close to zero
        self.assertEqual(dut_data, ref_data)
Exemplo n.º 2
0
    def test_04(self):
        tb = self.tb

        N = 10000  # number of samples
        history = 100  # num of samples to average
        data = make_random_complex_tuple(N, 1)  # generate random data

        #  pythonic MA filter
        data_padded = (history-1)*[0.0+1j*0.0]+list(data)  # history  
        expected_result = []
        moving_sum = sum(data_padded[:history-1])
        for i in range(N):
            moving_sum += data_padded[i+history-1]
            expected_result.append(moving_sum)
            moving_sum -= data_padded[i]

        src = blocks.vector_source_c(data, False)
        op  = blocks.moving_average_cc(history, 1)
        dst = blocks.vector_sink_c()
        
        tb.connect(src, op)
        tb.connect(op, dst)
        tb.run()
    
        dst_data = dst.data()

        # make sure result is close to zero
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4)
Exemplo n.º 3
0
    def test_complex_scalar(self):
        tb = self.tb

        N = 10000  # number of samples
        history = 100  # num of samples to average
        data = make_random_complex_tuple(N, 1)  # generate random data

        #  pythonic MA filter
        data_padded = (history - 1) * [complex(0.0, 0.0)] + list(
            data)  # history
        expected_result = []
        moving_sum = sum(data_padded[:history - 1])
        for i in range(N):
            moving_sum += data_padded[i + history - 1]
            expected_result.append(moving_sum)
            moving_sum -= data_padded[i]

        src = blocks.vector_source_c(data, False)
        op = blocks.moving_average_cc(history, 1)
        dst = blocks.vector_sink_c()

        tb.connect(src, op)
        tb.connect(op, dst)
        tb.run()

        dst_data = dst.data()

        # make sure result is close to zero
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 4)
Exemplo n.º 4
0
    def __init__(self, preamble_length):
        gr.hier_block2.__init__(self, "fqsweep_corr",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(2, 2, gr.sizeof_gr_complex))

        despread = self.gen_despread(preamble_length, np.pi * 3.0 / 4.0)

        # Blocks
        self.equiv_delay = blocks.delay(gr.sizeof_gr_complex,
                                        preamble_length + 2)

        self.despread_src = blocks.vector_source_c(despread, True, 1, [])
        self.despread_mul = blocks.multiply_conjugate_cc(1)

        self.deriv_0_delay = blocks.delay(gr.sizeof_gr_complex, 1)
        self.deriv_0_mul = blocks.multiply_conjugate_cc(1)

        self.deriv_1_delay = blocks.delay(gr.sizeof_gr_complex, 1)
        self.deriv_1_mul = blocks.multiply_conjugate_cc(1)

        self.avg = blocks.moving_average_cc(preamble_length,
                                            1.0 / preamble_length, 2**16)

        # Connections

        # pass output
        self.connect((self, 0), (self.equiv_delay, 0))
        self.connect((self.equiv_delay, 0), (self, 0))

        # despread
        self.connect((self, 0), (self.despread_mul, 0))
        self.connect((self.despread_src, 0), (self.despread_mul, 1))

        # first phase derivate (frequency)
        self.connect((self.despread_mul, 0), (self.deriv_0_mul, 0))
        self.connect((self.despread_mul, 0), (self.deriv_0_delay, 0))
        self.connect((self.deriv_0_delay, 0), (self.deriv_0_mul, 1))

        # second phase derivate (change of frequency)
        self.connect((self.deriv_0_mul, 0), (self.deriv_1_mul, 0))
        self.connect((self.deriv_0_mul, 0), (self.deriv_1_delay, 0))
        self.connect((self.deriv_1_delay, 0), (self.deriv_1_mul, 1))

        # average
        self.connect((self.deriv_1_mul, 0), (self.avg, 0))
        self.connect((self.avg, 0), (self, 1))
Exemplo n.º 5
0
    def __init__(self, vector):
        gr.top_block.__init__(self, "Stanley Tx")

        ##################################################
        # Variables
        ##################################################
        self.interp = interp = 1200
        self.baud_rate = baud_rate = 1872
        self.samp_rate = samp_rate = baud_rate*interp
        self.center_freq = center_freq = 433893000

        ##################################################
        # Blocks
        ##################################################
        self.osmosdr_sink_0 = osmosdr.sink(args="numchan=" + str(1) + " " + "")
        self.osmosdr_sink_0.set_sample_rate(samp_rate)
        self.osmosdr_sink_0.set_center_freq(center_freq, 0)
        self.osmosdr_sink_0.set_freq_corr(0, 0)
        self.osmosdr_sink_0.set_gain(14, 0)
        self.osmosdr_sink_0.set_if_gain(40, 0)
        self.osmosdr_sink_0.set_bb_gain(40, 0)
        self.osmosdr_sink_0.set_antenna("", 0)
        self.osmosdr_sink_0.set_bandwidth(2000000, 0)

        self.blocks_vector_source_x_0 = blocks.vector_source_c(
            (([int(v) for v in vector] + [0]*25) * 25), False, 1, []
        )
        self.blocks_repeat_0 = blocks.repeat(gr.sizeof_gr_complex*1, interp)
        self.blocks_moving_average_xx_0 = blocks.moving_average_cc(
            20, 0.9/20, 4000
        )

        ##################################################
        # Connections
        ##################################################
        self.connect(
            (self.blocks_moving_average_xx_0, 0), (self.osmosdr_sink_0, 0)
        )
        self.connect(
            (self.blocks_repeat_0, 0), (self.blocks_moving_average_xx_0, 0)
        )
        self.connect(
            (self.blocks_vector_source_x_0, 0), (self.blocks_repeat_0, 0)
        )
Exemplo n.º 6
0
    def test_02(self):
        tb = self.tb

        N = 10000
        data = make_random_complex_tuple(N, 1)
        expected_result = N*[0,]

        src = blocks.vector_source_c(data, False)
        op  = blocks.moving_average_cc(100, 0.001)
        dst = blocks.vector_sink_c()

        tb.connect(src, op)
        tb.connect(op, dst)
        tb.run()

        dst_data = dst.data()

        # make sure result is close to zero
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 1)
Exemplo n.º 7
0
    def test_02(self):
        tb = self.tb

        N = 10000
        seed = 0
        data = make_random_complex_tuple(N, 1)
        expected_result = N*[0,]

        src = blocks.vector_source_c(data, False)
        op  = blocks.moving_average_cc(100, 0.001)
        dst = blocks.vector_sink_c()

        tb.connect(src, op)
        tb.connect(op, dst)
        tb.run()

        dst_data = dst.data()

        # make sure result is close to zero
        self.assertComplexTuplesAlmostEqual(expected_result, dst_data, 1)
Exemplo n.º 8
0
    def __init__(self):
        gr.top_block.__init__(self, "Wifi Rx")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Wifi Rx")
        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", "wifi_rx")

        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.window_size = window_size = 48
        self.sync_length = sync_length = 320
        self.samp_rate = samp_rate = 2e6
        self.rf = rf = 14
        self.lo_offset = lo_offset = 0
        self.gain = gain = 0.75
        self.freqq = freqq = 2.412e6
        self.freq = freq = 2412000000.0
        self.device_6 = device_6 = "hackrf=26b468dc3540b58f"
        self.device_5 = device_5 = "hackrf=88869dc38686a1b"
        self.device_4 = device_4 = "hackrf=88869dc2930b41b"
        self.device_3 = device_3 = "hackrf=88869dc3347501b"
        self.device_2 = device_2 = "hackrf=88869dc3918701b"
        self.device_1 = device_1 = "hackrf=88869dc3397a01b"
        self.chan_est = chan_est = 0
        self.bb = bb = 20
        self.IF = IF = 30

        ##################################################
        # Blocks
        ##################################################
        # Create the options list
        self._samp_rate_options = [
            2000000.0, 5000000.0, 10000000.0, 20000000.0
        ]
        # Create the labels list
        self._samp_rate_labels = ['2MHz', '5 MHz', '10 MHz', '20 MHz']
        # Create the combo box
        self._samp_rate_tool_bar = Qt.QToolBar(self)
        self._samp_rate_tool_bar.addWidget(Qt.QLabel("samp_rate: "))
        self._samp_rate_combo_box = Qt.QComboBox()
        self._samp_rate_tool_bar.addWidget(self._samp_rate_combo_box)
        for _label in self._samp_rate_labels:
            self._samp_rate_combo_box.addItem(_label)
        self._samp_rate_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._samp_rate_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._samp_rate_options.index(i)))
        self._samp_rate_callback(self.samp_rate)
        self._samp_rate_combo_box.currentIndexChanged.connect(
            lambda i: self.set_samp_rate(self._samp_rate_options[i]))
        # Create the radio buttons
        self.top_layout.addWidget(self._samp_rate_tool_bar)
        self._rf_range = Range(0, 50, 1, 14, 200)
        self._rf_win = RangeWidget(self._rf_range, self.set_rf, 'rf',
                                   "counter_slider", int)
        self.top_layout.addWidget(self._rf_win)
        # Create the options list
        self._chan_est_options = [0, 1, 3, 2]
        # Create the labels list
        self._chan_est_labels = ['LS', 'LMS', 'STA', 'Linear Comb']
        # Create the combo box
        # Create the radio buttons
        self._chan_est_group_box = Qt.QGroupBox('chan_est' + ": ")
        self._chan_est_box = Qt.QHBoxLayout()

        class variable_chooser_button_group(Qt.QButtonGroup):
            def __init__(self, parent=None):
                Qt.QButtonGroup.__init__(self, parent)

            @pyqtSlot(int)
            def updateButtonChecked(self, button_id):
                self.button(button_id).setChecked(True)

        self._chan_est_button_group = variable_chooser_button_group()
        self._chan_est_group_box.setLayout(self._chan_est_box)
        for i, _label in enumerate(self._chan_est_labels):
            radio_button = Qt.QRadioButton(_label)
            self._chan_est_box.addWidget(radio_button)
            self._chan_est_button_group.addButton(radio_button, i)
        self._chan_est_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._chan_est_button_group, "updateButtonChecked",
            Qt.Q_ARG("int", self._chan_est_options.index(i)))
        self._chan_est_callback(self.chan_est)
        self._chan_est_button_group.buttonClicked[int].connect(
            lambda i: self.set_chan_est(self._chan_est_options[i]))
        self.top_layout.addWidget(self._chan_est_group_box)
        self._bb_range = Range(0, 70, 1, 20, 200)
        self._bb_win = RangeWidget(self._bb_range, self.set_bb, 'bb',
                                   "counter_slider", int)
        self.top_layout.addWidget(self._bb_win)
        self._IF_range = Range(0, 50, 1, 30, 200)
        self._IF_win = RangeWidget(self._IF_range, self.set_IF, 'IF',
                                   "counter_slider", int)
        self.top_layout.addWidget(self._IF_win)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
            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(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_axis_labels(True)
        self.qtgui_time_sink_x_0.enable_control_panel(False)
        self.qtgui_time_sink_x_0.enable_stem_plot(False)

        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]
        styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]

        for i in range(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(
            48 * 10,  #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_layout.addWidget(self._qtgui_const_sink_x_0_win)
        self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                               device_5)
        self.osmosdr_source_0.set_time_unknown_pps(osmosdr.time_spec_t())
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(2.45e9, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(0, 0)
        self.osmosdr_source_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_0.set_gain_mode(False, 0)
        self.osmosdr_source_0.set_gain(rf, 0)
        self.osmosdr_source_0.set_if_gain(IF, 0)
        self.osmosdr_source_0.set_bb_gain(bb, 0)
        self.osmosdr_source_0.set_antenna('', 0)
        self.osmosdr_source_0.set_bandwidth(0, 0)
        # Create the options list
        self._lo_offset_options = [0, 6000000.0, 11000000.0]
        # Create the labels list
        self._lo_offset_labels = ['0', '6000000.0', '11000000.0']
        # Create the combo box
        self._lo_offset_tool_bar = Qt.QToolBar(self)
        self._lo_offset_tool_bar.addWidget(Qt.QLabel("lo_offset: "))
        self._lo_offset_combo_box = Qt.QComboBox()
        self._lo_offset_tool_bar.addWidget(self._lo_offset_combo_box)
        for _label in self._lo_offset_labels:
            self._lo_offset_combo_box.addItem(_label)
        self._lo_offset_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._lo_offset_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._lo_offset_options.index(i)))
        self._lo_offset_callback(self.lo_offset)
        self._lo_offset_combo_box.currentIndexChanged.connect(
            lambda i: self.set_lo_offset(self._lo_offset_options[i]))
        # Create the radio buttons
        self.top_layout.addWidget(self._lo_offset_tool_bar)
        self.ieee802_11_sync_short_0 = ieee802_11.sync_short(
            0.56, 2, False, False)
        self.ieee802_11_sync_long_0 = ieee802_11.sync_long(
            sync_length, True, False)
        self.ieee802_11_parse_mac_0 = ieee802_11.parse_mac(True, True)
        self.ieee802_11_frame_equalizer_0 = ieee802_11.frame_equalizer(
            chan_est, 2.45e9, samp_rate, False, False)
        self.ieee802_11_decode_mac_0 = ieee802_11.decode_mac(True, False)
        self._gain_range = Range(0, 1, 0.01, 0.75, 200)
        self._gain_win = RangeWidget(self._gain_range, self.set_gain, 'gain',
                                     "counter_slider", float)
        self.top_layout.addWidget(self._gain_win)
        # Create the options list
        self._freqq_options = [2437000.0, 2462000.0, 2412000.0]
        # Create the labels list
        self._freqq_labels = ['ch6', 'ch11', 'ch1']
        # Create the combo box
        self._freqq_tool_bar = Qt.QToolBar(self)
        self._freqq_tool_bar.addWidget(Qt.QLabel("freqq: "))
        self._freqq_combo_box = Qt.QComboBox()
        self._freqq_tool_bar.addWidget(self._freqq_combo_box)
        for _label in self._freqq_labels:
            self._freqq_combo_box.addItem(_label)
        self._freqq_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._freqq_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._freqq_options.index(i)))
        self._freqq_callback(self.freqq)
        self._freqq_combo_box.currentIndexChanged.connect(
            lambda i: self.set_freqq(self._freqq_options[i]))
        # Create the radio buttons
        self.top_layout.addWidget(self._freqq_tool_bar)
        # Create the options list
        self._freq_options = [
            2412000000.0, 2417000000.0, 2422000000.0, 2427000000.0,
            2432000000.0, 2437000000.0, 2442000000.0, 2447000000.0,
            2452000000.0, 2457000000.0, 2462000000.0, 2467000000.0,
            2472000000.0, 2484000000.0, 5170000000.0, 5180000000.0,
            5190000000.0, 5200000000.0, 5210000000.0, 5220000000.0,
            5230000000.0, 5240000000.0, 5250000000.0, 5260000000.0,
            5270000000.0, 5280000000.0, 5290000000.0, 5300000000.0,
            5310000000.0, 5320000000.0, 5500000000.0, 5510000000.0,
            5520000000.0, 5530000000.0, 5540000000.0, 5550000000.0,
            5560000000.0, 5570000000.0, 5580000000.0, 5590000000.0,
            5600000000.0, 5610000000.0, 5620000000.0, 5630000000.0,
            5640000000.0, 5660000000.0, 5670000000.0, 5680000000.0,
            5690000000.0, 5700000000.0, 5710000000.0, 5720000000.0,
            5745000000.0, 5755000000.0, 5765000000.0, 5775000000.0,
            5785000000.0, 5795000000.0, 5805000000.0, 5825000000.0,
            5860000000.0, 5870000000.0, 5880000000.0, 5890000000.0,
            5900000000.0, 5910000000.0, 5920000000.0
        ]
        # Create the labels list
        self._freq_labels = [
            '  1 | 2412.0 | 11g', '  2 | 2417.0 | 11g', '  3 | 2422.0 | 11g',
            '  4 | 2427.0 | 11g', '  5 | 2432.0 | 11g', '  6 | 2437.0 | 11g',
            '  7 | 2442.0 | 11g', '  8 | 2447.0 | 11g', '  9 | 2452.0 | 11g',
            ' 10 | 2457.0 | 11g', ' 11 | 2462.0 | 11g', ' 12 | 2467.0 | 11g',
            ' 13 | 2472.0 | 11g', ' 14 | 2484.0 | 11g', ' 34 | 5170.0 | 11a',
            ' 36 | 5180.0 | 11a', ' 38 | 5190.0 | 11a', ' 40 | 5200.0 | 11a',
            ' 42 | 5210.0 | 11a', ' 44 | 5220.0 | 11a', ' 46 | 5230.0 | 11a',
            ' 48 | 5240.0 | 11a', ' 50 | 5250.0 | 11a', ' 52 | 5260.0 | 11a',
            ' 54 | 5270.0 | 11a', ' 56 | 5280.0 | 11a', ' 58 | 5290.0 | 11a',
            ' 60 | 5300.0 | 11a', ' 62 | 5310.0 | 11a', ' 64 | 5320.0 | 11a',
            '100 | 5500.0 | 11a', '102 | 5510.0 | 11a', '104 | 5520.0 | 11a',
            '106 | 5530.0 | 11a', '108 | 5540.0 | 11a', '110 | 5550.0 | 11a',
            '112 | 5560.0 | 11a', '114 | 5570.0 | 11a', '116 | 5580.0 | 11a',
            '118 | 5590.0 | 11a', '120 | 5600.0 | 11a', '122 | 5610.0 | 11a',
            '124 | 5620.0 | 11a', '126 | 5630.0 | 11a', '128 | 5640.0 | 11a',
            '132 | 5660.0 | 11a', '134 | 5670.0 | 11a', '136 | 5680.0 | 11a',
            '138 | 5690.0 | 11a', '140 | 5700.0 | 11a', '142 | 5710.0 | 11a',
            '144 | 5720.0 | 11a', '149 | 5745.0 | 11a (SRD)',
            '151 | 5755.0 | 11a (SRD)', '153 | 5765.0 | 11a (SRD)',
            '155 | 5775.0 | 11a (SRD)', '157 | 5785.0 | 11a (SRD)',
            '159 | 5795.0 | 11a (SRD)', '161 | 5805.0 | 11a (SRD)',
            '165 | 5825.0 | 11a (SRD)', '172 | 5860.0 | 11p',
            '174 | 5870.0 | 11p', '176 | 5880.0 | 11p', '178 | 5890.0 | 11p',
            '180 | 5900.0 | 11p', '182 | 5910.0 | 11p', '184 | 5920.0 | 11p'
        ]
        # Create the combo box
        self._freq_tool_bar = Qt.QToolBar(self)
        self._freq_tool_bar.addWidget(Qt.QLabel("freq: "))
        self._freq_combo_box = Qt.QComboBox()
        self._freq_tool_bar.addWidget(self._freq_combo_box)
        for _label in self._freq_labels:
            self._freq_combo_box.addItem(_label)
        self._freq_callback = lambda i: Qt.QMetaObject.invokeMethod(
            self._freq_combo_box, "setCurrentIndex",
            Qt.Q_ARG("int", self._freq_options.index(i)))
        self._freq_callback(self.freq)
        self._freq_combo_box.currentIndexChanged.connect(
            lambda i: self.set_freq(self._freq_options[i]))
        # Create the radio buttons
        self.top_layout.addWidget(self._freq_tool_bar)
        self.foo_wireshark_connector_0 = foo.wireshark_connector(127, False)
        self.fft_vxx_0 = fft.fft_vcc(64, True, window.rectangular(64), True, 1)
        self.correctiq_correctiq_0 = correctiq.correctiq()
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(
            gr.sizeof_gr_complex * 1, 64)
        self.blocks_pdu_to_tagged_stream_1 = blocks.pdu_to_tagged_stream(
            blocks.complex_t, 'packet_len')
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_moving_average_xx_1 = blocks.moving_average_cc(
            window_size, 1, 4000, 1)
        self.blocks_moving_average_xx_0 = blocks.moving_average_ff(
            window_size + 16, 1, 4000, 1)
        self.blocks_file_sink_2 = blocks.file_sink(
            gr.sizeof_gr_complex * 1, '/home/erc/SDN/symbols_5_1.bin', False)
        self.blocks_file_sink_2.set_unbuffered(True)
        self.blocks_file_sink_1_1 = blocks.file_sink(
            gr.sizeof_gr_complex * 64, '/home/erc/SDN/before_fft_5_1.bin',
            False)
        self.blocks_file_sink_1_1.set_unbuffered(True)
        self.blocks_file_sink_1_0 = blocks.file_sink(
            gr.sizeof_char * 48, '/home/erc/SDN/output_equ_5_1.bin', False)
        self.blocks_file_sink_1_0.set_unbuffered(True)
        self.blocks_file_sink_1 = blocks.file_sink(
            gr.sizeof_gr_complex * 64, '/home/erc/SDN/after_fft_5_1.bin',
            False)
        self.blocks_file_sink_1.set_unbuffered(True)
        self.blocks_file_sink_0 = blocks.file_sink(
            gr.sizeof_char * 1, '/home/erc/SDN/wifi_5_1.pcap', False)
        self.blocks_file_sink_0.set_unbuffered(True)
        self.blocks_divide_xx_0 = blocks.divide_ff(1)
        self.blocks_delay_0_0 = blocks.delay(gr.sizeof_gr_complex * 1, 16)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1,
                                           sync_length)
        self.blocks_conjugate_cc_0 = blocks.conjugate_cc()
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1)
        self.blocks_complex_to_mag_0 = blocks.complex_to_mag(1)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.ieee802_11_decode_mac_0, 'out'),
                         (self.foo_wireshark_connector_0, 'in'))
        self.msg_connect((self.ieee802_11_decode_mac_0, 'out'),
                         (self.ieee802_11_parse_mac_0, 'in'))
        self.msg_connect((self.ieee802_11_frame_equalizer_0, 'symbols'),
                         (self.blocks_pdu_to_tagged_stream_1, 'pdus'))
        self.connect((self.blocks_complex_to_mag_0, 0),
                     (self.blocks_divide_xx_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_0, 0),
                     (self.blocks_moving_average_xx_0, 0))
        self.connect((self.blocks_conjugate_cc_0, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_delay_0, 0),
                     (self.ieee802_11_sync_long_0, 1))
        self.connect((self.blocks_delay_0_0, 0),
                     (self.blocks_conjugate_cc_0, 0))
        self.connect((self.blocks_delay_0_0, 0),
                     (self.ieee802_11_sync_short_0, 0))
        self.connect((self.blocks_divide_xx_0, 0),
                     (self.ieee802_11_sync_short_0, 2))
        self.connect((self.blocks_divide_xx_0, 0),
                     (self.qtgui_time_sink_x_0, 0))
        self.connect((self.blocks_moving_average_xx_0, 0),
                     (self.blocks_divide_xx_0, 1))
        self.connect((self.blocks_moving_average_xx_1, 0),
                     (self.blocks_complex_to_mag_0, 0))
        self.connect((self.blocks_moving_average_xx_1, 0),
                     (self.ieee802_11_sync_short_0, 1))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.blocks_moving_average_xx_1, 0))
        self.connect((self.blocks_pdu_to_tagged_stream_1, 0),
                     (self.blocks_file_sink_2, 0))
        self.connect((self.blocks_pdu_to_tagged_stream_1, 0),
                     (self.qtgui_const_sink_x_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0),
                     (self.blocks_file_sink_1_1, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.correctiq_correctiq_0, 0),
                     (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.correctiq_correctiq_0, 0),
                     (self.blocks_delay_0_0, 0))
        self.connect((self.correctiq_correctiq_0, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.fft_vxx_0, 0), (self.blocks_file_sink_1, 0))
        self.connect((self.fft_vxx_0, 0),
                     (self.ieee802_11_frame_equalizer_0, 0))
        self.connect((self.foo_wireshark_connector_0, 0),
                     (self.blocks_file_sink_0, 0))
        self.connect((self.ieee802_11_frame_equalizer_0, 0),
                     (self.blocks_file_sink_1_0, 0))
        self.connect((self.ieee802_11_frame_equalizer_0, 0),
                     (self.ieee802_11_decode_mac_0, 0))
        self.connect((self.ieee802_11_sync_long_0, 0),
                     (self.blocks_stream_to_vector_0, 0))
        self.connect((self.ieee802_11_sync_short_0, 0),
                     (self.blocks_delay_0, 0))
        self.connect((self.ieee802_11_sync_short_0, 0),
                     (self.ieee802_11_sync_long_0, 0))
        self.connect((self.osmosdr_source_0, 0),
                     (self.correctiq_correctiq_0, 0))
Exemplo n.º 9
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block")
        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", "top_block")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 9142857.14286

        ##################################################
        # Blocks
        ##################################################
        self.blocks_moving_average = blocks.moving_average_cc(1, 1, 4000)
        self.blocks_delay = blocks.delay(gr.sizeof_gr_complex * 1, 0)
        self.t2_p1_detector_0 = t2_p1_detector()
        self.qtgui_time_sink_x_0_0_0 = qtgui.time_sink_f(
            1024000,  #size
            1,  #samp_rate
            "",  #name
            2  #number of inputs
        )
        self.qtgui_time_sink_x_0_0_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0_0_0.set_y_axis(0, 1)

        self.qtgui_time_sink_x_0_0_0.set_y_label('Amplitude', "")

        self.qtgui_time_sink_x_0_0_0.enable_tags(-1, True)
        self.qtgui_time_sink_x_0_0_0.set_trigger_mode(qtgui.TRIG_MODE_AUTO,
                                                      qtgui.TRIG_SLOPE_POS,
                                                      0.0, 50000, 0,
                                                      "p1_start")
        self.qtgui_time_sink_x_0_0_0.enable_autoscale(True)
        self.qtgui_time_sink_x_0_0_0.enable_grid(False)
        self.qtgui_time_sink_x_0_0_0.enable_axis_labels(True)
        self.qtgui_time_sink_x_0_0_0.enable_control_panel(True)

        if not True:
            self.qtgui_time_sink_x_0_0_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):
            if len(labels[i]) == 0:
                self.qtgui_time_sink_x_0_0_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_0_0_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0_0_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0_0_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0_0_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0_0_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0_0_0.set_line_alpha(i, alphas[i])

        self._qtgui_time_sink_x_0_0_0_win = sip.wrapinstance(
            self.qtgui_time_sink_x_0_0_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_time_sink_x_0_0_0_win)
        self.dvbt2rx_gi_est_decider_0 = dvbt2rx.gi_est_decider(3, 16)
        self.dvbt2rx_gi_est_control_cc_0 = dvbt2rx.gi_est_control_cc(
            self.blocks_delay, self.blocks_moving_average)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                 samp_rate, True)
        self.blocks_tag_gate_0_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1,
                                                   False)
        self.blocks_tag_gate_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1,
                                                 False)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_conjugate_0 = blocks.multiply_conjugate_cc(1)
        self.blocks_moving_average_1 = blocks.moving_average_ff(
            2**12, 1. / 2**24, 4000)
        (self.blocks_moving_average_1).set_min_output_buffer(500000)
        self.blocks_file_source_0_0 = blocks.file_source(
            gr.sizeof_gr_complex * 1,
            '/home/kmaier/workspace/gr-dvbt2rx/binary_testfiles/ard_multiplex_karlsruhe_rx_sr9142857.14286.iq',
            True)
        self.blocks_complex_to_mag_squared_1_0 = blocks.complex_to_mag_squared(
            1)
        self.blocks_complex_to_mag_squared_1 = blocks.complex_to_mag_squared(1)
        (self.blocks_complex_to_mag_squared_1).set_min_output_buffer(500000)
        self.analog_sig_source_x_1 = analog.sig_source_c(
            samp_rate, analog.GR_COS_WAVE, samp_rate / 1024 * 0, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_sig_source_x_1, 0),
                     (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_complex_to_mag_squared_1, 0),
                     (self.dvbt2rx_gi_est_decider_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_1, 0),
                     (self.qtgui_time_sink_x_0_0_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_1_0, 0),
                     (self.blocks_moving_average_1, 0))
        self.connect((self.blocks_delay, 0), (self.blocks_tag_gate_0, 0))
        self.connect((self.blocks_file_source_0_0, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_moving_average, 0),
                     (self.blocks_complex_to_mag_squared_1, 0))
        self.connect((self.blocks_moving_average_1, 0),
                     (self.dvbt2rx_gi_est_decider_0, 1))
        self.connect((self.blocks_moving_average_1, 0),
                     (self.qtgui_time_sink_x_0_0_0, 1))
        self.connect((self.blocks_multiply_conjugate_0, 0),
                     (self.blocks_moving_average, 0))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_tag_gate_0, 0),
                     (self.blocks_multiply_conjugate_0, 1))
        self.connect((self.blocks_tag_gate_0_0, 0),
                     (self.blocks_complex_to_mag_squared_1_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.t2_p1_detector_0, 0))
        self.connect((self.dvbt2rx_gi_est_control_cc_0, 0),
                     (self.blocks_delay, 0))
        self.connect((self.dvbt2rx_gi_est_control_cc_0, 0),
                     (self.blocks_multiply_conjugate_0, 0))
        self.connect((self.dvbt2rx_gi_est_control_cc_0, 0),
                     (self.blocks_tag_gate_0_0, 0))
        self.connect((self.t2_p1_detector_0, 0),
                     (self.dvbt2rx_gi_est_control_cc_0, 0))
Exemplo n.º 10
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Ceiling Fan Tx")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.interp = interp = 600
        self.baud_rate = baud_rate = 3211
        self.samp_rate = samp_rate = baud_rate * interp
        self.gain = gain = 15
        self.center_freq = center_freq = 303747000

        ##################################################
        # Blocks
        ##################################################
        _gain_sizer = wx.BoxSizer(wx.VERTICAL)
        self._gain_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_gain_sizer,
            value=self.gain,
            callback=self.set_gain,
            label='gain',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._gain_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_gain_sizer,
            value=self.gain,
            callback=self.set_gain,
            minimum=0,
            maximum=25,
            num_steps=50,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_gain_sizer)
        self.osmosdr_sink_0 = osmosdr.sink(args="numchan=" + str(1) + " " + '')
        self.osmosdr_sink_0.set_sample_rate(samp_rate)
        self.osmosdr_sink_0.set_center_freq(center_freq, 0)
        self.osmosdr_sink_0.set_freq_corr(0, 0)
        self.osmosdr_sink_0.set_gain(gain, 0)
        self.osmosdr_sink_0.set_if_gain(20, 0)
        self.osmosdr_sink_0.set_bb_gain(20, 0)
        self.osmosdr_sink_0.set_antenna('', 0)
        self.osmosdr_sink_0.set_bandwidth(2000000, 0)

        self.blocks_vector_source_x_0 = blocks.vector_source_c([
            1, 0, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1,
            0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
            0, 0, 0, 0, 0, 0, 0, 0
        ] * 10 + [0] * 3321, True, 1, [])
        self.blocks_repeat_0 = blocks.repeat(gr.sizeof_gr_complex * 1, interp)
        self.blocks_moving_average_xx_0 = blocks.moving_average_cc(
            20, 0.9 / 20, 4000, 1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_moving_average_xx_0, 0),
                     (self.osmosdr_sink_0, 0))
        self.connect((self.blocks_repeat_0, 0),
                     (self.blocks_moving_average_xx_0, 0))
        self.connect((self.blocks_vector_source_x_0, 0),
                     (self.blocks_repeat_0, 0))
Exemplo n.º 11
0
    def __init__(self):
        gr.top_block.__init__(self, "Top Block Iq2")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Top Block Iq2")
        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", "top_block_iq2")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.txgain = txgain = 65
        self.samp_rate = samp_rate = 32000
        self.rxgain = rxgain = 100
        self.button = button = 0

        ##################################################
        # Blocks
        ##################################################
        self._txgain_range = Range(0, 100, 1, 65, 200)
        self._txgain_win = RangeWidget(self._txgain_range, self.set_txgain,
                                       "txgain", "counter_slider", float)
        self.top_grid_layout.addWidget(self._txgain_win)
        self._rxgain_range = Range(0, 100, 1, 100, 200)
        self._rxgain_win = RangeWidget(self._rxgain_range, self.set_rxgain,
                                       "rxgain", "counter_slider", float)
        self.top_grid_layout.addWidget(self._rxgain_win)
        self.uhd_usrp_source_0 = uhd.usrp_source(
            ",".join(("", "")),
            uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd_usrp_source_0.set_samp_rate(samp_rate)
        self.uhd_usrp_source_0.set_center_freq(5e9, 0)
        self.uhd_usrp_source_0.set_gain(rxgain, 0)
        self.uhd_usrp_sink_0 = uhd.usrp_sink(
            ",".join(("", "")),
            uhd.stream_args(
                cpu_format="fc32",
                channels=range(1),
            ),
        )
        self.uhd_usrp_sink_0.set_samp_rate(samp_rate)
        self.uhd_usrp_sink_0.set_center_freq(5e9, 0)
        self.uhd_usrp_sink_0.set_gain(txgain, 0)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
            1024,  #size
            samp_rate,  #samp_rate
            "",  #name
            2  #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-5, 5)

        self.qtgui_time_sink_x_0.set_y_label('Magnitude & Phase', "")

        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_axis_labels(True)
        self.qtgui_time_sink_x_0.enable_control_panel(False)
        self.qtgui_time_sink_x_0.enable_stem_plot(False)

        if not True:
            self.qtgui_time_sink_x_0.disable_legend()

        labels = ['Magnitude', 'Phase', '', '', '', '', '', '', '', '']
        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):
            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_grid_layout.addWidget(self._qtgui_time_sink_x_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_y_label('Relative Gain', 'dB')
        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_axis_labels(True)
        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_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win)
        _button_push_button = Qt.QPushButton("button")
        self._button_choices = {'Pressed': 1, 'Released': 0}
        _button_push_button.pressed.connect(
            lambda: self.set_button(self._button_choices['Pressed']))
        _button_push_button.released.connect(
            lambda: self.set_button(self._button_choices['Released']))
        self.top_grid_layout.addWidget(_button_push_button)
        self.blocks_moving_average_xx_0 = blocks.moving_average_cc(
            1000, 1, 4000, 1)
        self.blocks_complex_to_magphase_0 = blocks.complex_to_magphase(1)
        self.analog_sig_source_x_0 = analog.sig_source_c(
            samp_rate, analog.GR_CONST_WAVE, 1, 1, 0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.uhd_usrp_sink_0, 0))
        self.connect((self.blocks_complex_to_magphase_0, 0),
                     (self.qtgui_time_sink_x_0, 0))
        self.connect((self.blocks_complex_to_magphase_0, 1),
                     (self.qtgui_time_sink_x_0, 1))
        self.connect((self.blocks_moving_average_xx_0, 0),
                     (self.blocks_complex_to_magphase_0, 0))
        self.connect((self.uhd_usrp_source_0, 0),
                     (self.blocks_moving_average_xx_0, 0))
        self.connect((self.uhd_usrp_source_0, 0),
                     (self.qtgui_freq_sink_x_0, 0))
Exemplo n.º 12
0
    def __init__(self,
                 final_decimation=4,
                 gain=21,
                 pllFreqMax=100,
                 pulse_duration=0.015,
                 pulse_freq=146000000,
                 samp_rate=3e6,
                 wnT=math.pi / 4.0 * 0 + 0.635):
        gr.hier_block2.__init__(
            self,
            "Pulsedetectbase",
            gr.io_signature(0, 0, 0),
            gr.io_signaturev(2, 2,
                             [gr.sizeof_float * 1, gr.sizeof_gr_complex * 1]),
        )

        ##################################################
        # Parameters
        ##################################################
        self.final_decimation = final_decimation
        self.gain = gain
        self.pllFreqMax = pllFreqMax
        self.pulse_duration = pulse_duration
        self.pulse_freq = pulse_freq
        self.samp_rate = samp_rate
        self.wnT = wnT

        ##################################################
        # Variables
        ##################################################
        self.decimate_1 = decimate_1 = 16
        self.samp_rate2 = samp_rate2 = samp_rate / decimate_1
        self.decimate_2 = decimate_2 = 16
        self.samp_rate3 = samp_rate3 = samp_rate2 / decimate_2
        self.taps3 = taps3 = firdes.low_pass_2(1.0, samp_rate3, 1.5e3, 0.3e3,
                                               30.0, firdes.WIN_KAISER,
                                               6.76 / 2)
        self.taps2 = taps2 = firdes.low_pass_2(1.0, samp_rate2, 1.5e3,
                                               16e3 - 1.5e3, 60.0,
                                               firdes.WIN_BLACKMAN_HARRIS,
                                               6.76)
        self.taps1 = taps1 = firdes.low_pass_2(1.0, samp_rate, 1.5e3,
                                               128e3 - 1.5e3, 60.0,
                                               firdes.WIN_BLACKMAN_HARRIS,
                                               6.76)
        self.decimate_3 = decimate_3 = final_decimation
        self.taps3_len = taps3_len = len(taps3)
        self.taps2_len = taps2_len = len(taps2)
        self.taps1_len = taps1_len = len(taps1)
        self.samp_rate4 = samp_rate4 = samp_rate3 / decimate_3
        self.inter_pulse_duration = inter_pulse_duration = 2
        self.fmin = fmin = -pllFreqMax
        self.fmax = fmax = pllFreqMax

        ##################################################
        # Blocks
        ##################################################
        self.osmosdr_source_0 = osmosdr.source(args="numchan=" + str(1) + " " +
                                               'airspy=0,sensitivity')
        self.osmosdr_source_0.set_clock_source('gpsdo', 0)
        self.osmosdr_source_0.set_sample_rate(samp_rate)
        self.osmosdr_source_0.set_center_freq(pulse_freq, 0)
        self.osmosdr_source_0.set_freq_corr(0, 0)
        self.osmosdr_source_0.set_dc_offset_mode(0, 0)
        self.osmosdr_source_0.set_iq_balance_mode(0, 0)
        self.osmosdr_source_0.set_gain_mode(False, 0)
        self.osmosdr_source_0.set_gain(gain, 0)
        self.osmosdr_source_0.set_if_gain(20, 0)
        self.osmosdr_source_0.set_bb_gain(20, 0)
        self.osmosdr_source_0.set_antenna('', 0)
        self.osmosdr_source_0.set_bandwidth(0, 0)

        self.freq_xlating_fir_filter_xxx_0 = filter.freq_xlating_fir_filter_ccc(
            decimate_1, (taps1), 0, samp_rate)
        self.fir_filter_xxx_0_0_0 = filter.fir_filter_ccf(decimate_3, (taps3))
        self.fir_filter_xxx_0_0_0.declare_sample_delay(0)
        self.fir_filter_xxx_0_0 = filter.fir_filter_ccf(decimate_2, (taps2))
        self.fir_filter_xxx_0_0.declare_sample_delay(0)
        self.blocks_multiply_conjugate_cc_0 = blocks.multiply_conjugate_cc(1)
        self.blocks_moving_average_xx_0_0 = blocks.moving_average_cc(
            int(samp_rate4 * pulse_duration), 1,
            int(samp_rate4 * inter_pulse_duration / 10.0))
        self.blocks_complex_to_mag_0_0 = blocks.complex_to_mag(1)
        self.analog_pll_refout_cc_0 = analog.pll_refout_cc(
            wnT, math.pi / (samp_rate4 / 2.0) * fmax,
            math.pi / (samp_rate4 / 2.0) * fmin)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_pll_refout_cc_0, 0),
                     (self.blocks_multiply_conjugate_cc_0, 1))
        self.connect((self.blocks_complex_to_mag_0_0, 0), (self, 0))
        self.connect((self.blocks_moving_average_xx_0_0, 0),
                     (self.blocks_complex_to_mag_0_0, 0))
        self.connect((self.blocks_multiply_conjugate_cc_0, 0),
                     (self.blocks_moving_average_xx_0_0, 0))
        self.connect((self.fir_filter_xxx_0_0, 0),
                     (self.fir_filter_xxx_0_0_0, 0))
        self.connect((self.fir_filter_xxx_0_0_0, 0),
                     (self.analog_pll_refout_cc_0, 0))
        self.connect((self.fir_filter_xxx_0_0_0, 0),
                     (self.blocks_multiply_conjugate_cc_0, 0))
        self.connect((self.fir_filter_xxx_0_0_0, 0), (self, 1))
        self.connect((self.freq_xlating_fir_filter_xxx_0, 0),
                     (self.fir_filter_xxx_0_0, 0))
        self.connect((self.osmosdr_source_0, 0),
                     (self.freq_xlating_fir_filter_xxx_0, 0))
Exemplo n.º 13
0
    def __init__(self):
        gr.top_block.__init__(self, "ELEKTRO-L2/L3 TLM Demodulator")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("ELEKTRO-L2/L3 TLM Demodulator")
        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", "elektro_tlm")

        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.file_rate = file_rate = 1024000
        self.sym_rate = sym_rate = 5000.0
        self.samp_rate = samp_rate = file_rate / 4
        self.sps = sps = samp_rate / sym_rate
        self.offset = offset = 0

        ##################################################
        # Blocks
        ##################################################
        self.rational_resampler_xxx_0 = filter.rational_resampler_ccc(
            interpolation=1, decimation=4, taps=None, fractional_bw=None)
        self.qtgui_time_raster_sink_x_0 = qtgui.time_raster_sink_b(
            samp_rate, 100, 1792, [], [], "", 1)

        self.qtgui_time_raster_sink_x_0.set_update_time(0.10)
        self.qtgui_time_raster_sink_x_0.set_intensity_range(-1, 1)
        self.qtgui_time_raster_sink_x_0.enable_grid(False)
        self.qtgui_time_raster_sink_x_0.enable_axis_labels(False)

        labels = ['', '', '', '', '', '', '', '', '', '']
        colors = [2, 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_time_raster_sink_x_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_time_raster_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_time_raster_sink_x_0.set_color_map(i, colors[i])
            self.qtgui_time_raster_sink_x_0.set_line_alpha(i, alphas[i])

        self._qtgui_time_raster_sink_x_0_win = sip.wrapinstance(
            self.qtgui_time_raster_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_time_raster_sink_x_0_win, 3,
                                       0, 1, 2)
        for r in range(3, 4):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c(
            2048,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "",  #name
            1)
        self.qtgui_freq_sink_x_0_0.set_update_time(0.01)
        self.qtgui_freq_sink_x_0_0.set_y_axis(-65, -15)
        self.qtgui_freq_sink_x_0_0.set_y_label('Relative Gain', 'dB')
        self.qtgui_freq_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, 0.0,
                                                    0, "")
        self.qtgui_freq_sink_x_0_0.enable_autoscale(False)
        self.qtgui_freq_sink_x_0_0.enable_grid(True)
        self.qtgui_freq_sink_x_0_0.set_fft_average(0.1)
        self.qtgui_freq_sink_x_0_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0_0.enable_control_panel(False)

        self.qtgui_freq_sink_x_0_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", "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 range(1):
            if len(labels[i]) == 0:
                self.qtgui_freq_sink_x_0_0.set_line_label(
                    i, "Data {0}".format(i))
            else:
                self.qtgui_freq_sink_x_0_0.set_line_label(i, labels[i])
            self.qtgui_freq_sink_x_0_0.set_line_width(i, widths[i])
            self.qtgui_freq_sink_x_0_0.set_line_color(i, colors[i])
            self.qtgui_freq_sink_x_0_0.set_line_alpha(i, alphas[i])

        self._qtgui_freq_sink_x_0_0_win = sip.wrapinstance(
            self.qtgui_freq_sink_x_0_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_freq_sink_x_0_0_win, 0, 0,
                                       1, 2)
        for r in range(0, 1):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
            2048,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            "",  #name
            1)
        self.qtgui_freq_sink_x_0.set_update_time(0.01)
        self.qtgui_freq_sink_x_0.set_y_axis(-65, 0)
        self.qtgui_freq_sink_x_0.set_y_label('Relative Gain', 'dB')
        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(True)
        self.qtgui_freq_sink_x_0.set_fft_average(0.05)
        self.qtgui_freq_sink_x_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0.enable_control_panel(False)

        self.qtgui_freq_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", "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 range(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_grid_layout.addWidget(self._qtgui_freq_sink_x_0_win, 1, 0, 1,
                                       1)
        for r in range(1, 2):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(0, 1):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.qtgui_const_sink_x_0 = qtgui.const_sink_c(
            256,  #size
            "",  #name
            1  #number of inputs
        )
        self.qtgui_const_sink_x_0.set_update_time(0.01)
        self.qtgui_const_sink_x_0.set_y_axis(-0.5, 0.5)
        self.qtgui_const_sink_x_0.set_x_axis(-0.5, 0.5)
        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(True)
        self.qtgui_const_sink_x_0.enable_axis_labels(False)

        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 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, 1, 1, 1,
                                       1)
        for r in range(1, 2):
            self.top_grid_layout.setRowStretch(r, 1)
        for c in range(1, 2):
            self.top_grid_layout.setColumnStretch(c, 1)
        self.low_pass_filter_0_0 = filter.fir_filter_ccf(
            1,
            firdes.low_pass(1, samp_rate, 4.5e3, 1e3, firdes.WIN_HAMMING,
                            6.76))
        self.low_pass_filter_0 = filter.fir_filter_ccf(
            1,
            firdes.low_pass(1, samp_rate, 10e3, 1e3, firdes.WIN_HAMMING, 6.76))
        self.freq_xlating_fft_filter_ccc_0 = filter.freq_xlating_fft_filter_ccc(
            1, firdes.low_pass(1, samp_rate, samp_rate / (2 * 1), 1000),
            offset, samp_rate)
        self.freq_xlating_fft_filter_ccc_0.set_nthreads(1)
        self.freq_xlating_fft_filter_ccc_0.declare_sample_delay(0)
        self.digital_costas_loop_cc_0 = digital.costas_loop_cc(3e-3, 2, False)
        self.digital_clock_recovery_mm_xx_1 = digital.clock_recovery_mm_cc(
            sps * (1 + 0.0), 0.625e-3, 0.5, 0.175, 0.005)
        self.digital_binary_slicer_fb_0 = digital.binary_slicer_fb()
        self.dc_blocker_xx_0 = filter.dc_blocker_cc(32, True)
        self.blocks_wavfile_source_0 = blocks.wavfile_source('', True)
        self.blocks_udp_sink_0 = blocks.udp_sink(gr.sizeof_gr_complex * 28,
                                                 '127.0.0.1', 52001, 1472,
                                                 True)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                 file_rate, True)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(
            gr.sizeof_char * 1, 224)
        self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(8)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_moving_average_xx_0 = blocks.moving_average_cc(
            2, 0.5, 4000, 1)
        self.blocks_float_to_complex_0 = blocks.float_to_complex(1)
        self.blocks_complex_to_real_0 = blocks.complex_to_real(1)
        self.analog_sig_source_x_0 = analog.sig_source_c(
            samp_rate, analog.GR_SIN_WAVE, -5000, 1, 0, 0)
        self.analog_agc_xx_0_0_0 = analog.agc_cc(10e-3, 500e-3, 0.5)
        self.analog_agc_xx_0_0_0.set_max_gain(4e3)
        self.analog_agc_xx_0_0 = analog.agc_cc(10e-3, 500e-3, 0.5)
        self.analog_agc_xx_0_0.set_max_gain(4e3)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_agc_xx_0_0, 0),
                     (self.rational_resampler_xxx_0, 0))
        self.connect((self.analog_agc_xx_0_0_0, 0),
                     (self.low_pass_filter_0, 0))
        self.connect((self.analog_sig_source_x_0, 0),
                     (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_complex_to_real_0, 0),
                     (self.digital_binary_slicer_fb_0, 0))
        self.connect((self.blocks_float_to_complex_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_moving_average_xx_0, 0),
                     (self.digital_costas_loop_cc_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0),
                     (self.low_pass_filter_0_0, 0))
        self.connect((self.blocks_pack_k_bits_bb_0, 0),
                     (self.blocks_stream_to_vector_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0),
                     (self.blocks_udp_sink_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.analog_agc_xx_0_0, 0))
        self.connect((self.blocks_wavfile_source_0, 0),
                     (self.blocks_float_to_complex_0, 0))
        self.connect((self.blocks_wavfile_source_0, 1),
                     (self.blocks_float_to_complex_0, 1))
        self.connect((self.dc_blocker_xx_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.digital_binary_slicer_fb_0, 0),
                     (self.blocks_pack_k_bits_bb_0, 0))
        self.connect((self.digital_binary_slicer_fb_0, 0),
                     (self.qtgui_time_raster_sink_x_0, 0))
        self.connect((self.digital_clock_recovery_mm_xx_1, 0),
                     (self.blocks_complex_to_real_0, 0))
        self.connect((self.digital_clock_recovery_mm_xx_1, 0),
                     (self.qtgui_const_sink_x_0, 0))
        self.connect((self.digital_costas_loop_cc_0, 0),
                     (self.digital_clock_recovery_mm_xx_1, 0))
        self.connect((self.freq_xlating_fft_filter_ccc_0, 0),
                     (self.analog_agc_xx_0_0_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.dc_blocker_xx_0, 0))
        self.connect((self.low_pass_filter_0, 0),
                     (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.low_pass_filter_0_0, 0),
                     (self.blocks_moving_average_xx_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0),
                     (self.freq_xlating_fft_filter_ccc_0, 0))
        self.connect((self.rational_resampler_xxx_0, 0),
                     (self.qtgui_freq_sink_x_0_0, 0))
Exemplo n.º 14
0
    def __init__(self,
                 fft_length,
                 cp_length,
                 preambles,
                 mode='RAW',
                 logging=False):
        gr.hier_block2.__init__(
            self,
            "ofdm_sync_pn",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature3(
                3,
                3,  # Output signature
                gr.sizeof_gr_complex,  # delayed input
                gr.sizeof_float,  # fine frequency offset
                gr.sizeof_char  # timing indicator
            ))

        period = fft_length / 2
        window = fft_length / 2

        # Calculate the frequency offset from the correlation of the preamble
        x_corr = blocks.multiply_cc()
        self.connect(self, blocks.conjugate_cc(), (x_corr, 0))
        self.connect(self, blocks.delay(gr.sizeof_gr_complex, period),
                     (x_corr, 1))
        P_d = blocks.moving_average_cc(window, 1.0)
        self.connect(x_corr, P_d)

        P_d_angle = blocks.complex_to_arg()
        self.connect(P_d, P_d_angle)

        # Get the power of the input signal to normalize the output of the correlation
        R_d = blocks.moving_average_ff(window, 1.0)
        self.connect(self, blocks.complex_to_mag_squared(), R_d)
        R_d_squared = blocks.multiply_ff()  # this is retarded
        self.connect(R_d, (R_d_squared, 0))
        self.connect(R_d, (R_d_squared, 1))
        M_d = blocks.divide_ff()
        self.connect(P_d, blocks.complex_to_mag_squared(), (M_d, 0))
        self.connect(R_d_squared, (M_d, 1))

        # Now we need to detect peak of M_d
        # the peak is up to cp_length long, but noisy, so average it out
        matched_filter = blocks.moving_average_ff(cp_length, 1.0 / cp_length)

        # NOTE: the look_ahead parameter doesn't do anything
        # these parameters are kind of magic, increase 1 and 2 (==) to be more tolerant
        peak_detect = raw.peak_detector_fb(0.25, 0.55, 30, 0.001)

        # offset by -1
        self.connect(M_d, matched_filter, blocks.add_const_ff(-1), peak_detect)

        # peak_detect indicates the time M_d is highest, which is the end of the symbol.
        # nco(t) = P_d_angle(t-offset) sampled at peak_detect(t)
        # modulate input(t - fft_length) by nco(t)
        # signal to sample input(t) at t-offset
        #
        ##########################################################
        # IMPORTANT NOTES:
        # We can't delay by < 0 so instead:
        # input is delayed by some_length
        # signal to sample is delayed by some_length - offset
        ##########################################################
        # peak_delay and offset are for cutting CP
        # FIXME: until we figure out how to do this, just offset by 6 or cp_length/2
        symbol_length = fft_length + cp_length
        peak_delay = cp_length
        offset = 6  #cp_length/2
        self.offset = offset

        # regenerate peak using cross-correlation
        # * RAW mode: use raw_generate_peak2 block to filter peaks
        # * PNC mode: use raw_generate_peak3 block to identify the proper peak for two users
        # PNC mode delays all input peak_delay samples
        # * cp_length: delay for cross-correlation since auto-correlation is not so accurate
        # * 3 symbol_length: delay for identifying mode for PNC
        # * -offset: for cp cut
        if mode == 'PNC':
            # The block structure is
            # signal -> 3*symbol_length+cp_length-offset     -> (self,0) [signal]
            # signal -> cp_length delay -> auto  -> (peak,0) -> (self,2) [peak]
            # signal -> cp_length delay          -> (peak,1) -> (self,1) [cfo]
            # cfo    -> cp_length delay          -> (peak,2)
            #
            # we let cross's signal go faster to identify the beginning
            # we use cross's peak output to find cfo, so the delay of cfo should = cross delay
            # we use raw_regenerate_peak to do cross-corr, and symbols energy after STS to identify mode
            # so the signal is further delayed by three symbols more
            self.signal_cross_delay = blocks.delay(gr.sizeof_gr_complex,
                                                   peak_delay)
            self.cfo_cross_delay = blocks.delay(gr.sizeof_float, peak_delay)

            LOOK_AHEAD_NSYM = 3
            self.connect(self, self.signal_cross_delay)
            self.connect(P_d_angle, self.cfo_cross_delay)

            peak = raw.regenerate_peak3(fft_length, fft_length + cp_length,
                                        LOOK_AHEAD_NSYM, peak_delay, preambles,
                                        False)
            self.connect(peak_detect, (peak, 0))
            self.connect(self.signal_cross_delay, (peak, 1))
            self.connect(self.cfo_cross_delay, (peak, 2))

            self.signal_delay = blocks.delay(
                gr.sizeof_gr_complex,
                LOOK_AHEAD_NSYM * symbol_length + peak_delay - offset)
            self.connect(self, self.signal_delay, (self, 0))  # signal output
            self.connect((peak, 1), (self, 1))  # cfo output
            self.connect((peak, 0), (self, 2))  # peak output

            if logging:
                self.connect(
                    self.cfo_cross_delay,
                    blocks.file_sink(gr.sizeof_float, 'logs/input-cfo.dat'))
                #self.connect(cross, blocks.file_sink(gr.sizeof_float, 'logs/cross.dat'))
                self.connect(
                    self.signal_cross_delay,
                    blocks.file_sink(gr.sizeof_gr_complex,
                                     'logs/cross-signal.dat'))

        if mode == 'RAW':
            LOOK_AHEAD_NSYM = 0
            peak = raw.regenerate_peak2(fft_length, fft_length + cp_length,
                                        LOOK_AHEAD_NSYM, preambles)
            self.signal_delay1 = blocks.delay(gr.sizeof_gr_complex,
                                              peak_delay - offset)
            self.signal_delay2 = blocks.delay(gr.sizeof_gr_complex, offset)
            self.cfo_delay = blocks.delay(
                gr.sizeof_float,
                peak_delay)  # we generate the same delay with signal
            self.connect(peak_detect, (peak, 0))
            self.connect(P_d_angle, self.cfo_delay, (peak, 1))
            self.connect(self, self.signal_delay1, self.signal_delay2,
                         (peak, 2))

            self.connect(self.signal_delay1, (self, 0))  # signal output
            self.connect((peak, 1), (self, 1))  # cfo output
            self.connect((peak, 0), (self, 2))  # raw peak output

            if logging:
                self.connect(
                    self.signal_delay1,
                    blocks.file_sink(gr.sizeof_gr_complex,
                                     'logs/test-out-signal.dat'))
                self.connect((peak, 0),
                             blocks.file_sink(gr.sizeof_char,
                                              'logs/test-out-peak.datb'))
                self.connect(
                    self.cfo_delay,
                    blocks.file_sink(gr.sizeof_float, 'logs/test-cfo.dat'))
                self.connect(
                    peak_detect,
                    blocks.file_sink(gr.sizeof_char,
                                     'logs/test-out-auto-peak.datb'))

        if logging:
            #self.connect(self.signal_delay1, blocks.file_sink(gr.sizeof_gr_complex, 'logs/test-signal.dat'))
            self.connect((peak, 0),
                         blocks.file_sink(gr.sizeof_char, 'logs/peak.datb'))
            self.connect((peak, 1),
                         blocks.file_sink(gr.sizeof_float,
                                          'logs/peak-cfo.dat'))
            self.connect(matched_filter,
                         blocks.file_sink(gr.sizeof_float, 'logs/sync-mf.dat'))
            self.connect(M_d,
                         blocks.file_sink(gr.sizeof_float, 'logs/sync-M.dat'))
            self.connect(
                P_d, blocks.file_sink(gr.sizeof_gr_complex,
                                      'logs/sync-pd.dat'))
            self.connect(R_d,
                         blocks.file_sink(gr.sizeof_float, 'logs/sync-rd.dat'))
            self.connect(
                R_d_squared,
                blocks.file_sink(gr.sizeof_float, 'logs/sync-rd-squared.dat'))
            self.connect(
                P_d_angle,
                blocks.file_sink(gr.sizeof_float, 'logs/sync-angle.dat'))
            self.connect(
                peak_detect,
                blocks.file_sink(gr.sizeof_char, 'logs/sync-peaks.datb'))
Exemplo n.º 15
0
    def __init__(self,
                 fft_length,
                 cp_length,
                 preambles,
                 sample_rate=10e6,
                 mode='RAW',
                 logging=False):
        gr.hier_block2.__init__(
            self,
            "ofdm_sync_fir",
            gr.io_signature(1, 1, gr.sizeof_gr_complex),  # Input signature
            gr.io_signature3(
                3,
                3,  # Output signature
                gr.sizeof_gr_complex,  # delayed input
                gr.sizeof_float,  # fine frequency offset
                gr.sizeof_char  # timing indicator
            ))

        period = 16
        window = 48
        symbol_length = fft_length + cp_length

        # Calculate the frequency offset from the correlation of the preamble
        x_corr = blocks.multiply_cc()
        P_d = blocks.moving_average_cc(window, 1.0)
        #P_d = gnuradio.filter.fir_filter_ccf(1, [1.0]*window)
        P_d_angle = blocks.complex_to_arg()
        period_delay = blocks.delay(gr.sizeof_gr_complex, period)
        conj = blocks.conjugate_cc()

        self.connect(self, period_delay, (x_corr, 0))
        self.connect(self, conj, (x_corr, 1))
        self.connect(x_corr, P_d, P_d_angle)

        # Get the power of the input signal to normalize the output of the correlation
        R_d = blocks.moving_average_ff(window, 1.0)
        #R_d = gnuradio.filter.fir_filter_fff(1, [1.0]*window)
        self.connect(self, blocks.complex_to_mag_squared(), R_d)

        ## using volk divide
        #M_d = blocks.divide_ff()
        M_d = raw.divide_ff()
        self.connect(P_d, blocks.complex_to_mag(), (M_d, 0))
        self.connect(R_d, (M_d, 1))

        peak_detect = raw.peak_detector2_fb(0.75)
        # NOTE: Trainning symbol format: STS STS LTS1 LTS2
        # because of the moving_average with parameter "window",  M_d outputs pulse which indicates the last sample of STS, but need to be adjusted
        # Cross correlation operation generate peaks only at the last sample of LTS
        # so, in order to reduce the cross-corr computation,
        # we delay the peak flag with some delay(less than symbol_length to get some tolerance)
        # the threshold setted in peak_detector will intruduce some samples
        if mode == 'PNC':
            autocorr_flag_delay = symbol_length * 2 - cp_length
        elif mode == 'RAW':
            autocorr_flag_delay = symbol_length
        autoflag_delay = blocks.delay(gr.sizeof_float, autocorr_flag_delay)

        self.connect(self, (peak_detect, 0))
        self.connect(M_d, autoflag_delay, (peak_detect, 1))

        if sample_rate > 15e6:
            period_delay.set_min_output_buffer(96000)
            conj.set_min_output_buffer(96000)
            x_corr.set_min_output_buffer(96000)
            P_d.set_min_output_buffer(96000)
            P_d_angle.set_min_output_buffer(96000)
            M_d.set_min_output_buffer(96000)
            peak_detect.set_min_output_buffer(96000)
            autoflag_delay.set_min_output_buffer(96000)

        if False:
            self.connect(
                M_d, blocks.file_sink(gr.sizeof_float, 'logs/rx-sync-M_d.dat'))
            self.connect(
                autoflag_delay,
                blocks.file_sink(gr.sizeof_float,
                                 'logs/rx-autoflag_delay.dat'))
            self.connect(
                peak_detect,
                blocks.file_sink(gr.sizeof_char, 'logs/rx-sync-peak.datb'))
            self.connect((peak_detect, 1),
                         blocks.file_sink(gr.sizeof_float,
                                          'logs/rx-sync-peak.datf'))

        ##########################################################
        # peak_delay and offset are for cutting CP
        # FIXME: until we figure out how to do this, just offset by 6 or cp_length/2
        #symbol_length = fft_length+cp_length
        peak_delay = cp_length
        offset = 8  #cp_length/2
        self.offset = offset

        # regenerate peak using cross-correlation
        # * RAW mode: use raw_generate_peak2 block to filter peaks
        # * PNC mode: use raw_generate_peak3 block to identify the proper peak for two users
        # PNC mode delays all input peak_delay samples
        # * cp_length: delay for cross-correlation since auto-correlation is not so accurate
        # * 3 symbol_length: delay for identifying mode for PNC
        # * -offset: for cp cut
        if mode == 'PNC':
            # The block structure is
            # signal -> 3*symbol_length+cp_length-offset     -> (self,0) [signal]
            # signal -> cp_length delay -> auto  -> (peak,0) -> (self,2) [peak]
            # signal -> cp_length delay          -> (peak,1) -> (self,1) [cfo]
            # cfo    -> cp_length delay          -> (peak,2)
            #
            # we let cross's signal go faster to identify the beginning
            # we use cross's peak output to find cfo, so the delay of cfo should = cross delay
            # we use raw_regenerate_peak to do cross-corr, and symbols energy after STS to identify mode
            # so the signal is further delayed by three symbols more
            self.cfo_cross_delay = blocks.delay(gr.sizeof_float, peak_delay)

            LOOK_AHEAD_NSYM = 0
            peak_cross_range = cp_length * 2

            #self.connect(autoflag_delay, blocks.file_sink(gr.sizeof_float, 'logs/rx-autoflag_delay.dat'))

            peak = raw.regenerate_peak3(fft_length, fft_length + cp_length,
                                        LOOK_AHEAD_NSYM, peak_cross_range,
                                        preambles, False)
            self.connect(peak_detect, (peak, 0))
            self.connect(self, (peak, 1))
            self.connect(P_d_angle, self.cfo_cross_delay, (peak, 2))

            self.signal_delay = blocks.delay(
                gr.sizeof_gr_complex,
                autocorr_flag_delay + cp_length + peak_cross_range - offset)
            self.connect(self, self.signal_delay, (self, 0))  # signal output
            self.connect((peak, 1), (self, 1))  # cfo output
            self.connect((peak, 0), (self, 2))  # peak output
            #self.connect((peak,1), blocks.null_sink(gr.sizeof_float))
            #self.connect((peak,0), blocks.null_sink(gr.sizeof_char))
            #self.connect(blocks.null_source(gr.sizeof_float), (self,1))
            #self.connect(blocks.null_source(gr.sizeof_char), (self,2))

            if logging:
                self.connect(
                    self.cfo_cross_delay,
                    blocks.file_sink(gr.sizeof_float, 'logs/input-cfo.dat'))
                #self.connect(cross, blocks.file_sink(gr.sizeof_float, 'logs/cross.dat'))
                self.connect(
                    self.signal_cross_delay,
                    blocks.file_sink(gr.sizeof_gr_complex,
                                     'logs/cross-signal.dat'))

        if mode == 'RAW':
            LOOK_AHEAD_NSYM = 0
            peak = raw.regenerate_peak2(fft_length, fft_length+cp_length, \
                                                    LOOK_AHEAD_NSYM, preambles, False)
            # do LTS cross correlation will set a flag at the last sample of LTS
            # signal delay is the same as the path(cross signal), but delay to pos(in 1st cp of LTS)
            # so as the sample cut the data from LTS to end;
            self.signal_delay = blocks.delay(
                gr.sizeof_gr_complex, symbol_length -
                offset)  #self.cross_delay + symbol_length - offset

            if sample_rate > 15e6:
                self.signal_delay.set_min_output_buffer(96000)
                #peak.set_max_noutput_items(2048)
                #peak.set_max_noutput_items(96000)

            self.cfo_delay = autocorr_flag_delay + peak_delay

            self.connect(peak_detect, (peak, 0))
            self.connect(P_d_angle,
                         blocks.delay(gr.sizeof_float, self.cfo_delay),
                         (peak, 1))
            self.connect(self, (peak, 2))

            self.connect(self, self.signal_delay, (self, 0))  # signal output
            self.connect((peak, 1), (self, 1))  # cfo output
            self.connect((peak, 0), (self, 2))  # raw peak output

            self.peak = peak