def __init__(self, constellation=[-1, 1]):
        gr.top_block.__init__(self, "Channel Model Gui")

        ##################################################
        # Parameters
        ##################################################
        self.constellation = constellation

        ##################################################
        # Variables
        ##################################################
        self.const_points = const_points = constellation
        self.taps = taps = [1.0, 0.25-0.25j, 0.50 + 0.10j, 0.3 + 0.2j]
        self.samp_rate = samp_rate = 8e6
        self.noise_level = noise_level = 0.3
        self.frequency = frequency = 2000000
        self.const_type = const_type = 1
        self.const_dist = const_dist = digital.constellation_calcdist(const_points,[],0,1)
        self.const = const = digital.constellation_qpsk()

        ##################################################
        # Blocks
        ##################################################
        self.digital_constellation_decoder_cb_0_0 = digital.constellation_decoder_cb(const_dist.base())
        self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(const_dist.base())
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc((const_dist.points()), 1)
        self.custom_ber_0 = custom_ber(
            n_bits=10000,
            bits_per_symbol=3,
        )
        self.channels_channel_model_0_0 = channels.channel_model(
        	noise_voltage=0,
        	frequency_offset=0,
        	epsilon=1,
        	taps=([1,0,0,0]),
        	noise_seed=0,
        	block_tags=False
        )
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage=noise_level,
        	frequency_offset=0,
        	epsilon=1,
        	taps=(taps),
        	noise_seed=0,
        	block_tags=False
        )
        self.blocks_vector_sink_x_1 = blocks.vector_sink_f(1)
        self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, len(const_points), 10000)), False)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.custom_ber_0, 0), (self.blocks_vector_sink_x_1, 0))
        self.connect((self.channels_channel_model_0, 0), (self.digital_constellation_decoder_cb_0, 0))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.channels_channel_model_0, 0))
        self.connect((self.analog_random_source_x_0, 0), (self.digital_chunks_to_symbols_xx_0, 0))
        self.connect((self.digital_constellation_decoder_cb_0_0, 0), (self.custom_ber_0, 0))
        self.connect((self.digital_constellation_decoder_cb_0, 0), (self.custom_ber_0, 1))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.channels_channel_model_0_0, 0))
        self.connect((self.channels_channel_model_0_0, 0), (self.digital_constellation_decoder_cb_0_0, 0))
    def test_000(self):
        N = 1000  # number of samples to use
        fs = 1000  # baseband sampling rate
        freq = 100

        signal = analog.sig_source_c(fs, analog.GR_SIN_WAVE, freq, 1)
        head = blocks.head(gr.sizeof_gr_complex, N)
        op = channels.channel_model(0.0, 0.0, 1.0, [
            1,
        ], 0)
        snk = blocks.vector_sink_c()
        snk1 = blocks.vector_sink_c()

        op.set_noise_voltage(0.0)
        op.set_frequency_offset(0.0)
        op.set_taps([
            1,
        ])
        op.set_timing_offset(1.0)

        self.tb.connect(signal, head, op, snk)
        self.tb.connect(op, snk1)
        self.tb.run()

        dst_data = snk.data()
        exp_data = snk1.data()
        self.assertComplexTuplesAlmostEqual(exp_data, dst_data, 5)
Esempio n. 3
0
    def __init__(self, N, sps, rolloff, ntaps, bw, noise, foffset, toffset, poffset):
        gr.top_block.__init__(self)

        rrc_taps = filter.firdes.root_raised_cosine(
            sps, sps, 1.0, rolloff, ntaps)

        data = 2.0*scipy.random.randint(0, 2, N) - 1.0
        data = scipy.exp(1j*poffset) * data

        self.src = blocks.vector_source_c(data.tolist(), False)
        self.rrc = filter.interp_fir_filter_ccf(sps, rrc_taps)
        self.chn = channels.channel_model(noise, foffset, toffset)
        self.fll = digital.fll_band_edge_cc(sps, rolloff, ntaps, bw)

        self.vsnk_src = blocks.vector_sink_c()
        self.vsnk_fll = blocks.vector_sink_c()
        self.vsnk_frq = blocks.vector_sink_f()
        self.vsnk_phs = blocks.vector_sink_f()
        self.vsnk_err = blocks.vector_sink_f()

        self.connect(self.src, self.rrc, self.chn, self.fll, self.vsnk_fll)
        self.connect(self.rrc, self.vsnk_src)
        self.connect((self.fll,1), self.vsnk_frq)
        self.connect((self.fll,2), self.vsnk_phs)
        self.connect((self.fll,3), self.vsnk_err)
 def test_004_ofdm_packets (self):
     """
     Send several bursts using ofdm_tx, see if the number of detects is correct.
     Burst lengths and content are random.
     """
     n_bursts = 42
     fft_len = 64
     cp_len = 16
     # Here, coarse freq offset is allowed
     max_freq_offset = 2*numpy.pi/fft_len * 4
     freq_offset = ((2 * random.random()) - 1) * max_freq_offset
     tx_signal = []
     packets = []
     tagname = "packet_length"
     min_packet_length = 10
     max_packet_length = 50
     sync_sequence = [random.randint(0, 1)*2-1 for x in range(fft_len/2)]
     for i in xrange(n_bursts):
         packet_length = random.randint(min_packet_length,
                                        max_packet_length+1)
         packet = [random.randint(0, 255) for i in range(packet_length)]
         packets.append(packet)
     data, tags = tagged_streams.packets_to_vectors(packets, tagname, vlen=1)
     total_length = len(data)
     src = blocks.vector_source_b(data, False, 1, tags)
     mod = ofdm_tx(packet_length_tag_key=tagname)
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
     sink_freq   = blocks.vector_sink_f()
     sink_detect = blocks.vector_sink_b()
     noise_level = 0.005
     channel = channels.channel_model(noise_level, freq_offset / 2 / numpy.pi)
     self.tb.connect(src, mod, channel, sync, sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     self.assertEqual(numpy.sum(sink_detect.data()), n_bursts)
    def __init__(self, ifile, ofile, options):
        gr.top_block.__init__(self)

        SNR = 10.0**(options.snr / 10.0)
        time_offset = options.time_offset
        phase_offset = options.phase_offset*(math.pi / 180.0)

        # calculate noise voltage from SNR
        power_in_signal = abs(options.tx_amplitude)**2
        noise_power = power_in_signal / SNR
        noise_voltage = math.sqrt(noise_power)
        print("Noise voltage: ", noise_voltage)

        frequency_offset = options.frequency_offset / options.fft_length

        self.src = blocks.file_source(gr.sizeof_gr_complex, ifile)
        #self.throttle = blocks.throttle(gr.sizeof_gr_complex, options.sample_rate)

        self.channel = channels.channel_model(noise_voltage, frequency_offset,
                                        time_offset, noise_seed=-random.randint(0,100000))
        self.phase = blocks.multiply_const_cc(complex(math.cos(phase_offset),
                                                  math.sin(phase_offset)))
        self.snk = blocks.file_sink(gr.sizeof_gr_complex, ofile)

        self.connect(self.src, self.channel, self.phase, self.snk)
    def __init__(self, ifile, ofile, options):
        gr.top_block.__init__(self)

        SNR = 10.0**(options.snr/10.0)
        time_offset = options.time_offset
        phase_offset = options.phase_offset*(math.pi/180.0)

        # calculate noise voltage from SNR
        power_in_signal = abs(options.tx_amplitude)**2
        noise_power = power_in_signal/SNR
        noise_voltage = math.sqrt(noise_power)
        print "Noise voltage: ", noise_voltage

        frequency_offset = options.frequency_offset / options.fft_length

        self.src = blocks.file_source(gr.sizeof_gr_complex, ifile)
        #self.throttle = blocks.throttle(gr.sizeof_gr_complex, options.sample_rate)

        self.channel = channels.channel_model(noise_voltage, frequency_offset,
                                        time_offset, noise_seed=-random.randint(0,100000))
        self.phase = blocks.multiply_const_cc(complex(math.cos(phase_offset),
                                                  math.sin(phase_offset)))
        self.snk = blocks.file_sink(gr.sizeof_gr_complex, ofile)

        self.connect(self.src, self.channel, self.phase, self.snk)
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 1000
        f2 = 2000

        npts = 2048

        self.qapp = QtGui.QApplication(sys.argv)

        self.filt_taps = [
            1,
        ]

        src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0)
        src = blocks.add_cc()
        channel = channels.channel_model(0.01)
        self.filt = filter.fft_filter_ccc(1, self.filt_taps)
        thr = blocks.throttle(gr.sizeof_gr_complex, 100 * npts)
        self.snk1 = qtgui.freq_sink_c(npts, filter.firdes.WIN_BLACKMAN_hARRIS,
                                      0, Rs, "Complex Freq Example", 1)

        self.connect(src1, (src, 0))
        self.connect(src2, (src, 1))
        self.connect(src, channel, thr, self.filt, (self.snk1, 0))

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)
        pyWin.show()
Esempio n. 8
0
    def __init__(self, ebn0, nbits):
        gr.hier_block2.__init__(self, 'BPSK',
            gr.io_signature(1, 1, gr.sizeof_char),
            gr.io_signature(1, 1, gr.sizeof_char))

        samp_rate = 48e3
        sps = 5
        self.head = blocks.head(gr.sizeof_char, nbits)
        self.pack = blocks.pack_k_bits_bb(8)
        self.bpsk_constellation = digital.constellation_bpsk().base()
        self.modulator = digital.generic_mod(
            constellation = self.bpsk_constellation,
            differential = False,
            samples_per_symbol = sps,
            pre_diff_code = True,
            excess_bw = 0.35,
            verbose = False,
            log = False)
        
        spb = sps
        self.channel = channels.channel_model(np.sqrt(spb)/10**(ebn0/20), 0, 1.0, [1], RAND_SEED, False)

        self.demod = bpsk_demodulator(samp_rate/sps, samp_rate, iq = True)
        self.slice = digital.binary_slicer_fb()

        self.connect(self, self.head, self.pack, self.modulator, self.channel,
                         self.demod, self.slice, self)
Esempio n. 9
0
    def __init__(self, ebn0, nbits):
        gr.hier_block2.__init__(self, 'FSK',
            gr.io_signature(1, 1, gr.sizeof_char),
            gr.io_signature(1, 1, gr.sizeof_char))

        samp_rate = 48e3
        sps = 5
        deviation = 5000
        bt = 1.0
        self.head = blocks.head(gr.sizeof_char, nbits)
        self.pack = blocks.pack_k_bits_bb(8)
        self.modulator = digital.gfsk_mod(
            samples_per_symbol = sps,
            sensitivity = 2*np.pi*deviation/samp_rate,
            bt = bt,
            verbose = False,
            log = False)
        
        spb = sps
        self.channel = channels.channel_model(np.sqrt(spb)/10**(ebn0/20), 0, 1.0, [1], RAND_SEED, False)

        self.demod = fsk_demodulator(samp_rate/sps, samp_rate, deviation = deviation, iq = True)
        self.slice = digital.binary_slicer_fb()

        self.connect(self, self.head, self.pack, self.modulator, self.channel,
                         self.demod, self.slice, self)
Esempio n. 10
0
    def test_qpsk_channel(self):
        upper_bound = tuple(50.0 * numpy.ones((self.num_data, )))
        lower_bound = tuple(0.0 * numpy.zeros((self.num_data, )))

        self.cons = cons = digital.constellation_qpsk().base()
        self.data = data = [
            random.randrange(len(cons.points())) for x in range(self.num_data)
        ]
        self.symbols = symbols = numpy.squeeze(
            [cons.map_to_points_v(i) for i in data])

        chan = channels.channel_model(noise_voltage=0.1,
                                      frequency_offset=0.0,
                                      epsilon=1.0,
                                      taps=[1.0 + 0.0j],
                                      noise_seed=0,
                                      block_tags=False)

        evm = digital.meas_evm_cc(cons, digital.evm_measurement_t_EVM_PERCENT)
        vso = blocks.vector_source_c(symbols, False, 1, [])
        mc = blocks.multiply_const_cc(3.0 + 2.0j)
        vsi = blocks.vector_sink_f()

        self.tb.connect(vso, chan, evm, vsi)
        self.tb.run()
        # check data

        output_data = vsi.data()
        self.assertLess(output_data, upper_bound)
        self.assertGreater(output_data, lower_bound)
Esempio n. 11
0
    def __init__(self, freq, rx_callback):
        gr.top_block.__init__(self)

        ##################################################
        # Variables
        ##################################################
        self.freq = freq
        self.samp_rate = 1e6
        self.rxgain = 0
        self.txgain = 0

        ##################################################
        # Blocks
        ##################################################
        self.txpath = transmit_path()
        self.rxpath = receive_path(rx_callback)

        # Perfect channel
        self.channel_model = channels.channel_model(noise_voltage=0.0,
                                                    frequency_offset=0.0,
                                                    epsilon=1.0,
                                                    taps=(1.0 + 1.0j, ),
                                                    noise_seed=0,
                                                    block_tags=False)

        self.throttle = blocks.throttle(gr.sizeof_char * 8, self.samp_rate,
                                        True)

        ##################################################
        # Connections
        ##################################################
        # self.connect(self.txpath, self.channel_model, self.rxpath)
        self.connect(self.txpath, self.throttle, self.channel_model,
                     self.rxpath)
Esempio n. 12
0
    def test_003_multiburst (self):
        """ Send several bursts, see if the number of detects is correct.
        Burst lengths and content are random.
        """
        n_bursts = 42
        fft_len = 32
        cp_len = 4
        tx_signal = []
        for i in xrange(n_bursts):
            sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2
            tx_signal += [0,] * random.randint(0, 2*fft_len) + \
                         sync_symbol[-cp_len:] + \
                         sync_symbol + \
                         [(random.randint(0, 1)*2)-1 for x in range(fft_len * random.randint(5,23))]
        add = blocks.add_cc()
        sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
        sink_freq   = blocks.vector_sink_f()
        sink_detect = blocks.vector_sink_b()
        channel = channels.channel_model(0.005)
        self.tb.connect(blocks.vector_source_c(tx_signal), channel, sync)
        self.tb.connect((sync, 0), sink_freq)
        self.tb.connect((sync, 1), sink_detect)
        self.tb.run()
        n_bursts_detected = numpy.sum(sink_detect.data())
        # We allow for one false alarm or missed burst
        self.assertTrue(abs(n_bursts_detected - n_bursts) <= 1,
                msg="""Because of statistics, it is possible (though unlikely)
that the number of detected bursts differs slightly. If the number of detects is
off by one or two, run the test again and see what happen.
Detection error was: %d """ % (numpy.sum(sink_detect.data()) - n_bursts)
        )
Esempio n. 13
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 100
        f2 = 200

        npts = 2048

        self.qapp = QtGui.QApplication(sys.argv)

        src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.5, 0)
        src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.5, 0)
        src = blocks.add_cc()
        channel = channels.channel_model(0.001)
        thr = blocks.throttle(gr.sizeof_gr_complex, 100 * npts)
        self.snk1 = qtgui.const_sink_c(npts, "Constellation Example", 1)

        self.connect(src1, (src, 0))
        self.connect(src2, (src, 1))
        self.connect(src, channel, thr, (self.snk1, 0))

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
    def __init__(self, N, sps, rolloff, ntaps, bw, noise, foffset, toffset, poffset):
        gr.top_block.__init__(self)

        rrc_taps = filter.firdes.root_raised_cosine(
            sps, sps, 1.0, rolloff, ntaps)

        data = 2.0*scipy.random.randint(0, 2, N) - 1.0
        data = scipy.exp(1j*poffset) * data

        self.src = blocks.vector_source_c(data.tolist(), False)
        self.rrc = filter.interp_fir_filter_ccf(sps, rrc_taps)
        self.chn = channels.channel_model(noise, foffset, toffset)
        self.fll = digital.fll_band_edge_cc(sps, rolloff, ntaps, bw)

        self.vsnk_src = blocks.vector_sink_c()
        self.vsnk_fll = blocks.vector_sink_c()
        self.vsnk_frq = blocks.vector_sink_f()
        self.vsnk_phs = blocks.vector_sink_f()
        self.vsnk_err = blocks.vector_sink_f()

        self.connect(self.src, self.rrc, self.chn, self.fll, self.vsnk_fll)
        self.connect(self.rrc, self.vsnk_src)
        self.connect((self.fll,1), self.vsnk_frq)
        self.connect((self.fll,2), self.vsnk_phs)
        self.connect((self.fll,3), self.vsnk_err)
Esempio n. 15
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 100
        f2 = 200

        npts = 2048

        self.qapp = QtGui.QApplication(sys.argv)

        src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.5, 0)
        src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.5, 0)
        src = blocks.add_cc()
        channel = channels.channel_model(0.001)
        thr = blocks.throttle(gr.sizeof_gr_complex, 100 * npts)
        self.snk1 = qtgui.const_sink_c(npts, "Constellation Example", 1)

        self.connect(src1, (src, 0))
        self.connect(src2, (src, 1))
        self.connect(src, channel, thr, (self.snk1, 0))

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
Esempio n. 16
0
 def test_004_ofdm_packets(self):
     """
     Send several bursts using ofdm_tx, see if the number of detects is correct.
     Burst lengths and content are random.
     """
     n_bursts = 42
     fft_len = 64
     cp_len = 16
     # Here, coarse freq offset is allowed
     max_freq_offset = 2 * numpy.pi / fft_len * 4
     freq_offset = ((2 * random.random()) - 1) * max_freq_offset
     packets = []
     tagname = "packet_length"
     min_packet_length = 10
     max_packet_length = 50
     for _ in range(n_bursts):
         packet_length = random.randint(min_packet_length,
                                        max_packet_length + 1)
         packet = [random.randint(0, 255) for i in range(packet_length)]
         packets.append(packet)
     data, tags = tagged_streams.packets_to_vectors(packets,
                                                    tagname,
                                                    vlen=1)
     src = blocks.vector_source_b(data, False, 1, tags)
     mod = ofdm_tx(packet_length_tag_key=tagname)
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
     sink_freq = blocks.vector_sink_f()
     sink_detect = blocks.vector_sink_b()
     noise_level = 0.005
     channel = channels.channel_model(noise_level,
                                      freq_offset / 2 / numpy.pi)
     self.tb.connect(src, mod, channel, sync, sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     self.assertEqual(numpy.sum(sink_detect.data()), n_bursts)
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 1000
        f2 = 2000

        npts = 2048

        self.qapp = QtGui.QApplication(sys.argv)

        self.filt_taps = [1,]
        
        src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0)
        src  = blocks.add_cc()
        channel = channels.channel_model(0.01)
        self.filt = filter.fft_filter_ccc(1, self.filt_taps)
        thr = blocks.throttle(gr.sizeof_gr_complex, 100*npts)
        self.snk1 = qtgui.freq_sink_c(npts, filter.firdes.WIN_BLACKMAN_hARRIS,
                                      0, Rs,
                                      "Complex Freq Example", 1)

        self.connect(src1, (src,0))
        self.connect(src2, (src,1))
        self.connect(src,  channel, thr, self.filt, (self.snk1, 0))

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt  = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)
        pyWin.show()
