Example #1
0
def run_test(f, Kb, bitspersymbol, K, dimensionality, constellation, N0, seed):
    tb = gr.top_block()

    # TX
    numpy.random.seed(-seed)
    packet = numpy.random.randint(0, 2, Kb)  # create Kb random bits
    packet[Kb - 10:Kb] = 0
    packet[0:Kb] = 0
    src = blocks.vector_source_s(packet.tolist(), False)
    b2s = blocks.unpacked_to_packed_ss(1,
                                       gr.GR_MSB_FIRST)  # pack bits in shorts
    s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation, dimensionality)

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

    # RX
    va = trellis.viterbi_combined_fs(
        f, K, 0, 0, dimensionality, constellation, digital.TRELLIS_EUCLIDEAN
    )  # Put -1 if the Initial/Final states are not set.
    fsmi2s = blocks.unpacked_to_packed_ss(
        bitspersymbol, gr.GR_MSB_FIRST)  # pack FSM input symbols to shorts
    s2b = blocks.packed_to_unpacked_ss(
        1, gr.GR_MSB_FIRST)  # unpack shorts to bits
    dst = blocks.vector_sink_s()

    tb.connect(src, b2s, s2fsmi, enc, mod)
    tb.connect(mod, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, 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()

    if len(dst.data()) != len(packet):
        print "Error: not enough data:", len(dst.data()), len(packet)
    ntotal = len(packet)
    nwrong = sum(abs(packet - numpy.array(dst.data())))
    return (ntotal, nwrong, abs(packet - numpy.array(dst.data())))
def run_test (f,Kb,bitspersymbol,K,dimensionality,tot_constellation,N0,seed):
    tb = gr.top_block ()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head (gr.sizeof_short,Kb/16) # packet size in shorts
    s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(tot_constellation,dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.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 = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = blocks.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)
Example #3
0
def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,seed):
    tb = gr.top_block ()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short,Kb/16) # packet size in shorts
    s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation,dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.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 = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = blocks.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)
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 = blocks.vector_source_s(packet,False)
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short,Kb/16) # packet size in shorts
    #b2s = blocks.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts
    s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation,dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.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 = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    #s2b = blocks.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits
    #dst = blocks.vector_sink_s();
    dst = blocks.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)
Example #5
0
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
    tb = gr.top_block ()

    # TX
    numpy.random.seed(-seed)
    packet = numpy.random.randint(0,2,Kb) # create Kb random bits
    packet[Kb-10:Kb]=0
    packet[0:Kb]=0
    src = blocks.vector_source_s(packet.tolist(),False)
    b2s = blocks.unpacked_to_packed_ss(1,gr.GR_MSB_FIRST) # pack bits in shorts
    s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation,dimensionality)

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

    # RX
    va = trellis.viterbi_combined_fs(f,K,0,0,dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set.
    fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    s2b = blocks.packed_to_unpacked_ss(1,gr.GR_MSB_FIRST) # unpack shorts to bits
    dst = blocks.vector_sink_s();


    tb.connect (src,b2s,s2fsmi,enc,mod)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,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()

    if len(dst.data()) != len(packet):
        print("Error: not enough data:", len(dst.data()), len(packet))
    ntotal=len(packet)
    nwrong = sum(abs(packet-numpy.array(dst.data())));
    return (ntotal,nwrong,abs(packet-numpy.array(dst.data())))
Example #6
0
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality,
             constellation, N0, seed):
    tb = gr.top_block()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short, Kb / 16)  # packet size in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(
        bitspersymbol, gr.GR_MSB_FIRST
    )  # unpack shorts to symbols compatible with the outer FSM input cardinality
    enc_out = trellis.encoder_ss(fo, 0)  # initial state = 0
    inter = trellis.permutation(interleaver.K(), interleaver.INTER(), 1,
                                gr.sizeof_short)
    enc_in = trellis.encoder_ss(fi, 0)  # initial state = 0
    mod = digital.chunks_to_symbols_sf(constellation, dimensionality)

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

    # RX
    metrics_in = trellis.metrics_f(
        fi.O(), dimensionality, constellation, digital.TRELLIS_EUCLIDEAN
    )  # data preprocessing to generate metrics for innner Viterbi
    gnd = blocks.vector_source_f([0], True)
    siso_in = trellis.siso_f(
        fi, K, 0, -1, True, False, trellis.TRELLIS_MIN_SUM
    )  # Put -1 if the Initial/Final states are not set.
    deinter = trellis.permutation(interleaver.K(), interleaver.DEINTER(),
                                  fi.I(), gr.sizeof_float)
    va_out = trellis.viterbi_s(
        fo, K, 0, -1)  # Put -1 if the Initial/Final states are not set.
    fsmi2s = blocks.unpacked_to_packed_ss(
        bitspersymbol, gr.GR_MSB_FIRST)  # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect(src, src_head, s2fsmi, enc_out, inter, enc_in, mod)
    tb.connect(mod, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, metrics_in)
    tb.connect(gnd, (siso_in, 0))
    tb.connect(metrics_in, (siso_in, 1))
    tb.connect(siso_in, deinter, va_out, fsmi2s, dst)

    tb.run()

    ntotal = dst.ntotal()
    nright = dst.nright()
    runlength = dst.runlength()
    return (ntotal, ntotal - nright)
