Exemplo n.º 1
0
def test_mod_cpm():
    tb = gr.top_block()
    precode = mlse.xor_encode_bb()
    nrz = gr.map_bb([1, -1])
    mod = gr.gmskmod_bc(1, 0.3, 4)
    #src = gr.vector_source_b([0,0,0,0,1,1,1,1,0,0])
    #src = gr.vector_source_b([1,1,0,0,1,0,0,1,1,1,0,0,0,0])
    src = gr.vector_source_b((1, ) * 1000)
    sink = gr.vector_sink_c()
    derot = mlse.derotate_cc(1, 4)
    tb.connect(src, precode, nrz, mod, derot, sink)
    precode_probe = gr.vector_sink_b()
    tb.connect(nrz, precode_probe)
    tb.run()
    d = sink.data()
    from cmath import phase, pi, rect
    real = lambda x: x.real
    import operator
    d_r = d  #list(decimate(d,5,2))
    d2 = [int(round((phase(i) / pi) * 100)) for i in d]
    derotate = [(-1j)**(i + 1) for i in range(len(d_r))]
    d3 = map(operator.mul, d_r, derotate)
    #    print "\n".join(map(str,map(real,d3)))
    print precode_probe.data()
    #    print "\n".join(map(str,map(phase,d)))
    print "\n".join([str(phase(i) / pi) for i in d])
    print len(d)
    print derotate
Exemplo n.º 2
0
def test_mod_cpm():
    tb = gr.top_block()
    precode = mlse.xor_encode_bb()
    nrz = gr.map_bb([1,-1])
    mod = gr.gmskmod_bc(1,0.3,4)
    #src = gr.vector_source_b([0,0,0,0,1,1,1,1,0,0])
    #src = gr.vector_source_b([1,1,0,0,1,0,0,1,1,1,0,0,0,0])
    src = gr.vector_source_b((1,)*1000)
    sink = gr.vector_sink_c()
    derot = mlse.derotate_cc(1,4)
    tb.connect(src, precode, nrz, mod, derot, sink)
    precode_probe = gr.vector_sink_b()
    tb.connect(nrz, precode_probe)
    tb.run()
    d = sink.data()
    from cmath import phase, pi, rect
    real = lambda x: x.real
    import operator
    d_r = d#list(decimate(d,5,2))
    d2 = [ int(round((phase(i)/pi)*100)) for i in d ]
    derotate = [ (-1j)**(i+1) for i in range(len(d_r))]
    d3 = map(operator.mul, d_r, derotate)
#    print "\n".join(map(str,map(real,d3)))
    print precode_probe.data()
#    print "\n".join(map(str,map(phase,d)))
    print "\n".join([str(phase(i)/pi) for i in d])
    print len(d)
    print derotate
Exemplo n.º 3
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())
Exemplo n.º 4
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())
Exemplo n.º 5
0
 def test_001_t (self):
     """tests sample mode"""
     input_data = (1.,)*40
     expected_result = (-1j, -1, 1j,1)*10
     # set up fg
     src = gr.vector_source_c(input_data)
     derot = mlse_swig.derotate_cc(1,4,1)
     sink = gr.vector_sink_c();
     self.tb.connect(src, derot, sink)
     self.tb.run ()
     # check data
     self.assertComplexTuplesAlmostEqual(expected_result, sink.data())
Exemplo n.º 6
0
 def test_001_t(self):
     """tests sample mode"""
     input_data = (1., ) * 40
     expected_result = (-1j, -1, 1j, 1) * 10
     # set up fg
     src = gr.vector_source_c(input_data)
     derot = mlse_swig.derotate_cc(1, 4, 1)
     sink = gr.vector_sink_c()
     self.tb.connect(src, derot, sink)
     self.tb.run()
     # check data
     self.assertComplexTuplesAlmostEqual(expected_result, sink.data())
Exemplo n.º 7
0
    def make_flowgraph(self):
        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, self.packets)
        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(self.snr, self.chan_taps)
        channel_apply = gsm.apply_channel_to_vect(148, channel, 3)
        #TODO: don't use to_vector and to_stream for the channel
        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)

        # mlse-decode
        if (self.no_decorr):
            decode = gsm.gsm_decode_harddecision()
        else:
            decode = mlse.equalizer_midamble_vcb(mlse.make_packet_config_gsm())
            tb.connect(random_tsc_index, (decode, 1))
        tb.connect(derot, decode)

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

        if (not self.no_decorr):
            # throw away channel-estimate data
            chanest_sink = gr.null_sink(6 * gr.sizeof_gr_complex)
            tb.connect((decode, 1), chanest_sink)

        # export members we need
        self.tb = tb
        self.ber = ber
        self.head = head
        self.channel = channel
