def __init__(self,
              constellation,
              differential,
              data_length=None,
              src_data=None):
     """
     constellation -- a constellation object
     differential -- whether differential encoding is used
     data_length -- the number of bits of data to use
     src_data -- a list of the bits to use
     """
     super(rec_test_tb, self).__init__()
     # Transmission Blocks
     if src_data is None:
         self.src_data = tuple(
             [random.randint(0, 1) for i in range(0, data_length)])
     else:
         self.src_data = src_data
     packer = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
     src = gr.vector_source_b(self.src_data)
     mod = generic_mod(constellation, differential=differential)
     # Channel
     channel = gr.channel_model(NOISE_VOLTAGE, FREQUENCY_OFFSET,
                                TIMING_OFFSET)
     # Receiver Blocks
     demod = generic_demod(constellation,
                           differential=differential,
                           freq_bw=FREQ_BW,
                           phase_bw=PHASE_BW)
     self.dst = gr.vector_sink_b()
     self.connect(src, packer, mod, channel, demod, self.dst)
Example #2
0
    def test_101(self):
        vlen = 256
        N = int(5e5)
        soff = 1.0
        taps = [1.0, 0.0, 2e-1 + 0.1j, 1e-4 - 0.04j]
        freqoff = 0.0
        norm_freq = freqoff / vlen
        rms_amplitude = 8000
        snr_db = 10
        snr = 10.0**(snr_db / 10.0)
        noise_sigma = sqrt(rms_amplitude**2 / snr)

        data = [1 + 1j] * vlen
        #data2 = [2] * vlen

        src = gr.vector_source_c(data, True, vlen)
        v2s = gr.vector_to_stream(gr.sizeof_gr_complex, vlen)

        channel = gr.channel_model(noise_sigma, norm_freq, soff, taps)

        dst = gr.null_sink(gr.sizeof_gr_complex)

        limit = gr.head(gr.sizeof_gr_complex * vlen, N)

        self.tb.connect(src, limit, v2s, channel, dst)

        r = time_it(self.tb)

        print "Rate: %s Samples/second" \
          % eng_notation.num_to_str( float(N) * vlen / r )
Example #3
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 = gr.add_cc()
        sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
        sink_freq = gr.vector_sink_f()
        sink_detect = gr.vector_sink_b()
        channel = gr.channel_model(0.005)
        self.tb.connect(gr.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))
Example #4
0
    def __init__(self, N, sps, rolloff, ntaps, bw, noise, foffset, toffset, poffset):
        gr.top_block.__init__(self)

        rrc_taps = gr.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 = gr.vector_source_c(data.tolist(), False)
        self.rrc = gr.interp_fir_filter_ccf(sps, rrc_taps)
        self.chn = gr.channel_model(noise, foffset, toffset)
        self.fll = digital.fll_band_edge_cc(sps, rolloff, ntaps, bw)

        self.vsnk_src = gr.vector_sink_c()
        self.vsnk_fll = gr.vector_sink_c()
        self.vsnk_frq = gr.vector_sink_f()
        self.vsnk_phs = gr.vector_sink_f()
        self.vsnk_err = gr.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)
Example #5
0
 def test_002_freq(self):
     """ Add a fine frequency offset and see if that get's 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
     sync_symbol = [(random.randint(0, 1) * 2) - 1
                    for x in range(fft_len / 2)] * 2
     tx_signal = sync_symbol[-cp_len:] + \
                 sync_symbol + \
                 [(random.randint(0, 1)*2)-1 for x in range(sig_len)]
     mult = gr.multiply_cc()
     add = gr.add_cc()
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len, True)
     channel = gr.channel_model(0.005, freq_offset / 2.0 / numpy.pi)
     sink_freq = gr.vector_sink_f()
     sink_detect = gr.vector_sink_b()
     self.tb.connect(gr.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)
 def test_002_freq (self):
     """ Add a fine frequency offset and see if that get's 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
     sync_symbol = [(random.randint(0, 1)*2)-1 for x in range(fft_len/2)] * 2
     tx_signal = sync_symbol[-cp_len:] + \
                 sync_symbol + \
                 [(random.randint(0, 1)*2)-1 for x in range(sig_len)]
     mult = gr.multiply_cc()
     add = gr.add_cc()
     sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len, True)
     channel = gr.channel_model(0.005, freq_offset / 2.0 / numpy.pi)
     sink_freq   = gr.vector_sink_f()
     sink_detect = gr.vector_sink_b()
     self.tb.connect(gr.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)
Example #7
0
  def test_101(self):
    vlen = 256
    N = int( 5e5 )
    soff=1.0
    taps = [1.0,0.0,2e-1+0.1j,1e-4-0.04j]
    freqoff = 0.0
    norm_freq = freqoff / vlen
    rms_amplitude = 8000
    snr_db = 10
    snr = 10.0**(snr_db/10.0)
    noise_sigma = sqrt( rms_amplitude**2 / snr)
    
    
    
    data = [1 + 1j] * vlen
    #data2 = [2] * vlen
    
    src = gr.vector_source_c( data, True, vlen )
    v2s = gr.vector_to_stream(gr.sizeof_gr_complex,vlen)
    
    
    channel = gr.channel_model(noise_sigma,norm_freq,soff,taps)
    
    dst = gr.null_sink( gr.sizeof_gr_complex )

    limit = gr.head( gr.sizeof_gr_complex * vlen, N )
    
    
    self.tb.connect( src, limit, v2s, channel, dst )
    
    r = time_it( self.tb )
    
    print "Rate: %s Samples/second" \
      % eng_notation.num_to_str( float(N) * vlen / r ) 
 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 = gr.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   = gr.vector_sink_f()
     sink_detect = gr.vector_sink_b()
     noise_level = 0.005
     channel = gr.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 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 = gr.add_cc()
        sync = digital.ofdm_sync_sc_cfb(fft_len, cp_len)
        sink_freq   = gr.vector_sink_f()
        sink_detect = gr.vector_sink_b()
        channel = gr.channel_model(0.005)
        self.tb.connect(gr.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)
        )
    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 = gr.file_source(gr.sizeof_gr_complex, ifile)
        #self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
        self.channel = gr.channel_model(noise_voltage,
                                        frequency_offset,
                                        time_offset,
                                        noise_seed=-random.randint(0, 100000))
        self.phase = gr.multiply_const_cc(
            complex(math.cos(phase_offset), math.sin(phase_offset)))
        self.snk = gr.file_sink(gr.sizeof_gr_complex, ofile)

        self.connect(self.src, self.channel, self.phase, self.snk)
