Exemple #1
0
    def test_003_stream(self):
        print "test_003_stream"
        nframes = 5
        expo = 8
        block_size = 2 ** expo
        num_info_bits = 2 ** (expo - 1)
        max_list_size = 2 ** (expo - 2)
        num_frozen_bits = block_size - num_info_bits
        frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0)
        frozen_bit_values = np.array([0] * num_frozen_bits,)

        encoder = PolarEncoder(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values)

        ref = np.array([], dtype=int)
        data = np.array([], dtype=int)
        for i in range(nframes):
            b = np.random.randint(2, size=num_info_bits)
            d = encoder.encode(b)
            data = np.append(data, d)
            ref = np.append(ref, b)
        gr_data = 2.0 * data - 1.0

        polar_decoder = fec.polar_decoder_sc_list.make(max_list_size, block_size, num_info_bits, frozen_bit_positions, frozen_bit_values)
        src = blocks.vector_source_f(gr_data, False)
        dec_block = extended_decoder(polar_decoder, None)
        snk = blocks.vector_sink_b(1)

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

        res = np.array(snk.data()).astype(dtype=int)
        self.assertTupleEqual(tuple(res), tuple(ref))
Exemple #2
0
    def test_002_one_vector(self):
        print "test_002_one_vector"
        expo = 6
        block_size = 2 ** expo
        num_info_bits = 2 ** (expo - 1)
        max_list_size = 2 ** (expo - 2)
        num_frozen_bits = block_size - num_info_bits
        frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0)
        frozen_bit_values = np.array([0] * num_frozen_bits,)

        bits = np.random.randint(2, size=num_info_bits)
        encoder = PolarEncoder(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values)
        data = encoder.encode(bits)
        gr_data = 2.0 * data - 1.0

        polar_decoder = fec.polar_decoder_sc_list.make(max_list_size, block_size, num_info_bits, frozen_bit_positions, frozen_bit_values)
        src = blocks.vector_source_f(gr_data, False)
        dec_block = extended_decoder(polar_decoder, None)
        snk = blocks.vector_sink_b(1)

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

        res = np.array(snk.data()).astype(dtype=int)

        print("\ninput -> result -> bits")
        print(data)
        print(res)
        print(bits)

        self.assertTupleEqual(tuple(res), tuple(bits))
Exemple #3
0
 def generate_test_data(self, block_size, num_info_bits, frozen_bit_positions, frozen_bit_values, nframes, onlyones):
     encoder = PolarEncoder(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values)
     bits = np.array([], dtype=int)
     data = np.array([], dtype=int)
     for n in range(nframes):
         if onlyones:
             b = np.ones(num_info_bits, dtype=int)
         else:
             b = np.random.randint(2, size=num_info_bits)
         d = encoder.encode(b)
         bits = np.append(bits, b)
         data = np.append(data, d)
     gr_data = 2.0 * data - 1.0
     return bits, gr_data
    def get_test_data(self, block_size, num_info_bits, num_blocks, is_packed):
        # helper function to set up test data and together with encoder object.
        num_frozen_bits = block_size - num_info_bits
        frozen_bit_positions = cc.frozen_bit_positions(block_size, num_info_bits, 0.0)
        frozen_bit_values = np.array([0] * num_frozen_bits,)
        python_encoder = PolarEncoder(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values)

        data = np.array([], dtype=int)
        ref = np.array([], dtype=int)
        for i in range(num_blocks):
            d = np.random.randint(2, size=num_info_bits)
            data = np.append(data, d)
            ref = np.append(ref, python_encoder.encode(d))
        polar_encoder = fec.polar_encoder.make(block_size, num_info_bits, frozen_bit_positions, frozen_bit_values, is_packed)
        return data, ref, polar_encoder
Exemple #5
0
    def get_test_data(self, block_size, num_info_bits, num_blocks):
        # helper function to set up test data and together with encoder object.
        num_frozen_bits = block_size - num_info_bits
        frozen_bit_positions = cc.frozen_bit_positions(block_size,
                                                       num_info_bits, 0.0)
        frozen_bit_values = np.array([0] * num_frozen_bits, )
        python_encoder = PolarEncoder(block_size, num_info_bits,
                                      frozen_bit_positions, frozen_bit_values)

        data = np.array([], dtype=int)
        ref = np.array([], dtype=int)
        for i in range(num_blocks):
            d = np.random.randint(2, size=num_info_bits)
            data = np.append(data, d)
            ref = np.append(ref, python_encoder.encode_systematic(d))
        polar_encoder = fec.polar_encoder_systematic.make(
            block_size, num_info_bits, frozen_bit_positions)
        return data, ref, polar_encoder