Example #7
0
    def __init__(self, constellation, f, N0=0.25, seed=-666):
        """
        constellation - a constellation object used for modulation.
        f - a finite state machine specification used for coding.
        N0 - noise level
        seed - random seed
        """
        super(trellis_tb, self).__init__()
        # packet size in bits (make it multiple of 16 so it can be packed in a
        # short)
        packet_size = 1024 * 16
        # bits per FSM input symbol
        # bits per FSM input symbol
        bitspersymbol = int(round(math.log(f.I()) / math.log(2)))
        # packet size in trellis steps
        K = packet_size // bitspersymbol

        # TX
        src = blocks.lfsr_32k_source_s()
        # packet size in shorts
        src_head = blocks.head(gr.sizeof_short, packet_size // 16)
        # unpack shorts to symbols compatible with the FSM input cardinality
        s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol, gr.GR_MSB_FIRST)
        # initial FSM state = 0
        enc = trellis.encoder_ss(f, 0)
        mod = digital.chunks_to_symbols_sc(constellation.points(), 1)

        # CHANNEL
        add = blocks.add_cc()
        noise = analog.noise_source_c(
            analog.GR_GAUSSIAN, math.sqrt(
                N0 / 2), seed)

        # RX
        # data preprocessing to generate metrics for Viterbi
        metrics = trellis.constellation_metrics_cf(
            constellation.base(), digital.TRELLIS_EUCLIDEAN)
        # Put -1 if the Initial/Final states are not set.
        va = trellis.viterbi_s(f, K, 0, -1)
        # pack FSM input symbols to shorts
        fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST)
        # check the output
        self.dst = blocks.check_lfsr_32k_s()

        self.connect(src, src_head, s2fsmi, enc, mod)
        self.connect(mod, (add, 0))
        self.connect(noise, (add, 1))
        self.connect(add, metrics, va, fsmi2s, self.dst)