Example #11
0
    def __init__(self,
                 N,
                 sps,
                 rolloff,
                 ntaps,
                 bw,
                 noise,
                 foffset,
                 toffset,
                 poffset,
                 mode=0):
        gr.top_block.__init__(self)

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

        gain = 2 * scipy.pi / 100.0
        nfilts = 32
        rrc_taps_rx = gr.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 = gr.vector_source_c(data.tolist(), False)
        self.rrc = gr.interp_fir_filter_ccf(sps, rrc_taps)
        self.chn = gr.channel_model(noise, foffset, toffset)
        self.off = gr.fractional_interpolator_cc(0.20, 1.0)

        if mode == 0:
            self.clk = gr.pfb_clock_sync_ccf(sps, gain, rrc_taps_rx, nfilts,
                                             nfilts // 2, 3.5)
            self.taps = self.clk.get_taps()
            self.dtaps = self.clk.get_diff_taps()

            self.vsnk_err = gr.vector_sink_f()
            self.vsnk_rat = gr.vector_sink_f()
            self.vsnk_phs = gr.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 = 0.1
            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 = gr.vector_sink_f()

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

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

        self.connect(self.src, self.rrc, self.chn, self.off, self.clk,
                     self.vsnk_clk)
        self.connect(self.off, self.vsnk_src)
 def __init__(self, constellation, differential,
              data_length=None, src_data=None):
     """
     constellation -- a constellation object
     differential -- whether differential encoding is used
     data_length -- the number of bits of data to use
     src_data -- a list of the bits to use
     """
     super(rec_test_tb, self).__init__()
     # Transmission Blocks
     if src_data is None:
         self.src_data = tuple([rndm.randint(0,1) for i in range(0, data_length)])
     else:
         self.src_data = src_data
     packer = gr.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
     src = gr.vector_source_b(self.src_data)
     mod = generic_mod(constellation, differential=differential)
     # Channel
     channel = gr.channel_model(NOISE_VOLTAGE, FREQUENCY_OFFSET, TIMING_OFFSET)
     # Receiver Blocks
     demod = generic_demod(constellation, differential=differential,
                           freq_bw=FREQ_BW,
                           phase_bw=PHASE_BW)
     self.dst = gr.vector_sink_b()
     self.connect(src, packer, mod, channel, demod, self.dst)
Example #13
0
    def __init__(self, callback, options):
        gr.top_block.__init__(self)

        if not options.channel_off:
            SNR = 10.0**(options.snr / 10.0)
            power_in_signal = abs(options.tx_amplitude)**2.0
            noise_power_in_channel = power_in_signal / SNR
            noise_voltage = math.sqrt(noise_power_in_channel / 2.0)
            print "Noise voltage: ", noise_voltage

            frequency_offset = options.frequency_offset / options.fft_length
            print "Frequency offset: ", frequency_offset

            if options.multipath_on:
                taps = [1.0, .2, 0.0, .1, .08, -.4, .12, -.2, 0, 0, 0, .3]
            else:
                taps = [1.0, 0.0]

        else:
            noise_voltage = 0.0
            frequency_offset = 0.0
            taps = [1.0, 0.0]

        symbols_per_packet = math.ceil(
            ((4 + options.size + 4) * 8) / options.occupied_tones)
        samples_per_packet = (symbols_per_packet + 2) * (options.fft_length +
                                                         options.cp_length)
        print "Symbols per Packet: ", symbols_per_packet
        print "Samples per Packet: ", samples_per_packet
        if options.discontinuous:
            stream_size = [
                100000,
                int(options.discontinuous * samples_per_packet)
            ]
        else:
            stream_size = [0, 100000]

        z = [
            0,
        ]
        self.zeros = gr.vector_source_c(z, True)
        self.txpath = transmit_path(options)

        #self.mux = gr.stream_mux(gr.sizeof_gr_complex, stream_size)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
        self.channel = gr.channel_model(noise_voltage, frequency_offset,
                                        options.clockrate_ratio, taps)
        self.rxpath = receive_path(callback, options)

        #self.connect(self.zeros, (self.mux,0))
        #self.connect(self.txpath, (self.mux,1))
        #self.connect(self.mux, self.throttle, self.channel, self.rxpath)
        #self.connect(self.mux, self.throttle, self.rxpath)
        self.connect(self.txpath, self.throttle, self.channel, self.rxpath)

        if options.log:
            self.connect(self.txpath,
                         gr.file_sink(gr.sizeof_gr_complex, "txpath.dat"))
Example #14
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 = gr.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)
Example #15
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 = gr.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)
Example #16
0
    def __init__(self, N, sps, rolloff, ntaps, bw, noise,
                 foffset, toffset, poffset, mode=0):
        gr.top_block.__init__(self)

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

        gain = 2*scipy.pi/100.0
        nfilts = 32
        rrc_taps_rx = gr.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 = gr.vector_source_c(data.tolist(), False)
        self.rrc = gr.interp_fir_filter_ccf(sps, rrc_taps)
        self.chn = gr.channel_model(noise, foffset, toffset)
        self.off = gr.fractional_interpolator_cc(0.20, 1.0)

        if mode == 0:
            self.clk = gr.pfb_clock_sync_ccf(sps, gain, rrc_taps_rx,
                                             nfilts, nfilts//2, 3.5)
            self.taps = self.clk.get_taps()
            self.dtaps = self.clk.get_diff_taps()

            self.vsnk_err = gr.vector_sink_f()
            self.vsnk_rat = gr.vector_sink_f()
            self.vsnk_phs = gr.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 = 0.1
            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 = gr.vector_sink_f()

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

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

        self.connect(self.src, self.rrc, self.chn, self.off, self.clk, self.vsnk_clk)
        self.connect(self.off, self.vsnk_src)
Example #17
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 100
        f2 = 200

        npts = 2048

        self.qapp = QtGui.QApplication(sys.argv)
        
        src1 = gr.sig_source_c(Rs, gr.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = gr.sig_source_c(Rs, gr.GR_SIN_WAVE, f2, 0.1, 0)
        src  = gr.add_cc()
        channel = gr.channel_model(0.01)
        thr = gr.throttle(gr.sizeof_gr_complex, 100*npts)
        self.snk1 = qtgui.time_sink_c(npts, Rs,
                                      "Complex Time Example", 3)

        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 PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

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

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

        #pyWin.show()
        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
Example #18
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 100
        f2 = 200

        npts = 2048

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

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

        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 PyQt4.QtGui.QWidget
        pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

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

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

        #pyWin.show()
        self.main_box = dialog_box(pyWin, self.ctrl_win)
        self.main_box.show()
Example #19
0
    def __init__(self, callback, options):
        gr.top_block.__init__(self)

        if not options.channel_off:
            SNR = 10.0**(options.snr/10.0)
            power_in_signal = abs(options.tx_amplitude)**2.0
            noise_power_in_channel = power_in_signal/SNR
            noise_voltage = math.sqrt(noise_power_in_channel/2.0)
            print "Noise voltage: ", noise_voltage

            frequency_offset = options.frequency_offset / options.fft_length
            print "Frequency offset: ", frequency_offset

            if options.multipath_on:
                taps = [1.0, .2, 0.0, .1, .08, -.4, .12, -.2, 0, 0, 0, .3]
            else:
                taps = [1.0, 0.0]

        else:
            noise_voltage = 0.0
            frequency_offset = 0.0
            taps = [1.0, 0.0]

        symbols_per_packet = math.ceil(((4+options.size+4) * 8) / options.occupied_tones)
        samples_per_packet = (symbols_per_packet+2) * (options.fft_length+options.cp_length)
        print "Symbols per Packet: ", symbols_per_packet
        print "Samples per Packet: ", samples_per_packet
        if options.discontinuous:
            stream_size = [100000, int(options.discontinuous*samples_per_packet)]
        else:
            stream_size = [0, 100000]

        z = [0,]
        self.zeros = gr.vector_source_c(z, True)
        self.txpath = transmit_path(options)

        #self.mux = gr.stream_mux(gr.sizeof_gr_complex, stream_size)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
        self.channel = gr.channel_model(noise_voltage, frequency_offset,
                                        options.clockrate_ratio, taps)
        self.rxpath = receive_path(callback, options)
                
        #self.connect(self.zeros, (self.mux,0))
        #self.connect(self.txpath, (self.mux,1))
        #self.connect(self.mux, self.throttle, self.channel, self.rxpath)
        #self.connect(self.mux, self.throttle, self.rxpath)
        self.connect(self.txpath, self.throttle, self.channel, self.rxpath)
        
        if options.log:
            self.connect(self.txpath, gr.file_sink(gr.sizeof_gr_complex, "txpath.dat"))
Example #20
0
    def __init__(self, mod_class, demod_class, rx_callback, options):
        gr.top_block.__init__(self)

        channelon = True

        SNR = 10.0**(options.snr / 10.0)
        frequency_offset = options.frequency_offset

        power_in_signal = abs(options.tx_amplitude)**2
        noise_power = power_in_signal / SNR
        noise_voltage = math.sqrt(noise_power)

        # With new interface, sps does not get set by default, but
        # in the loopback, we don't recalculate it; so just force it here
        if (options.samples_per_symbol == None):
            options.samples_per_symbol = 2

        self.txpath = transmit_path(mod_class, options)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
        self.rxpath = receive_path(demod_class, rx_callback, options)

        if channelon:
            self.channel = gr.channel_model(noise_voltage, frequency_offset,
                                            1.01)

            if options.discontinuous:
                z = 20000 * [
                    0,
                ]
                self.zeros = gr.vector_source_c(z, True)
                packet_size = 5 * ((4 + 8 + 4 + 1500 + 4) * 8)
                self.mux = gr.stream_mux(
                    gr.sizeof_gr_complex,
                    [packet_size - 0, int(9e5)])

                # Connect components
                self.connect(self.txpath, (self.mux, 0))
                self.connect(self.zeros, (self.mux, 1))
                self.connect(self.mux, self.channel, self.rxpath)

            else:
                self.connect(self.txpath, self.channel, self.rxpath)

        else:
            # Connect components
            self.connect(self.txpath, self.throttle, self.rxpath)
Example #21
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 1000
        f2 = 2000

        fftsize = 2048

        self.qapp = QtGui.QApplication(sys.argv)
        
        src1 = gr.sig_source_c(Rs, gr.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = gr.sig_source_c(Rs, gr.GR_SIN_WAVE, f2, 0.1, 0)
        src  = gr.add_cc()
        channel = gr.channel_model(0.001)
        thr = gr.throttle(gr.sizeof_gr_complex, 100*fftsize)

        self.snk1 = qtgui2.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                 0, Rs,
                                 "Complex Signal Example",
                                True, True, False, True, True, True, True)
                                #True, False, False, False, False, True, False)
								#fft , wfall, 3dwf , time , const, oGL , formui

        # 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
        self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

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

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

        

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

 

        self.main_box.show()
Example #22
0
  def __init__(self, options):
    gr.top_block.__init__(self)

    SNR = 10.0**(options.snr/10.0)
    noise_power_in_channel = 1.0/SNR
    noise_voltage = math.sqrt(noise_power_in_channel/2.0)
    print "Noise voltage: ", noise_voltage

    frequency_offset = options.frequency_offset / 64
    print "Frequency offset: ", frequency_offset

    if options.multipath_on:
      taps = [1.0, .2, 0.0, .1, .08, -.4, .12, -.2, 0, 0, 0, .3]
    else:
      taps = [1.0, 0.0]

    self.connect(gr.file_source(gr.sizeof_gr_complex, options.infile),
                 gr.channel_model(noise_voltage, frequency_offset,
                                  options.clockrate_ratio, taps),
                 gr.file_sink(gr.sizeof_gr_complex, options.outfile))
Example #23
0
    def __init__(self, mod_class, demod_class, rx_callback, options):
        gr.top_block.__init__(self)

        channelon = True;

        SNR = 10.0**(options.snr/10.0)
        frequency_offset = options.frequency_offset
        
        power_in_signal = abs(options.tx_amplitude)**2
        noise_power = power_in_signal/SNR
        noise_voltage = math.sqrt(noise_power)

        # With new interface, sps does not get set by default, but
        # in the loopback, we don't recalculate it; so just force it here
        if(options.samples_per_symbol == None):
            options.samples_per_symbol = 2

        self.txpath = transmit_path(mod_class, options)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
        self.rxpath = receive_path(demod_class, rx_callback, options)

        if channelon:
            self.channel = gr.channel_model(noise_voltage, frequency_offset, 1.01)

            if options.discontinuous:
                z = 20000*[0,]
                self.zeros = gr.vector_source_c(z, True)
                packet_size = 5*((4+8+4+1500+4) * 8)
                self.mux = gr.stream_mux(gr.sizeof_gr_complex, [packet_size-0, int(9e5)])

                # Connect components
                self.connect(self.txpath, (self.mux,0))
                self.connect(self.zeros, (self.mux,1))
                self.connect(self.mux, self.channel, self.rxpath)

            else:
                self.connect(self.txpath, self.channel, self.rxpath)

        else:
            # Connect components
            self.connect(self.txpath, self.throttle, self.rxpath)
Example #24
0
 def test_003_tx1packet(self):
     """ Transmit one packet, with slight AWGN and slight frequency + timing offset.
     Check packet is received and no bit errors have occurred. """
     len_tag_key = 'frame_len'
     n_bytes = 21
     fft_len = 64
     test_data = tuple([random.randint(0, 255) for x in range(n_bytes)])
     # 1.0/fft_len is one sub-carrier, a fine freq offset stays below that
     freq_offset = 1.0 / fft_len * 0.7
     channel = gr.channel_model(0.01, freq_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(tx_fg.tx.sync_word1, rx_fg.rx.sync_word1)
     self.assertEqual(tuple(tx_fg.tx.sync_word2), tuple(rx_fg.rx.sync_word2))
     self.assertEqual(test_data, rx_data)
Example #25
0
    def __init__(self, options):
        gr.top_block.__init__(self)

        SNR = 10.0**(options.snr / 10.0)
        noise_power_in_channel = 1.0 / SNR
        noise_voltage = math.sqrt(noise_power_in_channel / 2.0)
        print "Noise voltage: ", noise_voltage

        frequency_offset = options.frequency_offset / 64
        print "Frequency offset: ", frequency_offset

        if options.multipath_on:
            taps = [1.0, .2, 0.0, .1, .08, -.4, .12, -.2, 0, 0, 0, .3]
        else:
            taps = [1.0, 0.0]

        self.connect(
            gr.file_source(gr.sizeof_gr_complex, options.infile),
            gr.channel_model(noise_voltage, frequency_offset,
                             options.clockrate_ratio, taps),
            gr.file_sink(gr.sizeof_gr_complex, options.outfile))
Example #26
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 = gr.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(tx_fg.tx.sync_word1, rx_fg.rx.sync_word1)
     self.assertEqual(tuple(tx_fg.tx.sync_word2), tuple(rx_fg.rx.sync_word2))
     self.assertEqual(test_data, rx_data)
Example #27
0
 def test_003_tx1packet(self):
     """ Transmit one packet, with slight AWGN and slight frequency + timing offset.
     Check packet is received and no bit errors have occurred. """
     len_tag_key = 'frame_len'
     n_bytes = 21
     fft_len = 64
     test_data = tuple([random.randint(0, 255) for x in range(n_bytes)])
     # 1.0/fft_len is one sub-carrier, a fine freq offset stays below that
     freq_offset = 1.0 / fft_len * 0.7
     channel = gr.channel_model(0.01, freq_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(tx_fg.tx.sync_word1, rx_fg.rx.sync_word1)
     self.assertEqual(tuple(tx_fg.tx.sync_word2),
                      tuple(rx_fg.rx.sync_word2))
     self.assertEqual(test_data, rx_data)
    def __init__(self, ifile, ofile, options):
        gr.top_block.__init__(self)

        SNR = 10.0**(options.snr/10.0)
        frequency_offset = options.frequency_offset
        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)

        self.src = gr.file_source(gr.sizeof_gr_complex, ifile)
        #self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
        self.channel = gr.channel_model(noise_voltage, frequency_offset,
                                        time_offset, noise_seed=-random.randint(0,100000))
        self.phase = gr.multiply_const_cc(complex(math.cos(phase_offset),
                                                  math.sin(phase_offset)))
        self.snk = gr.file_sink(gr.sizeof_gr_complex, ofile)

        self.connect(self.src, self.channel, self.phase, self.snk)
Example #29
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
     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 = gr.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 = gr.vector_sink_f()
     sink_detect = gr.vector_sink_b()
     noise_level = 0.005
     channel = gr.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)
Example #30
0
    def __init__(self):
        gr.top_block.__init__(self)

        Rs = 8000
        f1 = 1000
        f2 = 2000

        fftsize = 2048

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

        src1 = gr.sig_source_c(Rs, gr.GR_SIN_WAVE, f1, 0.1, 0)
        src2 = gr.sig_source_c(Rs, gr.GR_SIN_WAVE, f2, 0.1, 0)
        src = gr.add_cc()
        channel = gr.channel_model(0.001)
        thr = gr.throttle(gr.sizeof_gr_complex, 100 * fftsize)
        self.snk1 = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS, 0, Rs,
                                 "Complex Signal Example", True, True, False,
                                 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
        self.pyWin = sip.wrapinstance(pyQt, QtGui.QWidget)

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

        self.main_box.show()
Example #31
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 = gr.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(tx_fg.tx.sync_word1, rx_fg.rx.sync_word1)
     self.assertEqual(tuple(tx_fg.tx.sync_word2),
                      tuple(rx_fg.rx.sync_word2))
     self.assertEqual(test_data, rx_data)
Example #32
0
    def __init__(self, mod_class, demod_class, rx_callback, options):
        gr.top_block.__init__(self)

        channelon = True

        SNR = 10.0 ** (options.snr / 10.0)
        frequency_offset = options.frequency_offset

        power_in_signal = abs(options.tx_amplitude) ** 2
        noise_power = power_in_signal / SNR
        noise_voltage = math.sqrt(noise_power)

        self.txpath = transmit_path(mod_class, options)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
        self.rxpath = receive_path(demod_class, rx_callback, options)

        if channelon:
            self.channel = gr.channel_model(noise_voltage, frequency_offset, 1.01)

            if options.discontinuous:
                z = 20000 * [0]
                self.zeros = gr.vector_source_c(z, True)
                packet_size = 5 * ((4 + 8 + 4 + 1500 + 4) * 8)
                self.mux = gr.stream_mux(gr.sizeof_gr_complex, [packet_size - 0, int(9e5)])

                # Connect components
                self.connect(self.txpath, (self.mux, 0))
                self.connect(self.zeros, (self.mux, 1))
                self.connect(self.mux, self.channel, self.rxpath)

            else:
                self.connect(self.txpath, self.channel, self.rxpath)

        else:
            # Connect components
            self.connect(self.txpath, self.throttle, self.rxpath)
Example #33
0
	def __init__(self, freq_corr=0, avg_frames=1, decim=16, N_id_2=0, N_id_1=134):
		grc_wxgui.top_block_gui.__init__(self, title="Sss Corr5 Gui")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Parameters
		##################################################
		self.freq_corr = freq_corr
		self.avg_frames = avg_frames
		self.decim = decim
		self.N_id_2 = N_id_2
		self.N_id_1 = N_id_1

		##################################################
		# Variables
		##################################################
		self.vec_half_frame = vec_half_frame = 30720*5/decim
		self.symbol_start = symbol_start = 144/decim
		self.slot_0_10 = slot_0_10 = 1
		self.samp_rate = samp_rate = 30720e3/decim
		self.rot = rot = 0
		self.noise_level = noise_level = 0
		self.fft_size = fft_size = 2048/decim
		self.N_re = N_re = 62

		##################################################
		# Blocks
		##################################################
		_rot_sizer = wx.BoxSizer(wx.VERTICAL)
		self._rot_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_rot_sizer,
			value=self.rot,
			callback=self.set_rot,
			label='rot',
			converter=forms.float_converter(),
			proportion=0,
		)
		self._rot_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_rot_sizer,
			value=self.rot,
			callback=self.set_rot,
			minimum=0,
			maximum=1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Add(_rot_sizer)
		self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS ML")
		self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS equ")
		self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS in")
		self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "PSS equ")
		self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "PSS ch est")
		self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "foo")
		self.Add(self.notebook_0)
		_noise_level_sizer = wx.BoxSizer(wx.VERTICAL)
		self._noise_level_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_noise_level_sizer,
			value=self.noise_level,
			callback=self.set_noise_level,
			label='noise_level',
			converter=forms.float_converter(),
			proportion=0,
		)
		self._noise_level_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_noise_level_sizer,
			value=self.noise_level,
			callback=self.set_noise_level,
			minimum=0,
			maximum=10,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Add(_noise_level_sizer)
		self.wxgui_scopesink2_0_1_0_1 = scopesink2.scope_sink_c(
			self.notebook_0.GetPage(3).GetWin(),
			title="Scope Plot",
			sample_rate=samp_rate,
			v_scale=0,
			v_offset=0,
			t_scale=0,
			ac_couple=False,
			xy_mode=False,
			num_inputs=2,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.notebook_0.GetPage(3).Add(self.wxgui_scopesink2_0_1_0_1.win)
		self.wxgui_scopesink2_0_1_0_0 = scopesink2.scope_sink_c(
			self.notebook_0.GetPage(2).GetWin(),
			title="Scope Plot",
			sample_rate=samp_rate,
			v_scale=0,
			v_offset=0,
			t_scale=0,
			ac_couple=False,
			xy_mode=False,
			num_inputs=1,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.notebook_0.GetPage(2).Add(self.wxgui_scopesink2_0_1_0_0.win)
		self.wxgui_scopesink2_0_1_0 = scopesink2.scope_sink_c(
			self.notebook_0.GetPage(1).GetWin(),
			title="Scope Plot",
			sample_rate=samp_rate,
			v_scale=0,
			v_offset=0,
			t_scale=0,
			ac_couple=False,
			xy_mode=False,
			num_inputs=1,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.notebook_0.GetPage(1).Add(self.wxgui_scopesink2_0_1_0.win)
		self.wxgui_scopesink2_0_1 = scopesink2.scope_sink_f(
			self.notebook_0.GetPage(0).GetWin(),
			title="Scope Plot",
			sample_rate=100/avg_frames,
			v_scale=0,
			v_offset=0,
			t_scale=0,
			ac_couple=False,
			xy_mode=False,
			num_inputs=1,
			trig_mode=gr.gr_TRIG_MODE_AUTO,
			y_axis_label="Counts",
		)
		self.notebook_0.GetPage(0).Add(self.wxgui_scopesink2_0_1.win)
		_symbol_start_sizer = wx.BoxSizer(wx.VERTICAL)
		self._symbol_start_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_symbol_start_sizer,
			value=self.symbol_start,
			callback=self.set_symbol_start,
			label='symbol_start',
			converter=forms.int_converter(),
			proportion=0,
		)
		self._symbol_start_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_symbol_start_sizer,
			value=self.symbol_start,
			callback=self.set_symbol_start,
			minimum=0,
			maximum=144/decim,
			num_steps=144/decim,
			style=wx.SL_HORIZONTAL,
			cast=int,
			proportion=1,
		)
		self.Add(_symbol_start_sizer)
		self.sss_ml_fd_0 = sss_ml_fd(
			decim=decim,
			avg_frames=avg_frames,
			N_id_1=N_id_1,
			N_id_2=N_id_2,
			slot_0_10=slot_0_10,
		)
		self.pss_chan_est2_0 = pss_chan_est2(
			N_id_2=N_id_2,
		)
		self.gr_vector_to_stream_0_0_1_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, N_re)
		self.gr_vector_to_stream_0_0_1 = gr.vector_to_stream(gr.sizeof_gr_complex*1, N_re)
		self.gr_vector_to_stream_0_0_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, N_re)
		self.gr_vector_to_stream_0_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, N_re)
		self.gr_vector_to_stream_0 = gr.vector_to_stream(gr.sizeof_gr_complex*1, fft_size)
		self.gr_vector_source_x_0_0_0 = gr.vector_source_c((gen_pss_fd(N_id_2, N_re, False).get_data()), True, N_re)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate)
		self.gr_stream_to_vector_0_0 = gr.stream_to_vector(gr.sizeof_gr_complex*1, N_re)
		self.gr_stream_to_vector_0 = gr.stream_to_vector(gr.sizeof_gr_complex*1, fft_size)
		self.gr_stream_mux_0 = gr.stream_mux(gr.sizeof_gr_complex*1, (N_re/2, N_re/2))
		self.gr_null_source_0 = gr.null_source(gr.sizeof_gr_complex*1)
		self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise_level, 0)
		self.gr_multiply_xx_1_0 = gr.multiply_vcc(N_re)
		self.gr_multiply_xx_1 = gr.multiply_vcc(N_re)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((0.005*exp(rot*2*numpy.pi*1j), ))
		self.gr_keep_m_in_n_0_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, N_re/2, fft_size, (fft_size-N_re)/2-1)
		self.gr_keep_m_in_n_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, N_re/2, fft_size, (fft_size)/2)
		self.gr_file_source_0 = gr.file_source(gr.sizeof_gr_complex*1, "/home/user/git/gr-lte/gr-lte/test/octave/foo_sss_td_in.cfile", True)
		self.gr_fft_vxx_0 = gr.fft_vcc(fft_size, True, (window.blackmanharris(1024)), True, 1)
		self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex*N_re)
		self.gr_channel_model_0 = gr.channel_model(
			noise_voltage=0.005*noise_level,
			frequency_offset=0.0,
			epsilon=1,
			taps=(0.005*exp(rot*2*numpy.pi*1j), ),
			noise_seed=0,
		)
		self.gr_add_xx_0 = gr.add_vcc(1)
		self.blks2_selector_0_0 = grc_blks2.selector(
			item_size=gr.sizeof_gr_complex*1,
			num_inputs=2,
			num_outputs=1,
			input_index=0,
			output_index=0,
		)
		self.blks2_selector_0 = grc_blks2.selector(
			item_size=gr.sizeof_gr_complex*1,
			num_inputs=3,
			num_outputs=2,
			input_index=0,
			output_index=0,
		)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1))
		self.connect((self.gr_add_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.blks2_selector_0, 0), (self.gr_channel_model_0, 0))
		self.connect((self.blks2_selector_0, 1), (self.gr_add_xx_0, 0))
		self.connect((self.gr_channel_model_0, 0), (self.blks2_selector_0_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.blks2_selector_0_0, 1))
		self.connect((self.gr_file_source_0, 0), (self.blks2_selector_0, 0))
		self.connect((self.blks2_selector_0_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_deinterleave_0, 0), (self.gr_vector_to_stream_0_0_0, 0))
		self.connect((self.gr_vector_to_stream_0_0_0, 0), (self.wxgui_scopesink2_0_1_0_0, 0))
		self.connect((self.gr_vector_to_stream_0_0, 0), (self.wxgui_scopesink2_0_1_0, 0))
		self.connect((self.gr_fft_vxx_0, 0), (self.gr_vector_to_stream_0, 0))
		self.connect((self.gr_vector_to_stream_0, 0), (self.gr_keep_m_in_n_0, 0))
		self.connect((self.gr_stream_to_vector_0_0, 0), (self.gr_deinterleave_0, 0))
		self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0))
		self.connect((self.gr_vector_to_stream_0_0_1, 0), (self.wxgui_scopesink2_0_1_0_1, 0))
		self.connect((self.gr_vector_to_stream_0_0_1_0, 0), (self.wxgui_scopesink2_0_1_0_1, 1))
		self.connect((self.gr_vector_source_x_0_0_0, 0), (self.gr_vector_to_stream_0_0_1_0, 0))
		self.connect((self.pss_chan_est2_0, 0), (self.gr_multiply_xx_1, 1))
		self.connect((self.gr_multiply_xx_1, 0), (self.sss_ml_fd_0, 0))
		self.connect((self.gr_multiply_xx_1, 0), (self.gr_vector_to_stream_0_0, 0))
		self.connect((self.pss_chan_est2_0, 0), (self.gr_multiply_xx_1_0, 0))
		self.connect((self.gr_deinterleave_0, 1), (self.gr_multiply_xx_1_0, 1))
		self.connect((self.gr_multiply_xx_1_0, 0), (self.gr_vector_to_stream_0_0_1, 0))
		self.connect((self.gr_deinterleave_0, 1), (self.pss_chan_est2_0, 0))
		self.connect((self.gr_vector_to_stream_0, 0), (self.gr_keep_m_in_n_0_0, 0))
		self.connect((self.gr_keep_m_in_n_0_0, 0), (self.gr_stream_mux_0, 0))
		self.connect((self.gr_keep_m_in_n_0, 0), (self.gr_stream_mux_0, 1))
		self.connect((self.gr_stream_mux_0, 0), (self.gr_stream_to_vector_0_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.gr_stream_to_vector_0, 0))
		self.connect((self.gr_null_source_0, 0), (self.blks2_selector_0, 1))
		self.connect((self.gr_null_source_0, 0), (self.blks2_selector_0, 2))
		self.connect((self.sss_ml_fd_0, 0), (self.wxgui_scopesink2_0_1, 0))
		self.connect((self.gr_deinterleave_0, 0), (self.gr_multiply_xx_1, 0))
