Beispiel #1
0
    def test_preamble(self):
        pream_len = 52
        pream = (mapper.preamble_generator(pream_len, 511,
                                           1033)).get_preamble()

        rand_src = blocks.vector_source_b(
            map(int, numpy.random.randint(0, 2, 1024)), True)
        head = blocks.head(gr.sizeof_char * 1, 1024)
        src_sink = blocks.vector_sink_b(1)
        pream_inst = mapper.preamble_insert_bb(pream_len * 10, (pream))
        bit2symb = mapper.mapper(mapper.BPSK, ([0, 1]))
        pream_sync = mapper.preamble_sync_cc(pream_len * 10, (pream),
                                             mapper.BPSK, ([0, 1]), .97, .90)
        symb2bit = mapper.demapper(mapper.BPSK, ([0, 1]))
        rec_sink = blocks.vector_sink_b(1)

        self.tb.connect((rand_src, 0), (head, 0))
        self.tb.connect((head, 0), (pream_inst, 0))
        self.tb.connect((head, 0), (src_sink, 0))
        self.tb.connect((pream_inst, 0), (bit2symb, 0))
        self.tb.connect((bit2symb, 0), (pream_sync, 0))
        self.tb.connect((pream_sync, 0), (symb2bit, 0))
        self.tb.connect((symb2bit, 0), (rec_sink, 0))

        self.tb.start()
        sleep(1)
        self.tb.stop()

        data_space = pream_len * 9
        sd = src_sink.data()
        rd = rec_sink.data()
        self.assertEqual(sd[0:data_space], rd[0:data_space])
Beispiel #2
0
    def test_preamble (self):
        pream_len = 52
        pream = (mapper.preamble_generator(pream_len,511,1033)).get_preamble()
        
        rand_src    = blocks.vector_source_b(map(int, numpy.random.randint(0, 2, 1024)), True)
        head        = blocks.head(gr.sizeof_char*1, 1024)
        src_sink    = blocks.vector_sink_b(1)
        pream_inst  = mapper.preamble_insert_bb(pream_len*10, (pream))
        bit2symb    = mapper.mapper(mapper.BPSK, ([0,1]))
        pream_sync  = mapper.preamble_sync_cc(pream_len*10, (pream), mapper.BPSK, ([0,1]), .97, .90)
        symb2bit    = mapper.demapper(mapper.BPSK, ([0,1]))
        rec_sink    = blocks.vector_sink_b(1)

        self.tb.connect((rand_src, 0), (head, 0))
        self.tb.connect((head, 0), (pream_inst, 0))
        self.tb.connect((head, 0), (src_sink, 0))
        self.tb.connect((pream_inst, 0), (bit2symb, 0))
        self.tb.connect((bit2symb, 0), (pream_sync, 0))
        self.tb.connect((pream_sync, 0), (symb2bit, 0))
        self.tb.connect((symb2bit, 0), (rec_sink, 0))
        
        self.tb.start()
        sleep(1)
        self.tb.stop()
        
        data_space = pream_len*9
        sd = src_sink.data()
        rd = rec_sink.data()
        self.assertEqual(sd[0:data_space],rd[0:data_space])
from gnuradio import gr
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
import mapper
import numpy
from time import *

tb = gr.top_block()

##################################################
# Variables
##################################################
pream_len = pream_len = 52
samp_rate = samp_rate = 32000
pream = pream = (mapper.preamble_generator(pream_len, 511,
                                           1033)).get_preamble()

##################################################
# Blocks
##################################################
rand_src = blocks.vector_source_b(map(int, numpy.random.randint(0, 2, 1024)),
                                  True)
#head        = blocks.head(gr.sizeof_char*1, 1024)
src_sink = blocks.vector_sink_b(1)
pream_inst = mapper.preamble_insert_bb(pream_len * 10, (pream))
pre_sink = blocks.vector_sink_b(1)
bit2symb = mapper.mapper(mapper.BPSK, ([0, 1]))
sym_sink = blocks.vector_sink_c(1)
pream_sync = mapper.preamble_sync_cc(pream_len * 10, (pream), mapper.BPSK,
                                     ([0, 1]), .97, .90)
snc_sink = blocks.vector_sink_c(1)
from gnuradio.eng_option import eng_option
from gnuradio.filter import firdes
from optparse import OptionParser
import mapper
import numpy
from time import *


tb = gr.top_block()

##################################################
# Variables
##################################################
pream_len = pream_len = 52
samp_rate = samp_rate = 32000
pream = pream = (mapper.preamble_generator(pream_len,511,1033)).get_preamble()