Example #8
0
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed,P):
    tb = gr.top_block ()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short,Kb/16*P) # packet size in shorts
    s2fsmi=blocks.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the FSM input cardinality
    s2p = blocks.stream_to_streams(gr.sizeof_short,P) # serial to parallel
    enc = trellis.encoder_ss(f,0) # initiali state = 0
    mod = digital.chunks_to_symbols_sf(constellation,dimensionality)

    # CHANNEL
    add=[]
    noise=[]
    for i in range(P):
        add.append(blocks.add_ff())
        noise.append(analog.noise_source_f(analog.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.
    p2s = blocks.streams_to_stream(gr.sizeof_short,P) # parallel to serial
    fsmi2s=blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect (src,src_head,s2fsmi,s2p)
    for i in range(P):
        tb.connect ((s2p,i),(enc,i),(mod,i))
        tb.connect ((mod,i),(add[i],0))
        tb.connect (noise[i],(add[i],1))
        tb.connect (add[i],(metrics,i))
        tb.connect ((metrics,i),(va,i),(p2s,i))
    tb.connect (p2s,fsmi2s,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 ()

    return (ntotal,ntotal-nright)
Example #9
0
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality,
             constellation, Es, N0, IT, seed):
    tb = gr.top_block()

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

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

    # RX
    metrics_in = trellis.metrics_f(
        fi.O() * fo.O(), dimensionality, constellation,
        digital.TRELLIS_EUCLIDEAN
    )  # data preprocessing to generate metrics for innner SISO
    scale = blocks.multiply_const_ff(1.0 / N0)
    dec = trellis.pccc_decoder_s(fo, 0, -1, fi, 0, -1, interleaver, K, IT,
                                 trellis.TRELLIS_MIN_SUM)

    fsmi2s = blocks.unpacked_to_packed_ss(
        bitspersymbol, gr.GR_MSB_FIRST)  # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect(src, src_head, s2fsmi, enc, mod)
    #tb.connect (src,enc,mod)
    #tb.connect(enc,code)
    tb.connect(mod, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, metrics_in, scale, dec, fsmi2s, dst)

    tb.run()

    #print code.data()

    ntotal = dst.ntotal()
    nright = dst.nright()
    runlength = dst.runlength()
    return (ntotal, ntotal - nright)
    def test_101b(self):
        random.seed(0)
        src_data = []
        for i in xrange(100):
            src_data.append((random.randint(-2**15,2**15-1)))
        src_data = tuple(src_data)
        expected_results = src_data
        src = blocks.vector_source_s(tuple(src_data), False)
        op1 = blocks.packed_to_unpacked_ss(8, gr.GR_LSB_FIRST)
        op2 = blocks.unpacked_to_packed_ss(8, gr.GR_LSB_FIRST)
        dst = blocks.vector_sink_s()

        self.tb.connect(src, op1, op2)
        self.tb.connect(op2, dst)
        self.tb.run()

        self.assertEqual(expected_results, dst.data())
Example #11
0
    def test_101b(self):
        random.seed(0)
        src_data = []
        for i in range(100):
            src_data.append((random.randint(-2**15,2**15-1)))
        src_data = tuple(src_data)
        expected_results = src_data
        src = blocks.vector_source_s(tuple(src_data), False)
        op1 = blocks.packed_to_unpacked_ss(8, gr.GR_LSB_FIRST)
        op2 = blocks.unpacked_to_packed_ss(8, gr.GR_LSB_FIRST)
        dst = blocks.vector_sink_s()

        self.tb.connect(src, op1, op2)
        self.tb.connect(op2, dst)
        self.tb.run()

        self.assertEqual(expected_results, dst.data())
Example #12
0
    def __init__(self, constellation, f, N0=0.25, seed=-666L):
        """
        constellation - a constellation object used for modulation.
        f - a finite state machine specification used for coding.
        N0 - noise level
        seed - random seed
        """
        super(trellis_tb, self).__init__()
        # packet size in bits (make it multiple of 16 so it can be packed in a short)
        packet_size = 1024*16
        # bits per FSM input symbol
        bitspersymbol = int(round(math.log(f.I())/math.log(2))) # bits per FSM input symbol
        # packet size in trellis steps
        K = packet_size/bitspersymbol

        # TX
        src = blocks.lfsr_32k_source_s()
        # packet size in shorts
        src_head = blocks.head(gr.sizeof_short, packet_size/16)
        # unpack shorts to symbols compatible with the FSM input cardinality
        s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol, gr.GR_MSB_FIRST)
        # initial FSM state = 0
        enc = trellis.encoder_ss(f, 0)
        mod = digital.chunks_to_symbols_sc(constellation.points(), 1)

        # CHANNEL
        add = blocks.add_cc()
        noise = analog.noise_source_c(analog.GR_GAUSSIAN,math.sqrt(N0/2),seed)

        # RX
        # data preprocessing to generate metrics for Viterbi
        metrics = trellis.constellation_metrics_cf(constellation.base(), digital.TRELLIS_EUCLIDEAN)
        # Put -1 if the Initial/Final states are not set.
        va = trellis.viterbi_s(f, K, 0, -1)
        # pack FSM input symbols to shorts
        fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST)
        # check the output
        self.dst = blocks.check_lfsr_32k_s()

        self.connect (src, src_head, s2fsmi, enc, mod)
        self.connect (mod, (add, 0))
        self.connect (noise, (add, 1))
        self.connect (add, metrics, va, fsmi2s, self.dst)
