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)
Exemplo n.º 2
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)
Exemplo n.º 3
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)
Exemplo n.º 4
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, 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)
Exemplo n.º 5
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)
Exemplo n.º 6
0
def run_test(f, Kb, bitspersymbol, K, dimensionality, constellation, N0, seed,
             P):
    tb = gr.top_block()

    # TX
    src = gr.lfsr_32k_source_s()
    src_head = gr.head(gr.sizeof_short, Kb / 16 * P)  # 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
    s2p = gr.stream_to_streams(gr.sizeof_short, P)  # serial to parallel
    enc = trellis.encoder_ss(f, 0)  # initiali state = 0
    mod = gr.chunks_to_symbols_sf(constellation, dimensionality)

    # CHANNEL
    add = []
    noise = []
    for i in range(P):
        add.append(gr.add_ff())
        noise.append(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.
    p2s = gr.streams_to_stream(gr.sizeof_short, P)  # parallel to serial
    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, 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)
def run_test(f, Kb, bitspersymbol, K, channel, modulation, dimensionality,
             tot_constellation, N0, seed):
    tb = gr.top_block()
    L = len(channel)

    # TX
    # this for loop is TOO slow in python!!!
    packet = [0] * (K + 2 * L)
    random.seed(seed)
    for i in range(len(packet)):
        packet[i] = random.randint(0, 2**bitspersymbol - 1)  # random symbols
    for i in range(L):  # first/last L symbols set to 0
        packet[i] = 0
        packet[len(packet) - i - 1] = 0
    src = gr.vector_source_s(packet, False)
    mod = gr.chunks_to_symbols_sf(modulation[1], modulation[0])

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

    # RX
    skip = gr.skiphead(
        gr.sizeof_float, L
    )  # skip the first L samples since you know they are coming from the L zero symbols
    #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+L,0,0) # Put -1 if the Initial/Final states are not set.
    va = trellis.viterbi_combined_s(
        f, K + L, 0, 0, dimensionality, tot_constellation,
        trellis.TRELLIS_EUCLIDEAN
    )  # using viterbi_combined_s instead of metrics_f/viterbi_s allows larger packet lengths because metrics_f is complaining for not being able to allocate large buffers. This is due to the large f.O() in this application...
    dst = gr.vector_sink_s()

    tb.connect(src, mod)
    tb.connect(mod, isi, (add, 0))
    tb.connect(noise, (add, 1))
    #tb.connect (add,metrics)
    #tb.connect (metrics,va,dst)
    tb.connect(add, skip, va, dst)

    tb.run()

    data = dst.data()
    ntotal = len(data) - L
    nright = 0
    for i in range(ntotal):
        if packet[i + L] == data[i]:
            nright = nright + 1
        #else:
        #print "Error in ", i

    return (ntotal, ntotal - nright)
Exemplo n.º 8
0
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality,
             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 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 = 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_in = trellis.metrics_f(
        fi.O(), dimensionality, constellation, digital.TRELLIS_EUCLIDEAN
    )  # data preprocessing to generate metrics for innner Viterbi
    gnd = gr.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 = 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(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 (f,Kb,bitspersymbol,K,dimensionality,constellation,N0,seed,P):
    fg = gr.flow_graph ()

    # TX
    src = gr.lfsr_32k_source_s()
    src_head = gr.head (gr.sizeof_short,Kb/16*P) # 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
    s2p = gr.stream_to_streams(gr.sizeof_short,P) # serial to parallel
    enc = trellis.encoder_ss(f,0) # initiali state = 0
    mod = gr.chunks_to_symbols_sf(constellation,dimensionality)

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

    fg.connect (src,src_head,s2fsmi,s2p)
    for i in range(P):
        fg.connect ((s2p,i),(enc,i),(mod,i))
        fg.connect ((mod,i),(add[i],0))
        fg.connect (noise[i],(add[i],1))
        fg.connect (add[i],(metrics,i))
        fg.connect ((metrics,i),(va,i),(p2s,i))
    fg.connect (p2s,fsmi2s,dst)
    

    fg.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)