Exemplo n.º 8
0
    def make_flowgraph(self):
        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,self.packets)
        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(self.snr, self.chan_taps)
        channel_apply = gsm.apply_channel_to_vect(148, channel, 3)
        #TODO: don't use to_vector and to_stream for the channel
        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)

        # mlse-decode
        if(self.no_decorr):
            decode = gsm.gsm_decode_harddecision()
        else:
            decode = mlse.equalizer_midamble_vcb(mlse.make_packet_config_gsm())
            tb.connect(random_tsc_index, (decode,1))
        tb.connect(derot,decode)

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

        if(not self.no_decorr):
            # throw away channel-estimate data
            chanest_sink = gr.null_sink(6*gr.sizeof_gr_complex)
            tb.connect((decode,1), chanest_sink)

        # export members we need
        self.tb = tb
        self.ber = ber
        self.head = head
        self.channel = channel
Exemplo n.º 9
0
def test_viterbi():
    tb=gr.top_block()
    channel = [0,1,0]
    prellen = len(channel) - 1
    data = [random.randint(0,1) for i in xrange(20+prellen)]
    data.extend([0,0,0]) # tailbits
    data.extend([0]*6) # to flush modulator


    # modulate
    datasrc = gr.vector_source_b(data)
    diffcode = mlse.xor_encode_bb();
    nrz = gr.map_bb([1,-1])
    mod = gr.gmskmod_bc(1, 0.3, 12)
    derot = mlse.derotate_cc();
    modsink = gr.vector_sink_c();
    tb.connect(datasrc, diffcode, nrz, mod, derot, modsink)
    tb.run()

    samples = modsink.data()[6:]
    printvect_c(samples)


    preload = data[:prellen]
    rest = data[prellen:][:20]

    tb=gr.top_block()
    conf=mlse.make_packet_config_gsm()
    vit = mlse.viterbi_vcb(20,len(channel),3,[1,-1])#conf.get_constellation())
    chansrc = gr.vector_source_c(channel,vlen=len(channel))
    preloadsrc = gr.vector_source_b(preload,vlen=len(preload))
    samplesrc = gr.vector_source_c(samples,vlen=len(samples))
    sink = gr.vector_sink_b(20)
    tb.connect(chansrc, (vit,0))
    tb.connect(samplesrc, (vit,1))
    tb.connect(preloadsrc, (vit,2))
    tb.connect(vit, sink)
    tb.run()
    print_bitvect(preload)
    print_bitvect(rest)
    print_bitvect(sink.data())
Exemplo n.º 10
0
def test_viterbi():
    tb = gr.top_block()
    channel = [0, 1, 0]
    prellen = len(channel) - 1
    data = [random.randint(0, 1) for i in xrange(20 + prellen)]
    data.extend([0, 0, 0])  # tailbits
    data.extend([0] * 6)  # to flush modulator

    # modulate
    datasrc = gr.vector_source_b(data)
    diffcode = mlse.xor_encode_bb()
    nrz = gr.map_bb([1, -1])
    mod = gr.gmskmod_bc(1, 0.3, 12)
    derot = mlse.derotate_cc()
    modsink = gr.vector_sink_c()
    tb.connect(datasrc, diffcode, nrz, mod, derot, modsink)
    tb.run()

    samples = modsink.data()[6:]
    printvect_c(samples)

    preload = data[:prellen]
    rest = data[prellen:][:20]

    tb = gr.top_block()
    conf = mlse.make_packet_config_gsm()
    vit = mlse.viterbi_vcb(20, len(channel), 3,
                           [1, -1])  #conf.get_constellation())
    chansrc = gr.vector_source_c(channel, vlen=len(channel))
    preloadsrc = gr.vector_source_b(preload, vlen=len(preload))
    samplesrc = gr.vector_source_c(samples, vlen=len(samples))
    sink = gr.vector_sink_b(20)
    tb.connect(chansrc, (vit, 0))
    tb.connect(samplesrc, (vit, 1))
    tb.connect(preloadsrc, (vit, 2))
    tb.connect(vit, sink)
    tb.run()
    print_bitvect(preload)
    print_bitvect(rest)
    print_bitvect(sink.data())