Example #13
0
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality,
             constellation, Es, N0, IT, seed):
    tb = gr.top_block()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short, Kb / 16)  # packet size in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(
        bitspersymbol, gr.GR_MSB_FIRST
    )  # unpack shorts to symbols compatible with the outer FSM input cardinality
    enc_out = trellis.encoder_ss(fo, 0)  # initial state = 0
    inter = trellis.permutation(interleaver.K(), interleaver.INTER(), 1,
                                gr.sizeof_short)
    enc_in = trellis.encoder_ss(fi, 0)  # initial state = 0
    mod = digital.chunks_to_symbols_sf(constellation, dimensionality)

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

    # RX
    (head, tail) = make_rx(tb, fo, fi, dimensionality, constellation, K,
                           interleaver, IT, Es, N0, trellis.TRELLIS_MIN_SUM)
    #(head,tail) = make_rx(tb,fo,fi,dimensionality,constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_SUM_PRODUCT)
    fsmi2s = blocks.unpacked_to_packed_ss(
        bitspersymbol, gr.GR_MSB_FIRST)  # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect(src, src_head, s2fsmi, enc_out, inter, enc_in, mod)
    tb.connect(mod, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, head)
    tb.connect(tail, fsmi2s, dst)

    tb.run()

    #print enc_out.ST(), enc_in.ST()

    ntotal = dst.ntotal()
    nright = dst.nright()
    runlength = dst.runlength()
    return (ntotal, ntotal - nright)
Example #14
0
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality,
             constellation, Es, N0, IT, seed):
    tb = gr.top_block()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short, Kb / 16)  # packet size in shorts
    s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation, dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.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 = blocks.unpacked_to_packed_ss(
        bitspersymbol, gr.GR_MSB_FIRST)  # pack FSM input symbols to shorts
    dst = blocks.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)
Example #15
0
def run_test(f, Kb, bitspersymbol, K, dimensionality, tot_constellation, N0,
             seed):
    tb = gr.top_block()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short, Kb / 16)  # packet size in shorts
    s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(tot_constellation, dimensionality)

    # CHANNEL
    add = blocks.add_ff()
    noise = analog.noise_source_f(analog.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 = blocks.unpacked_to_packed_ss(
        bitspersymbol, gr.GR_MSB_FIRST)  # pack FSM input symbols to shorts
    dst = blocks.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)
Example #16
0
def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,Es,N0,IT,seed):
    tb = gr.top_block ()


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

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

    # RX
    metrics_in = trellis.metrics_f(fi.O()*fo.O(),dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner SISO
    scale = blocks.multiply_const_ff(1.0/N0)
    dec = trellis.pccc_decoder_s(fo,0,-1,fi,0,-1,interleaver,K,IT,trellis.TRELLIS_MIN_SUM)

    fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect (src,src_head,s2fsmi,enc,mod)
    #tb.connect (src,enc,mod)
    #tb.connect(enc,code)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,metrics_in,scale,dec,fsmi2s,dst)

    tb.run()

    #print code.data()

    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()
    return (ntotal,ntotal-nright)
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
    tb = gr.top_block ()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short,Kb/16) # packet size in shorts
    s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation,dimensionality)


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


    # RX
    va = trellis.viterbi_combined_fs(f,K,0,-1,dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set.
    fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = blocks.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,va,fsmi2s,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 ()

    return (ntotal,ntotal-nright)
Example #18
0
def run_test (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
    tb = gr.top_block ()


    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head (gr.sizeof_short,Kb/16) # packet size in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(bitspersymbol,gr.GR_MSB_FIRST) # unpack shorts to symbols compatible with the outer FSM input cardinality
    enc_out = trellis.encoder_ss(fo,0) # initial state = 0
    inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short)
    enc_in = trellis.encoder_ss(fi,0) # initial state = 0
    mod = digital.chunks_to_symbols_sf(constellation,dimensionality)

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

    # RX
    metrics_in = trellis.metrics_f(fi.O(),dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner Viterbi
    gnd = blocks.vector_source_f([0],True);
    siso_in = trellis.siso_f(fi,K,0,-1,True,False,trellis.TRELLIS_MIN_SUM) # Put -1 if the Initial/Final states are not set.
    deinter = trellis.permutation(interleaver.K(),interleaver.DEINTER(),fi.I(),gr.sizeof_float)
    va_out = trellis.viterbi_s(fo,K,0,-1) # Put -1 if the Initial/Final states are not set.
    fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod)
    tb.connect (mod,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,metrics_in)
    tb.connect (gnd,(siso_in,0))
    tb.connect (metrics_in,(siso_in,1))
    tb.connect (siso_in,deinter,va_out,fsmi2s,dst)

    tb.run()

    ntotal = dst.ntotal ()
    nright = dst.nright ()
    runlength = dst.runlength ()
    return (ntotal,ntotal-nright)
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality, tot_constellation, Es, N0, IT, seed):
    tb = gr.top_block()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short, Kb / 16)  # packet size in shorts
    s2fsmi = blocks.packed_to_unpacked_ss(
        bitspersymbol, gr.GR_MSB_FIRST
    )  # unpack shorts to symbols compatible with the iouter FSM input cardinality
    enc_out = trellis.encoder_ss(fo, 0)  # initial state = 0
    inter = trellis.permutation(interleaver.K(), interleaver.INTER(), 1, gr.sizeof_short)
    enc_in = trellis.encoder_ss(fi, 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 innner FSM)
    mod = digital.chunks_to_symbols_sf(tot_constellation, dimensionality)

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

    # RX
    (head, tail) = make_rx(
        tb, fo, fi, dimensionality, tot_constellation, K, interleaver, IT, Es, N0, trellis.TRELLIS_MIN_SUM
    )
    fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol, gr.GR_MSB_FIRST)  # pack FSM input symbols to shorts
    dst = blocks.check_lfsr_32k_s()

    tb.connect(src, src_head, s2fsmi, enc_out, inter, enc_in, mod)
    tb.connect(mod, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, head)
    tb.connect(tail, fsmi2s, dst)

    tb.run()

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

    return (ntotal, ntotal - nright)
