コード例 #1
0
ファイル: audio_capture.py プロジェクト: alring/op25
    def __init__(self):
        gr.top_block.__init__(self)

        usage="%prog: [options] output_filename"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-I", "--audio-input", type="string", default="",
                          help="pcm input device name.  E.g., hw:0,0 or /dev/dsp")
        parser.add_option("-s", "--sample-rate", type="eng_float", default=48000,
                          help="set sample rate to RATE (48000)")
        parser.add_option("-N", "--nsamples", type="eng_float", default=None,
                          help="number of samples to collect [default=+inf]")
     
        (options, args) = parser.parse_args ()
        if len(args) != 2:
            parser.print_help()
            raise SystemExit, 1
        filename = args[0]
        filename2 = args[1]

        sample_rate = int(options.sample_rate)
        src = audio.source (sample_rate, options.audio_input)
        dst  = gr.file_sink (gr.sizeof_float, filename)
        dst2 = gr.file_sink (gr.sizeof_float, filename2)

        if options.nsamples is None:
            self.connect((src, 0), dst)
            self.connect((src, 1), dst2)
        else:
            head = gr.head(gr.sizeof_float, int(options.nsamples))
            head2 = gr.head(gr.sizeof_float, int(options.nsamples))
            self.connect((src, 0), head, dst)
            self.connect((src, 1), head2, dst2)
コード例 #2
0
ファイル: dial_tone_wav.py プロジェクト: Jhr-Ronyo/gnuradio-1
    def __init__(self):
        gr.top_block.__init__(self)

	usage = "%prog: [options] filename"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-r", "--sample-rate", type="eng_float", default=48000,
                          help="set sample rate to RATE (48000)")
	parser.add_option("-N", "--samples", type="eng_float", default=None,
			  help="number of samples to record")
        (options, args) = parser.parse_args ()
        if len(args) != 1 or options.samples is None:
            parser.print_help()
            raise SystemExit, 1

        sample_rate = int(options.sample_rate)
        ampl = 0.1

        src0 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 350, ampl)
        src1 = gr.sig_source_f (sample_rate, gr.GR_SIN_WAVE, 440, ampl)
	head0 = gr.head(gr.sizeof_float, int(options.samples))
	head1 = gr.head(gr.sizeof_float, int(options.samples))
	dst = gr.wavfile_sink(args[0], 2, int(options.sample_rate), 16)

        self.connect(src0, head0, (dst, 0))
        self.connect(src1, head1, (dst, 1))
コード例 #3
0
    def __init__(self):
        gr.top_block.__init__(self)

        usage = "%prog: [options] filename"
        parser = OptionParser(option_class=eng_option, usage=usage)
        parser.add_option("-r",
                          "--sample-rate",
                          type="eng_float",
                          default=48000,
                          help="set sample rate to RATE (48000)")
        parser.add_option("-N",
                          "--samples",
                          type="eng_float",
                          default=None,
                          help="number of samples to record")
        (options, args) = parser.parse_args()
        if len(args) != 1 or options.samples is None:
            parser.print_help()
            raise SystemExit, 1

        sample_rate = int(options.sample_rate)
        ampl = 0.1

        src0 = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, 350, ampl)
        src1 = gr.sig_source_f(sample_rate, gr.GR_SIN_WAVE, 440, ampl)
        head0 = gr.head(gr.sizeof_float, int(options.samples))
        head1 = gr.head(gr.sizeof_float, int(options.samples))
        dst = gr.wavfile_sink(args[0], 2, int(options.sample_rate), 16)

        self.connect(src0, head0, (dst, 0))
        self.connect(src1, head1, (dst, 1))
コード例 #4
0
ファイル: usrp_benchmark_usb.py プロジェクト: GREO/GNU-Radio
def run_test (usb_throughput, verbose):
    # usb_throughput is in bytes/sec.
    #
    # Returns True or False
    
    nsec = 1
    stream_length = int (usb_throughput/2 * nsec)   # length of stream to examine

    adc_freq =  64e6
    dac_freq = 128e6
    sizeof_sample = 2 * gr.sizeof_short

    usb_throughput_in_samples = usb_throughput / sizeof_sample

    # allocate usb throughput 50/50 between Tx and Rx

    tx_interp = int (dac_freq) / int (usb_throughput_in_samples / 2)
    rx_decim  = int (adc_freq) / int (usb_throughput_in_samples / 2)

    # print "tx_interp =", tx_interp, "rx_decim =", rx_decim
    assert (tx_interp == 2 * rx_decim)
    
    tb = gr.top_block ()

    # Build the Tx pipeline
    data_src = gr.lfsr_32k_source_s ()
    src_head = gr.head (gr.sizeof_short, int (stream_length * 2))
    usrp_tx = usrp.sink_s (0, tx_interp)
    tb.connect (data_src, src_head, usrp_tx)

    # and the Rx pipeline
    usrp_rx = usrp.source_s (0, rx_decim, 1, 0x32103210, usrp.FPGA_MODE_LOOPBACK)
    head = gr.head (gr.sizeof_short, stream_length)
    check = gr.check_lfsr_32k_s ()
    tb.connect (usrp_rx, head, check)

    tb.run ()

    ntotal = check.ntotal ()
    nright = check.nright ()
    runlength = check.runlength ()

    if verbose:
        print "usb_throughput =", eng_notation.num_to_str (usb_throughput)
        print "ntotal    =", ntotal
        print "nright    =", nright
        print "runlength =", runlength
        print "delta     =", ntotal - runlength

    return runlength >= stream_length - 80000
コード例 #5
0
    def __init__(self, inputfile, callback, options):
        gr.top_block.__init__(self)

        # settings for the demodulator: /usr/local/lib/python2.5/site-packages/gnuradio/blks2impl/gmsk.py
        # settings for the demodulator: /usr/local/lib/python2.5/site-packages/gnuradio/blks2impl/pkt.py

        if options.dsp:
            self.src = audio.source(options.dsp_sample_rate, "", True)
        else:
            self.src = gr.wavfile_source( inputfile, False )

        self.iq_to_c = gr.float_to_complex()
        if options.dsp and options.wait:
            samples = options.dsp_sample_rate * options.wait
            self._head0 = gr.head(gr.sizeof_float, samples)
            self._head1 = gr.head(gr.sizeof_float, samples)
            self.connect( (self.src, 0), self._head0, (self.iq_to_c, 0) )
            self.connect( (self.src, 1), self._head1, (self.iq_to_c, 1) )
            if verbose: print "installed %d second head filter on dsp (%d samples at %d sps)" % (options.wait, samples, options.dsp_sample_rate)
        else:
            self.connect( (self.src, 0), (self.iq_to_c, 0) )
            self.connect( (self.src, 1), (self.iq_to_c, 1) )

        self.demodulator = blks2.gmsk_demod(samples_per_symbol=options.samples_per_symbol)
        self.pkt_queue   = blks2.demod_pkts( demodulator=self.demodulator, callback=callback, threshold=options.threshold )

        if options.carrier_frequency == 0:
            self.mixer = self.iq_to_c
        else:
            self.carrier  = gr.sig_source_c( options.carrier_sample_rate, gr.GR_SIN_WAVE, - options.carrier_frequency, 1.0 )
            self.mixer    = gr.multiply_vcc(1)
            self.connect(self.iq_to_c, (self.mixer, 0) )
            self.connect(self.carrier, (self.mixer, 1) )

        self.amp = gr.multiply_const_cc(1); self.amp.set_k(options.amp_amplitude)
        self.connect(self.mixer, self.amp, self.pkt_queue)

        if options.debug_wavs:
            from myblks import debugwav
            self._dpass = debugwav("rx_passband", options)
            self._dbase = debugwav("rx_baseband", options)
            self.connect(self.iq_to_c, self._dpass)
            self.connect(self.mixer,   self._dbase)

        if options.debug_files:
            self._dpassf = gr.file_sink(gr.sizeof_gr_complex*1, "debug_rx_passband.d_c")
            self._dbasef = gr.file_sink(gr.sizeof_gr_complex*1, "debug_rx_baseband.d_c")
            self.connect(self.iq_to_c, self._dpassf)
            self.connect(self.mixer,   self._dbasef)