Example #34
0
    def __init__(self):
        gr.top_block.__init__(self)

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

        self._sample_rate = 2000e3

        self.sps = 2
        self.excess_bw = 0.35
        self.gray_code = True
        
        fftsize = 2048

        self.data = scipy.random.randint(0, 255, 1000)
        self.src = gr.vector_source_b(self.data.tolist(), True)
        self.mod = blks2.dqpsk_mod(self.sps, self.excess_bw, self.gray_code, False, False)

        self.rrctaps = gr.firdes.root_raised_cosine(1, self.sps, 1, self.excess_bw, 21)
        self.rx_rrc = gr.fir_filter_ccf(1, self.rrctaps)


        # Set up the carrier & clock recovery parameters
        self.arity = 4
        self.mu = 0.5
        self.gain_mu = 0.05
        self.omega = self.sps
        self.gain_omega = .25 * self.gain_mu * self.gain_mu
        self.omega_rel_lim = 0.05
        
        self.alpha = 0.15
        self.beta  = 0.25 * self.alpha * self.alpha
        self.fmin = -1000/self.sample_rate()
        self.fmax = 1000/self.sample_rate()
        
        self.receiver = gr.mpsk_receiver_cc(self.arity, 0,
                                            self.alpha, self.beta,
                                            self.fmin, self.fmax,
                                            self.mu, self.gain_mu,
                                            self.omega, self.gain_omega,
                                            self.omega_rel_lim)
        
        
        self.snr_dB = 15
        noise = self.get_noise_voltage(self.snr_dB)
        self.fo = 100/self.sample_rate()
        self.to = 1.0
        self.channel = gr.channel_model(noise, self.fo, self.to)

        self.thr = gr.throttle(gr.sizeof_char, self._sample_rate)
        self.snk_tx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS, 
                                   0, self._sample_rate*self.sps,
                                   "Tx", True, True, True, True)

        self.snk_rx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                   0, self._sample_rate,
                                   "Rx", True, True, True, True)

        self.connect(self.src, self.thr, self.mod, self.channel, self.snk_tx)
        self.connect(self.channel, self.rx_rrc, self.receiver, self.snk_rx)
        
        pyTxQt  = self.snk_tx.pyqwidget()
        pyTx = sip.wrapinstance(pyTxQt, QtGui.QWidget)

        pyRxQt  = self.snk_rx.pyqwidget()
        pyRx = sip.wrapinstance(pyRxQt, QtGui.QWidget)

        self.main_box = dialog_box(pyTx, pyRx, self);
        self.main_box.show()