Exemplo n.º 10
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
    #src = gr.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 = gr.vector_sink_s()
    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_in = trellis.metrics_f(
        fi.O() * fo.O(), dimensionality, constellation,
        digital.TRELLIS_EUCLIDEAN
    )  # data preprocessing to generate metrics for innner SISO
    scale = gr.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 = 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 (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,channel,modulation,dimensionality,tot_constellation,N0,seed):
    fg = gr.flow_graph ()
    L = len(channel)

    # TX
    # this for loop is TOO slow in python!!!
    packet = [0]*(K+2*L)
    random.seed(seed)
    for i in range(len(packet)):
        packet[i] = random.randint(0, 2**bitspersymbol - 1) # random symbols
    for i in range(L): # first/last L symbols set to 0
        packet[i] = 0
        packet[len(packet)-i-1] = 0
    src = gr.vector_source_s(packet,False)
    mod = gr.chunks_to_symbols_sf(modulation[1],modulation[0])

    # CHANNEL
    isi = gr.fir_filter_fff(1,channel)
    add = gr.add_ff()
    noise = gr.noise_source_f(gr.GR_GAUSSIAN,math.sqrt(N0/2),seed)
    
    # RX
    skip = gr.skiphead(gr.sizeof_float, L) # skip the first L samples since you know they are coming from the L zero symbols
    #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+L,-1,0) # Put -1 if the Initial/Final states are not set.
    va = trellis.viterbi_combined_fs(f,K+L,0,0,dimensionality,tot_constellation,trellis.TRELLIS_EUCLIDEAN) # using viterbi_combined_fs instead of metrics_f/viterbi_s allows larger packet lengths because metrics_f is complaining for not being able to allocate large buffers. This is due to the large f.O() in this application...
    dst = gr.vector_sink_s()

    fg.connect (src,mod)
    fg.connect (mod,isi,(add,0))
    fg.connect (noise,(add,1))
    #fg.connect (add,metrics)
    #fg.connect (metrics,va,dst)
    fg.connect (add,skip,va,dst)

    fg.run()

    data = dst.data() 
    ntotal = len(data) - L
    nright=0
    for i in range(ntotal):
        if packet[i+L]==data[i]:
            nright=nright+1
        #else:
            #print "Error in ", i
    
    return (ntotal,ntotal-nright)
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, channel, modulation,
             dimensionality, tot_constellation, Es, N0, IT, seed):
    tb = gr.top_block()
    L = len(channel)

    # TX
    # this for loop is TOO slow in python!!!
    packet = [0] * (K)
    random.seed(seed)
    for i in range(len(packet)):
        packet[i] = random.randint(0, 2**bitspersymbol - 1)  # random symbols
    src = gr.vector_source_s(packet, False)
    enc_out = trellis.encoder_ss(fo, 0)  # initial state = 0
    inter = trellis.permutation(interleaver.K(), interleaver.INTER(), 1,
                                gr.sizeof_short)
    mod = gr.chunks_to_symbols_sf(modulation[1], modulation[0])

    # CHANNEL
    isi = gr.fir_filter_fff(1, channel)
    add = gr.add_ff()
    noise = gr.noise_source_f(gr.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)
    dst = gr.vector_sink_s()

    tb.connect(src, enc_out, inter, mod)
    tb.connect(mod, isi, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, head)
    tb.connect(tail, dst)

    tb.run()

    data = dst.data()
    ntotal = len(data)
    nright = 0
    for i in range(ntotal):
        if packet[i] == data[i]:
            nright = nright + 1
        #else:
        #print "Error in ", i

    return (ntotal, ntotal - nright)