##################################################
# Blocks
##################################################
rand_src    = blocks.vector_source_b(map(int, numpy.random.randint(0, 2, 1024)), True)
#head        = blocks.head(gr.sizeof_char*1, 1024)
src_sink    = blocks.vector_sink_b(1)
pream_inst  = mapper.preamble_insert_bb(pream_len*10, (pream))
pre_sink    = blocks.vector_sink_b(1)
bit2symb    = mapper.mapper(mapper.BPSK, ([0,1]))
sym_sink    = blocks.vector_sink_c(1)
pream_sync  = mapper.preamble_sync_cc(pream_len*10, (pream), mapper.BPSK, ([0,1]), .97, .90)
snc_sink    = blocks.vector_sink_c(1)
symb2bit    = mapper.demapper(mapper.BPSK, ([0,1]))
rec_sink    = blocks.vector_sink_b(1)
Beispiel #5
0
    def __init__(self):
        gr.top_block.__init__(self, "Sync Test")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Sync Test")
        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", "sync_test")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Variables
        ##################################################
        self.pream_len = pream_len = 84
        self.samp_rate = samp_rate = 32000
        self.pream = pream = (mapper.preamble_generator(pream_len,511,1033)).get_preamble()
        self.SNR = SNR = 40
        self.Rotation = Rotation = 0
        self.Offset = Offset = 0

        ##################################################
        # Blocks
        ##################################################
        self._SNR_tool_bar = Qt.QToolBar(self)
        self._SNR_tool_bar.addWidget(Qt.QLabel("SNR"+": "))
        self._SNR_line_edit = Qt.QLineEdit(str(self.SNR))
        self._SNR_tool_bar.addWidget(self._SNR_line_edit)
        self._SNR_line_edit.returnPressed.connect(
        	lambda: self.set_SNR(eng_notation.str_to_num(self._SNR_line_edit.text().toAscii())))
        self.top_layout.addWidget(self._SNR_tool_bar)
        self._Rotation_layout = Qt.QVBoxLayout()
        self._Rotation_label = Qt.QLabel("Rotation")
        self._Rotation_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._Rotation_slider.setRange(0, 2*pi, pi/100)
        self._Rotation_slider.setValue(self.Rotation)
        self._Rotation_slider.setMinimumWidth(200)
        self._Rotation_slider.valueChanged.connect(self.set_Rotation)
        self._Rotation_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._Rotation_layout.addWidget(self._Rotation_label)
        self._Rotation_layout.addWidget(self._Rotation_slider)
        self.top_layout.addLayout(self._Rotation_layout)
        self._Offset_layout = Qt.QVBoxLayout()
        self._Offset_tool_bar = Qt.QToolBar(self)
        self._Offset_layout.addWidget(self._Offset_tool_bar)
        self._Offset_tool_bar.addWidget(Qt.QLabel("Offset"+": "))
        self._Offset_counter = Qwt.QwtCounter()
        self._Offset_counter.setRange(-100, 100, 1)
        self._Offset_counter.setNumButtons(2)
        self._Offset_counter.setValue(self.Offset)
        self._Offset_tool_bar.addWidget(self._Offset_counter)
        self._Offset_counter.valueChanged.connect(self.set_Offset)
        self._Offset_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._Offset_slider.setRange(-100, 100, 1)
        self._Offset_slider.setValue(self.Offset)
        self._Offset_slider.setMinimumWidth(200)
        self._Offset_slider.valueChanged.connect(self.set_Offset)
        self._Offset_layout.addWidget(self._Offset_slider)
        self.top_layout.addLayout(self._Offset_layout)
        self.qtgui_const_sink_x_0_1 = qtgui.const_sink_c(
        	840-84, #size
        	"QT GUI Plot", #name
        	1 #number of inputs
        )
        self.qtgui_const_sink_x_0_1.set_update_time(0.10)
        self.qtgui_const_sink_x_0_1.set_y_axis(-2, 2)
        self.qtgui_const_sink_x_0_1.set_x_axis(-2, 2)
        self._qtgui_const_sink_x_0_1_win = sip.wrapinstance(self.qtgui_const_sink_x_0_1.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_const_sink_x_0_1_win)
        self.qtgui_const_sink_x_0 = qtgui.const_sink_c(
        	840-84, #size
        	"QT GUI Plot", #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_win = sip.wrapinstance(self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_const_sink_x_0_win)
        self.mapper_preamble_sync_cc_0 = mapper.preamble_sync_cc(pream_len*10, (pream), mapper.PSK8, ([0,1,2,3,4,5,6,7]), .97, .90)
        self.mapper_preamble_insert_bb_0 = mapper.preamble_insert_bb(pream_len*10, (pream))
        self.mapper_mapper_0 = mapper.mapper(mapper.PSK8, ([0,1,2,3,4,5,6,7]))
        self.mapper_demapper_0 = mapper.demapper(mapper.PSK8, ([0,1,2,3,4,5,6,7]))
        self.digital_costas_loop_cc_0 = digital.costas_loop_cc(1.5*pi/100, 8)
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage=10**(-SNR/20.0),
        	frequency_offset=Offset,
        	epsilon=1.0,
        	taps=(exp( (0 + 1j*Rotation) ), ),
        	noise_seed=0,
        	block_tags=False
        )
        self.blocks_vector_sink_x_0_0 = blocks.vector_sink_b(1)
        self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(3)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char*1, samp_rate)
        self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 7, 10000)), True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.mapper_preamble_insert_bb_0, 0), (self.mapper_mapper_0, 0))
        self.connect((self.mapper_preamble_sync_cc_0, 0), (self.mapper_demapper_0, 0))
        self.connect((self.mapper_mapper_0, 0), (self.channels_channel_model_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.digital_costas_loop_cc_0, 0))
        self.connect((self.digital_costas_loop_cc_0, 0), (self.mapper_preamble_sync_cc_0, 0))
        self.connect((self.mapper_preamble_sync_cc_0, 0), (self.qtgui_const_sink_x_0_1, 0))
        self.connect((self.analog_random_source_x_0, 0), (self.blocks_unpack_k_bits_bb_0, 0))
        self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.mapper_preamble_insert_bb_0, 0))
        self.connect((self.mapper_demapper_0, 0), (self.blocks_vector_sink_x_0_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.qtgui_const_sink_x_0, 0))