Example #35
0
	def __init__(self):
		gr.top_block.__init__(self, "Simple TX/RX Path")

		##################################################
		# Blocks
		##################################################
		self.blks2_gmsk_demod_0 = blks2.gmsk_demod(
			samples_per_symbol=2,
			gain_mu=0.175,
			mu=0.5,
			omega_relative_limit=0.005,
			freq_error=0.0,
			verbose=False,
			log=False,
		)
		self.blks2_gmsk_mod_0 = blks2.gmsk_mod(
			samples_per_symbol=2,
			bt=0.35,
			verbose=False,
			log=False,
		)
		self.blks2_packet_decoder_0 = grc_blks2.packet_demod_b(grc_blks2.packet_decoder(
				access_code="",
				threshold=-1,
				callback=lambda ok, payload: self.blks2_packet_decoder_0.recv_pkt(ok, payload),
			),
		)
		self.blks2_packet_encoder_0 = grc_blks2.packet_mod_b(grc_blks2.packet_encoder(
				samples_per_symbol=1,
				bits_per_symbol=1,
				access_code="",
				pad_for_usrp=True,
			),
			payload_length=0,
		)
		self.blks2_tcp_sink_0 = grc_blks2.tcp_sink(
			itemsize=gr.sizeof_char*1,
			addr="127.0.0.1",
			port=9001,
			server=True,
		)
		self.blks2_tcp_source_0 = grc_blks2.tcp_source(
			itemsize=gr.sizeof_char*1,
			addr="127.0.0.1",
			port=9000,
			server=True,
		)
		self.gr_channel_model_0 = gr.channel_model(
			noise_voltage=0.0,
			frequency_offset=0.0,
			epsilon=1.0,
			taps=(1.0 + 1.0j, ),
			noise_seed=42,
		)

		##################################################
		# Connections
		##################################################
		self.connect((self.blks2_tcp_source_0, 0), (self.blks2_packet_encoder_0, 0))
		self.connect((self.blks2_packet_encoder_0, 0), (self.blks2_gmsk_mod_0, 0))
		self.connect((self.blks2_gmsk_mod_0, 0), (self.gr_channel_model_0, 0))
		self.connect((self.gr_channel_model_0, 0), (self.blks2_gmsk_demod_0, 0))
		self.connect((self.blks2_gmsk_demod_0, 0), (self.blks2_packet_decoder_0, 0))
		self.connect((self.blks2_packet_decoder_0, 0), (self.blks2_tcp_sink_0, 0))
Example #36
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="Simulated Sender GUI")

        ##################################################
        # Variables
        ##################################################
        self.samp_rate = samp_rate = 32000
        self.noise_voltage = noise_voltage = 0.01
        self.mult_const = mult_const = 1

        ##################################################
        # Controls
        ##################################################
        _noise_voltage_sizer = wx.BoxSizer(wx.VERTICAL)
        self._noise_voltage_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_noise_voltage_sizer,
            value=self.noise_voltage,
            callback=self.set_noise_voltage,
            label="Noise Voltage",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._noise_voltage_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_noise_voltage_sizer,
            value=self.noise_voltage,
            callback=self.set_noise_voltage,
            minimum=0,
            maximum=1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_noise_voltage_sizer)
        self._mult_const_text_box = forms.text_box(
            parent=self.GetWin(),
            value=self.mult_const,
            callback=self.set_mult_const,
            label="Multiplication Const",
            converter=forms.float_converter(),
        )
        self.Add(self._mult_const_text_box)

        ##################################################
        # Blocks
        ##################################################
        self.blks2_ofdm_mod_0 = grc_blks2.packet_mod_b(
            blks2.ofdm_mod(options=grc_blks2.options(
                modulation="bpsk",
                fft_length=512,
                occupied_tones=200,
                cp_length=128,
                pad_for_usrp=True,
                log=None,
                verbose=None,
            ), ),
            payload_length=512,
        )
        self.gr_channel_model_0 = gr.channel_model(
            noise_voltage=noise_voltage,
            frequency_offset=0.0,
            epsilon=1.0,
            taps=(1.0 + 1.0j, ),
            noise_seed=42,
        )
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((mult_const, ))
        self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate)
        self.random_source_x_0 = gr.vector_source_b(
            map(int, numpy.random.randint(0, 256, 512)), True)
        self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
            self.GetWin(),
            baseband_freq=0,
            y_per_div=10,
            y_divs=10,
            ref_level=50,
            sample_rate=samp_rate,
            fft_size=256,
            fft_rate=30,
            average=True,
            avg_alpha=0.1,
            title="FFT Plot",
            peak_hold=False,
        )
        self.Add(self.wxgui_fftsink2_0.win)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_throttle_0, 0), (self.wxgui_fftsink2_0, 0))
        self.connect((self.gr_channel_model_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_channel_model_0, 0))
        self.connect((self.random_source_x_0, 0), (self.blks2_ofdm_mod_0, 0))
        self.connect((self.blks2_ofdm_mod_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
Example #37
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Top Block")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 8*2**10
		self.nsps_mod = nsps_mod = 4
		self.noise = noise = .1
		self.freq_off = freq_off = 0
		self.ebw_mod = ebw_mod = 0.35

		##################################################
		# Notebooks
		##################################################
		self.n0 = wx.Notebook(self.GetWin(), style=wx.NB_TOP)
		self.n0.AddPage(grc_wxgui.Panel(self.n0), "tab1")
		self.n0.AddPage(grc_wxgui.Panel(self.n0), "tab2")
		self.n0.AddPage(grc_wxgui.Panel(self.n0), "tab3")
		self.Add(self.n0)

		##################################################
		# Controls
		##################################################
		_nsps_mod_sizer = wx.BoxSizer(wx.VERTICAL)
		self._nsps_mod_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_nsps_mod_sizer,
			value=self.nsps_mod,
			callback=self.set_nsps_mod,
			label="Samples per symbol for DPSK modulator",
			converter=forms.int_converter(),
			proportion=0,
		)
		self._nsps_mod_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_nsps_mod_sizer,
			value=self.nsps_mod,
			callback=self.set_nsps_mod,
			minimum=2,
			maximum=32,
			num_steps=31,
			style=wx.SL_HORIZONTAL,
			cast=int,
			proportion=1,
		)
		self.Add(_nsps_mod_sizer)
		_noise_sizer = wx.BoxSizer(wx.VERTICAL)
		self._noise_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_noise_sizer,
			value=self.noise,
			callback=self.set_noise,
			label="Noise",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._noise_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_noise_sizer,
			value=self.noise,
			callback=self.set_noise,
			minimum=0,
			maximum=1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Add(_noise_sizer)
		_freq_off_sizer = wx.BoxSizer(wx.VERTICAL)
		self._freq_off_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_freq_off_sizer,
			value=self.freq_off,
			callback=self.set_freq_off,
			label="Freq Offset",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._freq_off_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_freq_off_sizer,
			value=self.freq_off,
			callback=self.set_freq_off,
			minimum=-.5,
			maximum=.5,
			num_steps=1000,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Add(_freq_off_sizer)
		_ebw_mod_sizer = wx.BoxSizer(wx.VERTICAL)
		self._ebw_mod_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_ebw_mod_sizer,
			value=self.ebw_mod,
			callback=self.set_ebw_mod,
			label="Excess BW for DPSK modulator",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._ebw_mod_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_ebw_mod_sizer,
			value=self.ebw_mod,
			callback=self.set_ebw_mod,
			minimum=00.01,
			maximum=10.00,
			num_steps=10*100-1,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Add(_ebw_mod_sizer)

		##################################################
		# Blocks
		##################################################
		self.blks2_dxpsk2_mod_0 = blks2.dqpsk2_mod(
			samples_per_symbol=nsps_mod,
			excess_bw=ebw_mod,
			gray_code=True,
			verbose=False,
			log=False,
		)
		self.blks2_packet_encoder_0 = grc_blks2.packet_mod_b(grc_blks2.packet_encoder(
				samples_per_symbol=1,
				bits_per_symbol=1,
				access_code="",
				pad_for_usrp=True,
			),
			payload_length=0,
		)
		self.gr_agc2_xx_0 = gr.agc2_cc(1e-1, 1e-2, 1.0, 1.0, 1e3)
		self.gr_channel_model_0 = gr.channel_model(
			noise_voltage=noise,
			frequency_offset=freq_off,
			epsilon=1.0,
			taps=(16.0, ),
			noise_seed=42,
		)
		self.gr_throttle_1_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate*nsps_mod*8)
		self.random_source_x_0 = gr.vector_source_b(map(int, numpy.random.randint(0, 2, 1000)), True)
		self.wxgui_constellationsink2_0 = constsink_gl.const_sink_c(
			self.n0.GetPage(1).GetWin(),
			title="Constellation Plot",
			sample_rate=samp_rate*8*nsps_mod/2,
			frame_rate=5,
			const_size=512,
			M=4,
			theta=0,
			alpha=0.005,
			fmax=0.5,
			mu=0.5,
			gain_mu=0.005,
			symbol_rate=samp_rate*8/2,
			omega_limit=0.005,
		)
		self.n0.GetPage(1).Add(self.wxgui_constellationsink2_0.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.blks2_packet_encoder_0, 0), (self.blks2_dxpsk2_mod_0, 0))
		self.connect((self.random_source_x_0, 0), (self.blks2_packet_encoder_0, 0))
		self.connect((self.gr_channel_model_0, 0), (self.gr_agc2_xx_0, 0))
		self.connect((self.gr_throttle_1_0, 0), (self.wxgui_constellationsink2_0, 0))
		self.connect((self.blks2_dxpsk2_mod_0, 0), (self.gr_channel_model_0, 0))
		self.connect((self.gr_agc2_xx_0, 0), (self.gr_throttle_1_0, 0))