コード例 #6
0
ファイル: qa_freqshift.py プロジェクト: luwangg/gr-ofdm-1
    def test_100(self):
        vlen = 256
        cp_len = 12

        M = 10
        N = int(3e6)

        uut = ofdm.frequency_shift_vcc(vlen, 1.0 / vlen, cp_len)

        trig = [0] * M
        trig[0] = 1

        eps = [1.] * M

        src1 = gr.vector_source_c([1.] * (M * vlen), True, vlen)
        src2 = gr.vector_source_f(eps, True)
        src3 = gr.vector_source_b(trig, True)
        dst = gr.null_sink(gr.sizeof_gr_complex * vlen)

        limit3 = gr.head(gr.sizeof_char, N)

        self.fg.connect(src1, (uut, 0))
        self.fg.connect(src2, (uut, 1))
        self.fg.connect(src3, limit3, (uut, 2))
        self.fg.connect(uut, dst)

        r = time_it(self.fg)

        print "Rate %s" % \
          ( eng_notation.num_to_str( float( ( vlen + cp_len ) * N ) / r ) )
コード例 #7
0
 def setUp (self):
     self.tb = gr.top_block ()
     self.tp = drm.transm_params(1, 3, False, 0, False, 1, 0, 1, 1, 0, False, 24000, "station label", "text message")
     self.src = drm.generate_sdc_vb(self.tp)
     self.head = gr.head(self.tp.sdc().L(), 1)
     self.snk = gr.vector_sink_b(self.tp.sdc().L())
     self.tb.connect(self.src, self.head, self.snk)
コード例 #8
0
 def setUp (self):
     self.tb = gr.top_block ()
     
     #print os.getpid()
     #raw_input("Press the ANY key!")
     
     offset = 582  #sample15 = 21839 #sample20 = 43223
     fftl = 512
     cpl = 144*fftl/2048
     cpl0 = 160*fftl/2048
     slotl = 7*fftl+6*cpl+cpl0
     cell_id = 124
     N_rb_dl = 6
     
     
     mod=scipy.io.loadmat('/home/demel/exchange/matlab_test_first_freq.mat') 
     mat_u1=tuple(mod['test'].flatten())
     mat_d=range(len(mat_u1))
     for idx, val in enumerate(mat_u1):
         mat_d[idx]=val
     intu=tuple(mat_d)
     
     
     self.src  = gr.vector_source_c(intu,False,1)
     self.head = gr.head(gr.sizeof_gr_complex*fftl ,200)
     self.tag  = lte_swig.tag_symbol_cc(offset,fftl)
     self.sel = lte_swig.pss_selector_cvc(fftl)
     self.snk = gr.vector_sink_c(fftl)
     
     self.tb.connect(self.src, self.tag, self.sel, self.head, self.snk)
コード例 #9
0
def run_test (f,Kb,bitspersymbol,K,dimensionality,tot_constellation,N0,seed):
    tb = gr.top_block ()

    # TX
    src = gr.lfsr_32k_source_s()
    src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts
    s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality
    enc = trellis.encoder_ss(f,0) # initial state = 0
    # essentially here we implement the combination of modulation and channel as a memoryless modulation (the memory induced by the channel is hidden in the FSM)
    mod = gr.chunks_to_symbols_sf(tot_constellation,dimensionality)

    # CHANNEL
    add = gr.add_ff()
    noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed)
    
    # RX
    metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
    va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set.
    fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = gr.check_lfsr_32k_s(); 
    
    tb.connect (src,src_head,s2fsmi,enc,mod)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,metrics)
    tb.connect (metrics,va,fsmi2s,dst)
    
    tb.run()

    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()
    #print ntotal,nright,runlength 
    
    return (ntotal,ntotal-nright)
コード例 #10
0
    def test_000(self):
        N = 1000  # number of samples to use
        fs = 1000  # baseband sampling rate
        freq = 100

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

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

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

        dst_data = snk.data()
        exp_data = snk1.data()
        self.assertComplexTuplesAlmostEqual(exp_data, dst_data, 5)
コード例 #11
0
def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,seed):
    tb = gr.top_block ()

    # TX
    src = gr.lfsr_32k_source_s()
    src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts
    s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality
    enc = trellis.sccc_encoder_ss(fo,0,fi,0,interleaver,K)
    mod = gr.chunks_to_symbols_sf(constellation,dimensionality)

    # CHANNEL
    add = gr.add_ff()
    noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed)

    # RX
    dec = trellis.sccc_decoder_combined_fs(fo,0,-1,fi,0,-1,interleaver,K,IT,trellis.TRELLIS_MIN_SUM,dimensionality,constellation,digital.TRELLIS_EUCLIDEAN,1.0)
    fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = gr.check_lfsr_32k_s()
    
    #tb.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod)
    tb.connect (src,src_head,s2fsmi,enc,mod)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    #tb.connect (add,head)
    #tb.connect (tail,fsmi2s,dst)
    tb.connect (add,dec,fsmi2s,dst)

    tb.run()
 
    #print enc_out.ST(), enc_in.ST()
    
    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()
    return (ntotal,ntotal-nright)
コード例 #12
0
    def test_fff_000(self):
        N = 1000  # number of samples to use
        fs = 1000  # baseband sampling rate
        rrate = 1.123  # resampling rate

        nfilts = 32
        taps = filter.firdes.low_pass_2(
            nfilts,
            nfilts * fs,
            fs / 2,
            fs / 10,
            attenuation_dB=80,
            window=filter.firdes.WIN_BLACKMAN_hARRIS)

        freq = 100
        signal = gr.sig_source_f(fs, gr.GR_SIN_WAVE, freq, 1)
        head = gr.head(gr.sizeof_float, N)
        pfb = filter.pfb_arb_resampler_fff(rrate, taps)
        snk = gr.vector_sink_f()

        self.tb.connect(signal, head, pfb, snk)
        self.tb.run()

        Ntest = 50
        L = len(snk.data())
        t = map(lambda x: float(x) / (fs * rrate), xrange(L))

        phase = 0.53013
        expected_data = map(
            lambda x: math.sin(2. * math.pi * freq * x + phase), t)

        dst_data = snk.data()
        self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:],
                                          dst_data[-Ntest:], 3)
コード例 #13
0
  def test_002(self):
    vlen = 256
    subc = 208
    L = 8
    cplen = 12
    blocklen = vlen + cplen
    framelength = 11
    bits_per_subc = [2]*vlen
    data_blocks = 10
    
    N = int( 1e9 )
    
    # GI metric

    pre0,fd = morellimengali_designer.create( subc, vlen, L )

    
    ofdm_frames = \
      ofdm_frame_src( vlen, data_blocks, pre0, cplen, framelength, 
                      bits_per_subc )
    
    #uut = ofdm.autocorrelator0( vlen, cplen )
    uut = autocorrelator( vlen, cplen )
    
    limit_stream = gr.head( gr.sizeof_float, N )
    
    self.tb.connect( ofdm_frames, uut, limit_stream, 
                     gr.null_sink( gr.sizeof_float ) )