Beispiel #6
0
 def set_pream_len(self, pream_len):
     self.pream_len = pream_len
     self.set_pream((mapper.preamble_generator(self.pream_len,511,1033)).get_preamble())
     self.mapper_preamble_insert_bb_0.mapper.set_width(self.pream_len*10)
Beispiel #7
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.pilot_symbols = pilot_symbols = ((
            1,
            1,
            1,
            -1,
        ), )
        self.pilot_carriers = pilot_carriers = ((
            -21,
            -7,
            7,
            21,
        ), )
        self.payload_mod = payload_mod = digital.constellation_qpsk()
        self.packet_length_tag_key = packet_length_tag_key = "packet_len"
        self.occupied_carriers = occupied_carriers = (
            range(-26, -21) + range(-20, -7) + range(-6, 0) + range(1, 7) +
            range(8, 21) + range(22, 27), )
        self.length_tag_key = length_tag_key = "frame_len"
        self.header_mod = header_mod = digital.constellation_bpsk()
        self.fft_len = fft_len = 64
        self.sync_word2 = sync_word2 = [
            0j, 0j, 0j, 0j, 0j, 0j, (-1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j),
            (1 + 0j), (1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (1 + 0j),
            (-1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j),
            (-1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (1 + 0j),
            (-1 + 0j), (-1 + 0j), (1 + 0j), (-1 + 0j), 0j, (1 + 0j), (-1 + 0j),
            (1 + 0j), (1 + 0j), (1 + 0j), (-1 + 0j), (1 + 0j), (1 + 0j),
            (1 + 0j), (-1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j), (1 + 0j),
            (-1 + 0j), (1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (1 + 0j),
            (-1 + 0j), (1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j), (-1 + 0j),
            0j, 0j, 0j, 0j, 0j
        ]
        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.sro = sro = 0
        self.samp_rate = samp_rate = 500000
        self.samp_per_sym = samp_per_sym = 2
        self.rolloff = rolloff = 0
        self.pream = pream = (mapper.preamble_generator(32, 511,
                                                        1033)).get_preamble()
        self.payload_equalizer = payload_equalizer = digital.ofdm_equalizer_simpledfe(
            fft_len, payload_mod.base(), occupied_carriers, pilot_carriers,
            pilot_symbols, 1)
        self.packet_len = packet_len = 96
        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,
            bits_per_header_sym=header_mod.bits_per_symbol(),
            bits_per_payload_sym=payload_mod.bits_per_symbol(),
            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.frame_width_with_crc32 = frame_width_with_crc32 = 2016 + 32 + 32
        self.frame_width = frame_width = 1024 * 2
        self.cfo = cfo = 1e-2
        self.SNR = SNR = 15

        ##################################################
        # Blocks
        ##################################################
        self._sro_range = Range(-1e-1, 1e-1, 1e-3, 0, 200)
        self._sro_win = RangeWidget(self._sro_range, self.set_sro,
                                    'Sample Rate Offset', "counter_slider",
                                    float)
        self.top_grid_layout.addWidget(self._sro_win)
        self._cfo_range = Range(-1e-1, 1e-1, 1e-3, 1e-2, 200)
        self._cfo_win = RangeWidget(self._cfo_range, self.set_cfo,
                                    'Freq Offset', "counter_slider", float)
        self.top_grid_layout.addWidget(self._cfo_win)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
            1024,  #size
            samp_rate,  #samp_rate
            'Scope Plot',  #name
            1  #number of inputs
        )
        self.qtgui_time_sink_x_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0.set_y_axis(-1, 1)

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

        self.qtgui_time_sink_x_0.enable_tags(-1, True)
        self.qtgui_time_sink_x_0.set_trigger_mode(qtgui.TRIG_MODE_FREE,
                                                  qtgui.TRIG_SLOPE_POS, 0.0, 0,
                                                  0, "")
        self.qtgui_time_sink_x_0.enable_autoscale(True)
        self.qtgui_time_sink_x_0.enable_grid(False)
        self.qtgui_time_sink_x_0.enable_axis_labels(True)
        self.qtgui_time_sink_x_0.enable_control_panel(False)

        if not True:
            self.qtgui_time_sink_x_0.disable_legend()

        labels = ['', '', '', '', '', '', '', '', '', '']
        widths = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        colors = [
            "blue", "red", "green", "black", "cyan", "magenta", "yellow",
            "dark red", "dark green", "blue"
        ]
        styles = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]
        markers = [-1, -1, -1, -1, -1, -1, -1, -1, -1, -1]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0]

        for i in xrange(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_grid_layout.addWidget(self._qtgui_time_sink_x_0_win)
        self.qtgui_freq_sink_x_0_0 = qtgui.freq_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            'Tx Spectrum',  #name
            1  #number of inputs
        )
        self.qtgui_freq_sink_x_0_0.set_update_time(0.10)
        self.qtgui_freq_sink_x_0_0.set_y_axis(-140, 10)
        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(False)
        self.qtgui_freq_sink_x_0_0.set_fft_average(1.0)
        self.qtgui_freq_sink_x_0_0.enable_axis_labels(True)
        self.qtgui_freq_sink_x_0_0.enable_control_panel(False)

        if not True:
            self.qtgui_freq_sink_x_0_0.disable_legend()

        if "complex" == "float" or "complex" == "msg_float":
            self.qtgui_freq_sink_x_0_0.set_plot_pos_half(not True)

        labels = ['Rx Spectrum', '', '', '', '', '', '', '', '', '']
        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_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)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
            1024,  #size
            firdes.WIN_BLACKMAN_hARRIS,  #wintype
            0,  #fc
            samp_rate,  #bw
            'Rx Spectrum',  #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 = ['Rx Spectrum', '', '', '', '', '', '', '', '', '']
        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)
        self.mapper_prbs_source_b_0 = mapper.prbs_source_b(
            "PRBS31", packet_len)
        self.mapper_prbs_sink_b_0 = mapper.prbs_sink_b("PRBS31", packet_len)
        self.digital_ofdm_tx_0 = digital.ofdm_tx(
            fft_len=fft_len,
            cp_len=fft_len / 4,
            packet_length_tag_key=packet_length_tag_key,
            occupied_carriers=occupied_carriers,
            pilot_carriers=pilot_carriers,
            pilot_symbols=pilot_symbols,
            sync_word1=sync_word1,
            sync_word2=sync_word2,
            bps_header=1,
            bps_payload=2,
            rolloff=0,
            debug_log=True,
            scramble_bits=False)
        self.digital_ofdm_rx_0 = digital.ofdm_rx(
            fft_len=fft_len,
            cp_len=fft_len / 4,
            frame_length_tag_key='frame_' + "length",
            packet_length_tag_key="length",
            occupied_carriers=occupied_carriers,
            pilot_carriers=pilot_carriers,
            pilot_symbols=pilot_symbols,
            sync_word1=sync_word1,
            sync_word2=sync_word2,
            bps_header=1,
            bps_payload=2,
            debug_log=False,
            scramble_bits=False)
        self.channels_channel_model_0 = channels.channel_model(
            noise_voltage=0.1,
            frequency_offset=cfo,
            epsilon=1.0 + sro,
            taps=(1.0, ),
            noise_seed=0,
            block_tags=True)
        self.blocks_uchar_to_float_0 = blocks.uchar_to_float()
        self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                   samp_rate, True)
        self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(
            gr.sizeof_char, 1, packet_len, packet_length_tag_key)
        self._SNR_tool_bar = Qt.QToolBar(self)
        self._SNR_tool_bar.addWidget(Qt.QLabel('SNR' + ": "))
        self._SNR_line_edit = Qt.QLineEdit(str(self.SNR))
        self._SNR_tool_bar.addWidget(self._SNR_line_edit)
        self._SNR_line_edit.returnPressed.connect(lambda: self.set_SNR(
            eng_notation.str_to_num(str(self._SNR_line_edit.text().toAscii())))
                                                  )
        self.top_grid_layout.addWidget(self._SNR_tool_bar)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_stream_to_tagged_stream_0, 0),
                     (self.digital_ofdm_tx_0, 0))
        self.connect((self.blocks_throttle_0_0, 0),
                     (self.channels_channel_model_0, 0))
        self.connect((self.blocks_uchar_to_float_0, 0),
                     (self.qtgui_time_sink_x_0, 0))
        self.connect((self.channels_channel_model_0, 0),
                     (self.digital_ofdm_rx_0, 0))
        self.connect((self.channels_channel_model_0, 0),
                     (self.qtgui_freq_sink_x_0, 0))
        self.connect((self.digital_ofdm_rx_0, 0),
                     (self.blocks_uchar_to_float_0, 0))
        self.connect((self.digital_ofdm_rx_0, 0),
                     (self.mapper_prbs_sink_b_0, 0))
        self.connect((self.digital_ofdm_tx_0, 0),
                     (self.blocks_throttle_0_0, 0))
        self.connect((self.digital_ofdm_tx_0, 0),
                     (self.qtgui_freq_sink_x_0_0, 0))
        self.connect((self.mapper_prbs_source_b_0, 0),
                     (self.blocks_stream_to_tagged_stream_0, 0))
