def test_extended_pack_data(self):
        # test if extended encoder gets correct values for input and output conversion.
        n_frames = 10
        frame_size = 32

        data = np.random.randint(0, 2, n_frames * frame_size)
        packed_data = np.packbits(data)

        tb = gr.top_block()

        src = blocks.vector_source_b(data)
        snk0 = blocks.vector_sink_b(1)
        snk1 = blocks.vector_sink_b(1)
        snk2 = blocks.vector_sink_b(1)
        snk3 = blocks.vector_sink_b(1)

        packer = blocks.pack_k_bits_bb(8)
        tb.connect(src, packer, snk0)

        enc_unpacked = fec.dummy_encoder_make(frame_size, False, False)
        ext_enc_unp = extended_encoder(enc_unpacked,
                                       threading='none',
                                       puncpat='11')
        tb.connect(src, ext_enc_unp, snk1)

        enc_pack = fec.dummy_encoder_make(frame_size // 8, True, False)
        ext_enc_pack = extended_encoder(enc_pack,
                                        threading='none',
                                        puncpat='11')
        tb.connect(src, ext_enc_pack, snk2)

        enc_packed_bits = fec.dummy_encoder_make(frame_size // 8, False, True)
        ext_enc_packed_bits = extended_encoder(enc_packed_bits,
                                               threading='none',
                                               puncpat='11')
        tb.connect(packer, ext_enc_packed_bits, snk3)

        tb.run()

        r0 = snk0.data()
        r1 = snk1.data()
        r2 = snk2.data()
        r3 = snk3.data()

        data = tuple(data)
        packed_data = tuple(packed_data)
        self.assertTupleEqual(packed_data, r0)
        self.assertTupleEqual(data, r1)
        self.assertTupleEqual(packed_data, r2)
        self.assertTupleEqual(data, r3)
Beispiel #2
0
    def __init__(self, data_size, enc, dec, threading):
        gr.top_block.__init__(self, "_qa_helper")

        self.puncpat = puncpat = '11'

        self.enc = enc
        self.dec = dec
        self.data_size = data_size
        self.threading = threading

        self.ext_encoder = extended_encoder(enc,
                                            threading=self.threading,
                                            puncpat=self.puncpat)
        self.ext_decoder = extended_decoder(dec,
                                            threading=self.threading,
                                            ann=None,
                                            puncpat=self.puncpat,
                                            integration_period=10000)

        self.src = blocks.vector_source_b(
            data_size * [0, 1, 2, 3, 5, 7, 9, 13, 15, 25, 31, 45, 63, 95, 127],
            False)
        self.unpack = blocks.unpack_k_bits_bb(8)
        self.map = map_bb([-1, 1])
        self.to_float = blocks.char_to_float(1)
        self.snk_input = blocks.vector_sink_b()
        self.snk_output = blocks.vector_sink_b()

        self.connect(self.src, self.unpack, self.ext_encoder)
        self.connect(self.ext_encoder, self.map, self.to_float)
        self.connect(self.to_float, self.ext_decoder)
        self.connect(self.unpack, self.snk_input)
        self.connect(self.ext_decoder, self.snk_output)
Beispiel #3
0
    def __init__(self, data_size, enc, dec, threading):
        gr.top_block.__init__(self, "_qa_helper")

        self.puncpat = puncpat = '11'

        self.enc = enc
        self.dec = dec
        self.data_size = data_size
        self.threading = threading

        self.ext_encoder = extended_encoder(enc, threading=self.threading, puncpat=self.puncpat)
        self.ext_decoder= extended_decoder(dec, threading=self.threading, ann=None,
                                           puncpat=self.puncpat, integration_period=10000)

        self.src = blocks.vector_source_b(data_size*[0, 1, 2, 3, 5, 7, 9, 13, 15, 25, 31, 45, 63, 95, 127], False)
        self.unpack = blocks.unpack_k_bits_bb(8)
        self.map = map_bb([-1, 1])
        self.to_float = blocks.char_to_float(1)
        self.snk_input = blocks.vector_sink_b()
        self.snk_output = blocks.vector_sink_b()

        self.connect(self.src, self.unpack, self.ext_encoder)
        self.connect(self.ext_encoder, self.map, self.to_float)
        self.connect(self.to_float, self.ext_decoder)
        self.connect(self.unpack, self.snk_input)
        self.connect(self.ext_decoder, self.snk_output)
Beispiel #4
0
    def test_parallelism1_05(self):
        frame_size = 30
        dims = 5
        enc = map((lambda a: fec.dummy_encoder_make(frame_size*8)), range(0,dims))
        #dec = map((lambda a: fec.dummy_decoder.make(frame_size*8)), range(0,dims))
        threading = 'capillary'

        self.assertRaises(AttributeError, lambda: extended_encoder(enc, threading=threading, puncpat="11"))
    def test_parallelism1_05(self):
        frame_size = 30
        dims = 5
        enc = map((lambda a: fec.dummy_encoder_make(frame_size*8)), range(0,dims))
        #dec = map((lambda a: fec.dummy_decoder.make(frame_size*8)), range(0,dims))
        threading = 'capillary'

        self.assertRaises(AttributeError, lambda: extended_encoder(enc, threading=threading, puncpat="11"))
Beispiel #6
0
    def test_extended_pack_data(self):
        # test if extended encoder gets correct values for input and output conversion.
        n_frames = 10
        frame_size = 32

        data = np.random.randint(0, 2, n_frames * frame_size)
        packed_data = np.packbits(data)

        tb = gr.top_block()

        src = blocks.vector_source_b(data)
        snk0 = blocks.vector_sink_b(1)
        snk1 = blocks.vector_sink_b(1)
        snk2 = blocks.vector_sink_b(1)
        snk3 = blocks.vector_sink_b(1)

        packer = blocks.pack_k_bits_bb(8)
        tb.connect(src, packer, snk0)

        enc_unpacked = fec.dummy_encoder_make(frame_size, False, False)
        ext_enc_unp = extended_encoder(enc_unpacked, threading='none', puncpat='11')
        tb.connect(src, ext_enc_unp, snk1)

        enc_pack = fec.dummy_encoder_make(frame_size // 8, True, False)
        ext_enc_pack = extended_encoder(enc_pack, threading='none', puncpat='11')
        tb.connect(src, ext_enc_pack, snk2)

        enc_packed_bits = fec.dummy_encoder_make(frame_size // 8, False, True)
        ext_enc_packed_bits = extended_encoder(enc_packed_bits, threading='none', puncpat='11')
        tb.connect(packer, ext_enc_packed_bits, snk3)

        tb.run()

        r0 = snk0.data()
        r1 = snk1.data()
        r2 = snk2.data()
        r3 = snk3.data()

        data = tuple(data)
        packed_data = tuple(packed_data)
        self.assertTupleEqual(packed_data, r0)
        self.assertTupleEqual(data, r1)
        self.assertTupleEqual(packed_data, r2)
        self.assertTupleEqual(data, r3)
Beispiel #7
0
    def __init__(self,
                 generic_encoder=0,
                 generic_decoder=0,
                 esno=0,
                 samp_rate=3200000,
                 threading="capillary",
                 puncpat='11',
                 seed=0):
        gr.hier_block2.__init__(self, "fec_test",
                                gr.io_signature(1, 1, gr.sizeof_char * 1),
                                gr.io_signature(2, 2, gr.sizeof_char * 1))

        self.generic_encoder = generic_encoder
        self.generic_decoder = generic_decoder
        self.esno = esno
        self.samp_rate = samp_rate
        self.threading = threading
        self.puncpat = puncpat

        self.map_bb = digital.map_bb(([-1, 1]))
        self.b2f = blocks.char_to_float(1, 1)

        self.unpack8 = blocks.unpack_k_bits_bb(8)
        self.pack8 = blocks.pack_k_bits_bb(8)

        self.encoder = extended_encoder(encoder_obj_list=generic_encoder,
                                        threading=threading,
                                        puncpat=puncpat)

        self.decoder = extended_decoder(decoder_obj_list=generic_decoder,
                                        threading=threading,
                                        ann=None,
                                        puncpat=puncpat,
                                        integration_period=10000,
                                        rotator=None)

        noise = math.sqrt((10.0**(-esno / 10.0)) / 2.0)
        #self.fastnoise = analog.fastnoise_source_f(analog.GR_GAUSSIAN, noise, seed, 8192)
        self.fastnoise = analog.noise_source_f(analog.GR_GAUSSIAN, noise, seed)
        self.addnoise = blocks.add_ff(1)

        # Send packed input directly to the second output
        self.copy_packed = blocks.copy(gr.sizeof_char)
        self.connect(self, self.copy_packed)
        self.connect(self.copy_packed, (self, 1))

        # Unpack inputl encode, convert to +/-1, add noise, decode, repack
        self.connect(self, self.unpack8)
        self.connect(self.unpack8, self.encoder)
        self.connect(self.encoder, self.map_bb)
        self.connect(self.map_bb, self.b2f)
        self.connect(self.b2f, (self.addnoise, 0))
        self.connect(self.fastnoise, (self.addnoise, 1))
        self.connect(self.addnoise, self.decoder)
        self.connect(self.decoder, self.pack8)
        self.connect(self.pack8, (self, 0))
Beispiel #8
0
    def test_parallelism2_00(self):
        filename = LDPC_ALIST_DIR + "n_0100_k_0027_gap_04.alist"
        gap = 4
        dims = 5
        LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap)
        k = LDPC_matrix_object.k()
        dims1 = 16
        dims2 = 16
        enc = map((lambda b: map((lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)),
                                 range(0,dims1))), range(0,dims2))
        threading = 'capillary'

        self.assertRaises(AttributeError, lambda: extended_encoder(enc, threading=threading, puncpat="11"))
    def test_002_work_function_packed(self):
        block_size = 256
        num_info_bits = block_size // 2

        data, ref, polar_encoder = self.get_test_data(block_size, num_info_bits, 1)
        src = blocks.vector_source_b(data, False)
        enc_block = extended_encoder(polar_encoder, None, '11')
        snk = blocks.vector_sink_b(1)

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

        res = np.array(snk.data()).astype(dtype=int)
        self.assertTupleEqual(tuple(res), tuple(ref))
Beispiel #10
0
    def __init__(self, generic_encoder=0, generic_decoder=0, esno=0,
                 samp_rate=3200000, threading="capillary", puncpat='11',
                 seed=0):
        gr.hier_block2.__init__(self, "fec_test",
                                gr.io_signature(1, 1, gr.sizeof_char*1),
                                gr.io_signature(2, 2, gr.sizeof_char*1))

        self.generic_encoder = generic_encoder
        self.generic_decoder = generic_decoder
        self.esno = esno
        self.samp_rate = samp_rate
        self.threading = threading
        self.puncpat = puncpat

        self.map_bb = digital.map_bb(([-1, 1]))
        self.b2f = blocks.char_to_float(1, 1)

        self.unpack8 = blocks.unpack_k_bits_bb(8)
        self.pack8 = blocks.pack_k_bits_bb(8)

        self.encoder = extended_encoder(encoder_obj_list=generic_encoder,
                                        threading=threading,
                                        puncpat=puncpat)

        self.decoder = extended_decoder(decoder_obj_list=generic_decoder,
                                        threading=threading,
                                        ann=None, puncpat=puncpat,
                                        integration_period=10000, rotator=None)

        noise = math.sqrt((10.0**(-esno/10.0))/2.0)
        #self.fastnoise = analog.fastnoise_source_f(analog.GR_GAUSSIAN, noise, seed, 8192)
        self.fastnoise = analog.noise_source_f(analog.GR_GAUSSIAN, noise, seed)
        self.addnoise = blocks.add_ff(1)

        # Send packed input directly to the second output
        self.copy_packed = blocks.copy(gr.sizeof_char)
        self.connect(self, self.copy_packed)
        self.connect(self.copy_packed, (self, 1))

        # Unpack inputl encode, convert to +/-1, add noise, decode, repack
        self.connect(self, self.unpack8)
        self.connect(self.unpack8, self.encoder)
        self.connect(self.encoder, self.map_bb)
        self.connect(self.map_bb, self.b2f)
        self.connect(self.b2f, (self.addnoise, 0))
        self.connect(self.fastnoise, (self.addnoise,1))
        self.connect(self.addnoise, self.decoder)
        self.connect(self.decoder, self.pack8)
        self.connect(self.pack8, (self, 0))
    def test_004_big_input(self):
        num_blocks = 30
        block_size = 1024
        num_info_bits = block_size // 8

        data, ref, polar_encoder = self.get_test_data(block_size, num_info_bits, num_blocks)
        src = blocks.vector_source_b(data, False)
        enc_block = extended_encoder(polar_encoder, None, '11')
        snk = blocks.vector_sink_b(1)

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

        res = np.array(snk.data()).astype(dtype=int)
        self.assertTupleEqual(tuple(res), tuple(ref))
Beispiel #12
0
    def test_002_work_function_packed(self):
        block_size = 256
        num_info_bits = block_size // 2

        data, ref, polar_encoder = self.get_test_data(block_size,
                                                      num_info_bits, 1)
        src = blocks.vector_source_b(data, False)
        enc_block = extended_encoder(polar_encoder, None, '11')
        snk = blocks.vector_sink_b(1)

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

        res = np.array(snk.data()).astype(dtype=int)
        self.assertTupleEqual(tuple(res), tuple(ref))
Beispiel #13
0
    def test_parallelism2_00(self):
        filename = LDPC_ALIST_DIR + "n_0100_k_0027_gap_04.alist"
        gap = 4
        dims = 5
        LDPC_matrix_object = fec.ldpc_H_matrix(filename, gap)
        k = LDPC_matrix_object.k()
        dims1 = 16
        dims2 = 16
        enc = map((lambda b: map(
            (lambda a: fec.ldpc_par_mtrx_encoder.make_H(LDPC_matrix_object)),
            range(0, dims1))), range(0, dims2))
        threading = 'capillary'

        self.assertRaises(
            AttributeError,
            lambda: extended_encoder(enc, threading=threading, puncpat="11"))
Beispiel #14
0
    def test_004_big_input(self):
        num_blocks = 30
        block_size = 1024
        num_info_bits = block_size // 8

        data, ref, polar_encoder = self.get_test_data(block_size,
                                                      num_info_bits,
                                                      num_blocks)
        src = blocks.vector_source_b(data, False)
        enc_block = extended_encoder(polar_encoder, None, '11')
        snk = blocks.vector_sink_b(1)

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

        res = np.array(snk.data()).astype(dtype=int)
        self.assertTupleEqual(tuple(res), tuple(ref))
Beispiel #15
0
    def test_parallelism1_05(self):
        filename = LDPC_ALIST_DIR + "n_0100_k_0027_gap_04.alist"
        gap = 4
        dims = 5

        enc = []
        for n in range(0,dims):
            H = fec.ldpc_H_matrix(filename, gap)
            enc.append(fec.ldpc_par_mtrx_encoder.make_H(H))

        dec = []
        for n in range(0,dims):
            H = fec.ldpc_H_matrix(filename, gap)
            dec.append(fec.ldpc_bit_flip_decoder.make(H.get_base_sptr()))

        k = H.k()
        threading = 'capillary'
        self.assertRaises(AttributeError, lambda: extended_encoder(enc, threading=threading, puncpat="11"))
Beispiel #16
0
    def test_parallelism1_05(self):
        filename = LDPC_ALIST_DIR + "n_0100_k_0027_gap_04.alist"
        gap = 4
        dims = 5

        enc = []
        for n in range(0, dims):
            H = fec.ldpc_H_matrix(filename, gap)
            enc.append(fec.ldpc_par_mtrx_encoder.make_H(H))

        dec = []
        for n in range(0, dims):
            H = fec.ldpc_H_matrix(filename, gap)
            dec.append(fec.ldpc_bit_flip_decoder.make(H.get_base_sptr()))

        k = H.k()
        threading = 'capillary'
        self.assertRaises(
            AttributeError,
            lambda: extended_encoder(enc, threading=threading, puncpat="11"))