#    log_to_file( self.tb, limit_stream, "data/cyclicprefix_autocorr.float" )
    
    r = time_it( self.tb )
    
    print "Expected throughput:  %s Samples/s" % ( eng_notation.num_to_str( float(N) / r ) )
コード例 #14
0
 def setUp (self):
     self.tb   = gr.top_block ()
     
     my_map = range(46)
     for i in range(40):
         my_map[i+6] = int(i)
         
     my_map[0]=int(34)
     my_map[1]=int(35)
     my_map[2]=int(36)
     my_map[3]=int(37)
     my_map[4]=int(38)
     my_map[5]=int(39)
     
     my_data = range(40)
     for i in my_data:
         my_data[i]=int(i)
     
     self.src  = gr.vector_source_b(my_data,False,40)
     self.head = gr.head(40,1)
     
     self.vrs  = lte_swig.vector_resize_vbvb(my_map,40,46)
     
     self.snk  = gr.vector_sink_b(46)
     
     self.tb.connect(self.src,self.head,self.vrs,self.snk)
コード例 #15
0
    def setUp(self):
        self.tb = gr.top_block()

        #print os.getpid()
        #raw_input("Press the ANY key!")

        offset = 582  #sample15 = 21839 #sample20 = 43223
        fftl = 512
        cpl = 144 * fftl / 2048
        cpl0 = 160 * fftl / 2048
        slotl = 7 * fftl + 6 * cpl + cpl0
        cell_id = 124
        N_rb_dl = 6

        mod = scipy.io.loadmat(
            '/home/demel/exchange/matlab_test_first_freq.mat')
        mat_u1 = tuple(mod['test'].flatten())
        mat_d = range(len(mat_u1))
        for idx, val in enumerate(mat_u1):
            mat_d[idx] = val
        intu = tuple(mat_d)

        self.src = gr.vector_source_c(intu, False, 1)
        self.head = gr.head(gr.sizeof_gr_complex * fftl, 200)
        self.tag = lte_swig.tag_symbol_cc(offset, fftl)
        self.sel = lte_swig.pss_selector_cvc(fftl)
        self.snk = gr.vector_sink_c(fftl)

        self.tb.connect(self.src, self.tag, self.sel, self.head, self.snk)
コード例 #16
0
    def test_002(self):
        vlen = 256
        subc = 208
        L = 8
        cplen = 12
        blocklen = vlen + cplen
        framelength = 11
        bits_per_subc = [2] * vlen
        data_blocks = 10

        N = int(1e9)

        # GI metric

        pre0, fd = morellimengali_designer.create(subc, vlen, L)


        ofdm_frames = \
          ofdm_frame_src( vlen, data_blocks, pre0, cplen, framelength,
                          bits_per_subc )

        #uut = ofdm.autocorrelator0( vlen, cplen )
        uut = autocorrelator(vlen, cplen)

        limit_stream = gr.head(gr.sizeof_float, N)

        self.tb.connect(ofdm_frames, uut, limit_stream,
                        gr.null_sink(gr.sizeof_float))

        #    log_to_file( self.tb, limit_stream, "data/cyclicprefix_autocorr.float" )

        r = time_it(self.tb)

        print "Expected throughput:  %s Samples/s" % (eng_notation.num_to_str(
            float(N) / r))
コード例 #17
0
    def test_ccf_000(self):
        N = 1000  # number of samples to use
        fs = 1000  # baseband sampling rate
        rrate = 1.123  # resampling rate

        nfilts = 32

        freq = 100
        signal = gr.sig_source_c(fs, gr.GR_SIN_WAVE, freq, 1)
        head = gr.head(gr.sizeof_gr_complex, N)
        pfb = filter.pfb_arb_resampler_ccf(rrate, taps)
        snk = gr.vector_sink_c()

        self.tb.connect(signal, head, pfb, snk)
        self.tb.run()

        Ntest = 50
        L = len(snk.data())
        t = map(lambda x: float(x) / (fs * rrate), xrange(L))

        phase = 0.53013
        expected_data = map(lambda x: math.cos(2.*math.pi*freq*x+phase) + \
                                1j*math.sin(2.*math.pi*freq*x+phase), t)

        dst_data = snk.data()
        self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:],
                                            dst_data[-Ntest:], 3)
コード例 #18
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 )
コード例 #19
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(
            self, title="Zadoff Chu Sequence Correlator")
        _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 = 32000
        self.length = length = 63
        self.init_val = init_val = 29

        ##################################################
        # Blocks
        ##################################################
        self.lte_zadoff_chu_seq_generator_vc_0 = lte.zadoff_chu_seq_generator_vc(
            length, init_val)
        self.gr_vector_sink_x_0 = gr.vector_sink_c(length)
        self.gr_head_0 = gr.head(gr.sizeof_gr_complex * length, 1)

        ##################################################
        # Connections
        ##################################################
        self.connect((self.lte_zadoff_chu_seq_generator_vc_0, 0),
                     (self.gr_head_0, 0))
        self.connect((self.gr_head_0, 0), (self.gr_vector_sink_x_0, 0))
コード例 #20
0
    def test_001_t(self):
        self.degree = 5
        self.length = 2**self.degree - 1
        expected_result = (self.length - 1) * [-1.0 / self.length] + [1]

        # send a maximum length sequence with period 31
        src_real = digital.glfsr_source_f(self.degree, True, 0, 1)
        src_imag = gr.null_source(gr.sizeof_float * 1)
        f2c = gr.float_to_complex(1)

        mls_correlator = channelsounder_swig.mls_correlator(self.degree,
                                                            mask=0,
                                                            seed=1)

        # keep only the samples of the first two autocorrelation periods
        head = gr.head(gr.sizeof_gr_complex, 2 * self.length)
        dest = gr.vector_sink_c(1)

        self.tb.connect(src_real, (f2c, 0))
        self.tb.connect(src_imag, (f2c, 1))

        self.tb.connect(f2c, mls_correlator)
        self.tb.connect(mls_correlator, head, dest)
        # set up fg
        self.tb.run()

        # check data

        result_data = dest.data()
        # discard the first period, since it is tainted by the zeros inserted
        # by set_history()
        result_data = result_data[self.length:]
        self.assertFloatTuplesAlmostEqual(expected_result, result_data, 6)
コード例 #21
0
    def test_000(self):
        N = 1000         # number of samples to use
        M = 5            # Number of channels
        fs = 1000        # baseband sampling rate
        ifs = M*fs       # input samp rate to decimator

        #taps = filter.firdes.low_pass_2(M, ifs, fs/2, fs/10,
        #                                attenuation_dB=80,
        #                                window=filter.firdes.WIN_BLACKMAN_hARRIS)
        from pfb_interpolator_taps import taps

        freq = 100
        signal = gr.sig_source_c(fs, gr.GR_COS_WAVE, freq, 1)
        head = gr.head(gr.sizeof_gr_complex, N)
        pfb = filter.pfb_interpolator_ccf(M, taps)
        snk = gr.vector_sink_c()

        self.tb.connect(signal, head, pfb)
        self.tb.connect(pfb, snk)

        self.tb.run() 

        Ntest = 50
        L = len(snk.data())
        t = map(lambda x: float(x)/ifs, xrange(L))

        # Create known data as complex sinusoids at freq
        # of the channel at the interpolated rate.
        phase = 0.62833
        expected_data = map(lambda x: math.cos(2.*math.pi*freq*x+phase) + \
                                1j*math.sin(2.*math.pi*freq*x+phase), t)

        dst_data = snk.data()

        self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 4)