Esempio n. 18
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 100
        f2 = 200

        npts = 2048

        self.qapp = QtWidgets.QApplication(sys.argv)
        ss = open(gr.prefix() + '/share/gnuradio/themes/dark.qss')
        sstext = ss.read()
        ss.close()
        self.qapp.setStyleSheet(sstext)

        src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0)
        src  = blocks.add_cc()
        channel = channels.channel_model(0.01)
        thr = blocks.throttle(gr.sizeof_gr_complex, 100*npts)
        self.snk1 = qtgui.time_sink_c(npts, Rs,
                                      "Complex Time Example", 1)

        self.connect(src1, (src,0))
        self.connect(src2, (src,1))
        self.connect(src,  channel, thr, (self.snk1, 0))
        #self.connect(src1, (self.snk1, 1))
        #self.connect(src2, (self.snk1, 2))

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt  = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt5.QtWidgets.QWidget
        pyWin = sip.wrapinstance(pyQt, QtWidgets.QWidget)

        # Example of using signal/slot to set the title of a curve
        # FIXME: update for Qt5
        #pyWin.setLineLabel.connect(pyWin.setLineLabel)
        #pyWin.emit(QtCore.SIGNAL("setLineLabel(int, QString)"), 0, "Re{sum}")
        self.snk1.set_line_label(0, "Re{Sum}")
        self.snk1.set_line_label(1, "Im{Sum}")
        #self.snk1.set_line_label(2, "Re{src1}")
        #self.snk1.set_line_label(3, "Im{src1}")
        #self.snk1.set_line_label(4, "Re{src2}")
        #self.snk1.set_line_label(5, "Im{src2}")

        # Can also set the color of a curve
        #self.snk1.set_color(5, "blue")

        self.snk1.set_update_time(0.5)

        #pyWin.show()
        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
Esempio n. 19
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 100
        f2 = 200

        npts = 2048

        self.qapp = QtWidgets.QApplication(sys.argv)
        ss = open(gr.prefix() + '/share/gnuradio/themes/dark.qss')
        sstext = ss.read()
        ss.close()
        self.qapp.setStyleSheet(sstext)

        src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0)
        src = blocks.add_cc()
        channel = channels.channel_model(0.01)
        thr = blocks.throttle(gr.sizeof_gr_complex, 100 * npts)
        self.snk1 = qtgui.time_sink_c(npts, Rs, "Complex Time Example", 1,
                                      None)

        self.connect(src1, (src, 0))
        self.connect(src2, (src, 1))
        self.connect(src, channel, thr, (self.snk1, 0))
        #self.connect(src1, (self.snk1, 1))
        #self.connect(src2, (self.snk1, 2))

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt = self.snk1.qwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt5.QtWidgets.QWidget
        pyWin = sip.wrapinstance(pyQt, QtWidgets.QWidget)

        # Example of using signal/slot to set the title of a curve
        # FIXME: update for Qt5
        # pyWin.setLineLabel.connect(pyWin.setLineLabel)
        #pyWin.emit(QtCore.SIGNAL("setLineLabel(int, QString)"), 0, "Re{sum}")
        self.snk1.set_line_label(0, "Re{Sum}")
        self.snk1.set_line_label(1, "Im{Sum}")
        #self.snk1.set_line_label(2, "Re{src1}")
        #self.snk1.set_line_label(3, "Im{src1}")
        #self.snk1.set_line_label(4, "Re{src2}")
        #self.snk1.set_line_label(5, "Im{src2}")

        # Can also set the color of a curve
        #self.snk1.set_color(5, "blue")

        self.snk1.set_update_time(0.5)

        # pyWin.show()
        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
Esempio n. 20
0
def processInput1tx(file_num, snr):
    freq = numpy.random.permutation([0, -2.5e6, 2.5e6])
    source_A = blocks.vector_source_b(
        map(int, numpy.random.randint(0, 255, 1000000)), True)

    throttle_A = blocks.throttle(gr.sizeof_char * 1, samp_rate_base, True)

    constellation_modulator_A = digital.generic_mod(
        constellation=constellation_variable,
        differential=False,
        samples_per_symbol=sps,
        pre_diff_code=True,
        excess_bw=0.35,
        verbose=False,
        log=False,
    )

    sig_source_A = analog.sig_source_c(upsamp_rate, analog.GR_COS_WAVE,
                                       freq[0],
                                       (10**(snr / 20)) * noise_amplitude, 0)

    resampler_A = filter.rational_resampler_ccc(10,
                                                2,
                                                taps=None,
                                                fractional_bw=None)

    multiply_A = blocks.multiply_vcc(1)

    channel_A = channels.fading_model(12, 0, False, 4.0, 0)

    add_block = blocks.add_vcc(1)

    channel = channels.channel_model(noise_voltage=noise_amplitude,
                                     frequency_offset=0.0,
                                     epsilon=1.0,
                                     taps=(1 + 1j, ),
                                     noise_seed=0,
                                     block_tags=False)

    skip_head = blocks.skiphead(gr.sizeof_gr_complex * 1, 1024)
    head_block = blocks.head(gr.sizeof_gr_complex * 1, 1000000)
    file_sink = blocks.file_sink(
        gr.sizeof_gr_complex * 1,
        'data_1tx_' + str(snr) + 'dB_' + str(file_num) + '.dat', False)

    tb = gr.top_block()

    tb.connect(source_A, throttle_A, constellation_modulator_A, resampler_A,
               (multiply_A, 0))
    tb.connect(sig_source_A, (multiply_A, 1))
    tb.connect(multiply_A, channel_A)

    tb.connect(channel_A, channel)

    tb.connect(channel, skip_head)
    tb.connect(skip_head, head_block)
    tb.connect(head_block, file_sink)

    tb.run()
Esempio n. 21
0
 def test_002_rx_only_noise(self):
     """ Run the RX with only noise, check it doesn't crash
     or return a burst. """
     len_tag_key = 'frame_len'
     samples = (0,) * 1000
     channel = channels.channel_model(0.1)
     rx_fg = ofdm_rx_fg(samples, len_tag_key, channel)
     rx_fg.run()
     self.assertEqual(len(rx_fg.get_rx_bytes()), 0)
Esempio n. 22
0
 def test_002_rx_only_noise(self):
     """ Run the RX with only noise, check it doesn't crash
     or return a burst. """
     len_tag_key = 'frame_len'
     samples = (0, ) * 1000
     channel = channels.channel_model(0.1)
     rx_fg = ofdm_rx_fg(samples, len_tag_key, channel)
     rx_fg.run()
     self.assertEqual(len(rx_fg.get_rx_bytes()), 0)
Esempio n. 23
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")

        if StrictVersion(Qt.qVersion()) < StrictVersion("5.0.0"):
            self.restoreGeometry(self.settings.value("geometry").toByteArray())
        else:
            self.restoreGeometry(
                self.settings.value("geometry", type=QtCore.QByteArray))

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000

        ##################################################
        # Blocks
        ##################################################
        self.channels_channel_model_0 = channels.channel_model(
            noise_voltage=0.1,
            frequency_offset=0.01,
            epsilon=1.0,
            taps=([0.3j, 0.001, 0.0002J]),
            noise_seed=1,
            block_tags=False)
        self.source_0 = source.blk()  #data source
        self.tx_0 = transmitter()  #block to create the OFDM symbols
        self.rx_0 = receiver(
        )  #block to handle and demodulate the received signal
        #self.throttler = blocks.throttle(gr.sizeof_char*1, 5000000,False)
        self.connect((self.source_0, 0), (self.tx_0, 0))
        #self.connect((self.tx_0,0),(self.blocks_tag_gate_0,0), (self.pluto_transmitter,0))
        self.connect((self.tx_0, 0), (self.channels_channel_model_0, 0))
        self.connect((self.channels_channel_model_0, 0),
                     blocks.file_sink(gr.sizeof_gr_complex,
                                      "data/received.dat"))
        self.connect((self.channels_channel_model_0, 0), (self.rx_0, 0),
                     blocks.file_sink(gr.sizeof_char, "data/bits.dat"))
    def __init__(self, chan_est=1, encoding=0, freq_offset=0, interval=500, nmessages=50, snr=10):
        gr.top_block.__init__(self, "Wifi Loopback Nogui")

        ##################################################
        # Parameters
        ##################################################
        self.chan_est = chan_est
        self.encoding = encoding
        self.freq_offset = freq_offset
        self.interval = interval
        self.nmessages = nmessages
        self.snr = snr

        ##################################################
        # Variables
        ##################################################
        self.out_buf_size = out_buf_size = 96000

        ##################################################
        # Blocks
        ##################################################
        self.wifi_phy_hier_0 = wifi_phy_hier(
            encoding=encoding,
            chan_est=chan_est,
        )
        self.ieee802_11_ofdm_mac_0 = ieee802_11.ofdm_mac(([0x23, 0x23, 0x23, 0x23, 0x23, 0x23]), ([0x42, 0x42, 0x42, 0x42, 0x42, 0x42]), ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff]))
        self.foo_wireshark_connector_0 = foo.wireshark_connector(127, False)
        self.foo_periodic_msg_source_0 = foo.periodic_msg_source(pmt.intern("Hello World!"), interval, nmessages, True, False)
        self.foo_packet_pad2_0 = foo.packet_pad2(False, False, 0.001, 1000, 1000)
        (self.foo_packet_pad2_0).set_min_output_buffer(96000)
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage=.5**.5,
        	frequency_offset=freq_offset,
        	epsilon=1.0,
        	taps=(1.0, ),
        	noise_seed=0,
        	block_tags=False
        )
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*1)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc(((10**(snr/10.0))**.5, ))
        self.blocks_file_sink_0_0 = blocks.file_sink(gr.sizeof_char*1, "/tmp/ofdm_n" + str(nmessages) + "_s" + str(snr) + "_e" + str(encoding) + "_i" + str(interval) + ".pcap", False)
        self.blocks_file_sink_0_0.set_unbuffered(True)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.foo_periodic_msg_source_0, 'out'), (self.foo_wireshark_connector_0, 'in'))    
        self.msg_connect((self.foo_periodic_msg_source_0, 'out'), (self.ieee802_11_ofdm_mac_0, 'app in'))    
        self.msg_connect((self.ieee802_11_ofdm_mac_0, 'phy out'), (self.wifi_phy_hier_0, 'mac_in'))    
        self.msg_connect((self.wifi_phy_hier_0, 'mac_out'), (self.foo_wireshark_connector_0, 'in'))    
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.channels_channel_model_0, 0))    
        self.connect((self.channels_channel_model_0, 0), (self.wifi_phy_hier_0, 0))    
        self.connect((self.foo_packet_pad2_0, 0), (self.blocks_multiply_const_vxx_0, 0))    
        self.connect((self.foo_wireshark_connector_0, 0), (self.blocks_file_sink_0_0, 0))    
        self.connect((self.wifi_phy_hier_0, 1), (self.blocks_null_sink_0, 0))    
        self.connect((self.wifi_phy_hier_0, 0), (self.foo_packet_pad2_0, 0))    
Esempio n. 25
0
    def __init__(self):
        gr.top_block.__init__(self)

        self._nsamples = 1000000
        self._audio_rate = 8000

        # Set up N channels with their own baseband and IF frequencies
        self._N = 5
        chspacing = 16000
        freq = [10, 20, 30, 40, 50]
        f_lo = [0, 1*chspacing, -1*chspacing, 2*chspacing, -2*chspacing]

        self._if_rate = 4*self._N*self._audio_rate

        # Create a signal source and frequency modulate it
        self.sum = blocks.add_cc()
        for n in range(self._N):
            sig = analog.sig_source_f(self._audio_rate, analog.GR_SIN_WAVE, freq[n], 0.5)
            fm = fmtx(f_lo[n], self._audio_rate, self._if_rate)
            self.connect(sig, fm)
            self.connect(fm, (self.sum, n))

        self.head = blocks.head(gr.sizeof_gr_complex, self._nsamples)
        self.snk_tx = blocks.vector_sink_c()
        self.channel = channels.channel_model(0.1)

        self.connect(self.sum, self.head, self.channel, self.snk_tx)


        # Design the channlizer
        self._M = 10
        bw = chspacing / 2.0
        t_bw = chspacing / 10.0
        self._chan_rate = self._if_rate / self._M
        self._taps = filter.firdes.low_pass_2(1, self._if_rate, bw, t_bw,
                                              attenuation_dB=100,
                                              window=filter.firdes.WIN_BLACKMAN_hARRIS)
        tpc = math.ceil(float(len(self._taps)) / float(self._M))

        print("Number of taps:     ", len(self._taps))
        print("Number of channels: ", self._M)
        print("Taps per channel:   ", tpc)

        self.pfb = filter.pfb.channelizer_ccf(self._M, self._taps)

        self.connect(self.channel, self.pfb)

        # Create a file sink for each of M output channels of the filter and connect it
        self.fmdet = list()
        self.squelch = list()
        self.snks = list()
        for i in range(self._M):
            self.fmdet.append(analog.nbfm_rx(self._audio_rate, self._chan_rate))
            self.squelch.append(analog.standard_squelch(self._audio_rate*10))
            self.snks.append(blocks.vector_sink_f())
            self.connect((self.pfb, i), self.fmdet[i], self.squelch[i], self.snks[i])
Esempio n. 26
0
    def __init__(self):
        gr.top_block.__init__(self)

        self._nsamples = 1000000
        self._audio_rate = 8000

        # Set up N channels with their own baseband and IF frequencies
        self._N = 5
        chspacing = 16000
        freq = [10, 20, 30, 40, 50]
        f_lo = [0, 1*chspacing, -1*chspacing, 2*chspacing, -2*chspacing]

        self._if_rate = 4*self._N*self._audio_rate

        # Create a signal source and frequency modulate it
        self.sum = blocks.add_cc()
        for n in xrange(self._N):
            sig = analog.sig_source_f(self._audio_rate, analog.GR_SIN_WAVE, freq[n], 0.5)
            fm = fmtx(f_lo[n], self._audio_rate, self._if_rate)
            self.connect(sig, fm)
            self.connect(fm, (self.sum, n))

        self.head = blocks.head(gr.sizeof_gr_complex, self._nsamples)
        self.snk_tx = blocks.vector_sink_c()
        self.channel = channels.channel_model(0.1)

        self.connect(self.sum, self.head, self.channel, self.snk_tx)


        # Design the channlizer
        self._M = 10
        bw = chspacing/2.0
        t_bw = chspacing/10.0
        self._chan_rate = self._if_rate / self._M
        self._taps = filter.firdes.low_pass_2(1, self._if_rate, bw, t_bw,
                                              attenuation_dB=100,
                                              window=filter.firdes.WIN_BLACKMAN_hARRIS)
        tpc = math.ceil(float(len(self._taps)) /  float(self._M))

        print "Number of taps:     ", len(self._taps)
        print "Number of channels: ", self._M
        print "Taps per channel:   ", tpc

        self.pfb = filter.pfb.channelizer_ccf(self._M, self._taps)

        self.connect(self.channel, self.pfb)

        # Create a file sink for each of M output channels of the filter and connect it
        self.fmdet = list()
        self.squelch = list()
        self.snks = list()
        for i in xrange(self._M):
            self.fmdet.append(analog.nbfm_rx(self._audio_rate, self._chan_rate))
            self.squelch.append(analog.standard_squelch(self._audio_rate*10))
            self.snks.append(blocks.vector_sink_f())
            self.connect((self.pfb, i), self.fmdet[i], self.squelch[i], self.snks[i])
Esempio n. 27
0
    def __init__(self, N, sps, rolloff, ntaps, bw, noise,
                 foffset, toffset, poffset, mode=0):
        gr.top_block.__init__(self)

        rrc_taps = filter.firdes.root_raised_cosine(
            sps, sps, 1.0, rolloff, ntaps)

        gain = bw
        nfilts = 32
        rrc_taps_rx = filter.firdes.root_raised_cosine(
            nfilts, sps*nfilts, 1.0, rolloff, ntaps*nfilts)

        data = 2.0*scipy.random.randint(0, 2, N) - 1.0
        data = scipy.exp(1j*poffset) * data

        self.src = blocks.vector_source_c(data.tolist(), False)
        self.rrc = filter.interp_fir_filter_ccf(sps, rrc_taps)
        self.chn = channels.channel_model(noise, foffset, toffset)
        self.off = filter.fractional_resampler_cc(0.20, 1.0)

        if mode == 0:
            self.clk = digital.pfb_clock_sync_ccf(sps, gain, rrc_taps_rx,
                                                  nfilts, nfilts//2, 1)
            self.taps = self.clk.taps()
            self.dtaps = self.clk.diff_taps()

            self.delay = int(scipy.ceil(((len(rrc_taps)-1)/2 +
                                         (len(self.taps[0])-1)/2)/float(sps))) + 1


            self.vsnk_err = blocks.vector_sink_f()
            self.vsnk_rat = blocks.vector_sink_f()
            self.vsnk_phs = blocks.vector_sink_f()

            self.connect((self.clk,1), self.vsnk_err)
            self.connect((self.clk,2), self.vsnk_rat)
            self.connect((self.clk,3), self.vsnk_phs)

        else: # mode == 1
            mu = 0.5
            gain_mu = bw
            gain_omega = 0.25*gain_mu*gain_mu
            omega_rel_lim = 0.02
            self.clk = digital.clock_recovery_mm_cc(sps, gain_omega,
                                                    mu, gain_mu,
                                                    omega_rel_lim)

            self.vsnk_err = blocks.vector_sink_f()

            self.connect((self.clk,1), self.vsnk_err)

        self.vsnk_src = blocks.vector_sink_c()
        self.vsnk_clk = blocks.vector_sink_c()

        self.connect(self.src, self.rrc, self.chn, self.off, self.clk, self.vsnk_clk)
        self.connect(self.src, self.vsnk_src)
Esempio n. 28
0
    def __init__(self, snr_db_ae = 15, signal_len = 1024, samp_rate = 100000, samples = 1000, const_index = 3):
        gr.top_block.__init__(self, "Eve Sim")

        ##################################################
        # Variables
        ##################################################

        self.const_qpsk = const_qpsk = digital.constellation_qpsk().base()
        self.const_bpsk = const_bpsk = digital.constellation_bpsk().base()
        self.const_8psk = const_8psk = digital.constellation_8psk().base()
        self.const_16qam = const_16qam = digital.constellation_16qam().base()

        self.snr_db_ae = snr_db_ae # = 15
        self.signal_len = signal_len # = 1024
        self.samp_rate = samp_rate # = 100000
        self.constellations = constellations = [const_bpsk, const_qpsk, const_8psk, const_16qam]
        self.const_index = const_index

        ##################################################
        # Blocks
        ##################################################
        self.digital_chunks_to_symbols_xx_0 = digital.chunks_to_symbols_bc((constellations[const_index].points()), 1)
        self.classify_trained_model_classifier_vc_0 = classify.trained_model_classifier_vc(64, '/home/gvanhoy/gr-classify/apps/cumulant_classifier.pkl')
        self.channels_channel_model_0_0 = channels.channel_model(
        	noise_voltage=numpy.sqrt(10.0**(-snr_db_ae/10.0)/2),
        	frequency_offset=0.0,
        	epsilon=1.0,
        	taps=(1.0, ),
        	noise_seed=0,
        	block_tags=False
        )
        self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_stream_to_vector_0 = blocks.stream_to_vector(gr.sizeof_gr_complex*1, 64)
        self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(8, int(np.log2(constellations[const_index].arity())), "", False, gr.GR_MSB_FIRST)
        self.blocks_head_1 = blocks.head(gr.sizeof_gr_complex*64, samples)

        #message block to pull messages out of
        self.blocks_message_debug_0 = blocks.message_debug()
        self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 256, 10000)), True)

        ##################################################
        # Connections
        ##################################################
        #self.msg_connect((self.classify_trained_model_classifier_vc_0, 'classification_info'), (self.blocks_message_debug_0, 'print'))
        self.msg_connect((self.classify_trained_model_classifier_vc_0, 'classification_info'), (self.blocks_message_debug_0, 'store'))
        self.connect((self.analog_random_source_x_0, 0), (self.blocks_repack_bits_bb_0, 0))
        self.connect((self.blocks_repack_bits_bb_0, 0), (self.digital_chunks_to_symbols_xx_0, 0))
        
        #self.connect((self.blocks_stream_to_vector_0, 0), (self.classify_trained_model_classifier_vc_0, 0))
        self.connect((self.blocks_stream_to_vector_0, 0), (self.blocks_head_1, 0))
        self.connect((self.blocks_head_1, 0), (self.classify_trained_model_classifier_vc_0, 0))

        self.connect((self.blocks_throttle_0_0, 0), (self.blocks_stream_to_vector_0, 0))
        self.connect((self.channels_channel_model_0_0, 0), (self.blocks_throttle_0_0, 0))
        self.connect((self.digital_chunks_to_symbols_xx_0, 0), (self.channels_channel_model_0_0, 0))
