def __init__(self, constellation, differential, data_length=None, src_data=None, freq_offset=True):
     """
     Args:
         constellation: a constellation object
         differential: whether differential encoding is used
         data_length: the number of bits of data to use
         src_data: a list of the bits to use
         freq_offset: whether to use a frequency offset in the channel
     """
     super(rec_test_tb, self).__init__()
     # Transmission Blocks
     if src_data is None:
         self.src_data = tuple([rndm.randint(0, 1) for i in range(0, data_length)])
     else:
         self.src_data = src_data
     packer = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
     src = blocks.vector_source_b(self.src_data)
     mod = generic_mod(constellation, differential=differential)
     # Channel
     if freq_offset:
         channel = channel_model(NOISE_VOLTAGE, FREQUENCY_OFFSET, TIMING_OFFSET)
     else:
         channel = channel_model(NOISE_VOLTAGE, 0, TIMING_OFFSET)
     # Receiver Blocks
     if freq_offset:
         demod = generic_demod(constellation, differential=differential, freq_bw=FREQ_BW, phase_bw=PHASE_BW)
     else:
         demod = generic_demod(constellation, differential=differential, freq_bw=0, phase_bw=0)
     self.dst = blocks.vector_sink_b()
     self.connect(src, packer, mod, channel, demod, self.dst)
示例#2
0
    def __init__(self, constellation, differential, rotation):
        if constellation.arity() > 256:
            # If this becomes limiting some of the blocks should be generalised so
            # that they can work with shorts and ints as well as chars.
            raise ValueError("Constellation cannot contain more than 256 points.")

        gr.hier_block2.__init__(
            self,
            "mod_demod",
            gr.io_signature(1, 1, gr.sizeof_char),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_char),
        )  # Output signature

        arity = constellation.arity()

        # TX
        self.constellation = constellation
        self.differential = differential
        self.blocks = [self]
        # We expect a stream of unpacked bits.
        # First step is to pack them.
        self.blocks.append(blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST))
        # Second step we unpack them such that we have k bits in each byte where
        # each constellation symbol hold k bits.
        self.blocks.append(blocks.packed_to_unpacked_bb(self.constellation.bits_per_symbol(), gr.GR_MSB_FIRST))
        # Apply any pre-differential coding
        # Gray-coding is done here if we're also using differential coding.
        if self.constellation.apply_pre_diff_code():
            self.blocks.append(digital.map_bb(self.constellation.pre_diff_code()))
        # Differential encoding.
        if self.differential:
            self.blocks.append(digital.diff_encoder_bb(arity))
        # Convert to constellation symbols.
        self.blocks.append(
            digital.chunks_to_symbols_bc(self.constellation.points(), self.constellation.dimensionality())
        )
        # CHANNEL
        # Channel just consists of a rotation to check differential coding.
        if rotation is not None:
            self.blocks.append(blocks.multiply_const_cc(rotation))

        # RX
        # Convert the constellation symbols back to binary values.
        self.blocks.append(digital.constellation_decoder_cb(self.constellation.base()))
        # Differential decoding.
        if self.differential:
            self.blocks.append(digital.diff_decoder_bb(arity))
        # Decode any pre-differential coding.
        if self.constellation.apply_pre_diff_code():
            self.blocks.append(digital.map_bb(mod_codes.invert_code(self.constellation.pre_diff_code())))
        # unpack the k bit vector into a stream of bits
        self.blocks.append(blocks.unpack_k_bits_bb(self.constellation.bits_per_symbol()))
        # connect to block output
        check_index = len(self.blocks)
        self.blocks = self.blocks[:check_index]
        self.blocks.append(self)

        self.connect(*self.blocks)
示例#3
0
    def test_006(self):
        src_data = (0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1, 0)
        expected_results = (0x82, 0x5a)
        src = gr.vector_source_b(src_data, False)
        op = blocks.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST)
        dst = gr.vector_sink_b()

        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()

        self.assertEqual(expected_results, dst.data())
    def test_006(self):
        src_data = (0,1,0,0,0,0,0,1,0,1,0,1,1,0,1,0)
        expected_results = (0x82, 0x5a)
        src = blocks.vector_source_b(src_data, False)
        op = blocks.unpacked_to_packed_bb(1, gr.GR_LSB_FIRST)
        dst = blocks.vector_sink_b()

        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()

        self.assertEqual(expected_results, dst.data())
示例#5
0
    def test_008(self):
        src_data = (0, 4, 2, 0, 0)
        expected_results = (0x11, )
        src = blocks.vector_source_b(src_data, False)
        op = blocks.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST)
        dst = blocks.vector_sink_b()

        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()

        self.assertEqual(expected_results, dst.data())
    def test_008(self):
        src_data = (0, 4, 2,0,0)
        expected_results = (0x11,)
        src = gr.vector_source_b(src_data,False)
        op = blocks.unpacked_to_packed_bb(3, gr.GR_MSB_FIRST)
        dst = gr.vector_sink_b()

        self.tb.connect(src, op)
        self.tb.connect(op, dst)
        self.tb.run()

        self.assertEqual(expected_results, dst.data())