コード例 #22
0
    def __init__(self, N, fs):
        gr.hier_block2.__init__(self,
                "usrp_source",
                gr.io_signature(0,0,0),
                gr.io_signature(1,1, gr.sizeof_gr_complex))

        # Parameters.
        frequency = 1575.6e6
        decim_rate = int(64e6/fs)
        fpga_filename = "std_4rx_0tx.rbf"

        # Sources.
        usrp = usrp.source_c( decim_rate=decim_rate, fpga_filename=fpga_filename )
        head = gr.head( gr.sizeof_gr_complex, N*fs*1e-3 )
        self.connect( usrp, head, self )

        # USRP settings.
        rx_subdev_spec = usrp.pick_rx_subdevice(usrp)
        usrp.set_mux(usrp.determine_rx_mux_value(usrp, rx_subdev_spec))
        subdev = usrp.selected_subdev( usrp, rx_subdev_spec )
        print "Subdev gain range: "
        print subdev.gain_range()

        subdev.set_gain(70)
        r = usrp.tune( 0,_subdev, frequency )
        if not r:
            sys.exit('Failed to set frequency')
コード例 #23
0
    def __init__(self, N, fs):
        gr.hier_block2.__init__(self, "usrp_source", gr.io_signature(0, 0, 0),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))

        # Parameters.
        frequency = 1575.6e6
        decim_rate = int(64e6 / fs)
        fpga_filename = "std_4rx_0tx.rbf"

        # Sources.
        usrp = usrp.source_c(decim_rate=decim_rate,
                             fpga_filename=fpga_filename)
        head = gr.head(gr.sizeof_gr_complex, N * fs * 1e-3)
        self.connect(usrp, head, self)

        # USRP settings.
        rx_subdev_spec = usrp.pick_rx_subdevice(usrp)
        usrp.set_mux(usrp.determine_rx_mux_value(usrp, rx_subdev_spec))
        subdev = usrp.selected_subdev(usrp, rx_subdev_spec)
        print "Subdev gain range: "
        print subdev.gain_range()

        subdev.set_gain(70)
        r = usrp.tune(0, _subdev, frequency)
        if not r:
            sys.exit('Failed to set frequency')
コード例 #24
0
    def __init__(self,
                 N,
                 op,
                 isizeof=gr.sizeof_gr_complex,
                 osizeof=gr.sizeof_gr_complex,
                 nsrcs=1,
                 nsnks=1):
        gr.top_block.__init__(self, "helper")

        self.op = op
        self.srcs = []
        self.snks = []
        self.head = gr.head(isizeof, N)

        for n in xrange(nsrcs):
            self.srcs.append(gr.null_source(isizeof))

        for n in xrange(nsnks):
            self.snks.append(gr.null_sink(osizeof))

        self.connect(self.srcs[0], self.head, (self.op, 0))

        for n in xrange(1, nsrcs):
            self.connect(self.srcs[n], (self.op, n))

        for n in xrange(nsnks):
            self.connect((self.op, n), self.snks[n])
コード例 #25
0
    def test_001_t (self):
        self.degree = 5
        self.length = 2**self.degree - 1
        expected_result = (self.length - 1)*[-1.0/self.length]+[1]

        # send a maximum length sequence with period 31
        src_real = digital.glfsr_source_f(self.degree, True, 0, 1)
        src_imag = gr.null_source(gr.sizeof_float*1)
        f2c = gr.float_to_complex(1)

        mls_correlator = channelsounder_swig.mls_correlator(self.degree, mask = 0, seed = 1)

        # keep only the samples of the first two autocorrelation periods
        head = gr.head(gr.sizeof_gr_complex, 2*self.length)
        dest = gr.vector_sink_c(1)

        self.tb.connect( src_real, (f2c, 0))
        self.tb.connect( src_imag, (f2c, 1))

        self.tb.connect( f2c, mls_correlator )
        self.tb.connect( mls_correlator, head, dest )
        # set up fg
        self.tb.run ()

        # check data

        result_data = dest.data()
        # discard the first period, since it is tainted by the zeros inserted
        # by set_history()
        result_data = result_data[self.length:]
        self.assertFloatTuplesAlmostEqual (expected_result, result_data, 6)
コード例 #26
0
    def test_fff_000(self):
        N = 1000         # number of samples to use
        fs = 1000        # baseband sampling rate
        rrate = 1.123    # resampling rate

        nfilts = 32
        taps = filter.firdes.low_pass_2(nfilts, nfilts*fs, fs/2, fs/10,
                                        attenuation_dB=80,
                                        window=filter.firdes.WIN_BLACKMAN_hARRIS)

        freq = 100
        signal = gr.sig_source_f(fs, gr.GR_SIN_WAVE, freq, 1)
        head = gr.head(gr.sizeof_float, N)
        pfb = filter.pfb_arb_resampler_fff(rrate, taps)
        snk = gr.vector_sink_f()

        self.tb.connect(signal, head, pfb, snk)
        self.tb.run() 

        Ntest = 50
        L = len(snk.data())
        t = map(lambda x: float(x)/(fs*rrate), xrange(L))

        phase = 0.53013
        expected_data = map(lambda x: math.sin(2.*math.pi*freq*x+phase), t)

        dst_data = snk.data()
        self.assertFloatTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3)
コード例 #27
0
    def test_003_t (self):
        """ two states, random switching """
        n_bytes = 10000
        ber = (0, 0.5)
        trans_matrix = (0.5, 0.5,
                        0.5, 0.5)
        src = gr.glfsr_source_b(32)  # Create some pseudo-random bits
        head = gr.head(1, n_bytes)
        chan = cc.markovchan_bb(ber, trans_matrix, 8)
        ber = cc.ber_b(8)
        sink_state = gr.vector_sink_i()

        self.tb.connect(src, head, chan, (ber, 0))
        self.tb.connect(head, (ber, 1))
        self.tb.connect((chan, 1), sink_state)
        self.tb.run ()

        n_times_in_state_1 = np.sum(sink_state.data())
        print "\nNumber of times in state 1 = " + str(n_times_in_state_1)
        print "            Expected value = " + str(n_bytes/2)
        self.assertTrue(n_times_in_state_1 > 3500 and n_times_in_state_1 < 6500,
                 "Due to the statistical nature of the bsc, this can actually fail (though very unlikely). Try again.")
        print "  Measured BER = " + str(ber.ber())
        print "Expected value = 0.25"
        self.assertTrue(abs(ber.ber()- 0.25) < 0.05,
                 msg="Due to the statistical nature of the bsc, this can actually fail (though very unlikely). Try again.")
コード例 #28
0
ファイル: resampler.py プロジェクト: pgoeser/gnuradio
    def __init__(self, fs_in, fs_out, fc, N=10000):
        gr.top_block.__init__(self)

        rerate = float(fs_out) / float(fs_in)
        print "Resampling from %f to %f by %f " % (fs_in, fs_out, rerate)

        # Creating our own taps
        taps = gr.firdes.low_pass_2(32, 32, 0.25, 0.1, 80)

        self.src = gr.sig_source_c(fs_in, gr.GR_SIN_WAVE, fc, 1)
        #self.src = gr.noise_source_c(gr.GR_GAUSSIAN, 1)
        self.head = gr.head(gr.sizeof_gr_complex, N)

        # A resampler with our taps
        self.resamp_0 = blks2.pfb_arb_resampler_ccf(rerate, taps, flt_size=32)

        # A resampler that just needs a resampling rate.
        # Filter is created for us and designed to cover
        # entire bandwidth of the input signal.
        # An optional atten=XX rate can be used here to
        # specify the out-of-band rejection (default=80).
        self.resamp_1 = blks2.pfb_arb_resampler_ccf(rerate)

        self.snk_in = gr.vector_sink_c()
        self.snk_0 = gr.vector_sink_c()
        self.snk_1 = gr.vector_sink_c()

        self.connect(self.src, self.head, self.snk_in)
        self.connect(self.head, self.resamp_0, self.snk_0)
        self.connect(self.head, self.resamp_1, self.snk_1)