Esempio n. 29
0
    def __init__(self, N, sps, rolloff, ntaps, bw, noise,
                 foffset, toffset, poffset, mode=0):
        gr.top_block.__init__(self)

        rrc_taps = filter.firdes.root_raised_cosine(
            sps, sps, 1.0, rolloff, ntaps)

        gain = bw
        nfilts = 32
        rrc_taps_rx = filter.firdes.root_raised_cosine(
            nfilts, sps*nfilts, 1.0, rolloff, ntaps*nfilts)

        data = 2.0*scipy.random.randint(0, 2, N) - 1.0
        data = scipy.exp(1j*poffset) * data

        self.src = blocks.vector_source_c(data.tolist(), False)
        self.rrc = filter.interp_fir_filter_ccf(sps, rrc_taps)
        self.chn = channels.channel_model(noise, foffset, toffset)
        self.off = filter.mmse_resampler_cc(0.20, 1.0)

        if mode == 0:
            self.clk = digital.pfb_clock_sync_ccf(sps, gain, rrc_taps_rx,
                                                  nfilts, nfilts//2, 1)
            self.taps = self.clk.taps()
            self.dtaps = self.clk.diff_taps()

            self.delay = int(scipy.ceil(((len(rrc_taps)-1)//2 +
                                         (len(self.taps[0])-1)//2 )//float(sps))) + 1

            self.vsnk_err = blocks.vector_sink_f()
            self.vsnk_rat = blocks.vector_sink_f()
            self.vsnk_phs = blocks.vector_sink_f()

            self.connect((self.clk,1), self.vsnk_err)
            self.connect((self.clk,2), self.vsnk_rat)
            self.connect((self.clk,3), self.vsnk_phs)

        else: # mode == 1
            mu = 0.5
            gain_mu = bw
            gain_omega = 0.25*gain_mu*gain_mu
            omega_rel_lim = 0.02
            self.clk = digital.clock_recovery_mm_cc(sps, gain_omega,
                                                    mu, gain_mu,
                                                    omega_rel_lim)

            self.vsnk_err = blocks.vector_sink_f()

            self.connect((self.clk,1), self.vsnk_err)

        self.vsnk_src = blocks.vector_sink_c()
        self.vsnk_clk = blocks.vector_sink_c()

        self.connect(self.src, self.rrc, self.chn, self.off, self.clk, self.vsnk_clk)
        self.connect(self.src, self.vsnk_src)
Esempio n. 30
0
    def test_qpsk_3tap_lms_training(self):
        # set up fg
        gain = 0.01  # LMS gain
        num_taps = 16
        num_samp = 2000
        num_test = 500
        cons = digital.constellation_qpsk().base()
        rxmod = digital.generic_mod(cons, False, self.sps, True, self.eb,
                                    False, False)
        modulated_sync_word_pre = digital.modulate_vector_bc(
            rxmod.to_basic_block(), self.preamble + self.preamble, [1])
        modulated_sync_word = modulated_sync_word_pre[86:(
            512 + 86)]  # compensate for the RRC filter delay
        corr_max = numpy.abs(
            numpy.dot(modulated_sync_word, numpy.conj(modulated_sync_word)))
        corr_calc = self.corr_thresh / (corr_max * corr_max)
        preamble_symbols = self.map_symbols_to_constellation(
            self.unpack_values(self.preamble, 8, 2), cons)

        alg = digital.adaptive_algorithm_lms(cons, gain).base()
        evm = digital.meas_evm_cc(cons, digital.evm_measurement_t.EVM_PERCENT)
        leq = digital.linear_equalizer(num_taps, self.sps, alg, False,
                                       preamble_symbols, 'corr_est')
        correst = digital.corr_est_cc(modulated_sync_word, self.sps, 12,
                                      corr_calc, digital.THRESHOLD_ABSOLUTE)
        constmod = digital.generic_mod(constellation=cons,
                                       differential=False,
                                       samples_per_symbol=4,
                                       pre_diff_code=True,
                                       excess_bw=0.35,
                                       verbose=False,
                                       log=False)
        chan = channels.channel_model(noise_voltage=0.0,
                                      frequency_offset=0.0,
                                      epsilon=1.0,
                                      taps=(1.0 + 1.0j, 0.63 - .22j,
                                            -.1 + .07j),
                                      noise_seed=0,
                                      block_tags=False)
        vso = blocks.vector_source_b(self.preamble + self.data, True, 1, [])
        head = blocks.head(gr.sizeof_float * 1, num_samp)
        vsi = blocks.vector_sink_f()

        self.tb.connect(vso, constmod, chan, correst, leq, evm, head, vsi)
        self.tb.run()

        # look at the last 1000 samples, should converge quickly, below 5% EVM
        upper_bound = list(20.0 * numpy.ones((num_test, )))
        lower_bound = list(0.0 * numpy.zeros((num_test, )))
        output_data = vsi.data()
        output_data = output_data[-num_test:]
        self.assertLess(output_data, upper_bound)
        self.assertGreater(output_data, lower_bound)
Esempio n. 31
0
    def __init__(self, snr_db=10, num_symbols=1024, taps=[]):
        gr.top_block.__init__(self, "CMA Watterson Experiment")

        ##################################################
        # Variables
        ##################################################
        self.snr_db = snr_db
        self.samp_rate = samp_rate = 1000000
        self.num_symbols = num_symbols
        self.taps = taps

        self.const = const = digital.constellation_8psk().base()

        ##################################################
        # Blocks
        ##################################################
        #self.interp_fir_filter_xxx_0_0 = filter.interp_fir_filter_ccc(2, (firdes.low_pass_2(1, 1, .25, .1, 80)))
        #self.interp_fir_filter_xxx_0_0.declare_sample_delay(0)
        self.digital_cma_equalizer_cc_0 = digital.cma_equalizer_cc(
            4, 1, .01, 2)
        self.digital_chunks_to_symbols_xx_1 = digital.chunks_to_symbols_bc(
            (const.points()), 1)
        self.channels_channel_model_0 = channels.channel_model(
            noise_voltage=10**(-self.snr_db / 20.0) / numpy.sqrt(2),
            frequency_offset=0.0,
            epsilon=1.0,
            taps=self.taps,
            noise_seed=0,
            block_tags=False)
        self.blocks_vector_sink_x_0 = blocks.vector_sink_c(1)
        self.blocks_head_0 = blocks.head(gr.sizeof_gr_complex * 1, num_symbols)
        self.analog_random_source_x_1 = blocks.vector_source_b(
            map(int, numpy.random.randint(0, const.arity(), 1000)), True)
        self.blocks_repeat_0 = blocks.repeat(gr.sizeof_gr_complex * 1, 2)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.analog_random_source_x_1, 0),
                     (self.digital_chunks_to_symbols_xx_1, 0))
        self.connect((self.blocks_head_0, 0), (self.blocks_vector_sink_x_0, 0))
        self.connect((self.channels_channel_model_0, 0),
                     (self.digital_cma_equalizer_cc_0, 0))
        #self.connect((self.digital_chunks_to_symbols_xx_1, 0), (self.interp_fir_filter_xxx_0_0, 0))
        self.connect((self.digital_cma_equalizer_cc_0, 0),
                     (self.blocks_head_0, 0))
        #self.connect((self.interp_fir_filter_xxx_0_0, 0), (self.channels_channel_model_0, 0))
        self.connect((self.blocks_repeat_0, 0),
                     (self.channels_channel_model_0, 0))
        self.connect((self.digital_chunks_to_symbols_xx_1, 0),
                     (self.blocks_repeat_0, 0))
Esempio n. 32
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 100
        f2 = 2000

        npts = 2048

        taps = filter.firdes.complex_band_pass_2(1, Rs, 1500, 2500, 100, 60)

        self.qapp = QtWidgets.QApplication(sys.argv)
        ss = open(gr.prefix() + '/share/gnuradio/themes/dark.qss')
        sstext = ss.read()
        ss.close()
        self.qapp.setStyleSheet(sstext)

        src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0)
        src = blocks.add_cc()
        channel = channels.channel_model(0.01)
        thr = blocks.throttle(gr.sizeof_gr_complex, 100 * npts)
        filt = filter.fft_filter_ccc(1, taps)
        self.snk1 = qtgui.waterfall_sink_c(npts,
                                           filter.firdes.WIN_BLACKMAN_hARRIS,
                                           0, Rs, "Complex Waterfall Example",
                                           2)
        self.snk1.set_color_map(0, qtgui.INTENSITY_COLOR_MAP_TYPE_COOL)
        self.snk1.set_color_map(1, qtgui.INTENSITY_COLOR_MAP_TYPE_COOL)

        self.connect(src1, (src, 0))
        self.connect(src2, (src, 1))
        self.connect(src, channel, thr, (self.snk1, 0))
        self.connect(thr, filt, (self.snk1, 1))

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt5.QtWidgets.QWidget
        pyWin = sip.wrapinstance(pyQt, QtWidgets.QWidget)

        #pyWin.show()
        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
Esempio n. 33
0
    def __init__(self, xsource, linear_att, awgn_sigma, freq_offset,
                 outputfile):
        self.tb = gr.top_block()

        print 'final SNRdB:', 10 * np.log10(linear_att**2 / awgn_sigma**2)

        v = np.array(xsource, np.complex128)
        self.source = blocks.vector_source_c(v, False)
        self.attenuation = blocks.multiply_const_cc(linear_att + 0 * 1j)
        self.channel = channels.channel_model(awgn_sigma, freq_offset)
        self.fsink = blocks.file_sink(gr.sizeof_gr_complex, outputfile)

        self.tb.connect(self.source, self.attenuation)
        self.tb.connect(self.attenuation, self.channel)
        self.tb.connect(self.channel, self.fsink)
Esempio n. 34
0
 def setUp(self):
     self.tb = gr.top_block()
     self.nfreq_samps = 256
     self.freqs = [11. / 256, 41. / 256, 93. / 256]
     self.corr_reps = 4
     self.channel = channels.channel_model(
         noise_voltage=0.01,
         frequency_offset=1e-5,
         epsilon=1.0,
         taps=[0.8, 0.1, 0.05, 0.01, 0.01, 0.005])
     self.channel_in = blocks.pdu_to_tagged_stream(blocks.complex_t,
                                                   "frame")
     self.channel_out = blocks.tagged_stream_to_pdu(blocks.complex_t,
                                                    "frame")
     self.tb.connect(self.channel_in, self.channel)
     self.tb.connect(self.channel, self.channel_out)
Esempio n. 35
0
 def generate_noise(self):
     """
     Take data from sliders and create a noise generator from it
     
     param: none
     returns: none
     """
     SNRval = self.SNRSlider.value()
     if (SNRval % 2 != 0):
         SNRval = (SNRval + 1) % 20
     noise_model = channels.channel_model(noise_voltage=10**(-SNRval / 10),
                                          frequency_offset=0.0,
                                          epsilon=1.0,
                                          taps=(1.0 + 1.0j, ),
                                          noise_seed=0,
                                          block_tags=False)
     return noise_model
Esempio n. 36
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 100
        f2 = 2000

        npts = 2048

        taps = filter.firdes.complex_band_pass_2(1, Rs, 1500, 2500, 100, 60)

        self.qapp = QtGui.QApplication(sys.argv)
        ss = open(gr.prefix() + '/share/gnuradio/themes/dark.qss')
        sstext = ss.read()
        ss.close()
        self.qapp.setStyleSheet(sstext)

        src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0)
        src  = blocks.add_cc()
        channel = channels.channel_model(0.01)
        thr = blocks.throttle(gr.sizeof_gr_complex, 100*npts)
        filt = filter.fft_filter_ccc(1, taps)
        self.snk1 = qtgui.waterfall_sink_c(npts, filter.firdes.WIN_BLACKMAN_hARRIS,
                                           0, Rs,
                                           "Complex Waterfall Example", 2)

        self.connect(src1, (src,0))
        self.connect(src2, (src,1))
        self.connect(src,  channel, thr, (self.snk1, 0))
        self.connect(thr, filt, (self.snk1, 1))

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt  = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

        #pyWin.show()
        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
Esempio n. 37
0
    def fmGen(self, noiseLevel):

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 300000

        ##################################################
        # Blocks
        ##################################################

        self.blocks_wavfile_source_0 = blocks.wavfile_source(sys.argv[3], True)
        self.sink = blocks.vector_sink_c(1)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1,
                                                 samp_rate)  #, True)
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vcc((1, ))
        self.analog_wfm_tx_0 = analog.wfm_tx(
            audio_rate=44100,
            quad_rate=176400,
            tau=75e-6,
            max_dev=5e3,
            #       fh=-1.0,
        )

        self.channel = channels.channel_model(
            noise_voltage=
            noiseLevel,  # AWGN noise level as a voltage (edit depending on SNR)
            frequency_offset=0.0,  # No frequency offset
            epsilon=
            1.0,  # 1.0 to keep no difference between sampling rates of clocks of transmitter and receiver
            noise_seed=0,  # Normal random number generator for noise
            block_tags=False  # Only needed for multipath
        )
        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_wavfile_source_0, 0),
                     (self.analog_wfm_tx_0, 0))
        self.connect((self.analog_wfm_tx_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.blocks_throttle_0, 0),
                     (self.blocks_multiply_const_vxx_1, 0))
        self.connect((self.blocks_multiply_const_vxx_1, 0), (self.channel, 0))
        self.connect((self.channel, 0), (self.sink, 0))

        return self.sink
Esempio n. 38
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 100000
        npts = 2048

        #taps = filter.firdes.complex_band_pass_2(1, Rs, 1500, 2500, 100, 60)

        self.qapp = QtGui.QApplication(sys.argv)
        ss = open(gr.prefix() + '/share/gnuradio/themes/dark.qss')
        sstext = ss.read()
        ss.close()
        self.qapp.setStyleSheet(sstext)

        channel = channels.channel_model(0.01)
        thr = blocks.throttle(gr.sizeof_gr_complex, 100*npts)
        #filt = filter.fft_filter_ccc(1, taps)
        self.snk1 = qtgui.waterfall_sink_c(npts, filter.firdes.WIN_BLACKMAN_hARRIS,
                                           0, Rs,
                                           "Waterfall monitor", 2)

        float_to_complex = blocks.float_to_complex()

        input_rate = 96000
        #audio_input = "hw:Loopback,0,0"
        audio_input = "hw:PCH,0,0"
        src_audio = audio.source (input_rate, audio_input)
        self.connect((src_audio, 1), (float_to_complex, 0))
        self.connect((src_audio, 0), (float_to_complex, 1))

        self.connect(float_to_complex, channel, thr, (self.snk1, 0))
        #self.connect(thr, filt, (self.snk1, 1))
        self.connect(thr, (self.snk1, 1))

        self.ctrl_win = control_box()

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt  = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
    def __init__(self, snr_val, cfo=0, sto=0, verbose=False):
        gr.top_block.__init__(self, name="CFO estimation test")
        zc_seq_len = 503  #199
        sample_rate = 1e6
        frame_duration = 2.0e-3
        test_duration = 1.5 * frame_duration
        sigma_val = 1 / float(10.0**(snr_val / 20.0))
        thres = 0.25

        samples_per_frame = int(round(frame_duration * sample_rate))
        samples_per_test = int(round(test_duration * sample_rate))
        n_samples_snr_estim = zc_seq_len
        random_samples_skip = np.random.randint(
            samples_per_frame / 2) + samples_per_frame / 2
        preamble_seq = zadoffchu.generate_sequence(zc_seq_len, 1, 0)
        preamble_pwr_sum = np.sum(np.abs(preamble_seq)**2)

        self.framer = specmonitor.framer_c(sample_rate, frame_duration,
                                           preamble_seq)
        self.channel = channels.channel_model(sigma_val, cfo, sto, [1 + 1j])
        self.skiphead = blocks.skiphead(gr.sizeof_gr_complex,
                                        random_samples_skip)
        self.corr_est = specmonitor.corr_est_norm_cc(
            preamble_seq, 1, 0,
            thres)  #digital.corr_est_cc(preamble_seq, 1, 0)
        self.snr_est = specmonitor.framer_snr_est_cc(n_samples_snr_estim,
                                                     preamble_seq.size)
        if verbose is True:
            self.tag_db = blocks.tag_debug(gr.sizeof_gr_complex,
                                           "tag debugger")
        self.head = blocks.head(gr.sizeof_gr_complex, samples_per_test)
        self.dst = blocks.vector_sink_c()
        self.dst2 = blocks.vector_sink_c()

        self.connect(self.framer, self.channel)
        self.connect(self.channel, self.skiphead)
        # self.connect(self.framer,self.skiphead)
        self.connect(self.skiphead, self.head)
        self.connect(self.head, self.corr_est)
        self.connect(self.corr_est, self.snr_est)
        self.connect((self.corr_est, 1), self.dst2)
        if verbose is True:
            self.connect(self.snr_est, self.tag_db)
        self.connect(self.snr_est, self.dst)
