Example #1
0
def test_1024_rate_1_code():
    # effectively a Monte-Carlo simulation for channel polarization.
    ntests = 10000
    n = 256
    k = n
    transition_prob = 0.11
    num_transitions = int(k * transition_prob)
    frozenbits = np.zeros(n - k)
    frozenbitposition = np.array((), dtype=int)
    encoder = PolarEncoder(n, k, frozenbitposition, frozenbits)
    decoder = PolarDecoder(n, k, frozenbitposition, frozenbits)

    channel_counter = np.zeros(k)
    possible_indices = np.arange(n, dtype=int)
    for i in range(ntests):
        bits = np.random.randint(2, size=k)
        tx = encoder.encode(bits)
        np.random.shuffle(possible_indices)
        tx[possible_indices[0:num_transitions]] = (tx[possible_indices[0:num_transitions]] + 1) % 2
        rx = tx
        recv = decoder.decode(rx)
        channel_counter += (bits == recv)

    print channel_counter
    print(np.min(channel_counter), np.max(channel_counter))

    np.save('channel_counter_' + str(ntests) + '.npy', channel_counter)
Example #2
0
def test_1024_rate_1_code():
    # effectively a Monte-Carlo simulation for channel polarization.
    ntests = 10000
    n = 256
    k = n
    transition_prob = 0.11
    num_transitions = int(k * transition_prob)
    frozenbits = np.zeros(n - k)
    frozenbitposition = np.array((), dtype=int)
    encoder = PolarEncoder(n, k, frozenbitposition, frozenbits)
    decoder = PolarDecoder(n, k, frozenbitposition, frozenbits)

    channel_counter = np.zeros(k)
    possible_indices = np.arange(n, dtype=int)
    for i in range(ntests):
        bits = np.random.randint(2, size=k)
        tx = encoder.encode(bits)
        np.random.shuffle(possible_indices)
        tx[possible_indices[0:num_transitions]] = (tx[possible_indices[0:num_transitions]] + 1) % 2
        rx = tx
        recv = decoder.decode(rx)
        channel_counter += (bits == recv)

    print channel_counter
    print(np.min(channel_counter), np.max(channel_counter))

    np.save('channel_counter_' + str(ntests) + '.npy', channel_counter)
Example #3
0
def test_systematic_decoder():
    ntests = 1000
    n = 16
    k = 8
    frozenbitposition = np.array((0, 1, 2, 3, 4, 5, 8, 9), dtype=int)
    encoder = PolarEncoder(n, k, frozenbitposition)
    decoder = PolarDecoder(n, k, frozenbitposition)
    for i in range(ntests):
        bits = np.random.randint(2, size=k)
        y = encoder.encode_systematic(bits)
        u_hat = decoder.decode_systematic(y)
        assert (bits == u_hat).all()
Example #4
0
def test_systematic_decoder():
    ntests = 1000
    n = 16
    k = 8
    frozenbitposition = np.array((0, 1, 2, 3, 4, 5, 8, 9), dtype=int)
    encoder = PolarEncoder(n, k, frozenbitposition)
    decoder = PolarDecoder(n, k, frozenbitposition)
    for i in range(ntests):
        bits = np.random.randint(2, size=k)
        y = encoder.encode_systematic(bits)
        u_hat = decoder.decode_systematic(y)
        assert (bits == u_hat).all()
Example #5
0
def systematic_encoder_decoder_chain_test():
    print('systematic encoder decoder chain test')
    block_size = int(2 ** 8)
    info_bit_size = block_size // 2
    ntests = 100
    frozenbitposition = cc.get_frozen_bit_indices_from_z_parameters(cc.bhattacharyya_bounds(0.0, block_size), block_size - info_bit_size)
    encoder = PolarEncoder(block_size, info_bit_size, frozenbitposition)
    decoder = PolarDecoder(block_size, info_bit_size, frozenbitposition)
    for i in range(ntests):
        bits = np.random.randint(2, size=info_bit_size)
        y = encoder.encode_systematic(bits)
        u_hat = decoder.decode_systematic(y)
        assert (bits == u_hat).all()
Example #6
0
def test_reverse_enc_dec():
    n = 16
    k = 8
    frozenbits = np.zeros(n - k)
    frozenbitposition = np.array((0, 1, 2, 3, 4, 5, 8, 9), dtype=int)
    bits = np.random.randint(2, size=k)
    encoder = PolarEncoder(n, k, frozenbitposition, frozenbits)
    decoder = PolarDecoder(n, k, frozenbitposition, frozenbits)
    encoded = encoder.encode(bits)
    print 'encoded:', encoded
    rx = decoder.decode(encoded)
    print 'bits:', bits
    print 'rx  :', rx
    print (bits == rx).all()
Example #7
0
def test_reverse_enc_dec():
    n = 16
    k = 8
    frozenbits = np.zeros(n - k)
    frozenbitposition = np.array((0, 1, 2, 3, 4, 5, 8, 9), dtype=int)
    bits = np.random.randint(2, size=k)
    encoder = PolarEncoder(n, k, frozenbitposition, frozenbits)
    decoder = PolarDecoder(n, k, frozenbitposition, frozenbits)
    encoded = encoder.encode(bits)
    print 'encoded:', encoded
    rx = decoder.decode(encoded)
    print 'bits:', bits
    print 'rx  :', rx
    print(bits == rx).all()