Example #38
0
    def __init__(self,
                 freq_corr=0,
                 avg_frames=1,
                 decim=16,
                 N_id_2=0,
                 N_id_1=134):
        grc_wxgui.top_block_gui.__init__(self, title="Sss Corr5 Gui")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Parameters
        ##################################################
        self.freq_corr = freq_corr
        self.avg_frames = avg_frames
        self.decim = decim
        self.N_id_2 = N_id_2
        self.N_id_1 = N_id_1

        ##################################################
        # Variables
        ##################################################
        self.vec_half_frame = vec_half_frame = 30720 * 5 / decim
        self.symbol_start = symbol_start = 144 / decim
        self.slot_0_10 = slot_0_10 = 1
        self.samp_rate = samp_rate = 30720e3 / decim
        self.rot = rot = 0
        self.noise_level = noise_level = 0
        self.fft_size = fft_size = 2048 / decim
        self.N_re = N_re = 62

        ##################################################
        # Blocks
        ##################################################
        _rot_sizer = wx.BoxSizer(wx.VERTICAL)
        self._rot_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_rot_sizer,
            value=self.rot,
            callback=self.set_rot,
            label='rot',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._rot_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_rot_sizer,
            value=self.rot,
            callback=self.set_rot,
            minimum=0,
            maximum=1,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_rot_sizer)
        self.notebook_0 = self.notebook_0 = wx.Notebook(self.GetWin(),
                                                        style=wx.NB_TOP)
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS ML")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS equ")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "SSS in")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "PSS equ")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "PSS ch est")
        self.notebook_0.AddPage(grc_wxgui.Panel(self.notebook_0), "foo")
        self.Add(self.notebook_0)
        _noise_level_sizer = wx.BoxSizer(wx.VERTICAL)
        self._noise_level_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_noise_level_sizer,
            value=self.noise_level,
            callback=self.set_noise_level,
            label='noise_level',
            converter=forms.float_converter(),
            proportion=0,
        )
        self._noise_level_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_noise_level_sizer,
            value=self.noise_level,
            callback=self.set_noise_level,
            minimum=0,
            maximum=10,
            num_steps=100,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_noise_level_sizer)
        self.wxgui_scopesink2_0_1_0_1 = scopesink2.scope_sink_c(
            self.notebook_0.GetPage(3).GetWin(),
            title="Scope Plot",
            sample_rate=samp_rate,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=2,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.notebook_0.GetPage(3).Add(self.wxgui_scopesink2_0_1_0_1.win)
        self.wxgui_scopesink2_0_1_0_0 = scopesink2.scope_sink_c(
            self.notebook_0.GetPage(2).GetWin(),
            title="Scope Plot",
            sample_rate=samp_rate,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.notebook_0.GetPage(2).Add(self.wxgui_scopesink2_0_1_0_0.win)
        self.wxgui_scopesink2_0_1_0 = scopesink2.scope_sink_c(
            self.notebook_0.GetPage(1).GetWin(),
            title="Scope Plot",
            sample_rate=samp_rate,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.notebook_0.GetPage(1).Add(self.wxgui_scopesink2_0_1_0.win)
        self.wxgui_scopesink2_0_1 = scopesink2.scope_sink_f(
            self.notebook_0.GetPage(0).GetWin(),
            title="Scope Plot",
            sample_rate=100 / avg_frames,
            v_scale=0,
            v_offset=0,
            t_scale=0,
            ac_couple=False,
            xy_mode=False,
            num_inputs=1,
            trig_mode=gr.gr_TRIG_MODE_AUTO,
            y_axis_label="Counts",
        )
        self.notebook_0.GetPage(0).Add(self.wxgui_scopesink2_0_1.win)
        _symbol_start_sizer = wx.BoxSizer(wx.VERTICAL)
        self._symbol_start_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_symbol_start_sizer,
            value=self.symbol_start,
            callback=self.set_symbol_start,
            label='symbol_start',
            converter=forms.int_converter(),
            proportion=0,
        )
        self._symbol_start_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_symbol_start_sizer,
            value=self.symbol_start,
            callback=self.set_symbol_start,
            minimum=0,
            maximum=144 / decim,
            num_steps=144 / decim,
            style=wx.SL_HORIZONTAL,
            cast=int,
            proportion=1,
        )
        self.Add(_symbol_start_sizer)
        self.sss_ml_fd_0 = sss_ml_fd(
            decim=decim,
            avg_frames=avg_frames,
            N_id_1=N_id_1,
            N_id_2=N_id_2,
            slot_0_10=slot_0_10,
        )
        self.pss_chan_est2_0 = pss_chan_est2(N_id_2=N_id_2, )
        self.gr_vector_to_stream_0_0_1_0 = gr.vector_to_stream(
            gr.sizeof_gr_complex * 1, N_re)
        self.gr_vector_to_stream_0_0_1 = gr.vector_to_stream(
            gr.sizeof_gr_complex * 1, N_re)
        self.gr_vector_to_stream_0_0_0 = gr.vector_to_stream(
            gr.sizeof_gr_complex * 1, N_re)
        self.gr_vector_to_stream_0_0 = gr.vector_to_stream(
            gr.sizeof_gr_complex * 1, N_re)
        self.gr_vector_to_stream_0 = gr.vector_to_stream(
            gr.sizeof_gr_complex * 1, fft_size)
        self.gr_vector_source_x_0_0_0 = gr.vector_source_c(
            (gen_pss_fd(N_id_2, N_re, False).get_data()), True, N_re)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex * 1, samp_rate)
        self.gr_stream_to_vector_0_0 = gr.stream_to_vector(
            gr.sizeof_gr_complex * 1, N_re)
        self.gr_stream_to_vector_0 = gr.stream_to_vector(
            gr.sizeof_gr_complex * 1, fft_size)
        self.gr_stream_mux_0 = gr.stream_mux(gr.sizeof_gr_complex * 1,
                                             (N_re / 2, N_re / 2))
        self.gr_null_source_0 = gr.null_source(gr.sizeof_gr_complex * 1)
        self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN,
                                                     noise_level, 0)
        self.gr_multiply_xx_1_0 = gr.multiply_vcc(N_re)
        self.gr_multiply_xx_1 = gr.multiply_vcc(N_re)
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc(
            (0.005 * exp(rot * 2 * numpy.pi * 1j), ))
        self.gr_keep_m_in_n_0_0 = gr.keep_m_in_n(gr.sizeof_gr_complex,
                                                 N_re / 2, fft_size,
                                                 (fft_size - N_re) / 2 - 1)
        self.gr_keep_m_in_n_0 = gr.keep_m_in_n(gr.sizeof_gr_complex, N_re / 2,
                                               fft_size, (fft_size) / 2)
        self.gr_file_source_0 = gr.file_source(
            gr.sizeof_gr_complex * 1,
            "/home/user/git/gr-lte/gr-lte/test/octave/foo_sss_td_in.cfile",
            True)
        self.gr_fft_vxx_0 = gr.fft_vcc(fft_size, True,
                                       (window.blackmanharris(1024)), True, 1)
        self.gr_deinterleave_0 = gr.deinterleave(gr.sizeof_gr_complex * N_re)
        self.gr_channel_model_0 = gr.channel_model(
            noise_voltage=0.005 * noise_level,
            frequency_offset=0.0,
            epsilon=1,
            taps=(0.005 * exp(rot * 2 * numpy.pi * 1j), ),
            noise_seed=0,
        )
        self.gr_add_xx_0 = gr.add_vcc(1)
        self.blks2_selector_0_0 = grc_blks2.selector(
            item_size=gr.sizeof_gr_complex * 1,
            num_inputs=2,
            num_outputs=1,
            input_index=0,
            output_index=0,
        )
        self.blks2_selector_0 = grc_blks2.selector(
            item_size=gr.sizeof_gr_complex * 1,
            num_inputs=3,
            num_outputs=2,
            input_index=0,
            output_index=0,
        )

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1))
        self.connect((self.gr_add_xx_0, 0), (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.blks2_selector_0, 0), (self.gr_channel_model_0, 0))
        self.connect((self.blks2_selector_0, 1), (self.gr_add_xx_0, 0))
        self.connect((self.gr_channel_model_0, 0),
                     (self.blks2_selector_0_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.blks2_selector_0_0, 1))
        self.connect((self.gr_file_source_0, 0), (self.blks2_selector_0, 0))
        self.connect((self.blks2_selector_0_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.gr_deinterleave_0, 0),
                     (self.gr_vector_to_stream_0_0_0, 0))
        self.connect((self.gr_vector_to_stream_0_0_0, 0),
                     (self.wxgui_scopesink2_0_1_0_0, 0))
        self.connect((self.gr_vector_to_stream_0_0, 0),
                     (self.wxgui_scopesink2_0_1_0, 0))
        self.connect((self.gr_fft_vxx_0, 0), (self.gr_vector_to_stream_0, 0))
        self.connect((self.gr_vector_to_stream_0, 0),
                     (self.gr_keep_m_in_n_0, 0))
        self.connect((self.gr_stream_to_vector_0_0, 0),
                     (self.gr_deinterleave_0, 0))
        self.connect((self.gr_stream_to_vector_0, 0), (self.gr_fft_vxx_0, 0))
        self.connect((self.gr_vector_to_stream_0_0_1, 0),
                     (self.wxgui_scopesink2_0_1_0_1, 0))
        self.connect((self.gr_vector_to_stream_0_0_1_0, 0),
                     (self.wxgui_scopesink2_0_1_0_1, 1))
        self.connect((self.gr_vector_source_x_0_0_0, 0),
                     (self.gr_vector_to_stream_0_0_1_0, 0))
        self.connect((self.pss_chan_est2_0, 0), (self.gr_multiply_xx_1, 1))
        self.connect((self.gr_multiply_xx_1, 0), (self.sss_ml_fd_0, 0))
        self.connect((self.gr_multiply_xx_1, 0),
                     (self.gr_vector_to_stream_0_0, 0))
        self.connect((self.pss_chan_est2_0, 0), (self.gr_multiply_xx_1_0, 0))
        self.connect((self.gr_deinterleave_0, 1), (self.gr_multiply_xx_1_0, 1))
        self.connect((self.gr_multiply_xx_1_0, 0),
                     (self.gr_vector_to_stream_0_0_1, 0))
        self.connect((self.gr_deinterleave_0, 1), (self.pss_chan_est2_0, 0))
        self.connect((self.gr_vector_to_stream_0, 0),
                     (self.gr_keep_m_in_n_0_0, 0))
        self.connect((self.gr_keep_m_in_n_0_0, 0), (self.gr_stream_mux_0, 0))
        self.connect((self.gr_keep_m_in_n_0, 0), (self.gr_stream_mux_0, 1))
        self.connect((self.gr_stream_mux_0, 0),
                     (self.gr_stream_to_vector_0_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.gr_stream_to_vector_0, 0))
        self.connect((self.gr_null_source_0, 0), (self.blks2_selector_0, 1))
        self.connect((self.gr_null_source_0, 0), (self.blks2_selector_0, 2))
        self.connect((self.sss_ml_fd_0, 0), (self.wxgui_scopesink2_0_1, 0))
        self.connect((self.gr_deinterleave_0, 0), (self.gr_multiply_xx_1, 0))
Example #39
0
    def __init__(self, callback, options):
        gr.top_block.__init__(self)

        if not options.channel_off:
            SNR = 10.0**(options.snr/10.0)
            power_in_signal = abs(options.tx_amplitude)**2.0
            noise_power_in_channel = power_in_signal/SNR
            noise_voltage = math.sqrt(noise_power_in_channel/2.0)
            #noise_voltage = 0
            
            frequency_offset = options.frequency_offset / options.fft_length

            if options.multipath_on:
                taps = [1.0, .2, 0.0, .1, .08, -.4, .12, -.2, 0, 0, 0, .3]
                #taps = [0.5,0.5]
            else:
                taps = [1.0, 0.0]

            if options.verbose:
                print "Targeted SNR(dB): ",options.snr
                print "Noise Amplitude: ", noise_voltage
                print "Frequency offset: ", frequency_offset
                print "Taps: ",taps
        else:
            noise_voltage = 0.0
            frequency_offset = 0.0
            taps = [1.0, 0.0]

        z = [0,]
        self.zeros = gr.vector_source_c(z, True)
        self.txpath = transmit_path(options)

        self.subcarrier_size = self.txpath._pkt_input.subcarrier_size() 
        #self.subcarrier_size = options.occupied_tones-2
        
        # 4 bytes of Packet Length
        # 1 byte of whitener offset
        # 4 bytes of CRC
        symbols_per_packet = math.ceil(((4+1+options.size+4) * 8) / math.log(self.txpath.arity,2) / self.subcarrier_size)
        
        # 1 set of Preamble
        samples_per_packet = (symbols_per_packet + 3 + 0) * (options.fft_length+options.cp_length)



        print "Symbols per Packet: ", symbols_per_packet
        print "Samples per Packet: ", samples_per_packet


        if options.discontinuous:
            stream_size = [1000, int(options.discontinuous*samples_per_packet) + 512]
        else:
            stream_size = [0, 100000]

        print 'Stream Size=',stream_size

        self.mux = gr.stream_mux(gr.sizeof_gr_complex, stream_size)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)
        self.channel = gr.channel_model(noise_voltage, frequency_offset,
                                        options.clockrate_ratio, taps)
        self.rxpath = receive_path(callback, options)
                
        self.connect(self.zeros, (self.mux,0))
        self.connect(self.txpath, (self.mux,1))
        self.connect(self.mux, self.throttle, self.channel, self.rxpath)
        
        #self.connect(self.mux, self.throttle, self.rxpath)
        
        #self.connect(self.txpath, self.throttle, self.channel, self.rxpath)
        #self.connect(self.txpath, self.rxpath)
        
        if options.log:
            self.connect(self.txpath, gr.file_sink(gr.sizeof_gr_complex, "txpath.dat"))
            self.connect(self.mux, gr.file_sink(gr.sizeof_gr_complex, "mux.dat"))
    def __init__(self, mod_class, demod_class, rx_callback, options):
        gr.top_block.__init__(self)

        self._sample_rate = options.sample_rate

        channelon = True;

        self.gui_on = options.gui

        self._frequency_offset = options.frequency_offset
        self._timing_offset = options.timing_offset
        self._tx_amplitude = options.tx_amplitude
        self._snr_dB = options.snr

        self._noise_voltage = self.get_noise_voltage(self._snr_dB)

        # With new interface, sps does not get set by default, but
        # in the loopback, we don't recalculate it; so just force it here
        if(options.samples_per_symbol == None):
            options.samples_per_symbol = 2

        self.txpath = transmit_path(mod_class, options)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, self.sample_rate())
        self.rxpath = receive_path(demod_class, rx_callback, options)

        # FIXME: do better exposure to lower issues for control
        self._gain_clock = self.rxpath.packet_receiver._demodulator._timing_alpha
        self._gain_phase = self.rxpath.packet_receiver._demodulator._phase_alpha
        self._gain_freq  = self.rxpath.packet_receiver._demodulator._freq_alpha

        if channelon:
            self.channel = gr.channel_model(self._noise_voltage,
                                            self.frequency_offset(),
                                            self.timing_offset())
            
            if options.discontinuous:
                z = 20000*[0,]
                self.zeros = gr.vector_source_c(z, True)
                packet_size = 5*((4+8+4+1500+4) * 8)
                self.mux = gr.stream_mux(gr.sizeof_gr_complex, [packet_size-0, int(9e5)])

                # Connect components
                self.connect(self.txpath, self.throttle, (self.mux,0))
                self.connect(self.zeros, (self.mux,1))
                self.connect(self.mux, self.channel, self.rxpath)

            else:
                self.connect(self.txpath, self.throttle, self.channel, self.rxpath)

            if self.gui_on:
                self.qapp = QtGui.QApplication(sys.argv)
                fftsize = 2048

                self.snk_tx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                           0, 1,
                                           "Tx", True, True, False, True, True)
                self.snk_rx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                           0, 1,
                                           "Rx", True, True, False, True, True)

                self.snk_tx.set_frequency_axis(-80, 0)
                self.snk_rx.set_frequency_axis(-60, 20)

                self.freq_recov = self.rxpath.packet_receiver._demodulator.freq_recov
                self.phase_recov = self.rxpath.packet_receiver._demodulator.phase_recov
                self.time_recov = self.rxpath.packet_receiver._demodulator.time_recov
                self.freq_recov.set_alpha(self._gain_freq)
                self.freq_recov.set_beta(self._gain_freq/10.0)
                self.phase_recov.set_alpha(self._gain_phase)
                self.phase_recov.set_beta(0.25*self._gain_phase*self._gain_phase)
                self.time_recov.set_alpha(self._gain_clock)
                self.time_recov.set_beta(0.25*self._gain_clock*self._gain_clock)

                # Connect to the QT sinks
                # FIXME: make better exposure to receiver from rxpath
                self.connect(self.channel, self.snk_tx)
                self.connect(self.phase_recov, self.snk_rx)
                #self.connect(self.freq_recov, self.snk_rx)

                pyTxQt  = self.snk_tx.pyqwidget()
                pyTx = sip.wrapinstance(pyTxQt, QtGui.QWidget)
                 
                pyRxQt  = self.snk_rx.pyqwidget()
                pyRx = sip.wrapinstance(pyRxQt, QtGui.QWidget)

                self.main_box = dialog_box(pyTx, pyRx, self)
                self.main_box.show()
                
        else:
            # Connect components
            self.connect(self.txpath, self.throttle, self.rxpath)