Esempio n. 40
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 100
        f2 = 200

        npts = 2048

        self.qapp = QtWidgets.QApplication(sys.argv)
        ss = open(gr.prefix() + '/share/gnuradio/themes/dark.qss')
        sstext = ss.read()
        ss.close()
        self.qapp.setStyleSheet(sstext)

        src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0)
        src = blocks.add_cc()
        channel = channels.channel_model(0.01)
        thr = blocks.throttle(gr.sizeof_gr_complex, 100 * npts)
        self.snk1 = qtgui.freq_sink_c(npts, window.WIN_BLACKMAN_hARRIS, 0, Rs,
                                      "Complex Freq Example", 3, None)

        self.connect(src1, (src, 0))
        self.connect(src2, (src, 1))
        self.connect(src, channel, thr, (self.snk1, 0))
        self.connect(src1, (self.snk1, 1))
        self.connect(src2, (self.snk1, 2))

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt = self.snk1.qwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt5.QtWidgets.QWidget
        pyWin = sip.wrapinstance(pyQt, QtWidgets.QWidget)

        #pyWin.show()
        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
Esempio n. 41
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 1000
        f2 = 2000

        fftsize = 2048

        self.qapp = QtGui.QApplication(sys.argv)
        ss = open('dark.qss')
        sstext = ss.read()
        ss.close()
        self.qapp.setStyleSheet(sstext)

        src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0)
        src  = blocks.add_cc()
        channel = channels.channel_model(0.001)
        thr = blocks.throttle(gr.sizeof_gr_complex, 100*fftsize)
        self.snk1 = qtgui.sink_c(fftsize, filter.firdes.WIN_BLACKMAN_hARRIS,
                                 0, Rs,
                                 "Complex Signal Example",
                                 True, True, True, False)

        self.connect(src1, (src,0))
        self.connect(src2, (src,1))
        self.connect(src,  channel, thr, self.snk1)

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt  = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

        self.main_box = dialog_box(pyWin, self.ctrl_win)

        self.main_box.show()
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 1000
        f2 = 2000

        fftsize = 2048

        self.qapp = QtGui.QApplication(sys.argv)
        ss = open('dark.qss')
        sstext = ss.read()
        ss.close()
        self.qapp.setStyleSheet(sstext)

        src1 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = analog.sig_source_c(Rs, analog.GR_SIN_WAVE, f2, 0.1, 0)
        src = blocks.add_cc()
        channel = channels.channel_model(0.001)
        thr = blocks.throttle(gr.sizeof_gr_complex, 100 * fftsize)
        self.snk1 = qtgui.sink_c(fftsize, filter.firdes.WIN_BLACKMAN_hARRIS, 0,
                                 Rs, "Complex Signal Example", True, True,
                                 True, False)

        self.connect(src1, (src, 0))
        self.connect(src2, (src, 1))
        self.connect(src, channel, thr, self.snk1)

        self.ctrl_win = control_box()
        self.ctrl_win.attach_signal1(src1)
        self.ctrl_win.attach_signal2(src2)

        # Get the reference pointer to the SpectrumDisplayForm QWidget
        pyQt = self.snk1.pyqwidget()

        # Wrap the pointer as a PyQt SIP object
        # This can now be manipulated as a PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

        self.main_box = dialog_box(pyWin, self.ctrl_win)

        self.main_box.show()
Esempio n. 43
0
 def test_002_freq(self):
     """ Add a fine frequency offset and see if that gets detected properly """
     fft_len = 32
     cp_len = 4
     # This frequency offset is normalized to rads, i.e. \pi == f_s/2
     max_freq_offset = 2*numpy.pi/fft_len # Otherwise, it's coarse
     freq_offset = ((2 * random.random()) - 1) * max_freq_offset
     sig_len = (fft_len + cp_len) * 10
     tx_signal = make_bpsk_burst(fft_len, cp_len, sig_len)
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len, True)
     sink_freq = blocks.vector_sink_f()
     sink_detect = blocks.vector_sink_b()
     channel = channels.channel_model(0.005, freq_offset / 2.0 / numpy.pi)
     self.tb.connect(blocks.vector_source_c(tx_signal), channel, sync)
     self.tb.connect((sync, 0), sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     phi_hat = sink_freq.data()[sink_detect.data().index(1)]
     est_freq_offset = 2 * phi_hat / fft_len
     self.assertAlmostEqual(est_freq_offset, freq_offset, places=2)
Esempio n. 44
0
 def test_002_freq(self):
     """ Add a fine frequency offset and see if that gets detected properly """
     fft_len = 32
     cp_len = 4
     # This frequency offset is normalized to rads, i.e. \pi == f_s/2
     max_freq_offset = 2 * numpy.pi / fft_len  # Otherwise, it's coarse
     freq_offset = ((2 * random.random()) - 1) * max_freq_offset
     sig_len = (fft_len + cp_len) * 10
     tx_signal = make_bpsk_burst(fft_len, cp_len, sig_len)
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len, True)
     sink_freq = blocks.vector_sink_f()
     sink_detect = blocks.vector_sink_b()
     channel = channels.channel_model(0.005, freq_offset / 2.0 / numpy.pi)
     self.tb.connect(blocks.vector_source_c(tx_signal), channel, sync)
     self.tb.connect((sync, 0), sink_freq)
     self.tb.connect((sync, 1), sink_detect)
     self.tb.run()
     phi_hat = sink_freq.data()[sink_detect.data().index(1)]
     est_freq_offset = 2 * phi_hat / fft_len
     self.assertAlmostEqual(est_freq_offset, freq_offset, places=2)
Esempio n. 45
0
 def test_004_tx1packet_large_fO(self):
     """ Transmit one packet, with slight AWGN and large frequency offset.
     Check packet is received and no bit errors have occurred. """
     fft_len = 64
     len_tag_key = 'frame_len'
     n_bytes = 21
     test_data = tuple([random.randint(0, 255) for x in range(n_bytes)])
     #test_data = tuple([255 for x in range(n_bytes)])
     # 1.0/fft_len is one sub-carrier
     frequency_offset = 1.0 / fft_len * 2.5
     channel = channels.channel_model(0.00001, frequency_offset)
     # Tx
     tx_fg = ofdm_tx_fg(test_data, len_tag_key)
     tx_fg.run()
     tx_samples = tx_fg.get_tx_samples()
     # Rx
     rx_fg = ofdm_rx_fg(tx_samples, len_tag_key, channel, prepend_zeros=100)
     rx_fg.run()
     rx_data = rx_fg.get_rx_bytes()
     self.assertEqual(test_data, rx_data)
Esempio n. 46
0
    def __init__(self, N, sps, rolloff, ntaps, bw, noise, foffset, toffset, poffset):
        gr.top_block.__init__(self)

        rrc_taps = filter.firdes.root_raised_cosine(
            sps, sps, 1.0, rolloff, ntaps)

        data = 2.0*numpy.random.randint(0, 2, N) - 1.0
        data = numpy.exp(1j*poffset) * data

        self.src = blocks.vector_source_c(data.tolist(), False)
        self.rrc = filter.interp_fir_filter_ccf(sps, rrc_taps)
        self.chn = channels.channel_model(noise, foffset, toffset)
        self.cst = digital.costas_loop_cc(bw, 2)

        self.vsnk_src = blocks.vector_sink_c()
        self.vsnk_cst = blocks.vector_sink_c()
        self.vsnk_frq = blocks.vector_sink_f()

        self.connect(self.src, self.rrc, self.chn, self.cst, self.vsnk_cst)
        self.connect(self.rrc, self.vsnk_src)
        self.connect((self.cst,1), self.vsnk_frq)
Esempio n. 47
0
    def test_000(self):
        N = 1000         # number of samples to use
        fs = 1000        # baseband sampling rate
        freq = 100

        signal = analog.sig_source_c(fs, analog.GR_SIN_WAVE, freq, 1)
        head = blocks.head(gr.sizeof_gr_complex, N)
        op = channels.channel_model(0.0, 0.0, 1.0, [1,], 0)
        snk = blocks.vector_sink_c()
        snk1 = blocks.vector_sink_c()

        op.set_noise_voltage(0.0)
        op.set_frequency_offset(0.0)
        op.set_taps([1,])
        op.set_timing_offset(1.0)

        self.tb.connect(signal, head, op, snk)
        self.tb.connect(op, snk1)
        self.tb.run()

        dst_data = snk.data()
        exp_data = snk1.data()
        self.assertComplexTuplesAlmostEqual(exp_data, dst_data, 5)
Esempio n. 48
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="FHSS Packets")

        ##################################################
        # Variables
        ##################################################
        self.samp_sym = samp_sym = 64
        self.samp_rate = samp_rate = 800000
        self.init = init = 1, 1, 1, 1
        self.generator = generator = 1, 1, 0, 0, 1
        self.code_rate = code_rate = int(1389 * samp_sym)

        ##################################################
        # Blocks
        ##################################################
        self.wxgui_fftsink2_0_0 = fftsink2.fft_sink_c(
        	self.GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Received Spread Spectrum Signal",
        	peak_hold=False,
        )
        self.Add(self.wxgui_fftsink2_0_0.win)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
        	self.GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Despread Signal",
        	peak_hold=False,
        )
        self.Add(self.wxgui_fftsink2_0.win)
        self.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass(
        	1, samp_rate, 11000, 1000, firdes.WIN_HAMMING, 6.76))
        self.digital_gmsk_mod_0 = digital.gmsk_mod(
        	samples_per_symbol=samp_sym,
        	bt=0.35,
        	verbose=False,
        	log=False,
        )
        self.digital_gmsk_demod_0 = digital.gmsk_demod(
        	samples_per_symbol=samp_sym,
        	gain_mu=0.175,
        	mu=0.5,
        	omega_relative_limit=0.005,
        	freq_error=0.0,
        	verbose=False,
        	log=False,
        )
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage=0.01,
        	frequency_offset=1 / samp_rate,
        	epsilon=1 + 0.000001,
        	taps=(1.0 + 1.0j, ),
        	noise_seed=0,
        	block_tags=False
        )
        self.blocks_unpacked_to_packed_xx_0 = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
        self.Spread_synthesizer_0 = Spread.synthesizer(code_rate, 0, samp_rate, (generator), (init))
        self.Spread_sync_0 = Spread.sync()
        self.Spread_rx_synthesizer_0 = Spread.rx_synthesizer(code_rate, 
                                      samp_sym, 
                                      samp_rate, 
                                      11000, 
                                      10000, 
                                      0.01, 
                                      (generator), 
                                      (init))
        self.Spread_rx_sync_0 = Spread.rx_sync(12)
        self.Spread_msg_source_0 = Spread.msg_source(500, 100)
        self.Spread_framer_0 = Spread.framer(0)
        self.Spread_deframer_0 = Spread.deframer(0)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.Spread_synthesizer_0, 0), (self.channels_channel_model_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.Spread_rx_synthesizer_0, 0))
        self.connect((self.digital_gmsk_demod_0, 0), (self.Spread_rx_sync_0, 0))
        self.connect((self.digital_gmsk_mod_0, 0), (self.Spread_synthesizer_0, 0))
        self.connect((self.blocks_unpacked_to_packed_xx_0, 0), (self.digital_gmsk_mod_0, 0))
        self.connect((self.Spread_sync_0, 0), (self.blocks_unpacked_to_packed_xx_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.wxgui_fftsink2_0_0, 0))
        self.connect((self.Spread_rx_synthesizer_0, 0), (self.low_pass_filter_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.wxgui_fftsink2_0, 0))
        self.connect((self.low_pass_filter_0, 0), (self.digital_gmsk_demod_0, 0))

        ##################################################
        # Asynch Message Connections
        ##################################################
        self.msg_connect(self.Spread_framer_0, "out", self.Spread_sync_0, "in")
        self.msg_connect(self.Spread_msg_source_0, "out", self.Spread_framer_0, "in")
        self.msg_connect(self.Spread_rx_sync_0, "out", self.Spread_deframer_0, "in")
    def __init__(self):
        gr.top_block.__init__(self, "Ex Freq Sel Fading Model")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Ex Freq Sel Fading Model")
        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", "ex_freq_sel_fading_model")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Variables
        ##################################################
        self.trig_umts_ped_b = trig_umts_ped_b = 1.5
        self.trig_umts_ped_a = trig_umts_ped_a = 0.5
        self.trig_del_umts_ped_b = trig_del_umts_ped_b = 0.000001
        self.trig_del_umts_ped_a = trig_del_umts_ped_a = 0.000001
        self.trig_del_ca0 = trig_del_ca0 = 2e-9
        self.trig_ca0 = trig_ca0 = 2.8
        self.samp_rate_umts_ped_b = samp_rate_umts_ped_b = 7.68e6
        self.samp_rate_umts_ped_a = samp_rate_umts_ped_a = 7.68e6
        self.samp_rate_ca0 = samp_rate_ca0 = 4e9
        self.pdp_times_umts_ped_b = pdp_times_umts_ped_b = [0, 1.536, 6.144, 9.216, 17.664, 28.416]
        self.pdp_times_umts_ped_a = pdp_times_umts_ped_a = [0, 0.8448, 1.4592, 3.1488]
        self.pdp_times_ca0 = pdp_times_ca0 = [-0.25, -0.125, 0.0, 0.125, 0.25, 0.375, 0.5, 0.625, 0.75, 0.875, 1.0, 1.125, 1.25, 1.5, 1.625, 1.75, 1.875, 2.0, 2.125, 2.25, 2.375, 2.5, 2.75, 2.875, 3.0, 3.125, 3.25, 3.375, 3.5, 3.625, 3.75, 3.875, 4.0, 4.125, 4.25, 4.375, 4.5, 4.625, 4.75, 5.125, 5.25, 5.5, 5.625, 5.75, 6.0, 6.375, 6.5, 6.625, 6.75, 6.875, 7.25, 8.0, 8.125, 8.5, 8.625, 8.75, 8.875, 9.125, 9.25, 9.375, 9.5, 9.875, 10.0, 10.75, 10.875, 11.0, 11.125, 13.125, 13.25]
        self.pdp_mags_umts_ped_b = pdp_mags_umts_ped_b = [1, 0.9139311853, 0.6126263942, 0.4493289641, 0.4584060113, 0.0916296839]
        self.pdp_mags_umts_ped_a = pdp_mags_umts_ped_a = [1, 0.3790830381, 0.1466069621, 0.1022842067]
        self.pdp_mags_ca0 = pdp_mags_ca0 = [0.16529889, 0.46954084, 0.58274825, 0.24561255, 0.50459457, 0.69767633, 1.0, 0.77724474, 0.48675226, 0.46954084, 0.21267289, 0.19090106, 0.31600413, 0.45293801, 0.8057353, 0.64920938, 0.50459457, 0.1978987, 0.35204369, 0.54226525, 0.31600413, 0.15945397, 0.2204686, 0.35204369, 0.37832563, 0.37832563, 0.36494815, 0.2204686, 0.17763933, 0.45293801, 0.52309091, 0.52309091, 0.46954084, 0.35204369, 0.40656966, 0.25461568, 0.23692776, 0.32758753, 0.1978987, 0.21267289, 0.2204686, 0.19090106, 0.24561255, 0.17135806, 0.21267289, 0.16529889, 0.2204686, 0.30483032, 0.33959553, 0.18415085, 0.18415085, 0.22855006, 0.2940516, 0.19090106, 0.17135806, 0.18415085, 0.1978987, 0.17763933, 0.15945397, 0.26394884, 0.24561255, 0.21267289, 0.19090106, 0.17763933, 0.2204686, 0.21267289, 0.17135806, 0.17135806, 0.16529889]
        self.model = model = 2
        self.trig_del = trig_del = [trig_del_ca0, trig_del_umts_ped_a, trig_del_umts_ped_b][model]
        self.trig = trig = [trig_ca0, trig_umts_ped_a, trig_umts_ped_b][model]
        self.timing = timing = 1.000
        self.samp_rate = samp_rate = [samp_rate_ca0, samp_rate_umts_ped_a, samp_rate_umts_ped_b][model]
        self.pdp_times = pdp_times = [pdp_times_ca0, pdp_times_umts_ped_a, pdp_times_umts_ped_b][model]
        self.pdp_mags = pdp_mags = [pdp_mags_ca0, pdp_mags_umts_ped_a, pdp_mags_umts_ped_b][model]
        self.noise = noise = 0.01
        self.freq = freq = 0.0

        ##################################################
        # Blocks
        ##################################################
        self._timing_layout = Qt.QVBoxLayout()
        self._timing_tool_bar = Qt.QToolBar(self)
        self._timing_layout.addWidget(self._timing_tool_bar)
        self._timing_tool_bar.addWidget(Qt.QLabel("Timing Offset"+": "))
        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)
        self._timing_counter = qwt_counter_pyslot()
        self._timing_counter.setRange(0.999, 1.001, 0.0001)
        self._timing_counter.setNumButtons(2)
        self._timing_counter.setValue(self.timing)
        self._timing_tool_bar.addWidget(self._timing_counter)
        self._timing_counter.valueChanged.connect(self.set_timing)
        self._timing_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._timing_slider.setRange(0.999, 1.001, 0.0001)
        self._timing_slider.setValue(self.timing)
        self._timing_slider.setMinimumWidth(200)
        self._timing_slider.valueChanged.connect(self.set_timing)
        self._timing_layout.addWidget(self._timing_slider)
        self.top_grid_layout.addLayout(self._timing_layout, 3,0,1,1)
        self._noise_layout = Qt.QVBoxLayout()
        self._noise_tool_bar = Qt.QToolBar(self)
        self._noise_layout.addWidget(self._noise_tool_bar)
        self._noise_tool_bar.addWidget(Qt.QLabel("Noise Voltage"+": "))
        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)
        self._noise_counter = qwt_counter_pyslot()
        self._noise_counter.setRange(0, 1, 0.01)
        self._noise_counter.setNumButtons(2)
        self._noise_counter.setValue(self.noise)
        self._noise_tool_bar.addWidget(self._noise_counter)
        self._noise_counter.valueChanged.connect(self.set_noise)
        self._noise_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._noise_slider.setRange(0, 1, 0.01)
        self._noise_slider.setValue(self.noise)
        self._noise_slider.setMinimumWidth(200)
        self._noise_slider.valueChanged.connect(self.set_noise)
        self._noise_layout.addWidget(self._noise_slider)
        self.top_grid_layout.addLayout(self._noise_layout, 2,0,1,1)
        self._freq_layout = Qt.QVBoxLayout()
        self._freq_tool_bar = Qt.QToolBar(self)
        self._freq_layout.addWidget(self._freq_tool_bar)
        self._freq_tool_bar.addWidget(Qt.QLabel("Frequency Offset"+": "))
        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)
        self._freq_counter = qwt_counter_pyslot()
        self._freq_counter.setRange(-1, 1, 0.01)
        self._freq_counter.setNumButtons(2)
        self._freq_counter.setValue(self.freq)
        self._freq_tool_bar.addWidget(self._freq_counter)
        self._freq_counter.valueChanged.connect(self.set_freq)
        self._freq_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._freq_slider.setRange(-1, 1, 0.01)
        self._freq_slider.setValue(self.freq)
        self._freq_slider.setMinimumWidth(200)
        self._freq_slider.valueChanged.connect(self.set_freq)
        self._freq_layout.addWidget(self._freq_slider)
        self.top_grid_layout.addLayout(self._freq_layout, 2,1,1,1)
        self.qtgui_waterfall_sink_x_0 = qtgui.waterfall_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	samp_rate, #bw
        	"QT GUI Plot", #name
                1 #number of inputs
        )
        self.qtgui_waterfall_sink_x_0.set_update_time(0.10)
        self._qtgui_waterfall_sink_x_0_win = sip.wrapinstance(self.qtgui_waterfall_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_waterfall_sink_x_0_win, 0,1,1,1)
        self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f(
        	30, #size
        	samp_rate, #samp_rate
        	"QT GUI Plot", #name
        	1 #number of inputs
        )
        self.qtgui_time_sink_x_0_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0_0.set_y_axis(-1, 1)
        self.qtgui_time_sink_x_0_0.enable_tags(-1, True)
        self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_NORM, qtgui.TRIG_SLOPE_POS, trig, trig_del, 0, "")
        self._qtgui_time_sink_x_0_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_0_win, 1,1,1,1)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_c(
        	1024, #size
        	samp_rate, #samp_rate
        	"QT GUI 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(-3, 3)
        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_win = sip.wrapinstance(self.qtgui_time_sink_x_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_win, 1,0,1,1)
        self.qtgui_freq_sink_x_0 = qtgui.freq_sink_c(
        	1024, #size
        	firdes.WIN_BLACKMAN_hARRIS, #wintype
        	0, #fc
        	samp_rate, #bw
        	"QT GUI Plot", #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(-80, 10)
        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, 0,0,1,1)
        self.channels_selective_fading_model_0 = channels.selective_fading_model( 8, 10.0/samp_rate, False, 4.0, 0, (pdp_times), (pdp_mags), 8 )
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage=noise,
        	frequency_offset=freq,
        	epsilon=timing,
        	taps=(1.0, ),
        	noise_seed=0,
        	block_tags=False
        )
        self.blocks_vector_source_x_0 = blocks.vector_source_c(511*[0,] + [1,] + 512*[0,], True, 1, [])
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_complex_to_mag_squared_0 = blocks.complex_to_mag_squared(1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_vector_source_x_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.qtgui_waterfall_sink_x_0, 0))
        self.connect((self.channels_selective_fading_model_0, 0), (self.channels_channel_model_0, 0))
        self.connect((self.blocks_complex_to_mag_squared_0, 0), (self.qtgui_time_sink_x_0_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.channels_selective_fading_model_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.blocks_complex_to_mag_squared_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.qtgui_time_sink_x_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.qtgui_freq_sink_x_0, 0))