コード例 #29
0
    def __init__(self, N, fs, bw0, bw1, tw, atten, D):
        gr.top_block.__init__(self)

        self._nsamps = N
        self._fs = fs
        self._bw0 = bw0
        self._bw1 = bw1
        self._tw = tw
        self._at = atten
        self._decim = D
        taps = filter.firdes.complex_band_pass_2(1, self._fs,
                                                 self._bw0, self._bw1,
                                                 self._tw, self._at)
        print "Num. Taps: ", len(taps)

        self.src  = gr.noise_source_c(gr.GR_GAUSSIAN, 1)
        self.head = gr.head(gr.sizeof_gr_complex, self._nsamps)

        self.filt0 = filter.fft_filter_ccc(self._decim, taps)

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

        self.connect(self.src, self.head, self.vsnk_src)
        self.connect(self.head, self.filt0, self.vsnk_out)
コード例 #30
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 ) 
コード例 #31
0
    def test_ccf_000(self):
        N = 1000         # number of samples to use
        fs = 1000        # baseband sampling rate
        rrate = 1.123    # resampling rate

        nfilts = 32

        freq = 100
        signal = gr.sig_source_c(fs, gr.GR_SIN_WAVE, freq, 1)
        head = gr.head(gr.sizeof_gr_complex, N)
        pfb = filter.pfb_arb_resampler_ccf(rrate, taps)
        snk = gr.vector_sink_c()

        self.tb.connect(signal, head, pfb, snk)
        self.tb.run() 

        Ntest = 50
        L = len(snk.data())
        t = map(lambda x: float(x)/(fs*rrate), xrange(L))

        phase = 0.53013
        expected_data = map(lambda x: math.cos(2.*math.pi*freq*x+phase) + \
                                1j*math.sin(2.*math.pi*freq*x+phase), t)

        dst_data = snk.data()
        self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3)
コード例 #32
0
 def setUp (self):
     self.tb   = gr.top_block ()
     
     my_map = range(46)
     for i in range(40):
         my_map[i+6] = int(i)
         
     my_map[0]=int(34)
     my_map[1]=int(35)
     my_map[2]=int(36)
     my_map[3]=int(37)
     my_map[4]=int(38)
     my_map[5]=int(39)
     
     my_data = range(40)
     for i in my_data:
         my_data[i]=int(i)
     
     self.src  = gr.vector_source_b(my_data,False,40)
     self.head = gr.head(40,1)
     
     self.vrs  = lte_swig.vector_resize_vbvb(my_map,40,46)
     
     self.snk  = gr.vector_sink_b(46)
     
     self.tb.connect(self.src,self.head,self.vrs,self.snk)
コード例 #33
0
    def setUp(self):
        self.tb = gr.top_block()

        fftl = 512
        waveform = gr.GR_SIN_WAVE
        freq = 0.0
        ampl = 1.0
        offset = 0.0
        cpl = 144 * fftl / 2048
        cpl0 = 160 * fftl / 2048
        slotl = 7 * fftl + 6 * cpl + cpl0
        samp_rate = slotl / 0.0005

        self.sig = gr.sig_source_c(samp_rate, waveform, freq, ampl, offset)
        self.head = gr.head(gr.sizeof_gr_complex, 100000)

        print "amplitude\t" + str(self.sig.amplitude())
        print "frequency\t" + str(self.sig.frequency())
        print "name\t" + str(self.sig.name())
        print "offset\t" + str(self.sig.offset())
        print "samp_rate\t" + str(self.sig.sampling_freq())
        print "waveform\t" + str(self.sig.waveform())

        #print type(self.sig)

        self.est = lte_swig.freq_estimate_c(self.sig, fftl)

        self.tb.connect(self.sig, self.head, self.est)
コード例 #34
0
    def __init__(self, n_sinusoids = 1, SNR = 10, samp_rate = 32e3, nsamples = 2048):
        gr.hier_block2.__init__(self, "ESPRIT/MUSIC signal generator",
                                gr.io_signature(0, 0, gr.sizeof_float),
                                gr.io_signature(1, 1, gr.sizeof_gr_complex))
        sigampl = 10.0**(SNR/10.0) # noise power is 1
        self.srcs = list()

        self.n_sinusoids = n_sinusoids
        self.samp_rate = samp_rate
        # create our signals ...
        for s in range(n_sinusoids):
            self.srcs.append(gr.sig_source_c(samp_rate,
                gr.GR_SIN_WAVE,1000 * s + 2000,
                numpy.sqrt(sigampl/n_sinusoids)))

        seed = ord(os.urandom(1))
        self.noise = gr.noise_source_c(gr.GR_GAUSSIAN, 1, seed)
        self.add = gr.add_cc()
        self.head = gr.head(gr.sizeof_gr_complex, nsamples)
        self.sink = gr.vector_sink_f(vlen=n_sinusoids)
        # wire it up ... 
        for s in range(n_sinusoids):
            self.connect(self.srcs[s], (self.add, s))
        # Additive noise
        self.connect(self.noise, (self.add, n_sinusoids))
        self.connect(self.add, self.head, self)
コード例 #35
0
ファイル: selector.py プロジェクト: FOSSEE-Manipal/gnuradio
	def __init__(self, item_size, num_inputs, num_outputs, input_index, output_index):
		"""
		Selector constructor.
		@param item_size the size of the gr data stream in bytes
		@param num_inputs the number of inputs (integer)
		@param num_outputs the number of outputs (integer)
		@param input_index the index for the source data
		@param output_index the index for the destination data
		"""
		gr.hier_block2.__init__(
			self, 'selector',
			gr.io_signature(num_inputs, num_inputs, item_size),
			gr.io_signature(num_outputs, num_outputs, item_size),
		)
		#terminator blocks for unused inputs and outputs
		self.input_terminators = [gr.null_sink(item_size) for i in range(num_inputs)]
		self.output_terminators = [gr.head(item_size, 0) for i in range(num_outputs)]
		self.copy = gr.kludge_copy(item_size)
		#connections
		for i in range(num_inputs): self.connect((self, i), self.input_terminators[i])
		for i in range(num_outputs): self.connect(gr.null_source(item_size), self.output_terminators[i], (self, i))
		self.item_size = item_size
		self.input_index = input_index
		self.output_index = output_index
		self.num_inputs = num_inputs
		self.num_outputs = num_outputs
		self._connect_current()