Example #41
0
    def __init__(self, mod_class, demod_class, rx_callback, options):
        gr.top_block.__init__(self)

        self._sample_rate = options.sample_rate

        if(options.samples_per_symbol is None):
            options.samples_per_symbol = 2

        channelon = True;

        self.gui_on = options.gui

        self._frequency_offset = options.frequency_offset
        self._timing_offset = options.timing_offset
        self._tx_amplitude = options.tx_amplitude
        self._snr_dB = options.snr

        self._noise_voltage = self.get_noise_voltage(self._snr_dB)

        self.txpath = transmit_path(mod_class, options)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, self.sample_rate())
        self.rxpath = receive_path(demod_class, rx_callback, options)

        # FIXME: do better exposure to lower issues for control
        self._timing_gain_alpha = self.rxpath.packet_receiver._demodulator._mm_gain_mu
        self._alpha = self.rxpath.packet_receiver._demodulator._costas_alpha

        if channelon:
            self.channel = gr.channel_model(self._noise_voltage,
                                            self.frequency_offset(),
                                            self.timing_offset())
            
            if options.discontinuous:
                z = 20000*[0,]
                self.zeros = gr.vector_source_c(z, True)
                packet_size = 5*((4+8+4+1500+4) * 8)
                self.mux = gr.stream_mux(gr.sizeof_gr_complex, [packet_size-0, int(9e5)])

                # Connect components
                self.connect(self.txpath, self.throttle, (self.mux,0))
                self.connect(self.zeros, (self.mux,1))
                self.connect(self.mux, self.channel, self.rxpath)

            else:
                self.connect(self.txpath, self.throttle, self.channel, self.rxpath)

            if self.gui_on:
                self.qapp = QtGui.QApplication(sys.argv)
                fftsize = 2048

                self.snk_tx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                           0, self._sample_rate,
                                           "Tx", True, True, False, True, True)
                self.snk_rx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                           0, self._sample_rate,
                                           "Rx", True, True, False, True, True)

                self.snk_tx.set_frequency_axis(-80, 0)
                self.snk_rx.set_frequency_axis(-60, 20)
            
                # Connect to the QT sinks
                # FIXME: make better exposure to receiver from rxpath
                self.receiver = self.rxpath.packet_receiver._demodulator.receiver
                self.receiver.set_alpha(2)
                self.receiver.set_beta(0.02)
                self.connect(self.channel, self.snk_tx)
                self.connect(self.receiver, self.snk_rx)

                pyTxQt  = self.snk_tx.pyqwidget()
                pyTx = sip.wrapinstance(pyTxQt, QtGui.QWidget)
                 
                pyRxQt  = self.snk_rx.pyqwidget()
                pyRx = sip.wrapinstance(pyRxQt, QtGui.QWidget)

                self.main_box = dialog_box(pyTx, pyRx, self)
                self.main_box.show()
                
        else:
            # Connect components
            self.connect(self.txpath, self.throttle, self.rxpath)
Example #42
0
def main():
    N = 10000
    fs = 2000.0
    Ts = 1.0/fs
    t = scipy.arange(0, N*Ts, Ts)

    # When playing with the number of channels, be careful about the filter
    # specs and the channel map of the synthesizer set below.
    nchans = 10

    # Build the filter(s)
    bw = 1000
    tb = 400
    proto_taps = gr.firdes.low_pass_2(1, nchans*fs, bw, tb, 80,
                                      gr.firdes.WIN_BLACKMAN_hARRIS)
    print "Filter length: ", len(proto_taps)


    # Create a modulated signal
    npwr = 0.01
    data = scipy.random.randint(0, 256, N)
    rrc_taps = gr.firdes.root_raised_cosine(1, 2, 1, 0.35, 41)

    src = gr.vector_source_b(data.astype(scipy.uint8).tolist(), False)
    mod = digital.bpsk_mod(samples_per_symbol=2)
    chan = gr.channel_model(npwr)
    rrc = gr.fft_filter_ccc(1, rrc_taps)

    # Split it up into pieces
    channelizer = blks2.pfb_channelizer_ccf(nchans, proto_taps, 2)

    # Put the pieces back together again
    syn_taps = [nchans*t for t in proto_taps]
    synthesizer = gr.pfb_synthesizer_ccf(nchans, syn_taps, True)
    src_snk = gr.vector_sink_c()
    snk = gr.vector_sink_c()

    # Remap the location of the channels
    # Can be done in synth or channelizer (watch out for rotattions in
    # the channelizer)
    synthesizer.set_channel_map([ 0,  1,  2,  3,  4,
                                 15, 16, 17, 18, 19])

    tb = gr.top_block()
    tb.connect(src, mod, chan, rrc, channelizer)
    tb.connect(rrc, src_snk)

    vsnk = []
    for i in xrange(nchans):
        tb.connect((channelizer,i), (synthesizer, i))

        vsnk.append(gr.vector_sink_c())
        tb.connect((channelizer,i), vsnk[i])

    tb.connect(synthesizer, snk)
    tb.run()

    sin  = scipy.array(src_snk.data()[1000:])
    sout = scipy.array(snk.data()[1000:])


    # Plot original signal
    fs_in = nchans*fs
    f1 = pylab.figure(1, figsize=(16,12), facecolor='w')
    s11 = f1.add_subplot(2,2,1)
    s11.psd(sin, NFFT=fftlen, Fs=fs_in)
    s11.set_title("PSD of Original Signal")
    s11.set_ylim([-200, -20])

    s12 = f1.add_subplot(2,2,2)
    s12.plot(sin.real[1000:1500], "o-b")
    s12.plot(sin.imag[1000:1500], "o-r")
    s12.set_title("Original Signal in Time")

    start = 1
    skip  = 4
    s13 = f1.add_subplot(2,2,3)
    s13.plot(sin.real[start::skip], sin.imag[start::skip], "o")
    s13.set_title("Constellation")
    s13.set_xlim([-2, 2])
    s13.set_ylim([-2, 2])

    # Plot channels
    nrows = int(scipy.sqrt(nchans))
    ncols = int(scipy.ceil(float(nchans)/float(nrows)))

    f2 = pylab.figure(2, figsize=(16,12), facecolor='w')
    for n in xrange(nchans):
        s = f2.add_subplot(nrows, ncols, n+1)
        s.psd(vsnk[n].data(), NFFT=fftlen, Fs=fs_in)
        s.set_title("Channel {0}".format(n))
        s.set_ylim([-200, -20])

    # Plot reconstructed signal
    fs_out = 2*nchans*fs
    f3 = pylab.figure(3, figsize=(16,12), facecolor='w')
    s31 = f3.add_subplot(2,2,1)
    s31.psd(sout, NFFT=fftlen, Fs=fs_out)
    s31.set_title("PSD of Reconstructed Signal")
    s31.set_ylim([-200, -20])

    s32 = f3.add_subplot(2,2,2)
    s32.plot(sout.real[1000:1500], "o-b")
    s32.plot(sout.imag[1000:1500], "o-r")
    s32.set_title("Reconstructed Signal in Time")

    start = 2
    skip  = 4
    s33 = f3.add_subplot(2,2,3)
    s33.plot(sout.real[start::skip], sout.imag[start::skip], "o")
    s33.set_title("Constellation")
    s33.set_xlim([-2, 2])
    s33.set_ylim([-2, 2])

    pylab.show()
Example #43
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="DVB Simulator (GMSK)")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.signal = signal = 1
        self.samp_rate = samp_rate = 32000
        self.noise = noise = 10

        ##################################################
        # Blocks
        ##################################################
        _signal_sizer = wx.BoxSizer(wx.VERTICAL)
        self._signal_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_signal_sizer,
            value=self.signal,
            callback=self.set_signal,
            label="Signal",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._signal_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_signal_sizer,
            value=self.signal,
            callback=self.set_signal,
            minimum=0,
            maximum=1000,
            num_steps=1000,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_signal_sizer)
        _noise_sizer = wx.BoxSizer(wx.VERTICAL)
        self._noise_text_box = forms.text_box(
            parent=self.GetWin(),
            sizer=_noise_sizer,
            value=self.noise,
            callback=self.set_noise,
            label="Noise",
            converter=forms.float_converter(),
            proportion=0,
        )
        self._noise_slider = forms.slider(
            parent=self.GetWin(),
            sizer=_noise_sizer,
            value=self.noise,
            callback=self.set_noise,
            minimum=0,
            maximum=1000,
            num_steps=1000,
            style=wx.SL_HORIZONTAL,
            cast=float,
            proportion=1,
        )
        self.Add(_noise_sizer)
        self.gr_wavfile_source_0 = gr.wavfile_source(
            "/home/traviscollins/GNURADIO/tfc_models/test.wav", False)
        self.gr_throttle_0 = gr.throttle(gr.sizeof_float * 1, samp_rate)
        self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise, 42)
        self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((signal, ))
        self.gr_file_sink_1_0 = gr.file_sink(
            gr.sizeof_float * 1,
            "/home/traviscollins/GNURADIO/tfc_models/output_txt.wav")
        self.gr_file_sink_1_0.set_unbuffered(False)
        self.gr_channel_model_0 = gr.channel_model(
            noise_voltage=20,
            frequency_offset=0.0,
            epsilon=1.0,
            taps=(1.0 + 1.0j, ),
            noise_seed=42,
        )
        self.gr_add_xx_0 = gr.add_vcc(1)
        self.digital_gmsk_mod_0 = digital.gmsk_mod(
            samples_per_symbol=2,
            bt=0.35,
            verbose=False,
            log=False,
        )
        self.digital_gmsk_demod_0 = digital.gmsk_demod(
            samples_per_symbol=2,
            gain_mu=0.175,
            mu=0.5,
            omega_relative_limit=0.005,
            freq_error=0.0,
            verbose=False,
            log=False,
        )
        self.blks2_packet_encoder_0 = grc_blks2.packet_mod_f(
            grc_blks2.packet_encoder(
                samples_per_symbol=2,
                bits_per_symbol=1,
                access_code="",
                pad_for_usrp=True,
            ),
            payload_length=0,
        )
        self.blks2_packet_decoder_0 = grc_blks2.packet_demod_f(
            grc_blks2.packet_decoder(
                access_code="",
                threshold=-1,
                callback=lambda ok, payload: self.blks2_packet_decoder_0.
                recv_pkt(ok, payload),
            ), )
        self.audio_sink_0 = audio.sink(samp_rate, "", True)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1))
        self.connect((self.gr_add_xx_0, 0), (self.digital_gmsk_demod_0, 0))
        self.connect((self.blks2_packet_encoder_0, 0),
                     (self.digital_gmsk_mod_0, 0))
        self.connect((self.digital_gmsk_mod_0, 0),
                     (self.gr_multiply_const_vxx_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.blks2_packet_encoder_0, 0))
        self.connect((self.gr_throttle_0, 0), (self.gr_file_sink_1_0, 0))
        self.connect((self.digital_gmsk_demod_0, 0),
                     (self.blks2_packet_decoder_0, 0))
        self.connect((self.gr_multiply_const_vxx_0, 0),
                     (self.gr_channel_model_0, 0))
        self.connect((self.gr_channel_model_0, 0), (self.gr_add_xx_0, 0))
        self.connect((self.gr_wavfile_source_0, 0), (self.gr_throttle_0, 0))
        self.connect((self.blks2_packet_decoder_0, 0), (self.audio_sink_0, 0))