Esempio n. 50
0
 def __init__(self, name):
     gr.hier_block2.__init__(
         self, name,
         gr.io_signature(0, 0, 0),
         gr.io_signature(1, 1, gr.sizeof_gr_complex * 1),
     )
     
     rf_rate = self.rf_rate
     audio_rate = self.audio_rate
     
     self.__noise_level = -22
     self.__transmitters = CellDict(dynamic=True)
     
     self.__transmitters_cs = CollectionState(self.__transmitters)
     
     self.__bus = blocks.add_vcc(1)
     self.__channel_model = channels.channel_model(
         noise_voltage=dB(self.__noise_level),
         frequency_offset=0,
         epsilon=1.01,  # TODO: expose this parameter
         # taps=...,  # TODO: apply something here?
     )
     self.__rotator = blocks.rotator_cc()
     self.__throttle = blocks.throttle(gr.sizeof_gr_complex, rf_rate)
     self.connect(
         self.__bus,
         self.__throttle,
         self.__channel_model,
         self.__rotator,
         self)
     signals = []
     
     def add_modulator(freq, key, mode_or_modulator_ctor, **kwargs):
         if isinstance(mode_or_modulator_ctor, type):
             mode = None
             ctor = mode_or_modulator_ctor
         else:
             mode = mode_or_modulator_ctor
             mode_def = lookup_mode(mode)
             if mode_def is None:  # missing plugin, say
                 return
             ctor = mode_def.mod_class
         context = None  # TODO implement context
         modulator = ctor(context=context, mode=mode, **kwargs)
         tx = _SimulatedTransmitter(modulator, audio_rate, rf_rate, freq)
         
         self.connect(audio_signal, tx)
         signals.append(tx)
         self.__transmitters[key] = tx
     
     # Audio input signal
     pitch = analog.sig_source_f(audio_rate, analog.GR_SAW_WAVE, -1, 2000, 1000)
     audio_signal = vco = blocks.vco_f(audio_rate, 1, 1)
     self.connect(pitch, vco)
     
     # Channels
     add_modulator(0.0, 'usb', 'USB')
     add_modulator(10e3, 'am', 'AM')
     add_modulator(30e3, 'fm', 'NFM')
     add_modulator(-30e3, 'vor1', 'VOR', angle=0)
     add_modulator(-60e3, 'vor2', 'VOR', angle=math.pi / 2)
     add_modulator(50e3, 'rtty', 'RTTY', message='The quick brown fox jumped over the lazy dog.\n')
     add_modulator(80e3, 'chirp', ChirpModulator)
     
     bus_input = 0
     for signal in signals:
         self.connect(signal, (self.__bus, bus_input))
         bus_input = bus_input + 1
     
     self.__signal_type = SignalType(
         kind='IQ',
         sample_rate=rf_rate)
     self.__usable_bandwidth = RangeT([(-rf_rate / 2, rf_rate / 2)])
Esempio n. 51
0
    def __init__(self):
        gr.top_block.__init__(self, "Simulation for SDR TCC")
        Qt.QWidget.__init__(self)
        self.setWindowTitle("Simulation for SDR TCC")
        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", "sdrSim2")
        self.restoreGeometry(self.settings.value("geometry").toByteArray())


        ##################################################
        # Variables
        ##################################################
        self.sps = sps = 4
        self.nfilts = nfilts = 32
        self.eb = eb = 0.35
        self.timing_loop_bw = timing_loop_bw = 0.005
        self.time_offset = time_offset = 1.00
        self.taps = taps = [1.0, 0.25-0.25j, 0.50 + 0.10j, -0.3 + 0.2j]
        self.samp_rate = samp_rate = 32000
        self.rrc_taps = rrc_taps = firdes.root_raised_cosine(nfilts, nfilts, 1.0/float(sps), 0.35, 11*sps*nfilts)
        self.qpsk = qpsk = digital.constellation_rect(([0.707+0.707j, -0.707+0.707j, -0.707-0.707j, 0.707-0.707j]), ([0, 1, 2, 3]), 4, 2, 2, 1, 1).base()
        self.preamble = preamble = [1,-1,1,-1,1,1,-1,-1,1,1,-1,1,1,1,-1,1,1,-1,1,-1,-1,1,-1,-1,1,1,1,-1,-1,-1,1,-1,1,1,1,1,-1,-1,1,-1,1,-1,-1,-1,1,1,-1,-1,-1,-1,1,-1,-1,-1,-1,-1,1,1,1,1,1,1,-1,-1]
        self.phase_bw = phase_bw = 6.28/100.0
        self.payload_size = payload_size = 992
        self.noise_volt = noise_volt = 0.0001
        self.matched_filter = matched_filter = firdes.root_raised_cosine(nfilts, nfilts, 1, eb, int(11*sps*nfilts))
        self.freq_offset = freq_offset = 0
        self.freq_bw = freq_bw = 6.28/100.0
        self.excess_bw = excess_bw = 0.35
        self.eq_gain = eq_gain = 0.01
        self.delay = delay = 0
        self.arity = arity = 4

        ##################################################
        # Blocks
        ##################################################
        self.controls = Qt.QTabWidget()
        self.controls_widget_0 = Qt.QWidget()
        self.controls_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.controls_widget_0)
        self.controls_grid_layout_0 = Qt.QGridLayout()
        self.controls_layout_0.addLayout(self.controls_grid_layout_0)
        self.controls.addTab(self.controls_widget_0, "Channel")
        self.controls_widget_1 = Qt.QWidget()
        self.controls_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.controls_widget_1)
        self.controls_grid_layout_1 = Qt.QGridLayout()
        self.controls_layout_1.addLayout(self.controls_grid_layout_1)
        self.controls.addTab(self.controls_widget_1, "Receiver")
        self.top_grid_layout.addWidget(self.controls, 0,0,1,2)
        self._timing_loop_bw_layout = Qt.QVBoxLayout()
        self._timing_loop_bw_label = Qt.QLabel("Time: BW")
        self._timing_loop_bw_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._timing_loop_bw_slider.setRange(0.0, 0.2, 0.005)
        self._timing_loop_bw_slider.setValue(self.timing_loop_bw)
        self._timing_loop_bw_slider.setMinimumWidth(200)
        self._timing_loop_bw_slider.valueChanged.connect(self.set_timing_loop_bw)
        self._timing_loop_bw_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._timing_loop_bw_layout.addWidget(self._timing_loop_bw_label)
        self._timing_loop_bw_layout.addWidget(self._timing_loop_bw_slider)
        self.controls_grid_layout_1.addLayout(self._timing_loop_bw_layout,  0,0,1,1)
        self._time_offset_layout = Qt.QVBoxLayout()
        self._time_offset_tool_bar = Qt.QToolBar(self)
        self._time_offset_layout.addWidget(self._time_offset_tool_bar)
        self._time_offset_tool_bar.addWidget(Qt.QLabel("Timing Offset"+": "))
        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)
        self._time_offset_counter = qwt_counter_pyslot()
        self._time_offset_counter.setRange(0.999, 1.001, 0.0001)
        self._time_offset_counter.setNumButtons(2)
        self._time_offset_counter.setValue(self.time_offset)
        self._time_offset_tool_bar.addWidget(self._time_offset_counter)
        self._time_offset_counter.valueChanged.connect(self.set_time_offset)
        self._time_offset_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._time_offset_slider.setRange(0.999, 1.001, 0.0001)
        self._time_offset_slider.setValue(self.time_offset)
        self._time_offset_slider.setMinimumWidth(200)
        self._time_offset_slider.valueChanged.connect(self.set_time_offset)
        self._time_offset_layout.addWidget(self._time_offset_slider)
        self.controls_grid_layout_0.addLayout(self._time_offset_layout,  0,2,1,1)
        self.received = Qt.QTabWidget()
        self.received_widget_0 = Qt.QWidget()
        self.received_layout_0 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.received_widget_0)
        self.received_grid_layout_0 = Qt.QGridLayout()
        self.received_layout_0.addLayout(self.received_grid_layout_0)
        self.received.addTab(self.received_widget_0, "Constellation")
        self.received_widget_1 = Qt.QWidget()
        self.received_layout_1 = Qt.QBoxLayout(Qt.QBoxLayout.TopToBottom, self.received_widget_1)
        self.received_grid_layout_1 = Qt.QGridLayout()
        self.received_layout_1.addLayout(self.received_grid_layout_1)
        self.received.addTab(self.received_widget_1, "Symbols")
        self.top_grid_layout.addWidget(self.received, 2,0,1,1)
        self._phase_bw_layout = Qt.QVBoxLayout()
        self._phase_bw_label = Qt.QLabel("Phase: Bandwidth")
        self._phase_bw_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._phase_bw_slider.setRange(0.0, 1.0, 0.01)
        self._phase_bw_slider.setValue(self.phase_bw)
        self._phase_bw_slider.setMinimumWidth(200)
        self._phase_bw_slider.valueChanged.connect(self.set_phase_bw)
        self._phase_bw_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._phase_bw_layout.addWidget(self._phase_bw_label)
        self._phase_bw_layout.addWidget(self._phase_bw_slider)
        self.controls_grid_layout_1.addLayout(self._phase_bw_layout,  0,2,1,1)
        self._noise_volt_layout = Qt.QVBoxLayout()
        self._noise_volt_tool_bar = Qt.QToolBar(self)
        self._noise_volt_layout.addWidget(self._noise_volt_tool_bar)
        self._noise_volt_tool_bar.addWidget(Qt.QLabel("Noise Voltage"+": "))
        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)
        self._noise_volt_counter = qwt_counter_pyslot()
        self._noise_volt_counter.setRange(0, 1, 0.01)
        self._noise_volt_counter.setNumButtons(2)
        self._noise_volt_counter.setValue(self.noise_volt)
        self._noise_volt_tool_bar.addWidget(self._noise_volt_counter)
        self._noise_volt_counter.valueChanged.connect(self.set_noise_volt)
        self._noise_volt_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._noise_volt_slider.setRange(0, 1, 0.01)
        self._noise_volt_slider.setValue(self.noise_volt)
        self._noise_volt_slider.setMinimumWidth(200)
        self._noise_volt_slider.valueChanged.connect(self.set_noise_volt)
        self._noise_volt_layout.addWidget(self._noise_volt_slider)
        self.controls_grid_layout_0.addLayout(self._noise_volt_layout,  0,0,1,1)
        self._freq_offset_layout = Qt.QVBoxLayout()
        self._freq_offset_tool_bar = Qt.QToolBar(self)
        self._freq_offset_layout.addWidget(self._freq_offset_tool_bar)
        self._freq_offset_tool_bar.addWidget(Qt.QLabel("Frequency Offset"+": "))
        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)
        self._freq_offset_counter = qwt_counter_pyslot()
        self._freq_offset_counter.setRange(-0.1, 0.1, 0.001)
        self._freq_offset_counter.setNumButtons(2)
        self._freq_offset_counter.setValue(self.freq_offset)
        self._freq_offset_tool_bar.addWidget(self._freq_offset_counter)
        self._freq_offset_counter.valueChanged.connect(self.set_freq_offset)
        self._freq_offset_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._freq_offset_slider.setRange(-0.1, 0.1, 0.001)
        self._freq_offset_slider.setValue(self.freq_offset)
        self._freq_offset_slider.setMinimumWidth(200)
        self._freq_offset_slider.valueChanged.connect(self.set_freq_offset)
        self._freq_offset_layout.addWidget(self._freq_offset_slider)
        self.controls_grid_layout_0.addLayout(self._freq_offset_layout,  0,1,1,1)
        self._eq_gain_layout = Qt.QVBoxLayout()
        self._eq_gain_label = Qt.QLabel("Equalizer: rate")
        self._eq_gain_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._eq_gain_slider.setRange(0.0, 0.1, 0.001)
        self._eq_gain_slider.setValue(self.eq_gain)
        self._eq_gain_slider.setMinimumWidth(200)
        self._eq_gain_slider.valueChanged.connect(self.set_eq_gain)
        self._eq_gain_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._eq_gain_layout.addWidget(self._eq_gain_label)
        self._eq_gain_layout.addWidget(self._eq_gain_slider)
        self.controls_grid_layout_1.addLayout(self._eq_gain_layout,  0,1,1,1)
        self._delay_layout = Qt.QVBoxLayout()
        self._delay_tool_bar = Qt.QToolBar(self)
        self._delay_layout.addWidget(self._delay_tool_bar)
        self._delay_tool_bar.addWidget(Qt.QLabel("Delay"+": "))
        class qwt_counter_pyslot(Qwt.QwtCounter):
            def __init__(self, parent=None):
                Qwt.QwtCounter.__init__(self, parent)
            @pyqtSlot('double')
            def setValue(self, value):
                super(Qwt.QwtCounter, self).setValue(value)
        self._delay_counter = qwt_counter_pyslot()
        self._delay_counter.setRange(0, 200, 1)
        self._delay_counter.setNumButtons(2)
        self._delay_counter.setValue(self.delay)
        self._delay_tool_bar.addWidget(self._delay_counter)
        self._delay_counter.valueChanged.connect(self.set_delay)
        self._delay_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._delay_slider.setRange(0, 200, 1)
        self._delay_slider.setValue(self.delay)
        self._delay_slider.setMinimumWidth(200)
        self._delay_slider.valueChanged.connect(self.set_delay)
        self._delay_layout.addWidget(self._delay_slider)
        self.top_grid_layout.addLayout(self._delay_layout, 1,0,1,1)
        self.tutorial_my_qpsk_demod_cb_1 = tutorial.my_qpsk_demod_cb(True)
        self.qtgui_time_sink_x_0_0 = qtgui.time_sink_f(
        	500, #size
        	samp_rate, #samp_rate
        	"", #name
        	2 #number of inputs
        )
        self.qtgui_time_sink_x_0_0.set_update_time(0.10)
        self.qtgui_time_sink_x_0_0.set_y_axis(-1, 2)
        self.qtgui_time_sink_x_0_0.enable_tags(-1, True)
        self.qtgui_time_sink_x_0_0.set_trigger_mode(qtgui.TRIG_MODE_FREE, qtgui.TRIG_SLOPE_POS, 0.0, 0, 0, "")
        self.qtgui_time_sink_x_0_0.enable_autoscale(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", "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.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_time_sink_x_0_0.set_line_label(i, labels[i])
            self.qtgui_time_sink_x_0_0.set_line_width(i, widths[i])
            self.qtgui_time_sink_x_0_0.set_line_color(i, colors[i])
            self.qtgui_time_sink_x_0_0.set_line_style(i, styles[i])
            self.qtgui_time_sink_x_0_0.set_line_marker(i, markers[i])
            self.qtgui_time_sink_x_0_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_time_sink_x_0_0_win = sip.wrapinstance(self.qtgui_time_sink_x_0_0.pyqwidget(), Qt.QWidget)
        self.top_grid_layout.addWidget(self._qtgui_time_sink_x_0_0_win, 2,1,1,1)
        self.qtgui_time_sink_x_0 = qtgui.time_sink_f(
        	500, #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, 4)
        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)
        
        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.received_grid_layout_1.addWidget(self._qtgui_time_sink_x_0_win,  0,0,1,1)
        self.qtgui_const_sink_x_0 = qtgui.const_sink_c(
        	1024, #size
        	"", #name
        	1 #number of inputs
        )
        self.qtgui_const_sink_x_0.set_update_time(0.10)
        self.qtgui_const_sink_x_0.set_y_axis(-2, 2)
        self.qtgui_const_sink_x_0.set_x_axis(-2, 2)
        self.qtgui_const_sink_x_0.enable_autoscale(False)
        
        labels = ["", "", "", "", "",
                  "", "", "", "", ""]
        widths = [1, 1, 1, 1, 1,
                  1, 1, 1, 1, 1]
        colors = ["blue", "red", "red", "red", "red",
                  "red", "red", "red", "red", "red"]
        styles = [0, 0, 0, 0, 0,
                  0, 0, 0, 0, 0]
        markers = [0, 0, 0, 0, 0,
                   0, 0, 0, 0, 0]
        alphas = [1.0, 1.0, 1.0, 1.0, 1.0,
                  1.0, 1.0, 1.0, 1.0, 1.0]
        for i in xrange(1):
            if len(labels[i]) == 0:
                self.qtgui_const_sink_x_0.set_line_label(i, "Data {0}".format(i))
            else:
                self.qtgui_const_sink_x_0.set_line_label(i, labels[i])
            self.qtgui_const_sink_x_0.set_line_width(i, widths[i])
            self.qtgui_const_sink_x_0.set_line_color(i, colors[i])
            self.qtgui_const_sink_x_0.set_line_style(i, styles[i])
            self.qtgui_const_sink_x_0.set_line_marker(i, markers[i])
            self.qtgui_const_sink_x_0.set_line_alpha(i, alphas[i])
        
        self._qtgui_const_sink_x_0_win = sip.wrapinstance(self.qtgui_const_sink_x_0.pyqwidget(), Qt.QWidget)
        self.received_grid_layout_0.addWidget(self._qtgui_const_sink_x_0_win,  0,0,1,1)
        self._freq_bw_layout = Qt.QVBoxLayout()
        self._freq_bw_label = Qt.QLabel("Frequency Bandwidth")
        self._freq_bw_slider = Qwt.QwtSlider(None, Qt.Qt.Horizontal, Qwt.QwtSlider.BottomScale, Qwt.QwtSlider.BgSlot)
        self._freq_bw_slider.setRange(0.0, 1.0, 0.01)
        self._freq_bw_slider.setValue(self.freq_bw)
        self._freq_bw_slider.setMinimumWidth(200)
        self._freq_bw_slider.valueChanged.connect(self.set_freq_bw)
        self._freq_bw_label.setAlignment(Qt.Qt.AlignBottom | Qt.Qt.AlignHCenter)
        self._freq_bw_layout.addWidget(self._freq_bw_label)
        self._freq_bw_layout.addWidget(self._freq_bw_slider)
        self.controls_grid_layout_1.addLayout(self._freq_bw_layout,  0,3,1,1)
        self.digital_pfb_clock_sync_xxx_0 = digital.pfb_clock_sync_ccf(sps, timing_loop_bw, (rrc_taps), nfilts, nfilts/2, 1.5, 2)
        self.digital_map_bb_0 = digital.map_bb(([0,1,3,2]))
        self.digital_diff_decoder_bb_0 = digital.diff_decoder_bb(4)
        self.digital_costas_loop_cc_0 = digital.costas_loop_cc(phase_bw, arity)
        self.digital_correlate_and_sync_cc_0 = digital.correlate_and_sync_cc((preamble), (matched_filter), sps)
        self.digital_constellation_modulator_0 = digital.generic_mod(
          constellation=qpsk,
          differential=True,
          samples_per_symbol=sps,
          pre_diff_code=True,
          excess_bw=excess_bw,
          verbose=False,
          log=False,
          )
        self.digital_cma_equalizer_cc_0 = digital.cma_equalizer_cc(15, 1, eq_gain, 2)
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage=noise_volt,
        	frequency_offset=freq_offset,
        	epsilon=time_offset,
        	taps=(taps),
        	noise_seed=0,
        	block_tags=False
        )
        self.blocks_vector_source_x_0_0 = blocks.vector_source_b(map(lambda x: (-x+1)/2, preamble), True, 1, [])
        self.blocks_unpack_k_bits_bb_0_0 = blocks.unpack_k_bits_bb(8)
        self.blocks_unpack_k_bits_bb_0 = blocks.unpack_k_bits_bb(2)
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_stream_mux_0_0_0 = blocks.stream_mux(gr.sizeof_char*1, (len(preamble)/8,payload_size))
        self.blocks_pack_k_bits_bb_1 = blocks.pack_k_bits_bb(8)
        self.blocks_pack_k_bits_bb_0 = blocks.pack_k_bits_bb(8)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*1)
        self.blocks_file_source_0 = blocks.file_source(gr.sizeof_char*1, "/home/franchz/tcc/gnuradio/tx_teste.txt", True)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, "/home/franchz/tcc/gnuradio/rx_teste.txt", False)
        self.blocks_file_sink_0.set_unbuffered(False)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_float*1, int(delay))
        self.blocks_char_to_float_0_0_0 = blocks.char_to_float(1, 1)
        self.blocks_char_to_float_0_0 = blocks.char_to_float(1, 1)
        self.blocks_char_to_float_0 = blocks.char_to_float(1, 1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_throttle_0, 0), (self.channels_channel_model_0, 0))
        self.connect((self.digital_costas_loop_cc_0, 0), (self.qtgui_const_sink_x_0, 0))
        self.connect((self.blocks_char_to_float_0, 0), (self.qtgui_time_sink_x_0, 0))
        self.connect((self.digital_cma_equalizer_cc_0, 0), (self.digital_costas_loop_cc_0, 0))
        self.connect((self.digital_pfb_clock_sync_xxx_0, 0), (self.digital_cma_equalizer_cc_0, 0))
        self.connect((self.blocks_unpack_k_bits_bb_0_0, 0), (self.blocks_char_to_float_0_0_0, 0))
        self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_char_to_float_0_0, 0))
        self.connect((self.blocks_vector_source_x_0_0, 0), (self.blocks_pack_k_bits_bb_0, 0))
        self.connect((self.blocks_pack_k_bits_bb_0, 0), (self.blocks_stream_mux_0_0_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.digital_correlate_and_sync_cc_0, 0))
        self.connect((self.digital_correlate_and_sync_cc_0, 0), (self.digital_pfb_clock_sync_xxx_0, 0))
        self.connect((self.digital_correlate_and_sync_cc_0, 1), (self.blocks_null_sink_0, 0))
        self.connect((self.blocks_file_source_0, 0), (self.blocks_stream_mux_0_0_0, 1))
        self.connect((self.blocks_file_source_0, 0), (self.blocks_unpack_k_bits_bb_0_0, 0))
        self.connect((self.blocks_char_to_float_0_0, 0), (self.qtgui_time_sink_x_0_0, 1))
        self.connect((self.blocks_char_to_float_0_0_0, 0), (self.blocks_delay_0, 0))
        self.connect((self.blocks_delay_0, 0), (self.qtgui_time_sink_x_0_0, 0))
        self.connect((self.blocks_pack_k_bits_bb_1, 0), (self.blocks_file_sink_0, 0))
        self.connect((self.blocks_unpack_k_bits_bb_0, 0), (self.blocks_pack_k_bits_bb_1, 0))
        self.connect((self.blocks_stream_mux_0_0_0, 0), (self.digital_constellation_modulator_0, 0))
        self.connect((self.digital_constellation_modulator_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.tutorial_my_qpsk_demod_cb_1, 0), (self.digital_map_bb_0, 0))
        self.connect((self.digital_map_bb_0, 0), (self.digital_diff_decoder_bb_0, 0))
        self.connect((self.digital_costas_loop_cc_0, 0), (self.tutorial_my_qpsk_demod_cb_1, 0))
        self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_char_to_float_0, 0))
        self.connect((self.digital_diff_decoder_bb_0, 0), (self.blocks_unpack_k_bits_bb_0, 0))