def run_test (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed):
    tb = gr.top_block ()

    # TX
    src = blocks.lfsr_32k_source_s()
    src_head = blocks.head(gr.sizeof_short,Kb/16) # packet size in shorts
    s2fsmi = blocks.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 = digital.chunks_to_symbols_sf(constellation,dimensionality)


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


    # RX
    va = trellis.viterbi_combined_fs(f,K,0,-1,dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # Put -1 if the Initial/Final states are not set.
    fsmi2s = blocks.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = blocks.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,va,fsmi2s,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 ()

    return (ntotal,ntotal-nright)
Example #21
0
    def __init__(self):
        grc_wxgui.top_block_gui.__init__(self, title="FM radio FFT example")
        _icon_path = "/usr/share/icons/hicolor/32x32/apps/gnuradio-grc.png"
        self.SetIcon(wx.Icon(_icon_path, wx.BITMAP_TYPE_ANY))

        ##################################################
        # Variables
        ##################################################
        self.variable_sample_rate_0 = variable_sample_rate_0 = 1e6
        self.samp_rate = samp_rate = 44100
        self.xlatecenter_8 = xlatecenter_8 = 0
        self.xlatecenter_7 = xlatecenter_7 = 0
        self.xlatecenter_6 = xlatecenter_6 = 0
        self.xlatecenter_5 = xlatecenter_5 = 0
        self.xlatecenter_4 = xlatecenter_4 = 0
        self.xlatecenter_3 = xlatecenter_3 = 0
        self.xlatecenter_2 = xlatecenter_2 = 0
        self.xlatecenter = xlatecenter = 0
        self.xlate_filter2 = xlate_filter2 = firdes.low_pass(1, samp_rate, 4000, 1000, firdes.WIN_HAMMING, 6.76)
        self.xlate_filter = xlate_filter = firdes.low_pass(1, variable_sample_rate_0, 125000, 25000, firdes.WIN_HAMMING, 6.76)
        self.variable_function_probe_0 = variable_function_probe_0 = 0
        self.variable_1 = variable_1 = 0
        self.transition = transition = 1e6
        self.rri = rri = 441
        self.rrd = rrd = 500
        self.quadrature = quadrature = 500000
        self.pscfshift = pscfshift = 0
        self.pscf8 = pscf8 = 0
        self.pscf7 = pscf7 = 0
        self.pscf6 = pscf6 = 0
        self.pscf5 = pscf5 = 0
        self.pscf4 = pscf4 = 0
        self.pscf3 = pscf3 = 0
        self.pscf2 = pscf2 = 0
        self.pscf1 = pscf1 = 0
        self.globaltune = globaltune = 0
        self.cutoff = cutoff = 1e5
        self.bptrans = bptrans = 100
        self.bpsr = bpsr = 200000
        self.bplow_4 = bplow_4 = 100
        self.bplow_3 = bplow_3 = 100
        self.bplow_2 = bplow_2 = 100
        self.bplow_1 = bplow_1 = 100
        self.bphi_4 = bphi_4 = 2.8e3
        self.bphi_3 = bphi_3 = 2.8e3
        self.bphi_2 = bphi_2 = 2.8e3
        self.bphi_1 = bphi_1 = 2.8e3
        self.audio_interp = audio_interp = 4
        self.amp_fm = amp_fm = 1
        self.amp_am = amp_am = 1
        self.amp_8 = amp_8 = 0
        self.amp_7 = amp_7 = 0
        self.amp_6 = amp_6 = 0
        self.amp_5 = amp_5 = 0
        self.amp_4 = amp_4 = 0
        self.amp_3 = amp_3 = 0
        self.amp_2 = amp_2 = 0
        self.amp_1 = amp_1 = 0
        self.RF_Gain = RF_Gain = 35
        self.CF = CF = 125.6e6

        ##################################################
        # Blocks
        ##################################################
        self.wxgui_waterfallsink2_0 = waterfallsink2.waterfall_sink_c(
        	self.GetWin(),
        	baseband_freq=CF,
        	dynamic_range=100,
        	ref_level=0,
        	ref_scale=2.0,
        	sample_rate=variable_sample_rate_0,
        	fft_size=512,
        	fft_rate=15,
        	average=False,
        	avg_alpha=None,
        	title="Waterfall Plot",
        	size=(924,668),
        )
        self.Add(self.wxgui_waterfallsink2_0.win)
        self.video_sdl_sink_0 = video_sdl.sink_s(0, 640, 480, 0, 640, 480)
        def _variable_function_probe_0_probe():
            while True:
                val = self.my_block_0.get_number()
                try:
                    self.set_variable_function_probe_0(val)
                except AttributeError:
                    pass
                time.sleep(1.0 / (10))
        _variable_function_probe_0_thread = threading.Thread(target=_variable_function_probe_0_probe)
        _variable_function_probe_0_thread.daemon = True
        _variable_function_probe_0_thread.start()
        self.blocks_unpacked_to_packed_xx_0 = blocks.unpacked_to_packed_ss(2, gr.GR_MSB_FIRST)
        self.blocks_float_to_short_0_0 = blocks.float_to_short(1, 1)
        self.blocks_float_to_short_0 = blocks.float_to_short(1, 1)
        self.blocks_complex_to_float_0 = blocks.complex_to_float(1)
        self.RTL820T = osmosdr.source( args="numchan=" + str(1) + " " + "" )
        self.RTL820T.set_sample_rate(variable_sample_rate_0)
        self.RTL820T.set_center_freq(CF, 0)
        self.RTL820T.set_freq_corr(0, 0)
        self.RTL820T.set_dc_offset_mode(2, 0)
        self.RTL820T.set_iq_balance_mode(0, 0)
        self.RTL820T.set_gain_mode(False, 0)
        self.RTL820T.set_gain(RF_Gain, 0)
        self.RTL820T.set_if_gain(20, 0)
        self.RTL820T.set_bb_gain(20, 0)
        self.RTL820T.set_antenna("", 0)
        self.RTL820T.set_bandwidth(1e6, 0)
          

        ##################################################
        # Connections
        ##################################################
        self.connect((self.RTL820T, 0), (self.blocks_complex_to_float_0, 0))    
        self.connect((self.RTL820T, 0), (self.wxgui_waterfallsink2_0, 0))    
        self.connect((self.blocks_complex_to_float_0, 0), (self.blocks_float_to_short_0, 0))    
        self.connect((self.blocks_complex_to_float_0, 1), (self.blocks_float_to_short_0_0, 0))    
        self.connect((self.blocks_float_to_short_0, 0), (self.blocks_unpacked_to_packed_xx_0, 0))    
        self.connect((self.blocks_float_to_short_0_0, 0), (self.video_sdl_sink_0, 1))    
        self.connect((self.blocks_unpacked_to_packed_xx_0, 0), (self.video_sdl_sink_0, 0))