Esempio n. 1
0
 def test_scrambler_descrambler_003(self):
     src_data = np.random.randint(0, 2, 1000, dtype=np.int8)
     src = blocks.vector_source_b(src_data, False)
     # this is the product of the other two
     scrambler = digital.scrambler_bb(*lfsr_args(1, 12, 10, 3, 2, 0))
     descrambler1 = digital.descrambler_bb(*lfsr_args(1, 5, 3, 0))
     descrambler2 = digital.descrambler_bb(*lfsr_args(1, 7, 2, 0))
     dst = blocks.vector_sink_b()
     self.tb.connect(src, scrambler, descrambler1, descrambler2, dst)
     self.tb.run()
     # skip garbage during synchronization
     self.assertTrue(np.all(src_data[:-12] == dst.data()[12:]))
Esempio n. 2
0
 def test_scrambler_descrambler_001(self):
     src_data = np.random.randint(0, 2, 500, dtype=np.int8)
     src = blocks.vector_source_b(src_data, False)
     scrambler = digital.scrambler_bb(*lfsr_args(0b1, 7, 2,
                                                 0))  # p(x) = x^7 + x^2 + 1
     # we can use any seed here, it is descrambling.
     descrambler = digital.descrambler_bb(*lfsr_args(0b111, 7, 2, 0))
     m_tap = blocks.vector_sink_b()
     dst = blocks.vector_sink_b()
     self.tb.connect(src, scrambler, descrambler, dst)
     self.tb.connect(scrambler, m_tap)
     self.tb.run()
     # skip garbage during synchronization
     self.assertEqual(src_data[:-7].tolist(), dst.data()[7:])
     self.assertEqual(
         tuple(np.convolve(m_tap.data(), [1, 0, 0, 0, 0, 1, 0, 1]) %
               2)[7:-10], tuple(src_data[:-10]))  # manual descrambling test
Esempio n. 3
0
 def test_lfsr_002(self):
     _a = lfsr_args(1, 51, 3, 0)
     l = digital.lfsr(*_a)
     seq = [l.next_bit() for _ in range(2**10)]
     reg = np.zeros(52, np.int8)
     reg[::-1][(51, 3, 0), ] = 1
     res = (np.convolve(seq, reg) % 2)
     self.assertTrue(sum(res[52:-52]) == 0, "LRS not generated properly")
Esempio n. 4
0
 def test_additive_scrambler_001(self):
     _a = lfsr_args(1, 51, 3, 0)  # i p(x) = x^51+x^3+1, seed 0x1
     src_data = np.random.randint(0, 2, 1000, dtype=np.int8).tolist()
     src = blocks.vector_source_b(src_data, False)
     scrambler = digital.additive_scrambler_bb(*_a)
     descrambler = digital.additive_scrambler_bb(*_a)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, scrambler, descrambler, dst)
     self.tb.run()
     self.assertEqual(tuple(src_data), tuple(dst.data()))
Esempio n. 5
0
 def test_additive_scrambler_002(self):
     _a = lfsr_args(1, 51, 3, 0)  # i p(x) = x^51+x^3+1, seed 0x1
     src_data = [
         1,
     ] * 1000
     src = blocks.vector_source_b(src_data, False)
     scrambler = digital.additive_scrambler_bb(*_a)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, scrambler, dst)
     self.tb.run()
     reg = np.zeros(52, np.int8)
     reg[::-1][(51, 3, 0), ] = 1
     res = (np.convolve(dst.data(), reg) % 2)[52:-52]
     self.assertEqual(len(res), sum(res))  # when convolved with mask,
Esempio n. 6
0
    def test_lfsr_002(self):
        l = digital.lfsr(*lfsr_args(0b1, 5, 3, 0))
        result_data = [l.next_bit() for _ in range(2 * (2**5 - 1))]

        expected_result = [
            1, 0, 0, 0, 0, 1, 0, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 0, 1, 1, 1, 1,
            1, 0, 0, 1, 1, 0, 1, 0, 0
        ] * 2
        self.assertEqual(expected_result, result_data)

        seq1 = [l.next_bit() for _ in range(2**5 - 1)]
        seq2 = [l.next_bit() for _ in range(2**5 - 1)]
        self.assertEqual(seq1, seq2)

        res = (np.convolve(seq1, [1, 0, 1, 0, 0, 1]) % 2)
        self.assertTrue(sum(res[5:-5]) == 0, "LRS not generated properly")
Esempio n. 7
0
 def test_scrambler_descrambler_002(self):
     _a = lfsr_args(0b1, 51, 6, 0)  # p(x) = x^51+x^6+1
     src_data = np.random.randint(0, 2, 1000, dtype=np.int8)
     src = blocks.vector_source_b(src_data, False)
     scrambler = digital.scrambler_bb(*_a)
     m_tap = blocks.vector_sink_b()
     descrambler = digital.descrambler_bb(*_a)
     dst = blocks.vector_sink_b()
     self.tb.connect(src, scrambler, descrambler, dst)
     self.tb.connect(scrambler, m_tap)
     self.tb.run()
     # skip garbage during synchronization
     self.assertTrue(np.all(src_data[:-51] == dst.data()[51:]))
     reg = np.zeros(52, np.int8)
     reg[::-1][(51, 6, 0), ] = 1
     self.assertTrue(
         np.all(
             np.convolve(m_tap.data(), reg)[51:-60] %
             2 == src_data[:-60]))  # manual descrambling test