def main(args):
    nargs = len(args)
    if nargs == 3:
        fname_out = args[0]
        esn0_db = float(args[1])
        rep = int(args[2])
    else:
        sys.stderr.write(
            'usage: test_turbo_equalization.py fsm_name_out Es/No_db  repetitions\n'
        )
        sys.exit(1)

    # system parameters
    Kb = 64 * 16  # packet size in bits (multiple of 16)
    modulation = fsm_utils.pam4  # see fsm_utlis.py for available predefined modulations
    channel = fsm_utils.c_channel  # see fsm_utlis.py for available predefined test channels
    fo = trellis.fsm(fname_out)  # get the outer FSM specification from a file
    fi = trellis.fsm(len(modulation[1]),
                     len(channel))  # generate the FSM automatically
    if fo.O() != fi.I():
        sys.stderr.write(
            'Incompatible cardinality between outer and inner FSM.\n')
        sys.exit(1)
    bitspersymbol = int(round(math.log(fo.I()) /
                              math.log(2)))  # bits per FSM input symbol
    K = Kb / bitspersymbol  # packet size in trellis steps
    interleaver = trellis.interleaver(K, 666)  # construct a random interleaver
    tot_channel = fsm_utils.make_isi_lookup(
        modulation, channel,
        True)  # generate the lookup table (normalize energy to 1)
    dimensionality = tot_channel[0]
    tot_constellation = tot_channel[1]
    if len(tot_constellation) / dimensionality != fi.O():
        sys.stderr.write(
            'Incompatible FSM output cardinality and lookup table size.\n')
        sys.exit(1)
    N0 = pow(10.0, -esn0_db / 10.0)
    # noise variance
    IT = 3  # number of turbo iterations

    tot_s = 0  # total number of transmitted shorts
    terr_s = 0  # total number of shorts in error
    terr_p = 0  # total number of packets in error

    for i in range(rep):
        (s, e) = run_test(
            fo, fi, interleaver, Kb, bitspersymbol, K, channel, modulation,
            dimensionality, tot_constellation, 1, N0, IT, -long(666 + i)
        )  # run experiment with different seed to get different noise realizations
        tot_s = tot_s + s
        terr_s = terr_s + e
        terr_p = terr_p + (terr_s != 0)
        if ((i + 1) % 10 == 0):  # display progress
            print i + 1, terr_p, '%.2e' % ((1.0 * terr_p) /
                                           (i + 1)), tot_s, terr_s, '%.2e' % (
                                               (1.0 * terr_s) / tot_s)
    # estimate of the (short or bit) error rate
    print rep, terr_p, '%.2e' % ((1.0 * terr_p) /
                                 (i + 1)), tot_s, terr_s, '%.2e' % (
                                     (1.0 * terr_s) / tot_s)
def main(args):
    nargs = len(args)
    if nargs == 2:
        esn0_db = float(args[0])
        rep = int(args[1])
    else:
        sys.stderr.write(
            'usage: test_viterbi_equalization1.py Es/No_db  repetitions\n')
        sys.exit(1)

    # system parameters
    Kb = 2048  # packet size in bits
    modulation = fsm_utils.pam4  # see fsm_utlis.py for available predefined modulations
    channel = fsm_utils.c_channel  # see fsm_utlis.py for available predefined test channels
    f = trellis.fsm(len(modulation[1]),
                    len(channel))  # generate the FSM automatically
    bitspersymbol = int(round(math.log(f.I()) /
                              math.log(2)))  # bits per FSM input symbol
    K = Kb / bitspersymbol  # packet size in trellis steps

    tot_channel = fsm_utils.make_isi_lookup(
        modulation, channel,
        True)  # generate the lookup table (normalize energy to 1)
    dimensionality = tot_channel[0]
    tot_constellation = tot_channel[1]
    N0 = pow(10.0, -esn0_db / 10.0)
    # noise variance
    if len(tot_constellation) / dimensionality != f.O():
        sys.stderr.write(
            'Incompatible FSM output cardinality and lookup table size.\n')
        sys.exit(1)

    tot_s = 0  # total number of transmitted shorts
    terr_s = 0  # total number of shorts in error
    terr_p = 0  # total number of packets in error

    for i in range(rep):
        (s, e) = run_test(
            f, Kb, bitspersymbol, K, channel, modulation, dimensionality,
            tot_constellation, N0, -long(666 + i)
        )  # run experiment with different seed to get different data and noise realizations
        tot_s = tot_s + s
        terr_s = terr_s + e
        terr_p = terr_p + (terr_s != 0)
        if ((i + 1) % 100 == 0):  # display progress
            print i + 1, terr_p, '%.2e' % ((1.0 * terr_p) /
                                           (i + 1)), tot_s, terr_s, '%.2e' % (
                                               (1.0 * terr_s) / tot_s)
    # estimate of the (short or symbol) error rate
    print rep, terr_p, '%.2e' % ((1.0 * terr_p) /
                                 (i + 1)), tot_s, terr_s, '%.2e' % (
                                     (1.0 * terr_s) / tot_s)