Example #44
0
def main():
    N = 10000
    fs = 2000.0
    Ts = 1.0 / fs
    t = scipy.arange(0, N * Ts, Ts)

    # When playing with the number of channels, be careful about the filter
    # specs and the channel map of the synthesizer set below.
    nchans = 10

    # Build the filter(s)
    bw = 1000
    tb = 400
    proto_taps = gr.firdes.low_pass_2(1, nchans * fs, bw, tb, 80,
                                      gr.firdes.WIN_BLACKMAN_hARRIS)
    print "Filter length: ", len(proto_taps)

    # Create a modulated signal
    npwr = 0.01
    data = scipy.random.randint(0, 256, N)
    rrc_taps = gr.firdes.root_raised_cosine(1, 2, 1, 0.35, 41)

    src = gr.vector_source_b(data.astype(scipy.uint8).tolist(), False)
    mod = digital.bpsk_mod(samples_per_symbol=2)
    chan = gr.channel_model(npwr)
    rrc = gr.fft_filter_ccc(1, rrc_taps)

    # Split it up into pieces
    channelizer = blks2.pfb_channelizer_ccf(nchans, proto_taps, 2)

    # Put the pieces back together again
    syn_taps = [nchans * t for t in proto_taps]
    synthesizer = gr.pfb_synthesizer_ccf(nchans, syn_taps, True)
    src_snk = gr.vector_sink_c()
    snk = gr.vector_sink_c()

    # Remap the location of the channels
    # Can be done in synth or channelizer (watch out for rotattions in
    # the channelizer)
    synthesizer.set_channel_map([0, 1, 2, 3, 4, 15, 16, 17, 18, 19])

    tb = gr.top_block()
    tb.connect(src, mod, chan, rrc, channelizer)
    tb.connect(rrc, src_snk)

    vsnk = []
    for i in xrange(nchans):
        tb.connect((channelizer, i), (synthesizer, i))

        vsnk.append(gr.vector_sink_c())
        tb.connect((channelizer, i), vsnk[i])

    tb.connect(synthesizer, snk)
    tb.run()

    sin = scipy.array(src_snk.data()[1000:])
    sout = scipy.array(snk.data()[1000:])

    # Plot original signal
    fs_in = nchans * fs
    f1 = pylab.figure(1, figsize=(16, 12), facecolor='w')
    s11 = f1.add_subplot(2, 2, 1)
    s11.psd(sin, NFFT=fftlen, Fs=fs_in)
    s11.set_title("PSD of Original Signal")
    s11.set_ylim([-200, -20])

    s12 = f1.add_subplot(2, 2, 2)
    s12.plot(sin.real[1000:1500], "o-b")
    s12.plot(sin.imag[1000:1500], "o-r")
    s12.set_title("Original Signal in Time")

    start = 1
    skip = 4
    s13 = f1.add_subplot(2, 2, 3)
    s13.plot(sin.real[start::skip], sin.imag[start::skip], "o")
    s13.set_title("Constellation")
    s13.set_xlim([-2, 2])
    s13.set_ylim([-2, 2])

    # Plot channels
    nrows = int(scipy.sqrt(nchans))
    ncols = int(scipy.ceil(float(nchans) / float(nrows)))

    f2 = pylab.figure(2, figsize=(16, 12), facecolor='w')
    for n in xrange(nchans):
        s = f2.add_subplot(nrows, ncols, n + 1)
        s.psd(vsnk[n].data(), NFFT=fftlen, Fs=fs_in)
        s.set_title("Channel {0}".format(n))
        s.set_ylim([-200, -20])

    # Plot reconstructed signal
    fs_out = 2 * nchans * fs
    f3 = pylab.figure(3, figsize=(16, 12), facecolor='w')
    s31 = f3.add_subplot(2, 2, 1)
    s31.psd(sout, NFFT=fftlen, Fs=fs_out)
    s31.set_title("PSD of Reconstructed Signal")
    s31.set_ylim([-200, -20])

    s32 = f3.add_subplot(2, 2, 2)
    s32.plot(sout.real[1000:1500], "o-b")
    s32.plot(sout.imag[1000:1500], "o-r")
    s32.set_title("Reconstructed Signal in Time")

    start = 2
    skip = 4
    s33 = f3.add_subplot(2, 2, 3)
    s33.plot(sout.real[start::skip], sout.imag[start::skip], "o")
    s33.set_title("Constellation")
    s33.set_xlim([-2, 2])
    s33.set_ylim([-2, 2])

    pylab.show()
Example #45
0
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="DVB Simulator (GMSK)")
		_icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
		self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

		##################################################
		# Variables
		##################################################
		self.signal = signal = 1
		self.samp_rate = samp_rate = 32000
		self.noise = noise = 10

		##################################################
		# Blocks
		##################################################
		_signal_sizer = wx.BoxSizer(wx.VERTICAL)
		self._signal_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_signal_sizer,
			value=self.signal,
			callback=self.set_signal,
			label="Signal",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._signal_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_signal_sizer,
			value=self.signal,
			callback=self.set_signal,
			minimum=0,
			maximum=1000,
			num_steps=1000,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Add(_signal_sizer)
		_noise_sizer = wx.BoxSizer(wx.VERTICAL)
		self._noise_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_noise_sizer,
			value=self.noise,
			callback=self.set_noise,
			label="Noise",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._noise_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_noise_sizer,
			value=self.noise,
			callback=self.set_noise,
			minimum=0,
			maximum=1000,
			num_steps=1000,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Add(_noise_sizer)
		self.gr_wavfile_source_0 = gr.wavfile_source("/home/traviscollins/GNURADIO/tfc_models/test.wav", False)
		self.gr_throttle_0 = gr.throttle(gr.sizeof_float*1, samp_rate)
		self.gr_noise_source_x_0 = gr.noise_source_c(gr.GR_GAUSSIAN, noise, 42)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((signal, ))
		self.gr_file_sink_1_0 = gr.file_sink(gr.sizeof_float*1, "/home/traviscollins/GNURADIO/tfc_models/output_txt.wav")
		self.gr_file_sink_1_0.set_unbuffered(False)
		self.gr_channel_model_0 = gr.channel_model(
			noise_voltage=20,
			frequency_offset=0.0,
			epsilon=1.0,
			taps=(1.0 + 1.0j, ),
			noise_seed=42,
		)
		self.gr_add_xx_0 = gr.add_vcc(1)
		self.digital_gmsk_mod_0 = digital.gmsk_mod(
			samples_per_symbol=2,
			bt=0.35,
			verbose=False,
			log=False,
		)
		self.digital_gmsk_demod_0 = digital.gmsk_demod(
			samples_per_symbol=2,
			gain_mu=0.175,
			mu=0.5,
			omega_relative_limit=0.005,
			freq_error=0.0,
			verbose=False,
			log=False,
		)
		self.blks2_packet_encoder_0 = grc_blks2.packet_mod_f(grc_blks2.packet_encoder(
				samples_per_symbol=2,
				bits_per_symbol=1,
				access_code="",
				pad_for_usrp=True,
			),
			payload_length=0,
		)
		self.blks2_packet_decoder_0 = grc_blks2.packet_demod_f(grc_blks2.packet_decoder(
				access_code="",
				threshold=-1,
				callback=lambda ok, payload: self.blks2_packet_decoder_0.recv_pkt(ok, payload),
			),
		)
		self.audio_sink_0 = audio.sink(samp_rate, "", True)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_noise_source_x_0, 0), (self.gr_add_xx_0, 1))
		self.connect((self.gr_add_xx_0, 0), (self.digital_gmsk_demod_0, 0))
		self.connect((self.blks2_packet_encoder_0, 0), (self.digital_gmsk_mod_0, 0))
		self.connect((self.digital_gmsk_mod_0, 0), (self.gr_multiply_const_vxx_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.blks2_packet_encoder_0, 0))
		self.connect((self.gr_throttle_0, 0), (self.gr_file_sink_1_0, 0))
		self.connect((self.digital_gmsk_demod_0, 0), (self.blks2_packet_decoder_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_channel_model_0, 0))
		self.connect((self.gr_channel_model_0, 0), (self.gr_add_xx_0, 0))
		self.connect((self.gr_wavfile_source_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.blks2_packet_decoder_0, 0), (self.audio_sink_0, 0))
Example #46
0
    def __init__(self, mod_class, demod_class, rx_callback, options):
        gr.top_block.__init__(self)

        self._sample_rate = options.sample_rate

        channelon = True;

        self.gui_on = options.gui

        self._frequency_offset = options.frequency_offset
        self._timing_offset = options.timing_offset
        self._tx_amplitude = options.tx_amplitude
        self._snr_dB = options.snr

        self._noise_voltage = self.get_noise_voltage(self._snr_dB)

        self.txpath = transmit_path(mod_class, options)
        self.throttle = gr.throttle(gr.sizeof_gr_complex, self.sample_rate())
        self.rxpath = receive_path(demod_class, rx_callback, options)

        # FIXME: do better exposure to lower issues for control
        self._gain_mu = self.rxpath.packet_receiver._demodulator._mm_gain_mu
        self._alpha = self.rxpath.packet_receiver._demodulator._costas_alpha

        if channelon:
            self.channel = gr.channel_model(self._noise_voltage,
                                            self.frequency_offset(),
                                            self.timing_offset())
            
            if options.discontinuous:
                z = 20000*[0,]
                self.zeros = gr.vector_source_c(z, True)
                packet_size = 5*((4+8+4+1500+4) * 8)
                self.mux = gr.stream_mux(gr.sizeof_gr_complex, [packet_size-0, int(9e5)])

                # Connect components
                self.connect(self.txpath, self.throttle, (self.mux,0))
                self.connect(self.zeros, (self.mux,1))
                self.connect(self.mux, self.channel, self.rxpath)

            else:
                self.connect(self.txpath, self.throttle, self.channel, self.rxpath)

            if self.gui_on:
                self.qapp = QtGui.QApplication(sys.argv)
                fftsize = 2048

                self.snk_tx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                           0, 1,
                                           "Tx", True, True, False, True, True)
                self.snk_rx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                           0, 1,
                                           "Rx", True, True, False, True, True)

                self.snk_tx.set_frequency_axis(-80, 0)
                self.snk_rx.set_frequency_axis(-60, 20)
            
                # Connect to the QT sinks
                # FIXME: make better exposure to receiver from rxpath
                self.receiver = self.rxpath.packet_receiver._demodulator.receiver
                self.connect(self.channel, self.snk_tx)
                self.connect(self.receiver, self.snk_rx)

                pyTxQt  = self.snk_tx.pyqwidget()
                pyTx = sip.wrapinstance(pyTxQt, QtGui.QWidget)
                
                pyRxQt  = self.snk_rx.pyqwidget()
                pyRx = sip.wrapinstance(pyRxQt, QtGui.QWidget)
                
                self.main_box = dialog_box(pyTx, pyRx, self)
                self.main_box.show()
                
        else:
            # Connect components
            self.connect(self.txpath, self.throttle, self.rxpath)