コード例 #36
0
    def setUp (self):
        print "qa_remove_cp2_cvc SetUp!"
        self.fftl = fftl = 2048
        cpl = 144*fftl/2048
        cpl0 = 160*fftl/2048
        self.slotl = slotl = 7*fftl+6*cpl+cpl0

        self.tb = gr.top_block ()
        
        #provide test data
        self.src = gr.noise_source_c(gr.GR_GAUSSIAN,1)
        self.head = gr.head( gr.sizeof_gr_complex, 10*slotl )
        self.tag = lte.pss_tagging_cc(fftl)
        # set up tagging block
        self.tag.set_half_frame_start(0)
        self.tag.set_N_id_2(1)
        self.tag.lock()
        
        # UUT
        self.rcp = lte.remove_cp2_cvc(fftl)
        
        # sinks
        self.snk = gr.vector_sink_c(fftl)
        self.tagsnc = gr.tag_debug(gr.sizeof_gr_complex*fftl, "remove_cp2_cvc")
        
        # connect blocks
        self.tb.connect(self.src, self.head, self.tag, self.rcp, self.snk )
コード例 #37
0
def run_test (f,Kb,bitspersymbol,K,dimensionality,tot_constellation,N0,seed):
    tb = gr.top_block ()

    # TX
    src = gr.lfsr_32k_source_s()
    src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts
    s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality
    enc = trellis.encoder_ss(f,0) # initial state = 0
    # essentially here we implement the combination of modulation and channel as a memoryless modulation (the memory induced by the channel is hidden in the FSM)
    mod = gr.chunks_to_symbols_sf(tot_constellation,dimensionality)

    # CHANNEL
    add = gr.add_ff()
    noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed)

    # RX
    metrics = trellis.metrics_f(f.O(),dimensionality,tot_constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
    va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set.
    fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = gr.check_lfsr_32k_s();

    tb.connect (src,src_head,s2fsmi,enc,mod)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,metrics)
    tb.connect (metrics,va,fsmi2s,dst)

    tb.run()

    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()
    #print ntotal,nright,runlength

    return (ntotal,ntotal-nright)
コード例 #38
0
    def test_002_cc(self):
        N = 10000        # number of samples to use
        fs = 1000        # baseband sampling rate
        rrate = 1.123    # resampling rate

        freq = 10
        signal = gr.sig_source_c(fs, gr.GR_SIN_WAVE, freq, 1)
        head = gr.head(gr.sizeof_gr_complex, N)
        op = filter.fractional_interpolator_cc(0.0, rrate)
        snk = gr.vector_sink_c()

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

        Ntest = 5000
        L = len(snk.data())
        t = map(lambda x: float(x)/(fs/rrate), xrange(L))

        phase = 0.1884
        expected_data = map(lambda x: math.cos(2.*math.pi*freq*x+phase) + \
                                1j*math.sin(2.*math.pi*freq*x+phase), t)

        dst_data = snk.data()

        self.assertComplexTuplesAlmostEqual(expected_data[-Ntest:], dst_data[-Ntest:], 3)
コード例 #39
0
ファイル: qa_sampler.py プロジェクト: WindyCitySDR/gr-ofdm
  def test_007_vector_sampler(self):
    data = range(1,577,1) # 1..576
    trigger = numpy.concatenate([[0]*575,[1]])
    blocks = 10000
    expected = data[64:577]
    assert(len(expected)==512)
    expected = numpy.concatenate([expected*blocks])
    assert(len(expected) == 512*blocks)

    src = gr.vector_source_c(data,True)
    src2 = gr.vector_source_b(trigger.tolist(),True)
    dst = gr.vector_sink_c()
    sampler = ofdm.vector_sampler(gr.sizeof_gr_complex,512)
    v2s = gr.vector_to_stream(gr.sizeof_gr_complex,512)

    self.fg.connect(src, (sampler,0))
    self.fg.connect(src2,gr.head(gr.sizeof_char,blocks*576), (sampler,1))
    self.fg.connect(sampler, v2s, dst)

    self.fg.run()
    #self.assertEqual(numpy.array(expected,numpy.Complex), numpy.array(dst.data(), numpy.Complex))
    if numpy.array(expected).all() != numpy.array(dst.data()).all():
      print "up"
      print len(expected),len(dst.data())
      vec = dst.data()
      for i in range(min(len(expected),len(dst.data()))):
        if vec[i] != expected[i]:
          print "e at ",i
コード例 #40
0
    def setUp (self):
        self.tb = gr.top_block ()
        
        
        fftl = 512
        waveform = gr.GR_SIN_WAVE
        freq = 0.0
        ampl = 1.0
        offset = 0.0
        cpl = 144 * fftl / 2048
        cpl0 = 160 * fftl / 2048
        slotl = 7 * fftl + 6 * cpl + cpl0
        samp_rate = slotl / 0.0005

        self.sig = gr.sig_source_c(samp_rate,waveform,freq,ampl,offset)
        self.head = gr.head(gr.sizeof_gr_complex, 100000)
        
        print "amplitude\t" + str(self.sig.amplitude())
        print "frequency\t" + str(self.sig.frequency())
        print "name\t" + str(self.sig.name())
        print "offset\t" + str(self.sig.offset())
        print "samp_rate\t" + str(self.sig.sampling_freq())
        print "waveform\t" + str(self.sig.waveform())
        
        #print type(self.sig)
        
        self.est = lte_swig.freq_estimate_c(self.sig,fftl)
        
        self.tb.connect(self.sig,self.head,self.est)
コード例 #41
0
    def setUp(self):
        self.tb = gr.top_block()

        offset = 43223  # sample15 = 21839 # sample20 = 43223
        fftl = 512
        cell_id = 124
        N_rb_dl = 6
        # get test input from matlab
        mod = scipy.io.loadmat(
            '/home/demel/exchange/matlab_test_first_freq.mat')
        mat_u1 = tuple(mod['test'].flatten())
        mat_d = range(len(mat_u1))
        for idx, val in enumerate(mat_u1):
            mat_d[idx] = val
        intu = tuple(mat_d)
        self.myintu = intu
        #for i in range(20):
        #    print intu[i+100000]

        self.src = gr.vector_source_c(intu, False, 1)
        self.tag = lte_swig.tag_symbol_cc(offset, fftl)

        self.est = lte.hier_freq_estimate_cc(fftl)

        self.head = gr.head(gr.sizeof_gr_complex, len(intu) - 100000)

        self.snk = gr.vector_sink_c(1)
        self.tb.connect(self.src, self.tag, self.head, self.est, self.snk)
コード例 #42
0
 def setUp (self):
     self.tb = gr.top_block ()
     
     offset = 43223# sample15 = 21839 # sample20 = 43223
     fftl = 512
     cell_id = 124
     N_rb_dl = 6
     # get test input from matlab
     mod=scipy.io.loadmat('/home/demel/exchange/matlab_test_first_freq.mat') 
     mat_u1=tuple(mod['test'].flatten())
     mat_d=range(len(mat_u1))
     for idx, val in enumerate(mat_u1):
         mat_d[idx]=val
     intu=tuple(mat_d)
     self.myintu = intu
     #for i in range(20):
     #    print intu[i+100000]
     
     self.src  = gr.vector_source_c(intu,False,1)
     self.tag  = lte_swig.tag_symbol_cc(offset,fftl)
     
     self.est  = lte.hier_freq_estimate_cc(fftl)
     
     self.head = gr.head(gr.sizeof_gr_complex,len(intu)-100000)
     
     self.snk  = gr.vector_sink_c(1)
     self.tb.connect(self.src,self.tag,self.head,self.est,self.snk)