Beispiel #8
0
    def __init__(self):
        gr.top_block.__init__(self, "Sync Test")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Sync Test")
        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", "sync_test")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())

        ##################################################
        # Variables
        ##################################################
        self.pream_len = pream_len = 84
        self.samp_rate = samp_rate = 32000
        self.pream = pream = (mapper.preamble_generator(pream_len, 511,
                                                        1033)).get_preamble()
        self.SNR = SNR = 40
        self.Rotation = Rotation = 0
        self.Offset = Offset = 0

        ##################################################
        # Blocks
        ##################################################
        self._SNR_tool_bar = Qt.QToolBar(self)
        self._SNR_tool_bar.addWidget(Qt.QLabel("SNR" + ": "))
        self._SNR_line_edit = Qt.QLineEdit(str(self.SNR))
        self._SNR_tool_bar.addWidget(self._SNR_line_edit)
        self._SNR_line_edit.returnPressed.connect(lambda: self.set_SNR(
            eng_notation.str_to_num(self._SNR_line_edit.text().toAscii())))
        self.top_layout.addWidget(self._SNR_tool_bar)
        self._Rotation_layout = Qt.QVBoxLayout()
        self._Rotation_label = Qt.QLabel("Rotation")
        self._Rotation_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal,
                                              Qwt.QwtSlider.BottomScale,
                                              Qwt.QwtSlider.BgSlot)
        self._Rotation_slider.setRange(0, 2 * pi, pi / 100)
        self._Rotation_slider.setValue(self.Rotation)
        self._Rotation_slider.setMinimumWidth(200)
        self._Rotation_slider.valueChanged.connect(self.set_Rotation)
        self._Rotation_label.setAlignment(Qt.Qt.AlignBottom
                                          | Qt.Qt.AlignHCenter)
        self._Rotation_layout.addWidget(self._Rotation_label)
        self._Rotation_layout.addWidget(self._Rotation_slider)
        self.top_layout.addLayout(self._Rotation_layout)
        self._Offset_layout = Qt.QVBoxLayout()
        self._Offset_tool_bar = Qt.QToolBar(self)
        self._Offset_layout.addWidget(self._Offset_tool_bar)
        self._Offset_tool_bar.addWidget(Qt.QLabel("Offset" + ": "))
        self._Offset_counter = Qwt.QwtCounter()
        self._Offset_counter.setRange(-100, 100, 1)
        self._Offset_counter.setNumButtons(2)
        self._Offset_counter.setValue(self.Offset)
        self._Offset_tool_bar.addWidget(self._Offset_counter)
        self._Offset_counter.valueChanged.connect(self.set_Offset)
        self._Offset_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal,
                                            Qwt.QwtSlider.BottomScale,
                                            Qwt.QwtSlider.BgSlot)
        self._Offset_slider.setRange(-100, 100, 1)
        self._Offset_slider.setValue(self.Offset)
        self._Offset_slider.setMinimumWidth(200)
        self._Offset_slider.valueChanged.connect(self.set_Offset)
        self._Offset_layout.addWidget(self._Offset_slider)
        self.top_layout.addLayout(self._Offset_layout)
        self.qtgui_const_sink_x_0_1 = qtgui.const_sink_c(
            840 - 84,  #size
            "QT GUI Plot",  #name
            1  #number of inputs
        )
        self.qtgui_const_sink_x_0_1.set_update_time(0.10)
        self.qtgui_const_sink_x_0_1.set_y_axis(-2, 2)
        self.qtgui_const_sink_x_0_1.set_x_axis(-2, 2)
        self._qtgui_const_sink_x_0_1_win = sip.wrapinstance(
            self.qtgui_const_sink_x_0_1.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_const_sink_x_0_1_win)
        self.qtgui_const_sink_x_0 = qtgui.const_sink_c(
            840 - 84,  #size
            "QT GUI Plot",  #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_win = sip.wrapinstance(
            self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_layout.addWidget(self._qtgui_const_sink_x_0_win)
        self.mapper_preamble_sync_cc_0 = mapper.preamble_sync_cc(
            pream_len * 10, (pream), mapper.PSK8, ([0, 1, 2, 3, 4, 5, 6, 7]),
            .97, .90)
        self.mapper_preamble_insert_bb_0 = mapper.preamble_insert_bb(
            pream_len * 10, (pream))
        self.mapper_mapper_0 = mapper.mapper(mapper.PSK8,
                                             ([0, 1, 2, 3, 4, 5, 6, 7]))
        self.mapper_demapper_0 = mapper.demapper(mapper.PSK8,
                                                 ([0, 1, 2, 3, 4, 5, 6, 7]))
        self.digital_costas_loop_cc_0 = digital.costas_loop_cc(
            1.5 * pi / 100, 8)
        self.channels_channel_model_0 = channels.channel_model(
            noise_voltage=10**(-SNR / 20.0),
            frequency_offset=Offset,
            epsilon=1.0,
            taps=(exp((0 + 1j * Rotation)), ),
            noise_seed=0,
            block_tags=False)
        self.blocks_vector_sink_x_0_0 = blocks.vector_sink_b(1)
        self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(3)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_char * 1, samp_rate)
        self.analog_random_source_x_0 = blocks.vector_source_b(
            map(int, numpy.random.randint(0, 7, 10000)), True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.mapper_preamble_insert_bb_0, 0),
                     (self.mapper_mapper_0, 0))
        self.connect((self.mapper_preamble_sync_cc_0, 0),
                     (self.mapper_demapper_0, 0))
        self.connect((self.mapper_mapper_0, 0),
                     (self.channels_channel_model_0, 0))
        self.connect((self.channels_channel_model_0, 0),
                     (self.digital_costas_loop_cc_0, 0))
        self.connect((self.digital_costas_loop_cc_0, 0),
                     (self.mapper_preamble_sync_cc_0, 0))
        self.connect((self.mapper_preamble_sync_cc_0, 0),
                     (self.qtgui_const_sink_x_0_1, 0))
        self.connect((self.analog_random_source_x_0, 0),
                     (self.blocks_unpack_k_bits_bb_0, 0))
        self.connect((self.blocks_unpack_k_bits_bb_0, 0),
                     (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.mapper_preamble_insert_bb_0, 0))
        self.connect((self.mapper_demapper_0, 0),
                     (self.blocks_vector_sink_x_0_0, 0))
        self.connect((self.channels_channel_model_0, 0),
                     (self.qtgui_const_sink_x_0, 0))
Beispiel #9
0
 def set_pream_len(self, pream_len):
     self.pream_len = pream_len
     self.set_pream((mapper.preamble_generator(self.pream_len, 511,
                                               1033)).get_preamble())
     self.mapper_preamble_insert_bb_0.mapper.set_width(self.pream_len * 10)