def main(args):
    nargs = len(args)
    if nargs == 3:
        fname_out = args[0]
        esn0_db = float(args[1])
        rep = int(args[2])
    else:
        sys.stderr.write("usage: test_turbo_equalization.py fsm_name_out Es/No_db  repetitions\n")
        sys.exit(1)

    # system parameters
    Kb = 64 * 16  # packet size in bits (multiple of 16)
    modulation = fsm_utils.pam4  # see fsm_utlis.py for available predefined modulations
    channel = fsm_utils.c_channel  # see fsm_utlis.py for available predefined test channels
    fo = trellis.fsm(fname_out)  # get the outer FSM specification from a file
    fi = trellis.fsm(len(modulation[1]), len(channel))  # generate the FSM automatically
    if fo.O() != fi.I():
        sys.stderr.write("Incompatible cardinality between outer and inner FSM.\n")
        sys.exit(1)
    bitspersymbol = int(round(math.log(fo.I()) / math.log(2)))  # bits per FSM input symbol
    K = Kb / bitspersymbol  # packet size in trellis steps
    print "size = ", K
    interleaver = trellis.interleaver(K, 666)  # construct a random interleaver
    tot_channel = fsm_utils.make_isi_lookup(
        modulation, channel, True
    )  # generate the lookup table (normalize energy to 1)
    dimensionality = tot_channel[0]
    tot_constellation = tot_channel[1]
    if len(tot_constellation) / dimensionality != fi.O():
        sys.stderr.write("Incompatible FSM output cardinality and lookup table size.\n")
        sys.exit(1)
    N0 = pow(10.0, -esn0_db / 10.0)
    # noise variance
    IT = 3  # number of turbo iterations

    tot_s = 0  # total number of transmitted shorts
    terr_s = 0  # total number of shorts in error
    terr_p = 0  # total number of packets in error

    for i in range(rep):
        (s, e) = run_test(
            fo, fi, interleaver, Kb, bitspersymbol, K, dimensionality, tot_constellation, 1, N0, IT, -long(666 + i)
        )  # run experiment with different seed to get different noise realizations
        print s
        tot_s = tot_s + s
        terr_s = terr_s + e
        terr_p = terr_p + (terr_s != 0)
        if (i + 1) % 10 == 0:  # display progress
            print i + 1, terr_p, "%.2e" % ((1.0 * terr_p) / (i + 1)), tot_s, terr_s, "%.2e" % ((1.0 * terr_s) / tot_s)
    # estimate of the (short or bit) error rate
    print rep, terr_p, "%.2e" % ((1.0 * terr_p) / (i + 1)), tot_s, terr_s, "%.2e" % ((1.0 * terr_s) / tot_s)
def main(args):
    nargs = len(args)
    if nargs == 2:
        esn0_db = float(args[0])
        rep = int(args[1])
    else:
        sys.stderr.write("usage: test_viterbi_equalization.py Es/No_db  repetitions\n")
        sys.exit(1)

    # system parameters
    Kb = 128 * 16  # packet size in bits (multiple of 16)
    modulation = fsm_utils.pam4  # see fsm_utlis.py for available predefined modulations
    channel = fsm_utils.c_channel  # see fsm_utlis.py for available predefined test channels
    f = trellis.fsm(len(modulation[1]), len(channel))  # generate the FSM automatically
    bitspersymbol = int(round(math.log(f.I()) / math.log(2)))  # bits per FSM input symbol
    K = Kb / bitspersymbol  # packet size in trellis steps

    tot_channel = fsm_utils.make_isi_lookup(
        modulation, channel, True
    )  # generate the lookup table (normalize energy to 1)
    dimensionality = tot_channel[0]
    tot_constellation = tot_channel[1]
    N0 = pow(10.0, -esn0_db / 10.0)
    # noise variance
    if len(tot_constellation) / dimensionality != f.O():
        sys.stderr.write("Incompatible FSM output cardinality and lookup table size.\n")
        sys.exit(1)

    tot_s = 0  # total number of transmitted shorts
    terr_s = 0  # total number of shorts in error
    terr_p = 0  # total number of packets in error

    for i in range(rep):
        (s, e) = run_test(
            f, Kb, bitspersymbol, K, dimensionality, tot_constellation, N0, -long(666 + i)
        )  # run experiment with different seed to get different noise realizations
        tot_s = tot_s + s
        terr_s = terr_s + e
        terr_p = terr_p + (terr_s != 0)
        if (i + 1) % 100 == 0:  # display progress
            print i + 1, terr_p, "%.2e" % ((1.0 * terr_p) / (i + 1)), tot_s, terr_s, "%.2e" % ((1.0 * terr_s) / tot_s)
    # estimate of the (short or bit) error rate
    print rep, terr_p, "%.2e" % ((1.0 * terr_p) / (i + 1)), tot_s, terr_s, "%.2e" % ((1.0 * terr_s) / tot_s)