import scipy
from gnuradio import gr, digital
import cspl

N = 10e5
ntag = 10e1
gr_est = digital.SNR_EST_M2M4

bits = tuple(range(0,255))*100

SNR = 10.0**(10/10.0) # 5dB
scale = scipy.sqrt(SNR)

src = gr.vector_source_b(bits, False)
mod = digital.bpsk_mod()
chn = gr.channel_model(1.0/scale)
snr = digital.mpsk_snr_est_cc(gr_est)
demod = digital.bpsk_demod()
snk = cspl.snr_file_sink_b("data.foo")
tb = gr.top_block()
tb.connect(src, mod, chn, snr, demod, snk)
tb.run()

Example #48
0
    def __init__(self):
        gr.top_block.__init__(self)

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

        self._sample_rate = 2000e3

        self.sps = 2
        self.excess_bw = 0.35
        self.gray_code = digital.mod_codes.GRAY_CODE
        
        fftsize = 2048

        self.data = scipy.random.randint(0, 255, 1000)
        self.src = gr.vector_source_b(self.data.tolist(), True)
        self.mod = digital.dqpsk_mod(self.gray_code,
                                     samples_per_symbol=self.sps,
                                     excess_bw=self.excess_bw,
                                     verbose=False, log=False)

        self.rrctaps = gr.firdes.root_raised_cosine(1, self.sps, 1, self.excess_bw, 21)
        self.rx_rrc = gr.fir_filter_ccf(1, self.rrctaps)


        # Set up the carrier & clock recovery parameters
        self.arity = 4
        self.mu = 0.5
        self.gain_mu = 0.05
        self.omega = self.sps
        self.gain_omega = .25 * self.gain_mu * self.gain_mu
        self.omega_rel_lim = 0.05
        
        self._loop_bw = 2*scipy.pi/100.0
        self.fmin = -1000/self.sample_rate()
        self.fmax = 1000/self.sample_rate()
        
        self.receiver = digital.mpsk_receiver_cc(self.arity, 0,
                                                 self._loop_bw,
                                                 self.fmin, self.fmax,
                                                 self.mu, self.gain_mu,
                                                 self.omega, self.gain_omega,
                                                 self.omega_rel_lim)
        
        
        self.snr_dB = 15
        noise = self.get_noise_voltage(self.snr_dB)
        self.fo = 100/self.sample_rate()
        self.to = 1.0
        self.channel = gr.channel_model(noise, self.fo, self.to)

        self.thr = gr.throttle(gr.sizeof_char, self._sample_rate)
        self.snk_tx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS, 
                                   0, self._sample_rate*self.sps,
                                   "Tx", True, True, True, True)

        self.snk_rx = qtgui.sink_c(fftsize, gr.firdes.WIN_BLACKMAN_hARRIS,
                                   0, self._sample_rate,
                                   "Rx", True, True, True, True)

        self.connect(self.src, self.thr, self.mod, self.channel, self.snk_tx)
        self.connect(self.channel, self.rx_rrc, self.receiver, self.snk_rx)
        
        pyTxQt  = self.snk_tx.pyqwidget()
        pyTx = sip.wrapinstance(pyTxQt, QtGui.QWidget)

        pyRxQt  = self.snk_rx.pyqwidget()
        pyRx = sip.wrapinstance(pyRxQt, QtGui.QWidget)

        self.main_box = dialog_box(pyTx, pyRx, self);
        self.main_box.show()
Example #49
0
def main():
    gr_estimators = {"simple": digital.SNR_EST_SIMPLE,
                     "skew": digital.SNR_EST_SKEW,
                     "m2m4": digital.SNR_EST_M2M4,
                     "svr": digital.SNR_EST_SVR}
    py_estimators = {"simple": snr_est_simple,
                     "skew": snr_est_skew,
                     "m2m4": snr_est_m2m4,
                     "svr": snr_est_svr}
    
    
    parser = OptionParser(option_class=eng_option, conflict_handler="resolve")
    parser.add_option("-N", "--nsamples", type="int", default=10000,
                      help="Set the number of samples to process [default=%default]")
    parser.add_option("", "--snr-min", type="float", default=-5,
                      help="Minimum SNR [default=%default]")
    parser.add_option("", "--snr-max", type="float", default=20,
                      help="Maximum SNR [default=%default]")
    parser.add_option("", "--snr-step", type="float", default=0.5,
                      help="SNR step amount [default=%default]")
    parser.add_option("-t", "--type", type="choice",
                      choices=gr_estimators.keys(), default="simple",
                      help="Estimator type {0} [default=%default]".format(
                            gr_estimators.keys()))
    (options, args) = parser.parse_args ()

    N = options.nsamples
    xx = scipy.random.randn(N)
    xy = scipy.random.randn(N)
    bits = 2*scipy.complex64(scipy.random.randint(0, 2, N)) - 1

    snr_known = list()
    snr_python = list()
    snr_gr = list()
    
    # when to issue an SNR tag; can be ignored in this example.
    ntag = 10000

    n_cpx = xx + 1j*xy

    py_est = py_estimators[options.type]
    gr_est = gr_estimators[options.type]

    SNR_min = options.snr_min
    SNR_max = options.snr_max
    SNR_step = options.snr_step
    SNR_dB = scipy.arange(SNR_min, SNR_max+SNR_step, SNR_step)
    for snr in SNR_dB:
        SNR = 10.0**(snr/10.0)
        scale = scipy.sqrt(SNR)
        yy = bits + n_cpx/scale
        print "SNR: ", snr

        Sknown = scipy.mean(yy**2)
        Nknown = scipy.var(n_cpx/scale)/2
        snr0 = Sknown/Nknown
        snr0dB = 10.0*scipy.log10(snr0)
        snr_known.append(snr0dB)

        snrdB, snr = py_est(yy)        
        snr_python.append(snrdB)

        gr_src = gr.vector_source_c(bits.tolist(), False)
        gr_snr = digital.mpsk_snr_est_cc(gr_est, ntag, 0.001)
        gr_chn = gr.channel_model(1.0/scale)
        gr_snk = gr.null_sink(gr.sizeof_gr_complex)
        tb = gr.top_block()
        tb.connect(gr_src, gr_chn, gr_snr, gr_snk)
        tb.run()

        snr_gr.append(gr_snr.snr())

    f1 = pylab.figure(1)
    s1 = f1.add_subplot(1,1,1)
    s1.plot(SNR_dB, snr_known, "k-o", linewidth=2, label="Known")
    s1.plot(SNR_dB, snr_python, "b-o", linewidth=2, label="Python")
    s1.plot(SNR_dB, snr_gr, "g-o", linewidth=2, label="GNU Radio")
    s1.grid(True)
    s1.set_title('SNR Estimators')
    s1.set_xlabel('SNR (dB)')
    s1.set_ylabel('Estimated SNR')
    s1.legend()

    pylab.show()
Example #50
0
    def __init__(self, options, samples_per_packet):

	gr.hier_block2.__init__(self, "channel_emulator_path",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex), # Input signature
                                gr.io_signature(1, 1, gr.sizeof_gr_complex)) # Output signature

        
        if not options.channel_off:

            SNR = 10.0**(options.snr/10.0)
            power_in_signal = abs(options.tx_amplitude)**2.0
            noise_power_in_channel = power_in_signal/SNR
            noise_voltage = math.sqrt(noise_power_in_channel/2.0)
            print "Noise voltage: ", noise_voltage

            frequency_offset = options.frequency_offset# / options.fft_length
            clock_ratio = options.clock_ratio
            print "Frequency offset: ", frequency_offset

            if options.multipath_on:
                taps = [1.0, .2, 0.0, .1, .08, -.4, .12, -.2, 0, 0, 0, .3]
            else:
                taps = [1.0, 0.0]

        else:
            noise_voltage = 0.0
            frequency_offset = 0.0
            clock_ratio = 1.0
            taps = [1.0, 0.0]

        self.samples_per_packet = samples_per_packet
        self.length_of_silence = options.silence_length
        
        self.channel = gr.channel_model(noise_voltage, frequency_offset, clock_ratio,taps)
       
        self.scale = gr.multiply_const_cc(1)          # (Note that on the RFX cards this is a nop.)
        self.scale.set_k(options.scale)


        print "Channel : Samples per Packet ",int(self.samples_per_packet)
        # Stream Mux        
        if options.discontinuous:
            stream_size = [self.length_of_silence, int(self.samples_per_packet)]
        else:
            stream_size = [1, 100000]

        z = [0,]
        self.zeros = gr.vector_source_c(z, True)

        self.mux = gtlib.channel_mux(gr.sizeof_gr_complex, stream_size)
        #self.throttle = gr.throttle(gr.sizeof_gr_complex, options.sample_rate)

        """
        
        self.connect(self.zeros, (self.mux,0))
        self.connect(self, (self.mux,1))
        # Connect
        if options.fractional_delay:
            self.lagrange_filter=gr.fir_filter_ccf(1, [0.2734, 1.0938, -0.5469, 0.2188])                
            self.connect(self.mux, self.channel, self.lagrange_filter, self.scale)
        else:
            self.connect(self.mux, self.channel, self.scale)

        """
        #self.trimmer = gtlib.usrp_timetag_insert()     
        """
        
        self.connect(self.scale,self.trimmer,self)
        """
        self.connect( self, self.scale, self)
	def __init__(self):
		grc_wxgui.top_block_gui.__init__(self, title="Simulated Sender GUI")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 32000
		self.noise_voltage = noise_voltage = 0.01
		self.mult_const = mult_const = 1

		##################################################
		# Controls
		##################################################
		_noise_voltage_sizer = wx.BoxSizer(wx.VERTICAL)
		self._noise_voltage_text_box = forms.text_box(
			parent=self.GetWin(),
			sizer=_noise_voltage_sizer,
			value=self.noise_voltage,
			callback=self.set_noise_voltage,
			label="Noise Voltage",
			converter=forms.float_converter(),
			proportion=0,
		)
		self._noise_voltage_slider = forms.slider(
			parent=self.GetWin(),
			sizer=_noise_voltage_sizer,
			value=self.noise_voltage,
			callback=self.set_noise_voltage,
			minimum=0,
			maximum=1,
			num_steps=100,
			style=wx.SL_HORIZONTAL,
			cast=float,
			proportion=1,
		)
		self.Add(_noise_voltage_sizer)
		self._mult_const_text_box = forms.text_box(
			parent=self.GetWin(),
			value=self.mult_const,
			callback=self.set_mult_const,
			label="Multiplication Const",
			converter=forms.float_converter(),
		)
		self.Add(self._mult_const_text_box)

		##################################################
		# Blocks
		##################################################
		self.blks2_ofdm_mod_0 = grc_blks2.packet_mod_b(blks2.ofdm_mod(
				options=grc_blks2.options(
					modulation="bpsk",
					fft_length=512,
					occupied_tones=200,
					cp_length=128,
					pad_for_usrp=True,
					log=None,
					verbose=None,
				),
			),
			payload_length=512,
		)
		self.gr_channel_model_0 = gr.channel_model(
			noise_voltage=noise_voltage,
			frequency_offset=0.0,
			epsilon=1.0,
			taps=(1.0 + 1.0j, ),
			noise_seed=42,
		)
		self.gr_multiply_const_vxx_0 = gr.multiply_const_vcc((mult_const, ))
		self.gr_throttle_0 = gr.throttle(gr.sizeof_gr_complex*1, samp_rate)
		self.random_source_x_0 = gr.vector_source_b(map(int, numpy.random.randint(0, 256, 512)), True)
		self.wxgui_fftsink2_0 = fftsink2.fft_sink_c(
			self.GetWin(),
			baseband_freq=0,
			y_per_div=10,
			y_divs=10,
			ref_level=50,
			sample_rate=samp_rate,
			fft_size=256,
			fft_rate=30,
			average=True,
			avg_alpha=0.1,
			title="FFT Plot",
			peak_hold=False,
		)
		self.Add(self.wxgui_fftsink2_0.win)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_throttle_0, 0), (self.wxgui_fftsink2_0, 0))
		self.connect((self.gr_channel_model_0, 0), (self.gr_throttle_0, 0))
		self.connect((self.gr_multiply_const_vxx_0, 0), (self.gr_channel_model_0, 0))
		self.connect((self.random_source_x_0, 0), (self.blks2_ofdm_mod_0, 0))
		self.connect((self.blks2_ofdm_mod_0, 0), (self.gr_multiply_const_vxx_0, 0))