コード例 #43
0
ファイル: qa_freqshift.py プロジェクト: WindyCitySDR/gr-ofdm
 def test_100(self):
   vlen = 256
   cp_len = 12
   
   M = 10
   N = int(3e6)
   
   uut = ofdm.frequency_shift_vcc( vlen, 1.0/vlen, cp_len )
   
   trig = [0]*M
   trig[0] = 1
   
   eps = [1.]*M
       
   src1 = gr.vector_source_c( [1.]*(M*vlen), True, vlen )
   src2 = gr.vector_source_f( eps, True )
   src3 = gr.vector_source_b( trig, True )
   dst = gr.null_sink( gr.sizeof_gr_complex * vlen )
   
   limit3 = gr.head( gr.sizeof_char, N )
   
   self.fg.connect( src1, ( uut, 0 ) )
   self.fg.connect( src2, ( uut, 1 ) )
   self.fg.connect( src3, limit3, ( uut, 2 ) )
   self.fg.connect( uut, dst )
   
   r = time_it( self.fg )
   
   print "Rate %s" % \
     ( eng_notation.num_to_str( float( ( vlen + cp_len ) * N ) / r ) )
コード例 #44
0
    def __init__(self, fs_in, fs_out, fc, N=10000):
        gr.top_block.__init__(self)
        
        rerate = float(fs_out) / float(fs_in)
        print "Resampling from %f to %f by %f " %(fs_in, fs_out, rerate)

        # Creating our own taps
        taps = gr.firdes.low_pass_2(32, 32, 0.25, 0.1, 80)

        self.src = gr.sig_source_c(fs_in, gr.GR_SIN_WAVE, fc, 1)
        #self.src = gr.noise_source_c(gr.GR_GAUSSIAN, 1)
        self.head = gr.head(gr.sizeof_gr_complex, N)

        # A resampler with our taps
        self.resamp_0 = blks2.pfb_arb_resampler_ccf(rerate, taps,
                                                    flt_size=32)

        # A resampler that just needs a resampling rate.
        # Filter is created for us and designed to cover
        # entire bandwidth of the input signal.
        # An optional atten=XX rate can be used here to 
        # specify the out-of-band rejection (default=80).
        self.resamp_1 = blks2.pfb_arb_resampler_ccf(rerate)

        self.snk_in = gr.vector_sink_c()
        self.snk_0 = gr.vector_sink_c()
        self.snk_1 = gr.vector_sink_c()

        self.connect(self.src, self.head, self.snk_in)
        self.connect(self.head, self.resamp_0, self.snk_0)
        self.connect(self.head, self.resamp_1, self.snk_1)
コード例 #45
0
ファイル: receiver.py プロジェクト: luwangg/BLISS
	def __init__(self):
		gr.top_block.__init__(self, "Receiver")

		##################################################
		# Variables
		##################################################
		self.samp_rate = samp_rate = 100000

		##################################################
		# Blocks
		##################################################
		self.uhd_usrp_source_0 = uhd.usrp_source(
			device_addr="",
			stream_args=uhd.stream_args(
				cpu_format="fc32",
				channels=range(1),
			),
		)
		self.uhd_usrp_source_0.set_samp_rate(samp_rate)
		self.uhd_usrp_source_0.set_center_freq(2.4e9, 0)
		self.uhd_usrp_source_0.set_gain(15, 0)
		self.gr_pll_carriertracking_cc_0 = gr.pll_carriertracking_cc(1.5*3.1459/200, 2, -2)
		self.gr_head_0 = gr.head(gr.sizeof_gr_complex*1, 1024*100)
		self.gr_file_sink_0 = gr.file_sink(gr.sizeof_gr_complex*1, "/home/traviscollins/data/Models/USRP_Receiver/received_data_C.txt")
		self.gr_file_sink_0.set_unbuffered(False)

		##################################################
		# Connections
		##################################################
		self.connect((self.gr_head_0, 0), (self.gr_file_sink_0, 0))
		self.connect((self.uhd_usrp_source_0, 0), (self.gr_pll_carriertracking_cc_0, 0))
		self.connect((self.gr_pll_carriertracking_cc_0, 0), (self.gr_head_0, 0))
コード例 #46
0
ファイル: test_tcm.py プロジェクト: jmccormack200/SDR
def run_test(f, Kb, bitspersymbol, K, dimensionality, constellation, N0, seed):
    tb = gr.top_block()

    # TX
    # packet = [0]*Kb
    # for i in range(Kb-1*16): # last 16 bits = 0 to drive the final state to 0
    # packet[i] = random.randint(0, 1) # random 0s and 1s
    # src = gr.vector_source_s(packet,False)
    src = gr.lfsr_32k_source_s()
    src_head = gr.head(gr.sizeof_short, Kb / 16)  # packet size in shorts
    # b2s = gr.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts
    s2fsmi = gr.packed_to_unpacked_ss(
        bitspersymbol, gr.GR_MSB_FIRST
    )  # unpack shorts to symbols compatible with the FSM input cardinality
    enc = trellis.encoder_ss(f, 0)  # initial state = 0
    mod = gr.chunks_to_symbols_sf(constellation, dimensionality)

    # CHANNEL
    add = gr.add_ff()
    noise = gr.noise_source_f(gr.GR_GAUSSIAN, math.sqrt(N0 / 2), seed)

    # RX
    metrics = trellis.metrics_f(
        f.O(), dimensionality, constellation, digital.TRELLIS_EUCLIDEAN
    )  # data preprocessing to generate metrics for Viterbi
    va = trellis.viterbi_s(f, K, 0, -1)  # Put -1 if the Initial/Final states are not set.
    fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST)  # pack FSM input symbols to shorts
    # s2b = gr.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits
    # dst = gr.vector_sink_s();
    dst = gr.check_lfsr_32k_s()

    tb.connect(src, src_head, s2fsmi, enc, mod)
    # tb.connect (src,b2s,s2fsmi,enc,mod)
    tb.connect(mod, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, metrics)
    tb.connect(metrics, va, fsmi2s, dst)
    # tb.connect (metrics,va,fsmi2s,s2b,dst)

    tb.run()

    # A bit of cheating: run the program once and print the
    # final encoder state..
    # Then put it as the last argument in the viterbi block
    # print "final state = " , enc.ST()

    ntotal = dst.ntotal()
    nright = dst.nright()
    runlength = dst.runlength()
    # ntotal = len(packet)
    # if len(dst.data()) != ntotal:
    # print "Error: not enough data\n"
    # nright = 0;
    # for i in range(ntotal):
    # if packet[i]==dst.data()[i]:
    # nright=nright+1
    # else:
    # print "Error in ", i
    return (ntotal, ntotal - nright)
コード例 #47
0
  def test_30( self ):
    
    gamma = 0.001
    beta = -0.1
    
    vlen = 208
    N = 20
    M = 5
    pcount = 8
    pdist = vlen / pcount
    assert( ( pdist % 2 ) == 0 )
    
    nondata_blocks = [0, 1]
    pilot_subc = numpy.arange(pcount) * pdist + pdist/2 - vlen/2
    assert( pilot_subc[0] == - pilot_subc[len(pilot_subc)-1] )

    data = [1.+0.j] * vlen
    frame_start = [0] * N
    frame_start[0] = 1
    
    sub_dc = vlen/2
    
    ind_range = numpy.arange( vlen ) - vlen/2
    assert( ind_range[0] == -vlen/2 )
    
    phase_offset = ind_range * gamma + numpy.ones(vlen) * beta
    assert( phase_offset[sub_dc] == beta )
    phase = phase_offset
    
    phase_offset = exp( 1j * phase_offset )
    
    data = data * phase_offset
    data = concatenate( [data] * N )
    
    src = gr.vector_source_c( data, True, vlen )
    src2 = gr.vector_source_b( frame_start, True )
    dst = gr.vector_sink_c()
    
    limit2 = gr.head( gr.sizeof_char, N * M )
    
    uut = ofdm.LMS_phase_tracking2( vlen, pilot_subc.tolist(), nondata_blocks )
    
    self.tb.connect( src, uut, 
                     gr.vector_to_stream( gr.sizeof_gr_complex, vlen ), dst ) 
    self.tb.connect( src2, limit2, ( uut, 1 ) )
    
    self.tb.run()
    
    d = numpy.array( dst.data() )
    
    for i in range( M ):
      xx = i * N * vlen
      ad = numpy.angle( d[ (xx+len(nondata_blocks)*vlen):(xx+N*vlen) ] )
      ad2 = numpy.angle( d[ xx : (xx+len(nondata_blocks)*vlen) ] )
      
      self.assertFloatTuplesAlmostEqual( 
        concatenate( [phase]*len(nondata_blocks) ), ad2, 3 )
      
      self.assertFloatTuplesAlmostEqual( numpy.zeros(len(ad)), ad, 3 )