Exemplo n.º 13
0
def run_test(fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality, 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 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 = 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_in = trellis.metrics_f(
        fi.O(), dimensionality, constellation, trellis.TRELLIS_EUCLIDEAN
    )  # data preprocessing to generate metrics for innner Viterbi
    va_in = trellis.viterbi_s(fi, K, 0, -1)  # Put -1 if the Initial/Final states are not set.
    deinter = trellis.permutation(interleaver.K(), interleaver.DEINTER(), 1, gr.sizeof_short)
    metrics_out = trellis.metrics_s(
        fo.O(), 1, [0, 1, 2, 3], trellis.TRELLIS_HARD_SYMBOL
    )  # data preprocessing to generate metrics for outer Viterbi (hard decisions)
    va_out = trellis.viterbi_s(fo, 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_out, inter, enc_in, mod)
    tb.connect(mod, (add, 0))
    tb.connect(noise, (add, 1))
    tb.connect(add, metrics_in)
    tb.connect(metrics_in, va_in, deinter, metrics_out, 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,channel,modulation,dimensionality,tot_constellation,Es,N0,IT,seed):
    tb = gr.top_block ()
    L = len(channel)

    # TX
    # this for loop is TOO slow in python!!!
    packet = [0]*(K)
    random.seed(seed)
    for i in range(len(packet)):
        packet[i] = random.randint(0, 2**bitspersymbol - 1) # random symbols
    src = gr.vector_source_s(packet,False)
    enc_out = trellis.encoder_ss(fo,0) # initial state = 0
    inter = trellis.permutation(interleaver.K(),interleaver.INTER(),1,gr.sizeof_short)
    mod = gr.chunks_to_symbols_sf(modulation[1],modulation[0])

    # CHANNEL
    isi = gr.fir_filter_fff(1,channel)
    add = gr.add_ff()
    noise = gr.noise_source_f(gr.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) 
    dst = gr.vector_sink_s(); 
    
    tb.connect (src,enc_out,inter,mod)
    tb.connect (mod,isi,(add,0))
    tb.connect (noise,(add,1))
    tb.connect (add,head)
    tb.connect (tail,dst)
    
    tb.run()

    data = dst.data()
    ntotal = len(data)
    nright=0
    for i in range(ntotal):
        if packet[i]==data[i]:
            nright=nright+1
        #else:
            #print "Error in ", i
 
    return (ntotal,ntotal-nright)
Exemplo n.º 15
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_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 = 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
    (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 = 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(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)
Exemplo n.º 16
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)
Exemplo n.º 17
0
def run_test(f, Kb, bitspersymbol, K, dimensionality, 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
    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
    va = trellis.viterbi_combined_fs(
        f, K, 0, -1, dimensionality, constellation, trellis.TRELLIS_EUCLIDEAN
    )  # 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, 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)
Exemplo n.º 18
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_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 = 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
    (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 = 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(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)
Exemplo n.º 19
0
def run_test (f,Kb,bitspersymbol,K,dimensionality,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
    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
    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 = 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,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)
Exemplo n.º 20
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
    #src = gr.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 = gr.vector_sink_s()
    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_in = trellis.metrics_f(fi.O()*fo.O(),dimensionality,constellation,digital.TRELLIS_EUCLIDEAN) # data preprocessing to generate metrics for innner SISO
    scale = gr.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 = 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 (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 (fo,fi,interleaver,Kb,bitspersymbol,K,dimensionality,tot_constellation,Es,N0,IT,seed):
    fg = gr.flow_graph ()

    # 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 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 = 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
    (head,tail) = make_rx(fg,fo,fi,dimensionality,tot_constellation,K,interleaver,IT,Es,N0,trellis.TRELLIS_MIN_SUM) 
    fsmi2s = gr.unpacked_to_packed_ss(bitspersymbol,gr.GR_MSB_FIRST) # pack FSM input symbols to shorts
    dst = gr.check_lfsr_32k_s(); 
    
    fg.connect (src,src_head,s2fsmi,enc_out,inter,enc_in,mod)
    fg.connect (mod,(add,0))
    fg.connect (noise,(add,1))
    fg.connect (add,head)
    fg.connect (tail,fsmi2s,dst)
    
    fg.run()

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