Esempio n. 52
0
    def __init__(self, M=1024, K=4, syms_per_frame=10, exclude_multipath=0, sel_taps=0, freq_offset=0, exclude_noise=0, sel_noise_type=0, SNR=20, exclude_preamble=0, sel_preamble=0, zero_pads=1, extra_pad=False):
        gr.hier_block2.__init__(self,
            "fbmc_channel_hier_cc",
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
            gr.io_signature(1, 1, gr.sizeof_gr_complex*1),
        )

        ##################################################
        # Parameters
        ##################################################
        self.freq_offset = freq_offset
        self.sel_noise_type = sel_noise_type
        self.sel_taps = sel_taps
        self.SNR = SNR
        self.exclude_multipath = exclude_multipath
        self.exclude_noise = exclude_noise
        self.exclude_preamble = exclude_preamble
        self.K = K
        self.M = M
        self.syms_per_frame = syms_per_frame
        self.zero_pads =zero_pads

        ##################################################
        # Variables
        ##################################################
        self.taps = taps = (1)
        if sel_taps == 0: #epa
            self.taps = taps = (0.998160541385960,0.0605566335500750,0.00290305927764350)
        elif sel_taps == 1: #eva
            self.taps = taps = (0.748212004186014,0.317358833370450,0.572776845645705,0,0.0538952624324030,0.0874078808126807,0,0,0,0.0276407988816600,0,0,0,0.00894438719057275)
        elif sel_taps ==2: #etu
            self.taps = taps = (0.463990169152204,0.816124099344485,0,0.292064507384192,0,0,0,0,0.146379002496595,0,0,0,0.0923589067029112,0,0,0,0,0,0,0,0,0,0,0,0,0.0582745305123628)
        
        self.noise_type = analog.GR_GAUSSIAN
        if sel_noise_type == 200:
            self.noise_type = analog.GR_UNIFORM
        elif sel_noise_type ==201:
            self.noise_type = analog.GR_GAUSSIAN
        elif sel_noise_type == 202:
            self.noise_type = analog.GR_LAPLACIAN
        elif sel_noise_type ==203:
            self.noise_type = analog.GR_IMPULSE

        if sel_preamble == 0: # standard one vector center preamble [1,-j,-1,j]
            self.num_center_vectors = num_center_vectors = 1
        elif sel_preamble == 1: # standard preamble with triple repetition
            self.num_center_vectors = num_center_vectors = 3
        elif sel_preamble ==2: # IAM-R preamble [1, -1,-1, 1]
            self.num_center_vectors = num_center_vectors = 1
        else: # standard one vector center preamble [1,-j,-1,j]
            self.num_center_vectors = num_center_vectors = 1

        if extra_pad:
            self.total_zeros = total_zeros = 1+2*zero_pads
        else:
            self.total_zeros = total_zeros = 2*zero_pads

        

        # normalizing factor to be added if normalization takes place in transmitter
        self.normalizing_factor = float(1)/(M*.6863)
        if exclude_preamble:
            self.amp = self.normalizing_factor*math.sqrt((10**(float(-1*SNR)/10))*(2*K*M+(2*syms_per_frame-1)*M)/(4*syms_per_frame))/math.sqrt(2)
        else:
            syms_per_frame_2 = syms_per_frame + (self.num_center_vectors+self.total_zeros)/2
            self.amp = self.normalizing_factor*math.sqrt((10**(float(-1*SNR)/10))*(M*(syms_per_frame+self.num_center_vectors)/(syms_per_frame+self.num_center_vectors+self.total_zeros))*((K*M+(2*syms_per_frame_2-1)*M/2)/(M*syms_per_frame_2)))/math.sqrt(2)
            # self.amp = self.normalizing_factor*math.sqrt((10**(float(-1*SNR)/10))*(M*(syms_per_frame+self.num_center_vectors)/(syms_per_frame+self.num_center_vectors+self.total_zeros))*((K*M+(2*syms_per_frame-1)*M/2)/(M*syms_per_frame)))/math.sqrt(2)

        ##################################################
        # Blocks
        ##################################################
        self.channels_channel_model_0 = channels.channel_model(
            noise_voltage=0.0,
            frequency_offset=freq_offset,
            epsilon=1.0,
            taps=taps,
            noise_seed=0,
            block_tags=False
        )
        self.blocks_null_source_0 = blocks.null_source(gr.sizeof_gr_complex*1)
        self.blocks_add_xx_0 = blocks.add_vcc(1)
        self.blks2_selector_1 = grc_blks2.selector(
            item_size=gr.sizeof_gr_complex*1,
            num_inputs=2,
            num_outputs=1,
            input_index=exclude_noise,
            output_index=0,
        )
        self.blks2_selector_0 = grc_blks2.selector(
            item_size=gr.sizeof_gr_complex*1,
            num_inputs=2,
            num_outputs=1,
            input_index=exclude_multipath,
            output_index=0,
        )
        self.analog_fastnoise_source_x_0 = analog.fastnoise_source_c(self.noise_type, self.amp, 0, 8192)

        ##################################################
        # Connections
        ##################################################
        self.connect((self, 0), (self.channels_channel_model_0, 0))
        self.connect((self, 0), (self.blks2_selector_0, 1))
        self.connect((self.channels_channel_model_0, 0), (self.blks2_selector_0, 0))
        self.connect((self.blks2_selector_0, 0), (self.blocks_add_xx_0, 0))
        self.connect((self.analog_fastnoise_source_x_0, 0), (self.blks2_selector_1, 0))
        self.connect((self.blocks_null_source_0, 0), (self.blks2_selector_1, 1))
        self.connect((self.blks2_selector_1, 0), (self.blocks_add_xx_0, 1))
        self.connect((self.blocks_add_xx_0, 0), (self, 0))
Esempio n. 53
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Top Block")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000
        self.noise_volt = noise_volt = 10e-3
        self.mult_const = mult_const = 1
        self.cutoff = cutoff = 10.7e3

        ##################################################
        # Blocks
        ##################################################
        _noise_volt_sizer = wx.BoxSizer(wx.VERTICAL)
        self._noise_volt_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_noise_volt_sizer,
        	value=self.noise_volt,
        	callback=self.set_noise_volt,
        	label="Noise Voltage",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._noise_volt_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_noise_volt_sizer,
        	value=self.noise_volt,
        	callback=self.set_noise_volt,
        	minimum=0,
        	maximum=1,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_noise_volt_sizer)
        _mult_const_sizer = wx.BoxSizer(wx.VERTICAL)
        self._mult_const_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_mult_const_sizer,
        	value=self.mult_const,
        	callback=self.set_mult_const,
        	label="Amplifier",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._mult_const_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_mult_const_sizer,
        	value=self.mult_const,
        	callback=self.set_mult_const,
        	minimum=0,
        	maximum=2,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_mult_const_sizer)
        _cutoff_sizer = wx.BoxSizer(wx.VERTICAL)
        self._cutoff_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_cutoff_sizer,
        	value=self.cutoff,
        	callback=self.set_cutoff,
        	label="Cutoff Frequency",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._cutoff_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_cutoff_sizer,
        	value=self.cutoff,
        	callback=self.set_cutoff,
        	minimum=5e3,
        	maximum=16e3,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_cutoff_sizer)
        self.wxgui_fftsink2_0_0 = fftsink2.fft_sink_c(
        	self.GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Tx",
        	peak_hold=False,
        )
        self.Add(self.wxgui_fftsink2_0_0.win)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
        	self.GetWin(),
        	baseband_freq=0,
        	y_per_div=10,
        	y_divs=10,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=samp_rate,
        	fft_size=1024,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Rx",
        	peak_hold=False,
        )
        self.Add(self.wxgui_fftsink2_0.win)
        self.low_pass_filter_0 = filter.fir_filter_ccf(1, firdes.low_pass(
        	1, samp_rate, cutoff, 100, firdes.WIN_HAMMING, 6.76))
        self.digital_gfsk_mod_0 = digital.gfsk_mod(
        	samples_per_symbol=2,
        	sensitivity=1.0,
        	bt=0.35,
        	verbose=False,
        	log=False,
        )
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage=noise_volt,
        	frequency_offset=0.0,
        	epsilon=1.0,
        	taps=(1.0 + 1.0j, ),
        	noise_seed=42,
        	block_tags=False
        )
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex*1, samp_rate,True)
        self.blocks_multiply_xx_1 = blocks.multiply_vcc(1)
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc((mult_const, ))
        self.blks2_packet_encoder_0 = grc_blks2.packet_mod_b(grc_blks2.packet_encoder(
        		samples_per_symbol=2,
        		bits_per_symbol=1,
        		preamble="",
        		access_code="",
        		pad_for_usrp=True,
        	),
        	payload_length=0,
        )
        self.analog_sig_source_x_0 = analog.sig_source_c(samp_rate, analog.GR_SIN_WAVE, 10000, 1, 0)
        self.analog_random_source_x_0 = blocks.vector_source_b(map(int, numpy.random.randint(0, 256, 512)), True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.blocks_throttle_0, 0), (self.wxgui_fftsink2_0, 0))
        self.connect((self.analog_random_source_x_0, 0), (self.blks2_packet_encoder_0, 0))
        self.connect((self.blks2_packet_encoder_0, 0), (self.digital_gfsk_mod_0, 0))
        self.connect((self.blocks_multiply_xx_0, 0), (self.blocks_multiply_const_vxx_0, 0))
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.channels_channel_model_0, 0))
        self.connect((self.digital_gfsk_mod_0, 0), (self.low_pass_filter_0, 0))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.low_pass_filter_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.blocks_multiply_xx_1, 0))
        self.connect((self.blocks_multiply_xx_1, 0), (self.blocks_throttle_0, 0))
        self.connect((self.analog_sig_source_x_0, 0), (self.blocks_multiply_xx_1, 1))
        self.connect((self.blocks_multiply_xx_0, 0), (self.wxgui_fftsink2_0_0, 0))
Esempio n. 54
0
    def __init__(self,q_rx,q_tx,noise_voltage=0.01,frequency_offset=0.01,epsilon=1.001,taps=(1+0.5j, ),):
        '''Constructor.
        
        @param q_rx:
        '''
	samp_per_sym =5
        gr.top_block.__init__(self)
        self.sink_queue = gr.msg_queue()
        #self.Add(self.wxgui_scopesink2_0_0.win)
        self.hier_rx_0 = hier_rx.hier_rx(
            bw_clock_sync=2*math.pi/5,
            bw_fll=math.pi/400,
            bits_per_sym=2,
            bw_costas=2*math.pi/100,
            n_filts=32,
            len_sym_srrc=7,
            constellation=digital.constellation_calcdist([-1-1j, 1-1j, 1+1j, -1+1j], [], 4, 1).base(),
            samp_per_sym=samp_per_sym,
            alfa=0.35,
        )
        
        
        self.hier_tx_0 = hier_tx.hier_tx(
            alfa=0.35,
            samp_per_sym=samp_per_sym,
            bits_per_sym=2,
            constellation=[-1-1j,1-1j, 1+1j, -1+1j],
            len_sym_srrc=7,
            out_const_mul=0.4,
        )

        #self.hier_rx_0 = hier_rx()
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage,
        	frequency_offset,
        	epsilon,
        	taps,
        	noise_seed=0,
        	block_tags=False
        )
        threshold = 12              # FIXME raise exception
        access_code = packet_utils.default_access_code
        

        self.blocks_message_source_0 = blocks.message_source(gr.sizeof_char*1, 4)
        self._rcvd_pktq = gr.msg_queue()          # holds packets from the PHY
        self.correlator = digital.correlate_access_code_bb( access_code, threshold)
        #"Arreglar access_code en la llamada a correlate""""""
        self.framer_sink = digital.framer_sink_1(self._rcvd_pktq)
        
        self.vsnk_src = blocks.vector_sink_b()
        self.m_sink   = blocks.message_sink(gr.sizeof_char*1, self.sink_queue,True)
        ##################################################
        # Connections
        ##################################################
        #self.connect((self.hier_tx_pencoder_0, 0), (self.wxgui_scopesink2_0_0, 0))
        self.connect(( self.blocks_message_source_0, 0),(self.hier_tx_0, 0) )
        self.connect((self.hier_tx_0, 0), (self.channels_channel_model_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.hier_rx_0, 0))        
        self.connect((self.hier_rx_0, 0), self.correlator, self.framer_sink)
        self._watcher = _queue_watcher_thread(self._rcvd_pktq,q_rx)
        queue = self.blocks_message_source_0.msgq()
        self.snd = SendData(q_tx,queue,samp_per_sym)   