Example #8
0
def systematic_encoder_decoder_chain_test():
    print('systematic encoder decoder chain test')
    block_size = int(2**8)
    info_bit_size = block_size // 2
    ntests = 100
    frozenbitposition = cc.get_frozen_bit_indices_from_z_parameters(
        cc.bhattacharyya_bounds(0.0, block_size), block_size - info_bit_size)
    encoder = PolarEncoder(block_size, info_bit_size, frozenbitposition)
    decoder = PolarDecoder(block_size, info_bit_size, frozenbitposition)
    for i in range(ntests):
        bits = np.random.randint(2, size=info_bit_size)
        y = encoder.encode_systematic(bits)
        u_hat = decoder.decode_systematic(y)
        assert (bits == u_hat).all()
Example #9
0
def test_enc_dec_chain():
    ntests = 100
    n = 256
    k = n // 2
    frozenbits = np.zeros(n - k)
    frozenbitposition = get_frozen_bit_position()
    for i in range(ntests):
        bits = np.random.randint(2, size=k)
        encoder = PolarEncoder(n, k, frozenbitposition, frozenbits)
        decoder = PolarDecoder(n, k, frozenbitposition, frozenbits)
        encoded = encoder.encode(bits)
        rx = decoder.decode(encoded)
        if not is_equal(bits, rx):
            raise ValueError('Test #', i, 'failed, input and output differ', bits, '!=', rx)
            return
Example #10
0
def test_enc_dec_chain():
    ntests = 100
    n = 256
    k = n // 2
    frozenbits = np.zeros(n - k)
    frozenbitposition = get_frozen_bit_position()
    for i in range(ntests):
        bits = np.random.randint(2, size=k)
        encoder = PolarEncoder(n, k, frozenbitposition, frozenbits)
        decoder = PolarDecoder(n, k, frozenbitposition, frozenbits)
        encoded = encoder.encode(bits)
        rx = decoder.decode(encoded)
        if not is_equal(bits, rx):
            raise ValueError('Test #', i, 'failed, input and output differ', bits, '!=', rx)
            return
Example #11
0
def compare_decoder_impls():
    print '\nthis is decoder test'
    n = 8
    k = 4
    frozenbits = np.zeros(n - k)
    # frozenbitposition16 = np.array((0, 1, 2, 3, 4, 5, 8, 9), dtype=int)
    frozenbitposition = np.array((0, 1, 2, 4), dtype=int)
    bits = np.random.randint(2, size=k)
    print 'bits:', bits
    encoder = PolarEncoder(n, k, frozenbitposition, frozenbits)
    decoder = PolarDecoder(n, k, frozenbitposition, frozenbits)
    encoded = encoder.encode(bits)
    print 'encoded:', encoded
    rx_st = decoder._lr_sc_decoder(encoded)
    rx_eff = decoder._lr_sc_decoder_efficient(encoded)
    print 'standard :', rx_st
    print 'efficient:', rx_eff
    print (rx_st == rx_eff).all()
Example #12
0
def compare_decoder_impls():
    print '\nthis is decoder test'
    n = 8
    k = 4
    frozenbits = np.zeros(n - k)
    # frozenbitposition16 = np.array((0, 1, 2, 3, 4, 5, 8, 9), dtype=int)
    frozenbitposition = np.array((0, 1, 2, 4), dtype=int)
    bits = np.random.randint(2, size=k)
    print 'bits:', bits
    encoder = PolarEncoder(n, k, frozenbitposition, frozenbits)
    decoder = PolarDecoder(n, k, frozenbitposition, frozenbits)
    encoded = encoder.encode(bits)
    print 'encoded:', encoded
    rx_st = decoder._lr_sc_decoder(encoded)
    rx_eff = decoder._lr_sc_decoder_efficient(encoded)
    print 'standard :', rx_st
    print 'efficient:', rx_eff
    print(rx_st == rx_eff).all()
Example #13
0
def main():
    power = 3
    n = 2 ** power
    k = 4
    frozenbits = np.zeros(n - k, dtype=int)
    frozenbitposition = np.array((0, 1, 2, 4), dtype=int)
    frozenbitposition4 = np.array((0, 1), dtype=int)

    encoder = PolarEncoder(n, k, frozenbitposition, frozenbits)
    decoder = PolarDecoder(n, k, frozenbitposition, frozenbits)

    bits = np.ones(k, dtype=int)
    print "bits: ", bits
    evec = encoder.encode(bits)
    print "froz: ", encoder._insert_frozen_bits(bits)
    print "evec: ", evec

    evec[1] = 0
    deced = decoder._lr_sc_decoder(evec)
    print "SC decoded:", deced

    test_reverse_enc_dec()
    compare_decoder_impls()
Example #14
0
def main():
    power = 3
    n = 2**power
    k = 4
    frozenbits = np.zeros(n - k, dtype=int)
    frozenbitposition = np.array((0, 1, 2, 4), dtype=int)
    frozenbitposition4 = np.array((0, 1), dtype=int)

    encoder = PolarEncoder(n, k, frozenbitposition, frozenbits)
    decoder = PolarDecoder(n, k, frozenbitposition, frozenbits)

    bits = np.ones(k, dtype=int)
    print "bits: ", bits
    evec = encoder.encode(bits)
    print "froz: ", encoder._insert_frozen_bits(bits)
    print "evec: ", evec

    evec[1] = 0
    deced = decoder._lr_sc_decoder(evec)
    print 'SC decoded:', deced

    test_reverse_enc_dec()
    compare_decoder_impls()