示例#7
0
    def test_011(self):
        random.seed(0)
        src_data = []
        for i in xrange(56):
            src_data.append((random.randint(0, 255)))
        src_data = tuple(src_data)
        expected_results = src_data
        src = gr.vector_source_b(tuple(src_data), False)
        op1 = blocks.packed_to_unpacked_bb(7, gr.GR_LSB_FIRST)
        op2 = blocks.unpacked_to_packed_bb(7, gr.GR_LSB_FIRST)
        dst = gr.vector_sink_b()

        self.tb.connect(src, op1, op2)
        self.tb.connect(op2, dst)
        self.tb.run()

        self.assertEqual(expected_results[0:201], dst.data())
    def test_011(self):
        random.seed(0)
        src_data = []
        for i in xrange(56):
            src_data.append((random.randint(0,255)))
        src_data = tuple(src_data)
        expected_results = src_data
        src = blocks.vector_source_b(tuple(src_data),False)
        op1 = blocks.packed_to_unpacked_bb(7, gr.GR_LSB_FIRST)
        op2 = blocks.unpacked_to_packed_bb(7, gr.GR_LSB_FIRST)
        dst = blocks.vector_sink_b()

        self.tb.connect(src, op1, op2)
        self.tb.connect(op2, dst)
        self.tb.run()

        self.assertEqual(expected_results[0:201], dst.data())
示例#9
0
 def __init__(self,
              constellation,
              differential,
              data_length=None,
              src_data=None,
              freq_offset=True):
     """
     Args:
         constellation: a constellation object
         differential: whether differential encoding is used
         data_length: the number of bits of data to use
         src_data: a list of the bits to use
         freq_offset: whether to use a frequency offset in the channel
     """
     super(rec_test_tb, self).__init__()
     # Transmission Blocks
     if src_data is None:
         self.src_data = tuple(
             [rndm.randint(0, 1) for i in range(0, data_length)])
     else:
         self.src_data = src_data
     packer = blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST)
     src = blocks.vector_source_b(self.src_data)
     mod = generic_mod(constellation, differential=differential)
     # Channel
     if freq_offset:
         channel = channel_model(NOISE_VOLTAGE, FREQUENCY_OFFSET,
                                 TIMING_OFFSET)
     else:
         channel = channel_model(NOISE_VOLTAGE, 0, TIMING_OFFSET)
     # Receiver Blocks
     if freq_offset:
         demod = generic_demod(constellation,
                               differential=differential,
                               freq_bw=FREQ_BW,
                               phase_bw=PHASE_BW)
     else:
         demod = generic_demod(constellation,
                               differential=differential,
                               freq_bw=0,
                               phase_bw=0)
     self.dst = blocks.vector_sink_b()
     self.connect(src, packer, mod, channel, demod, self.dst)
示例#10
0
    def __init__(self, constellation, differential, rotation):
        if constellation.arity() > 256:
            # If this becomes limiting some of the blocks should be generalised so
            # that they can work with shorts and ints as well as chars.
            raise ValueError(
                "Constellation cannot contain more than 256 points.")

        gr.hier_block2.__init__(
            self,
            "mod_demod",
            gr.io_signature(1, 1, gr.sizeof_char),  # Input signature
            gr.io_signature(1, 1, gr.sizeof_char))  # Output signature

        arity = constellation.arity()

        # TX
        self.constellation = constellation
        self.differential = differential
        self.blocks = [self]
        # We expect a stream of unpacked bits.
        # First step is to pack them.
        self.blocks.append(blocks.unpacked_to_packed_bb(1, gr.GR_MSB_FIRST))
        # Second step we unpack them such that we have k bits in each byte where
        # each constellation symbol hold k bits.
        self.blocks.append(
            blocks.packed_to_unpacked_bb(self.constellation.bits_per_symbol(),
                                         gr.GR_MSB_FIRST))
        # Apply any pre-differential coding
        # Gray-coding is done here if we're also using differential coding.
        if self.constellation.apply_pre_diff_code():
            self.blocks.append(
                digital.map_bb(self.constellation.pre_diff_code()))
        # Differential encoding.
        if self.differential:
            self.blocks.append(digital.diff_encoder_bb(arity))
        # Convert to constellation symbols.
        self.blocks.append(
            digital.chunks_to_symbols_bc(self.constellation.points(),
                                         self.constellation.dimensionality()))
        # CHANNEL
        # Channel just consists of a rotation to check differential coding.
        if rotation is not None:
            self.blocks.append(blocks.multiply_const_cc(rotation))

        # RX
        # Convert the constellation symbols back to binary values.
        self.blocks.append(
            digital.constellation_decoder_cb(self.constellation.base()))
        # Differential decoding.
        if self.differential:
            self.blocks.append(digital.diff_decoder_bb(arity))
        # Decode any pre-differential coding.
        if self.constellation.apply_pre_diff_code():
            self.blocks.append(
                digital.map_bb(
                    mod_codes.invert_code(self.constellation.pre_diff_code())))
        # unpack the k bit vector into a stream of bits
        self.blocks.append(
            blocks.unpack_k_bits_bb(self.constellation.bits_per_symbol()))
        # connect to block output
        check_index = len(self.blocks)
        self.blocks = self.blocks[:check_index]
        self.blocks.append(self)

        self.connect(*self.blocks)