Esempio n. 55
0
    def __init__(self, chan_est=1, encoding=0, freq_offset=0, interval=500, pdu_length=500, snr=10):
        gr.top_block.__init__(self, "Wifi Loopback")

        ##################################################
        # Parameters
        ##################################################
        self.chan_est = chan_est
        self.encoding = encoding
        self.freq_offset = freq_offset
        self.interval = interval
        self.pdu_length = pdu_length
        self.snr = snr

        ##################################################
        # Variables
        ##################################################
        self.out_buf_size = out_buf_size = 96000

        ##################################################
        # Blocks
        ##################################################
        self.wifi_phy_hier_0 = wifi_phy_hier(
            encoding=encoding,
            chan_est=chan_est,
        )
        self.ieee802_11_ofdm_parse_mac_0 = ieee802_11.ofdm_parse_mac(False, True)
        self.ieee802_11_ofdm_mac_0 = ieee802_11.ofdm_mac(([0x23, 0x23, 0x23, 0x23, 0x23, 0x23]), ([0x42, 0x42, 0x42, 0x42, 0x42, 0x42]), ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff]))
        self.foo_wireshark_connector_0 = foo.wireshark_connector(127, False)
        self.foo_packet_pad2_0 = foo.packet_pad2(False, False, 0.001, 500, 0)
        (self.foo_packet_pad2_0).set_min_output_buffer(96000)
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage=.5**.5,
        	frequency_offset=freq_offset,
        	epsilon=1.0,
        	taps=(1.0, ),
        	noise_seed=0,
        	block_tags=False
        )
        self.blocks_pdu_to_tagged_stream_0 = blocks.pdu_to_tagged_stream(blocks.float_t, "packet_len")
        self.blocks_null_sink_1 = blocks.null_sink(gr.sizeof_float*1)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_gr_complex*1)
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc(((10**(snr/10.0))**.5, ))
        self.blocks_message_strobe_0 = blocks.message_strobe(pmt.intern("".join("x" for i in range(pdu_length))), interval)
        self.blocks_file_sink_0 = blocks.file_sink(gr.sizeof_char*1, "/tmp/sim.csv", False)
        self.blocks_file_sink_0.set_unbuffered(True)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.blocks_message_strobe_0, 'strobe'), (self.foo_wireshark_connector_0, 'in'))    
        self.msg_connect((self.blocks_message_strobe_0, 'strobe'), (self.ieee802_11_ofdm_mac_0, 'app in'))    
        self.msg_connect((self.ieee802_11_ofdm_mac_0, 'phy out'), (self.wifi_phy_hier_0, 'mac_in'))    
        self.msg_connect((self.ieee802_11_ofdm_parse_mac_0, 'fer'), (self.blocks_pdu_to_tagged_stream_0, 'pdus'))    
        self.msg_connect((self.wifi_phy_hier_0, 'mac_out'), (self.foo_wireshark_connector_0, 'in'))    
        self.msg_connect((self.wifi_phy_hier_0, 'mac_out'), (self.ieee802_11_ofdm_parse_mac_0, 'in'))    
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.channels_channel_model_0, 0))    
        self.connect((self.blocks_pdu_to_tagged_stream_0, 0), (self.blocks_null_sink_1, 0))    
        self.connect((self.channels_channel_model_0, 0), (self.wifi_phy_hier_0, 0))    
        self.connect((self.foo_packet_pad2_0, 0), (self.blocks_multiply_const_vxx_0, 0))    
        self.connect((self.foo_wireshark_connector_0, 0), (self.blocks_file_sink_0, 0))    
        self.connect((self.wifi_phy_hier_0, 1), (self.blocks_null_sink_0, 0))    
        self.connect((self.wifi_phy_hier_0, 0), (self.foo_packet_pad2_0, 0))    
Esempio n. 56
0
	def __init__(self, name='Simulated Source', freq=0):
		Source.__init__(self, name=name)
		
		audio_rate = 1e4
		rf_rate = self.__sample_rate = 200e3
		interp = int(rf_rate / audio_rate)
		
		self.__freq = freq
		self.noise_level = -2
		
		interp_taps = firdes.low_pass(
			1,  # gain
			rf_rate,
			audio_rate / 2,
			audio_rate * 0.2,
			firdes.WIN_HAMMING)
		
		def make_interpolator():
			return filter.interp_fir_filter_ccf(interp, interp_taps)
		
		def make_channel(freq):
			osc = analog.sig_source_c(rf_rate, analog.GR_COS_WAVE, freq, 1, 0)
			mult = blocks.multiply_cc(1)
			self.connect(osc, (mult, 1))
			return mult
		
		self.bus = blocks.add_vcc(1)
		self.channel_model = channels.channel_model(
			noise_voltage=10 ** self.noise_level,
			frequency_offset=0,
			epsilon=1.01,  # TODO: expose this parameter
			#taps=...,  # TODO: apply something here?
			)
		self.throttle = blocks.throttle(gr.sizeof_gr_complex, rf_rate)
		self.connect(
			self.bus,
			self.channel_model,
			self.throttle,
			self)
		signals = []
		
		# Audio input signal
		pitch = analog.sig_source_f(audio_rate, analog.GR_SAW_WAVE, -1, 2000, 1000)
		audio_signal = vco = blocks.vco_f(audio_rate, 1, 1)
		self.connect(pitch, vco)
		
		# Baseband / DSB channel
		baseband_interp = make_interpolator()
		self.connect(
			audio_signal,
			blocks.float_to_complex(1),
			baseband_interp)
		signals.append(baseband_interp)
		
		# AM channel
		am_channel = make_channel(10e3)
		self.connect(
			audio_signal,
			blocks.float_to_complex(1),
			blocks.add_const_cc(1),
			make_interpolator(),
			am_channel)
		signals.append(am_channel)
		
		# NFM channel
		nfm_channel = make_channel(30e3)
		self.connect(
			audio_signal,
			analog.nbfm_tx(
				audio_rate=audio_rate,
				quad_rate=rf_rate,
				tau=75e-6,
				max_dev=5e3),
			nfm_channel)
		signals.append(nfm_channel)
		
		# VOR channels
		# TODO: My signal level parameters are probably wrong because this signal doesn't look like a real VOR signal
		def add_vor(freq, angle):
			compensation = math.pi / 180 * -6.5  # empirical, calibrated against VOR receiver (and therefore probably wrong)
			angle = angle + compensation
			angle = angle % (2 * math.pi)
			vor_sig_freq = 30
			phase_shift = int(rf_rate / vor_sig_freq * (angle / (2 * math.pi)))
			vor_dev = 480
			vor_channel = make_channel(freq)
			vor_30 = analog.sig_source_f(audio_rate, analog.GR_COS_WAVE, vor_sig_freq, 1, 0)
			vor_add = blocks.add_cc(1)
			vor_audio = blocks.add_ff(1)
			# Audio/AM signal
			self.connect(
				vor_30,
				blocks.multiply_const_ff(0.3),  # M_n
				(vor_audio, 0))
			self.connect(audio_signal,
				blocks.multiply_const_ff(0.07),  # M_i
				(vor_audio, 1))
			# Carrier component
			self.connect(
				analog.sig_source_c(0, analog.GR_CONST_WAVE, 0, 0, 1),
				(vor_add, 0))
			# AM component
			self.connect(
				vor_audio,
				blocks.float_to_complex(1),
				make_interpolator(),
				blocks.delay(gr.sizeof_gr_complex, phase_shift),
				(vor_add, 1))
			# FM component
			vor_fm_mult = blocks.multiply_cc(1)
			self.connect(  # carrier generation
				analog.sig_source_f(rf_rate, analog.GR_COS_WAVE, 9960, 1, 0), 
				blocks.float_to_complex(1),
				(vor_fm_mult, 1))
			self.connect(  # modulation
				vor_30,
				filter.interp_fir_filter_fff(interp, interp_taps),  # float not complex
				analog.frequency_modulator_fc(2 * math.pi * vor_dev / rf_rate),
				blocks.multiply_const_cc(0.3),  # M_d
				vor_fm_mult,
				(vor_add, 2))
			self.connect(
				vor_add,
				vor_channel)
			signals.append(vor_channel)
		add_vor(-30e3, 0)
		add_vor(-60e3, math.pi / 2)
		
		bus_input = 0
		for signal in signals:
			self.connect(signal, (self.bus, bus_input))
			bus_input = bus_input + 1
Esempio n. 57
0
    def __init__(
        self, ipp1="127.0.0.1", ipp2="127.0.0.1", ipp3="127.0.0.1", ipp4="127.0.0.1", iptx="127.0.0.1", samp_rate=1000
    ):
        gr.top_block.__init__(self, "OFDM Rx")

        ##################################################
        # Parameters
        ##################################################
        self.ipp1 = ipp1
        self.ipp2 = ipp2
        self.ipp3 = ipp3
        self.ipp4 = ipp4
        self.iptx = iptx
        self.samp_rate = samp_rate

        ##################################################
        # 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.0,
            0.0,
            0.0,
            0.0,
            1.41421356,
            0.0,
            -1.41421356,
            0.0,
            1.41421356,
            0.0,
            -1.41421356,
            0.0,
            -1.41421356,
            0.0,
            -1.41421356,
            0.0,
            1.41421356,
            0.0,
            -1.41421356,
            0.0,
            1.41421356,
            0.0,
            -1.41421356,
            0.0,
            -1.41421356,
            0.0,
            -1.41421356,
            0.0,
            -1.41421356,
            0.0,
            1.41421356,
            0.0,
            -1.41421356,
            0.0,
            1.41421356,
            0.0,
            1.41421356,
            0.0,
            1.41421356,
            0.0,
            -1.41421356,
            0.0,
            1.41421356,
            0.0,
            1.41421356,
            0.0,
            1.41421356,
            0.0,
            -1.41421356,
            0.0,
            1.41421356,
            0.0,
            1.41421356,
            0.0,
            1.41421356,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
            0.0,
        ]
        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
        )

        ##################################################
        # Blocks
        ##################################################
        self.zeromq_push_sink_0_0_1_0_0 = zeromq.push_sink(gr.sizeof_char, 1, "tcp://" + ipp3 + ":55530", 100, True)
        self.zeromq_push_sink_0_0_1_0 = zeromq.push_sink(
            gr.sizeof_gr_complex, 64, "tcp://" + ipp2 + ":55521", 100, True
        )
        self.zeromq_push_sink_0_0_1 = zeromq.push_sink(gr.sizeof_gr_complex, 64, "tcp://" + ipp2 + ":55520", 100, True)
        self.zeromq_push_sink_0_0_0 = zeromq.push_sink(gr.sizeof_char, 1, "tcp://" + ipp1 + ":55511", 100, True)
        self.zeromq_push_sink_0_0 = zeromq.push_sink(gr.sizeof_gr_complex, 1, "tcp://" + ipp1 + ":55510", 100, True)
        self.zeromq_push_sink_0 = zeromq.push_sink(gr.sizeof_gr_complex, 1, "tcp://" + iptx + ":55500", 100, True)
        self.zeromq_pull_source_0_0_0_0_0_0 = zeromq.pull_source(
            gr.sizeof_gr_complex, 64, "tcp://" + ipp2 + ":55521", 100, True
        )
        self.zeromq_pull_source_0_0_0_0_0 = zeromq.pull_source(
            gr.sizeof_gr_complex, 64, "tcp://" + ipp2 + ":55520", 100, True
        )
        self.zeromq_pull_source_0_0_0_0 = zeromq.pull_source(gr.sizeof_char, 1, "tcp://" + ipp3 + ":55530", 100, True)
        self.zeromq_pull_source_0_0_0 = zeromq.pull_source(gr.sizeof_char, 1, "tcp://" + ipp1 + ":55511", 100, True)
        self.zeromq_pull_source_0_0 = zeromq.pull_source(gr.sizeof_gr_complex, 1, "tcp://" + ipp1 + ":55510", 100, True)
        self.zeromq_pull_source_0 = zeromq.pull_source(gr.sizeof_gr_complex, 1, "tcp://" + iptx + ":55500", 100, True)
        self.my_random_source_limit_rate_0 = my.random_source_limit_rate(1000)
        self.my_number_sync_timestamp_0 = my.number_sync_timestamp()
        self.fft_vxx_1 = fft.fft_vcc(fft_len, True, (), True, 1)
        self.fft_vxx_0 = fft.fft_vcc(fft_len, True, (()), True, 1)
        self.digital_packet_headerparser_b_0 = digital.packet_headerparser_b(header_formatter.base())
        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_sync_sc_cfb_0 = digital.ofdm_sync_sc_cfb(fft_len, fft_len / 4, False)
        self.digital_ofdm_serializer_vcc_payload = digital.ofdm_serializer_vcc(
            fft_len, occupied_carriers, length_tag_key, packet_length_tag_key, 1, "", True
        )
        self.digital_ofdm_serializer_vcc_header = digital.ofdm_serializer_vcc(
            fft_len, occupied_carriers, length_tag_key, "", 0, "", True
        )
        self.digital_ofdm_frame_equalizer_vcvc_1 = digital.ofdm_frame_equalizer_vcvc(
            payload_equalizer.base(), fft_len / 4, length_tag_key, True, 0
        )
        self.digital_ofdm_frame_equalizer_vcvc_0 = digital.ofdm_frame_equalizer_vcvc(
            header_equalizer.base(), fft_len / 4, length_tag_key, True, 1
        )
        self.digital_ofdm_chanest_vcvc_0 = digital.ofdm_chanest_vcvc((sync_word1), (sync_word2), 1, 0, 3, False)
        self.digital_header_payload_demux_0 = digital.header_payload_demux(
            3, fft_len, fft_len / 4, length_tag_key, "", True, gr.sizeof_gr_complex, "rx_time", samp_rate, ()
        )
        self.digital_crc32_bb_0 = digital.crc32_bb(True, packet_length_tag_key, True)
        self.digital_constellation_decoder_cb_1 = digital.constellation_decoder_cb(payload_mod.base())
        self.digital_constellation_decoder_cb_0 = digital.constellation_decoder_cb(header_mod.base())
        self.channels_channel_model_0 = channels.channel_model(
            noise_voltage=0.1,
            frequency_offset=0 * 1.0 / fft_len,
            epsilon=1.0,
            taps=(1.0,),
            noise_seed=0,
            block_tags=True,
        )
        self.blocks_throttle_0 = blocks.throttle(gr.sizeof_gr_complex * 1, samp_rate, True)
        self.blocks_tag_debug_1 = blocks.tag_debug(gr.sizeof_char * 1, "Rx Bytes", "")
        self.blocks_tag_debug_1.set_display(True)
        self.blocks_stream_to_tagged_stream_0 = blocks.stream_to_tagged_stream(
            gr.sizeof_char, 1, packet_len, packet_length_tag_key
        )
        self.blocks_repack_bits_bb_0 = blocks.repack_bits_bb(
            payload_mod.bits_per_symbol(), 8, packet_length_tag_key, True, gr.GR_LSB_FIRST
        )
        self.blocks_multiply_xx_0 = blocks.multiply_vcc(1)
        self.blocks_delay_0 = blocks.delay(gr.sizeof_gr_complex * 1, fft_len + fft_len / 4)
        self.analog_frequency_modulator_fc_0 = analog.frequency_modulator_fc(-2.0 / fft_len)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect(
            (self.digital_packet_headerparser_b_0, "header_data"), (self.digital_header_payload_demux_0, "header_data")
        )
        self.connect((self.analog_frequency_modulator_fc_0, 0), (self.blocks_multiply_xx_0, 0))
        self.connect((self.blocks_delay_0, 0), (self.blocks_multiply_xx_0, 1))
        self.connect((self.blocks_multiply_xx_0, 0), (self.zeromq_push_sink_0_0, 0))
        self.connect((self.blocks_repack_bits_bb_0, 0), (self.digital_crc32_bb_0, 0))
        self.connect((self.blocks_stream_to_tagged_stream_0, 0), (self.digital_ofdm_tx_0, 0))
        self.connect((self.blocks_throttle_0, 0), (self.zeromq_push_sink_0, 0))
        self.connect((self.channels_channel_model_0, 0), (self.blocks_throttle_0, 0))
        self.connect((self.digital_constellation_decoder_cb_0, 0), (self.zeromq_push_sink_0_0_1_0_0, 0))
        self.connect((self.digital_constellation_decoder_cb_1, 0), (self.blocks_repack_bits_bb_0, 0))
        self.connect((self.digital_crc32_bb_0, 0), (self.blocks_tag_debug_1, 0))
        self.connect((self.digital_crc32_bb_0, 0), (self.my_number_sync_timestamp_0, 0))
        self.connect((self.digital_header_payload_demux_0, 0), (self.zeromq_push_sink_0_0_1, 0))
        self.connect((self.digital_header_payload_demux_0, 1), (self.zeromq_push_sink_0_0_1_0, 0))
        self.connect((self.digital_ofdm_chanest_vcvc_0, 0), (self.digital_ofdm_frame_equalizer_vcvc_0, 0))
        self.connect((self.digital_ofdm_frame_equalizer_vcvc_0, 0), (self.digital_ofdm_serializer_vcc_header, 0))
        self.connect((self.digital_ofdm_frame_equalizer_vcvc_1, 0), (self.digital_ofdm_serializer_vcc_payload, 0))
        self.connect((self.digital_ofdm_serializer_vcc_header, 0), (self.digital_constellation_decoder_cb_0, 0))
        self.connect((self.digital_ofdm_serializer_vcc_payload, 0), (self.digital_constellation_decoder_cb_1, 0))
        self.connect((self.digital_ofdm_sync_sc_cfb_0, 0), (self.analog_frequency_modulator_fc_0, 0))
        self.connect((self.digital_ofdm_sync_sc_cfb_0, 1), (self.zeromq_push_sink_0_0_0, 0))
        self.connect((self.digital_ofdm_tx_0, 0), (self.channels_channel_model_0, 0))
        self.connect((self.fft_vxx_0, 0), (self.digital_ofdm_chanest_vcvc_0, 0))
        self.connect((self.fft_vxx_1, 0), (self.digital_ofdm_frame_equalizer_vcvc_1, 0))
        self.connect((self.my_random_source_limit_rate_0, 0), (self.blocks_stream_to_tagged_stream_0, 0))
        self.connect((self.zeromq_pull_source_0, 0), (self.blocks_delay_0, 0))
        self.connect((self.zeromq_pull_source_0, 0), (self.digital_ofdm_sync_sc_cfb_0, 0))
        self.connect((self.zeromq_pull_source_0_0, 0), (self.digital_header_payload_demux_0, 0))
        self.connect((self.zeromq_pull_source_0_0_0, 0), (self.digital_header_payload_demux_0, 1))
        self.connect((self.zeromq_pull_source_0_0_0_0, 0), (self.digital_packet_headerparser_b_0, 0))
        self.connect((self.zeromq_pull_source_0_0_0_0_0, 0), (self.fft_vxx_0, 0))
        self.connect((self.zeromq_pull_source_0_0_0_0_0_0, 0), (self.fft_vxx_1, 0))