コード例 #48
0
 def test_tags(self):
     src = tag_source()
     sink = tag_sink()
     head = gr.head(gr.sizeof_float, 50000) #should be enough items to get a tag through
     tb = gr.top_block()
     tb.connect(src, head, sink)
     tb.run()
     self.assertEqual(sink.key, "example_key")
コード例 #49
0
 def setUp (self):
     self.tb = gr.top_block ()
     self.src = gr.vector_source_b((1,1,0,1), True, 4)
     self.head = gr.head(4,3)
     self.add_tailbits = drm.add_tailbits_vbvb(4,2)
     self.snk = gr.vector_sink_b(6)
     
     self.tb.connect(self.src, self.head, self.add_tailbits, self.snk)
コード例 #50
0
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
    tb = gr.top_block ()


    # TX
    #packet = [0]*Kb
    #for i in range(Kb-1*16): # last 16 bits = 0 to drive the final state to 0
        #packet[i] = random.randint(0, 1) # random 0s and 1s
    #src = gr.vector_source_s(packet,False)
    src = gr.lfsr_32k_source_s()
    src_head = gr.head (gr.sizeof_short,Kb/16) # packet size in shorts
    #b2s = gr.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts
    s2fsmi = gr.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality
    enc = trellis.encoder_ss(f,0) # initial state = 0
    mod = gr.chunks_to_symbols_sf(constellation,dimensionality)

    # CHANNEL
    add = gr.add_ff()
    noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed)

    # RX
    metrics = trellis.metrics_f(f.O(),dimensionality,constellation,trellis.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for Viterbi
    va = trellis.viterbi_s(f,K,0,-1) # Put -1 if the Initial/Final states are not set.
    fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    #s2b = gr.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits
    #dst = gr.vector_sink_s(); 
    dst = gr.check_lfsr_32k_s()
    

    tb.connect (src,src_head,s2fsmi,enc,mod)
    #tb.connect (src,b2s,s2fsmi,enc,mod)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,metrics)
    tb.connect (metrics,va,fsmi2s,dst)
    #tb.connect (metrics,va,fsmi2s,s2b,dst)
    

    tb.run()
    
    # A bit of cheating: run the program once and print the 
    # final encoder state..
    # Then put it as the last argument in the viterbi block
    #print "final state = " , enc.ST()

    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()
    #ntotal = len(packet)
    #if len(dst.data()) != ntotal:
        #print "Error: not enough data\n"
    #nright = 0;
    #for i in range(ntotal):
        #if packet[i]==dst.data()[i]:
            #nright=nright+1
        #else:
            #print "Error in ", i
    return (ntotal,ntotal-nright)
コード例 #51
0
ファイル: bts_top.py プロジェクト: csboyer/RFID-BTS
    def __init__(self, usrp_rate, usrp_interp):
        gr.hier_block2.__init__(self, "downlink_test_file_sink",
                                gr.io_signature(1, 1, gr.sizeof_gr_complex),
                                gr.io_signature(0, 0, 0))
        self.c_to_f = gr.complex_to_real()
        self.chop = gr.head(gr.sizeof_float, 350)
        self.f = gr.file_sink(gr.sizeof_float, 'output.dat')

        self.connect(self, self.c_to_f, self.chop, self.f)
コード例 #52
0
 def setUp (self):
     self.tb = gr.top_block ()
     
     mylen = 63
     self.zc = lte_swig.zadoff_chu_seq_generator_vc(mylen,29)
     self.head = gr.head(gr.sizeof_gr_complex*mylen,1)
     self.snk = gr.vector_sink_c(63)
     
     self.tb.connect(self.zc, self.head, self.snk )
コード例 #53
0
    def setUp(self):
        self.tb = gr.top_block()
        self.src = gr.vector_source_b((0, 1, 2, 3, 4, 5, 6, 7, 8, 9), True, 10)
        self.head = gr.head(10, 2)
        seq = (3, 7, 5, 8, 6, 1, 9, 4, 2, 0)
        self.interleaver = drm.interleaver_vbvb(seq)
        self.snk = gr.vector_sink_b(10)

        self.tb.connect(self.src, self.head, self.interleaver, self.snk)
コード例 #54
0
ファイル: qa_pmtfile_source.py プロジェクト: osh/gr-pmtfile
    def test_001_t(self):
        tb = gr.top_block()
        src = pmtfile.source("test1.pf", True)
        #        op = gr.add_const_bb(1);
        head = gr.head(2, 200000)
        snk = pmtfile.sink("test2.pf", pmtfile.pmtfile.RI16)

        tb.connect(src, head, snk)
        tb.run()
コード例 #55
0
def main():
    tb = gr.top_block()
    # noise source
    n = mlse.randint_b(2)
    reshape_n = gr.stream_to_vector(1, 58 * 2)
    tb.connect(n, reshape_n)
    # limit experiment length
    head = gr.head(58 * 2, 1)
    tb.connect(reshape_n, head)

    # modulate
    gsm_burstmod = gsm.gsm_modulate_burst()
    tb.connect(head, gsm_burstmod)
    random_tsc_index = mlse.randint_b(8)
    tb.connect(random_tsc_index, (gsm_burstmod, 1))

    # apply channel
    channel = gsm.my_channel(-100, [0.2, 1, 0.2])
    channel_apply = gsm.apply_channel_to_vect(148, channel, 1)
    tb.connect(gsm_burstmod, channel_apply)

    # derotate
    derot = mlse.derotate_cc(148, 4,
                             -1)  #FIXME: why -1? (not as if it matters)
    tb.connect(channel_apply, derot)

    modsink = gr.vector_sink_c(148)
    datasink = gr.vector_sink_b(58 * 2)
    tb.connect(derot, modsink)
    tb.connect(head, datasink)

    # mlse-decode
    decode = mlse.equalizer_midamble_vcb(mlse.make_packet_config_gsm())
    tb.connect(derot, decode)
    tb.connect(random_tsc_index, (decode, 1))

    # ber
    ber = mlse.ber_vbi(58 * 2)
    tb.connect(decode, ber)
    tb.connect(head, (ber, 1))

    result_sink = gr.vector_sink_b(58 * 2)
    tb.connect(decode, result_sink)

    chanest_sink = gr.vector_sink_c(7)
    tb.connect((decode, 1), chanest_sink)

    tb.run()
    tb.run()
    d = modsink.data()
    #    printvect_c(d)
    print ber.bit_error_rate()
    print_bitvect(datasink.data())
    print_bitvect(result_sink.data())
    import operator
    print_bitvect(map(operator.xor, datasink.data(), result_sink.data()))
    printvect_c(chanest_sink.data())