コード例 #1
0
def qam64_map_demap_chain():
    constellation_order = 6
    snr_db = 20
    constellation, bits_rep = cstl.generate_gray_constellation(
        constellation_order)
    print(constellation)
    print(bits_rep)
    app_llrs = np.zeros(constellation_order)
    for i in range(2):
        for j in range(2):
            for k in range(2):
                for l in range(2):
                    for m in range(2):
                        for n in range(2):
                            bits = np.array((i, j, k, l, m, n))
                            print(bits)
                            s = map_to_constellation(bits, constellation)
                            print(s)
                            l_prob = calculate_log_probability_vector(
                                s, constellation, snr_db)
                            print(l_prob)
                            llrs = calculate_64qam_llrs_messages(
                                app_llrs, l_prob)
                            llrs = np.array(llrs)
                            print(llrs)
                            hat_bits = decide_bits(llrs)
                            print(hat_bits)
                            print(np.all(bits == hat_bits))
                            if not np.all(bits == hat_bits):
                                raise RuntimeError(
                                    '64QAM Mapping --> Demapping fails!')
コード例 #2
0
def qam16_map_demap_chain():
    constellation_order = 4
    snr_db = 20
    constellation, bits_rep = cstl.generate_gray_constellation(
        constellation_order)
    print(constellation)
    print(bits_rep)
    app_llrs = np.zeros(constellation_order)
    for i in range(2):
        for j in range(2):
            for k in range(2):
                for l in range(2):
                    bits = np.array((i, j, k, l))
                    # print(utils.pack_bits(bits, 4), bits)
                    app_llrs = 100. * (2. * bits - 1)
                    print(app_llrs)
                    s = map_to_constellation(bits, constellation)
                    print(s)
                    l_prob = calculate_log_probability_vector(
                        s, constellation, snr_db)
                    print(l_prob)
                    llrs = calculate_16qam_llrs_messages(app_llrs, l_prob)
                    # llrs = np.array(llrs)
                    print(llrs)
                    hat_bits = decide_bits(llrs)
                    print(hat_bits)
                    print(np.all(bits == hat_bits))
                    if not np.all(bits == hat_bits):
                        raise RuntimeError(
                            '16QAM Mapping --> Demapping fails!')
コード例 #3
0
    def verify_vector_snr(self, constellation_order, nbits):
        constellation, bits_rep = generate_gray_constellation(
            constellation_order)
        data = np.random.randint(0, 2,
                                 constellation_order * nbits).astype(np.uint8)
        symbols = map_to_constellation(data, constellation)

        snr = np.arange(35, dtype=np.float) + 1.
        snr_step = 2.5
        tags = []
        offsets = (0, 50, 400, 450, 800)
        last_offset = 0
        ref = np.array([], dtype=np.float32)
        for offset in offsets:
            valuevector = pmt.init_f32vector(snr.size, snr.tolist())
            t = gr.tag_utils.python_to_tag(
                (offset, pmt.string_to_symbol("snr"), valuevector))
            tags.append(t)

            syms = symbols[last_offset:offset]
            # print(syms.size)
            ref_ln_probs = calculate_symbol_log_probabilities(
                syms, constellation, snr - snr_step)
            refs = calculate_llrs(ref_ln_probs)
            ref = np.concatenate((ref, refs))
            last_offset = offset
            snr += snr_step

        syms = symbols[last_offset:]
        ref_ln_probs = calculate_symbol_log_probabilities(
            syms, constellation, snr - snr_step)
        refs = calculate_llrs(ref_ln_probs)
        ref = np.concatenate((ref, refs))
        ref *= .5

        # print(f'test: Order={constellation_order}, bits={nbits}/{data.size}, packed={is_packed}')

        mapper = symbolmapping.symbol_demapper_cf(constellation_order, "GRAY",
                                                  "snr")
        src = blocks.vector_source_c(symbols, False, 1, tags)
        snk = blocks.vector_sink_f()

        self.tb.connect(src, mapper, snk)
        self.tb.run()

        res = np.array(snk.data())
        if constellation_order > 3:
            self.assertFloatTuplesAlmostEqual(tuple(np.sign(res)),
                                              tuple(np.sign(ref)))
        else:
            # for i in range(ref.size - 10):
            #     if not np.abs(ref[i + 10] - res[i + 10]) < 1e-5:
            #         print(i, ref[i], res[i], np.abs(ref[i] - res[i]) < 1e-5)
            self.assertFloatTuplesAlmostEqual(tuple(res), tuple(ref), 5)
コード例 #4
0
def qpsk_map_demap_chain():
    constellation_order = 2
    snr_db = 20
    constellation, bits_rep = cstl.generate_gray_constellation(
        constellation_order)
    print(constellation)
    print(bits_rep)
    app_llrs = np.zeros(constellation_order)
    for i in range(2):
        for j in range(2):
            bits = np.array((i, j))
            print(bits)
            s = map_to_constellation(bits, constellation)
            print(s)
            l_prob = calculate_log_probability_vector(s, constellation, snr_db)
            print(l_prob)
            llr0, llr1 = calculate_qpsk_llrs_messages(app_llrs, l_prob)
            print(llr0, llr1)
            hat_bits = decide_bits((llr0, llr1))
            print(hat_bits)
            print(np.all(bits == hat_bits))
            if not np.all(bits == hat_bits):
                raise RuntimeError('QPSK Mapping --> Demapping fails!')
コード例 #5
0
def main():
    np.set_printoptions(precision=2)

    qpsk_map_demap_chain()
    qam16_map_demap_chain()
    qam64_map_demap_chain()

    try:
        calculate_llrs(np.array([
            [1, 4, 5, 6, 7, 8, 4, 3],
        ]))
    except NotImplementedError:
        pass
    # return
    rx = .6 + .7j
    constellation_order = 4
    snr_db = 20
    constellation, bits_rep = cstl.generate_gray_constellation(
        constellation_order)
    l_prob = calculate_log_probability_vector(rx, constellation, snr_db)
    # print(constellation)
    # print(bits_rep)
    # print(l_prob)
    llr0, llr1 = calculate_qpsk_log_probs_to_llrs(l_prob)
    calculate_qpsk_probs_to_llrs(np.exp(l_prob))
    # print(llr0)
    # print(llr1)

    bits = np.random.randint(0, 2, constellation_order * 300)
    symbols = map_to_constellation(bits, constellation)
    # print(symbols)
    # symbols += utils.generate_complex_noise_symbols(len(symbols), snr_db)
    log_probs = calculate_symbol_log_probabilities(symbols, constellation,
                                                   snr_db)

    calculate_16qam_llrs(log_probs)
コード例 #6
0
    def verify_constellation_unpacked(self, constellation_order, nbits,
                                      is_packed):
        constellation, bits_rep = generate_gray_constellation(
            constellation_order)

        data = np.random.randint(0, 2,
                                 constellation_order * nbits).astype(np.uint8)
        ref = map_to_constellation(data, constellation)

        if is_packed:
            data = np.packbits(data)

        # print(f'test: Order={constellation_order}, bits={nbits}/{data.size}, packed={is_packed}')

        mapper = symbolmapping.symbol_mapper_bc(constellation_order, "GRAY",
                                                is_packed)
        src = blocks.vector_source_b(data)
        snk = blocks.vector_sink_c()

        self.tb.connect(src, mapper, snk)
        self.tb.run()

        res = np.array(snk.data())
        self.assertComplexTuplesAlmostEqual(tuple(res), tuple(ref), 6)