Esempio n. 58
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="cdma_txrx")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.N0est = N0est = 1.0
        self.Esest = Esest = 1e-1
        self.EsN0dB_est = EsN0dB_est = 10*numpy.log10( cp.epsilon+ abs(Esest)/ (abs(N0est)+cp.epsilon) ) 
        self.symbol_rate = symbol_rate = 100e3
        self.DataEsN0dBthreshold = DataEsN0dBthreshold = 10
        self.DataEsN0dB_est = DataEsN0dB_est = EsN0dB_est + 10*numpy.log10( 1.0-cp.training_percent/100.0 ) 
        self.samp_rate = samp_rate = symbol_rate*cp.chips_per_symbol
        self.onoff_manual = onoff_manual = 1
        self.onoff_auto = onoff_auto = 0 if DataEsN0dB_est>DataEsN0dBthreshold else 1
        self.manual = manual = 1
        self.onoff = onoff = onoff_auto if manual==0 else onoff_manual
        self.freq_acq_est = freq_acq_est = 0
        self.df = df = cp.df*samp_rate
        self.TrainingEsN0dB_est = TrainingEsN0dB_est = EsN0dB_est + 10*numpy.log10( cp.training_percent/100.0 ) 
        self.EsN0dB = EsN0dB = 20
        self.Es = Es = 1
        self.variable_static_text = variable_static_text = 'Acquisition' if onoff==1 else 'Tracking'
        self.n_filt = n_filt = cp.n_filt
        self.freq_est_acq = freq_est_acq = freq_acq_est
        self.fmaxt = fmaxt = cp.freqs[-1]*samp_rate
        self.drift = drift = 0
        self.dft = dft = df
        self.df_Hz = df_Hz = 0
        self.delay = delay = 0
        self.acq_threshold_dB = acq_threshold_dB = -8.5
        self.TrainingEsN0dB = TrainingEsN0dB = TrainingEsN0dB_est
        self.N0 = N0 = 10**(-EsN0dB/10) * Es
        self.DataEsN0dB_estimated = DataEsN0dB_estimated = DataEsN0dB_est

        ##################################################
        # Blocks
        ##################################################
        _drift_sizer = wx.BoxSizer(wx.VERTICAL)
        self._drift_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_drift_sizer,
        	value=self.drift,
        	callback=self.set_drift,
        	label="drift  (ppm)",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._drift_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_drift_sizer,
        	value=self.drift,
        	callback=self.set_drift,
        	minimum=0,
        	maximum=2,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_drift_sizer, 3, 0, 1, 1)
        _df_Hz_sizer = wx.BoxSizer(wx.VERTICAL)
        self._df_Hz_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_df_Hz_sizer,
        	value=self.df_Hz,
        	callback=self.set_df_Hz,
        	label="df_Hz",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._df_Hz_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_df_Hz_sizer,
        	value=self.df_Hz,
        	callback=self.set_df_Hz,
        	minimum=(cp.freqs[0]*samp_rate)-1e-6,
        	maximum=cp.freqs[-1]*samp_rate,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_df_Hz_sizer, 1, 0, 1, 1)
        _delay_sizer = wx.BoxSizer(wx.VERTICAL)
        self._delay_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_delay_sizer,
        	value=self.delay,
        	callback=self.set_delay,
        	label="delay",
        	converter=forms.int_converter(),
        	proportion=0,
        )
        self._delay_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_delay_sizer,
        	value=self.delay,
        	callback=self.set_delay,
        	minimum=0,
        	maximum=100-1,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=int,
        	proportion=1,
        )
        self.GridAdd(_delay_sizer, 2, 0, 1, 1)
        self.blocks_probe_signal_n0 = blocks.probe_signal_f()
        self.blocks_probe_signal_amp = blocks.probe_signal_f()
        self.blocks_probe_freq = blocks.probe_signal_f()
        _acq_threshold_dB_sizer = wx.BoxSizer(wx.VERTICAL)
        self._acq_threshold_dB_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_acq_threshold_dB_sizer,
        	value=self.acq_threshold_dB,
        	callback=self.set_acq_threshold_dB,
        	label="acq_threshold_dB",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._acq_threshold_dB_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_acq_threshold_dB_sizer,
        	value=self.acq_threshold_dB,
        	callback=self.set_acq_threshold_dB,
        	minimum=-30,
        	maximum=20,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_acq_threshold_dB_sizer, 7, 0, 1, 1)
        self._variable_static_text_static_text = forms.static_text(
        	parent=self.GetWin(),
        	value=self.variable_static_text,
        	callback=self.set_variable_static_text,
        	label="Ack/Tra Status",
        	converter=forms.str_converter(),
        )
        self.GridAdd(self._variable_static_text_static_text, 4, 0, 1, 1)
        self._onoff_manual_chooser = forms.button(
        	parent=self.GetWin(),
        	value=self.onoff_manual,
        	callback=self.set_onoff_manual,
        	label="Manual Acq/Tra",
        	choices=[0,1],
        	labels=['Tracking','Acquisition'],
        )
        self.GridAdd(self._onoff_manual_chooser, 5, 0, 1, 1)
        self._n_filt_static_text = forms.static_text(
        	parent=self.GetWin(),
        	value=self.n_filt,
        	callback=self.set_n_filt,
        	label="n_filt",
        	converter=forms.int_converter(),
        )
        self.Add(self._n_filt_static_text)
        self._manual_chooser = forms.radio_buttons(
        	parent=self.GetWin(),
        	value=self.manual,
        	callback=self.set_manual,
        	label="Manual/Auto",
        	choices=[0,1],
        	labels=['Auto','Manual'],
        	style=wx.RA_HORIZONTAL,
        )
        self.GridAdd(self._manual_chooser, 6, 0, 1, 1)
        self._freq_est_acq_static_text = forms.static_text(
        	parent=self.GetWin(),
        	value=self.freq_est_acq,
        	callback=self.set_freq_est_acq,
        	label='freq_est_acq',
        	converter=forms.float_converter(),
        )
        self.Add(self._freq_est_acq_static_text)
        def _freq_acq_est_probe():
            while True:
                val = self.blocks_probe_freq.level()
                try:
                    self.set_freq_acq_est(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (10))
        _freq_acq_est_thread = threading.Thread(target=_freq_acq_est_probe)
        _freq_acq_est_thread.daemon = True
        _freq_acq_est_thread.start()
        self._fmaxt_static_text = forms.static_text(
        	parent=self.GetWin(),
        	value=self.fmaxt,
        	callback=self.set_fmaxt,
        	label="f_max (Hz)",
        	converter=forms.float_converter(),
        )
        self.Add(self._fmaxt_static_text)
        self._dft_static_text = forms.static_text(
        	parent=self.GetWin(),
        	value=self.dft,
        	callback=self.set_dft,
        	label="Deltaf (Hz)",
        	converter=forms.float_converter(),
        )
        self.Add(self._dft_static_text)
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage=(cp.chips_per_symbol*cp.samples_per_chip*N0/2)**0.5,
        	frequency_offset=df_Hz/samp_rate,
        	epsilon=1.0+drift*1e-6,
        	taps=((delay)*(0,)+(1,)+(100-1-delay)*(0,)),
        	noise_seed=0,
        	block_tags=False
        )
        self.cdma_tx_hier_0 = cdma_tx_hier()
        self.cdma_rx_hier_0 = cdma_rx_hier(
            acq=onoff,
            acq_threshold_dB=acq_threshold_dB,
        )
        self.cdma_pac_err_cal_0 = cdma.pac_err_cal(1000, 2**cp.cdma_packet_num_bit, "cdma_packet_num")
        self.blocks_vector_source_x_0_1 = blocks.vector_source_b(map(int,numpy.random.randint(0,256,cp.payload_bytes_per_frame)), True, 1, tagged_streams.make_lengthtags((cp.payload_bytes_per_frame,), (0,), cp.length_tag_name))
        self.blocks_throttle_0_0 = blocks.throttle(gr.sizeof_char*1, (symbol_rate*cp.bits_per_uncoded_symbol)/8,True)
        self.blocks_tag_gate_0 = blocks.tag_gate(gr.sizeof_gr_complex * 1, False)
        self.blocks_null_sink_0_0 = blocks.null_sink(gr.sizeof_gr_complex*1)
        self.blocks_null_sink_0 = blocks.null_sink(gr.sizeof_char*1)
        self.blocks_multiply_const_vxx_1_0 = blocks.multiply_const_vff((samp_rate, ))
        self.blocks_multiply_const_vxx_1 = blocks.multiply_const_vcc((Es**0.5, ))
        self._TrainingEsN0dB_static_text = forms.static_text(
        	parent=self.GetWin(),
        	value=self.TrainingEsN0dB,
        	callback=self.set_TrainingEsN0dB,
        	label="TrainingEsN0dB_est",
        	converter=forms.float_converter(),
        )
        self.Add(self._TrainingEsN0dB_static_text)
        def _N0est_probe():
            while True:
                val = self.blocks_probe_signal_n0.level()
                try:
                    self.set_N0est(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (10))
        _N0est_thread = threading.Thread(target=_N0est_probe)
        _N0est_thread.daemon = True
        _N0est_thread.start()
        def _Esest_probe():
            while True:
                val = self.blocks_probe_signal_amp.level()
                try:
                    self.set_Esest(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (10))
        _Esest_thread = threading.Thread(target=_Esest_probe)
        _Esest_thread.daemon = True
        _Esest_thread.start()
        _EsN0dB_sizer = wx.BoxSizer(wx.VERTICAL)
        self._EsN0dB_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_EsN0dB_sizer,
        	value=self.EsN0dB,
        	callback=self.set_EsN0dB,
        	label="EsN0dB",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._EsN0dB_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_EsN0dB_sizer,
        	value=self.EsN0dB,
        	callback=self.set_EsN0dB,
        	minimum=-20,
        	maximum=80,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_EsN0dB_sizer, 0, 0, 1, 1)
        _DataEsN0dBthreshold_sizer = wx.BoxSizer(wx.VERTICAL)
        self._DataEsN0dBthreshold_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_DataEsN0dBthreshold_sizer,
        	value=self.DataEsN0dBthreshold,
        	callback=self.set_DataEsN0dBthreshold,
        	label="DataEsN0dBthreshold",
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._DataEsN0dBthreshold_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_DataEsN0dBthreshold_sizer,
        	value=self.DataEsN0dBthreshold,
        	callback=self.set_DataEsN0dBthreshold,
        	minimum=0,
        	maximum=20,
        	num_steps=100,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.GridAdd(_DataEsN0dBthreshold_sizer, 8, 0, 1, 1)
        self._DataEsN0dB_estimated_static_text = forms.static_text(
        	parent=self.GetWin(),
        	value=self.DataEsN0dB_estimated,
        	callback=self.set_DataEsN0dB_estimated,
        	label="DataEsN0dB_est",
        	converter=forms.float_converter(),
        )
        self.Add(self._DataEsN0dB_estimated_static_text)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.cdma_rx_hier_0, 'decoded_header'), (self.cdma_pac_err_cal_0, 'errCal'))    
        self.connect((self.blocks_multiply_const_vxx_1, 0), (self.channels_channel_model_0, 0))    
        self.connect((self.blocks_multiply_const_vxx_1_0, 0), (self.blocks_probe_freq, 0))    
        self.connect((self.blocks_tag_gate_0, 0), (self.blocks_null_sink_0_0, 0))    
        self.connect((self.blocks_tag_gate_0, 0), (self.cdma_rx_hier_0, 0))    
        self.connect((self.blocks_throttle_0_0, 0), (self.cdma_tx_hier_0, 0))    
        self.connect((self.blocks_vector_source_x_0_1, 0), (self.blocks_throttle_0_0, 0))    
        self.connect((self.cdma_rx_hier_0, 3), (self.blocks_multiply_const_vxx_1_0, 0))    
        self.connect((self.cdma_rx_hier_0, 1), (self.blocks_null_sink_0, 0))    
        self.connect((self.cdma_rx_hier_0, 2), (self.blocks_probe_signal_amp, 0))    
        self.connect((self.cdma_rx_hier_0, 0), (self.blocks_probe_signal_n0, 0))    
        self.connect((self.cdma_tx_hier_0, 0), (self.blocks_multiply_const_vxx_1, 0))    
        self.connect((self.channels_channel_model_0, 0), (self.blocks_tag_gate_0, 0))    
Esempio n. 59
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Wifi Loopback Ah")

        ##################################################
        # Variables
        ##################################################
        self.snr = snr = 20
        self.pdu_length = pdu_length = 500
        self.out_buf_size = out_buf_size = 96000
        self.interval = interval = 100
        self.encoding = encoding = 0
        self.chan_est = chan_est = 1

        ##################################################
        # Blocks
        ##################################################
        _snr_sizer = wx.BoxSizer(wx.VERTICAL)
        self._snr_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_snr_sizer,
        	value=self.snr,
        	callback=self.set_snr,
        	label='snr',
        	converter=forms.float_converter(),
        	proportion=0,
        )
        self._snr_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_snr_sizer,
        	value=self.snr,
        	callback=self.set_snr,
        	minimum=-15,
        	maximum=30,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=float,
        	proportion=1,
        )
        self.Add(_snr_sizer)
        _pdu_length_sizer = wx.BoxSizer(wx.VERTICAL)
        self._pdu_length_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_pdu_length_sizer,
        	value=self.pdu_length,
        	callback=self.set_pdu_length,
        	label='pdu_length',
        	converter=forms.int_converter(),
        	proportion=0,
        )
        self._pdu_length_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_pdu_length_sizer,
        	value=self.pdu_length,
        	callback=self.set_pdu_length,
        	minimum=0,
        	maximum=1500,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=int,
        	proportion=1,
        )
        self.Add(_pdu_length_sizer)
        _interval_sizer = wx.BoxSizer(wx.VERTICAL)
        self._interval_text_box = forms.text_box(
        	parent=self.GetWin(),
        	sizer=_interval_sizer,
        	value=self.interval,
        	callback=self.set_interval,
        	label="PDU Interval (ms)",
        	converter=forms.int_converter(),
        	proportion=0,
        )
        self._interval_slider = forms.slider(
        	parent=self.GetWin(),
        	sizer=_interval_sizer,
        	value=self.interval,
        	callback=self.set_interval,
        	minimum=10,
        	maximum=1000,
        	num_steps=1000,
        	style=wx.SL_HORIZONTAL,
        	cast=int,
        	proportion=1,
        )
        self.Add(_interval_sizer)
        self._encoding_chooser = forms.radio_buttons(
        	parent=self.GetWin(),
        	value=self.encoding,
        	callback=self.set_encoding,
        	label="Encoding",
        	choices=[0,1,2,3,4,5,6,7,8],
        	labels=["BPSK 1/2", "QPSK 1/2", "QPSK 3/4",  "16QAM 1/2", "16QAM 3/4", "64QAM 2/3", "64QAM 3/4", "64QAM 5/6", "256QAM 3/4"  ],
        	style=wx.RA_HORIZONTAL,
        )
        self.Add(self._encoding_chooser)
        self._chan_est_chooser = forms.radio_buttons(
        	parent=self.GetWin(),
        	value=self.chan_est,
        	callback=self.set_chan_est,
        	label='chan_est',
        	choices=[0, 1],
        	labels=["LMS", "Linear Comb"],
        	style=wx.RA_HORIZONTAL,
        )
        self.Add(self._chan_est_chooser)
        self.wxgui_scopesink2_0 = scopesink2.scope_sink_c(
        	self.GetWin(),
        	title="Scope Plot",
        	sample_rate=12500,
        	v_scale=0,
        	v_offset=0,
        	t_scale=0,
        	ac_couple=False,
        	xy_mode=True,
        	num_inputs=1,
        	trig_mode=wxgui.TRIG_MODE_AUTO,
        	y_axis_label="Counts",
        )
        self.Add(self.wxgui_scopesink2_0.win)
        self.wxgui_numbersink2_0 = numbersink2.number_sink_f(
        	self.GetWin(),
        	unit="%",
        	minval=0,
        	maxval=100,
        	factor=1.0,
        	decimal_places=2,
        	ref_level=0,
        	sample_rate=1,
        	number_rate=15,
        	average=True,
        	avg_alpha=0.02,
        	label="Frame Error Rate",
        	peak_hold=False,
        	show_gauge=True,
        )
        self.Add(self.wxgui_numbersink2_0.win)
        self.wifi_phy_hier_ah_0 = wifi_phy_hier_ah(
            chan_est=chan_est,
            encoding=encoding,
            sensitivity=0.56,
        )
        self.ieee802_11_ofdm_parse_mac_0 = ieee802_11.ofdm_parse_mac(False, True)
        self.ieee802_11_ofdm_mac_0 = ieee802_11.ofdm_mac(([0x23, 0x23, 0x23, 0x23, 0x23, 0x23]), ([0x42, 0x42, 0x42, 0x42, 0x42, 0x42]), ([0xff, 0xff, 0xff, 0xff, 0xff, 0xff]))
        self.foo_packet_pad2_0 = foo.packet_pad2(False, False, 0.001, 500, 0)
        (self.foo_packet_pad2_0).set_min_output_buffer(96000)
        self.channels_channel_model_0 = channels.channel_model(
        	noise_voltage=1,
        	frequency_offset=0,
        	epsilon=1.0,
        	taps=(1.0, ),
        	noise_seed=0,
        	block_tags=False
        )
        self.blocks_pdu_to_tagged_stream_0 = blocks.pdu_to_tagged_stream(blocks.float_t, "packet_len")
        self.blocks_multiply_const_vxx_0 = blocks.multiply_const_vcc(((10**(snr/10.0))**.5, ))
        self.blocks_message_strobe_0 = blocks.message_strobe(pmt.intern("".join("x" for i in range(pdu_length))), interval)

        ##################################################
        # Connections
        ##################################################
        self.msg_connect((self.blocks_message_strobe_0, 'strobe'), (self.ieee802_11_ofdm_mac_0, 'app in'))    
        self.msg_connect((self.ieee802_11_ofdm_mac_0, 'phy out'), (self.wifi_phy_hier_ah_0, 'mac_in'))    
        self.msg_connect((self.ieee802_11_ofdm_parse_mac_0, 'fer'), (self.blocks_pdu_to_tagged_stream_0, 'pdus'))    
        self.msg_connect((self.wifi_phy_hier_ah_0, 'mac_out'), (self.ieee802_11_ofdm_parse_mac_0, 'in'))    
        self.connect((self.blocks_multiply_const_vxx_0, 0), (self.channels_channel_model_0, 0))    
        self.connect((self.blocks_pdu_to_tagged_stream_0, 0), (self.wxgui_numbersink2_0, 0))    
        self.connect((self.channels_channel_model_0, 0), (self.wifi_phy_hier_ah_0, 0))    
        self.connect((self.foo_packet_pad2_0, 0), (self.blocks_multiply_const_vxx_0, 0))    
        self.connect((self.wifi_phy_hier_ah_0, 0), (self.foo_packet_pad2_0, 0))    
        self.connect((self.wifi_phy_hier_ah_0, 1), (self.wxgui_scopesink2_0, 0))