Beispiel #1
0
    def test_050_weak_interferer(self):
        print("test_050_weak_interferer")

        Pi_dB = -3
        phi_u = 6.6
        sto_frac_u = 0.49
        sto_int_u = 48

        S = [0, 64, 32, 96, 0, 64, 24, 100] * 4
        x_i = lora.gen_syms(SF, S, R=R)[:int(N * R * 15.25)]
        n_pad = sto_int_u * R + int(sto_frac_u * R)
        x_u = np.concatenate([
            np.zeros(n_pad),
            lora.gen_preamble(SF, R=R, sto_frac=np.mod(sto_frac_u, 1.0 / R)),
            np.zeros(3 * N * R - n_pad)
        ])

        P_i = 10**(Pi_dB / 10.0)
        x = lora.add_cfo(SF, x_u, phi_u, R=R) + np.sqrt(P_i) * x_i
        y, detects = self._feed_detector(x)

        self.assertEqual(len(detects), 1)
        d = detects[0]

        cfo_int = np.round(phi_u).astype(int)
        residual_int = ((d.value['sto_int'] + d.value['cfo_int']) -
                        (sto_int_u + cfo_int) - N / 4) % N
        self.assertIn(residual_int, (N - 1, 0, 1))
        self.assertAlmostEqual(d.value['cfo_frac'], phi_u - cfo_int, places=1)
        self.assertAlmostEqual(d.value['sto_frac'], round_sto(sto_frac_u))
Beispiel #2
0
    def test_002_simple_preamble(self):
        print("test_002_simple_preamble")
        x = np.concatenate([lora.gen_preamble(SF, R=R), np.zeros(3 * N * R)])
        y, detects = self._feed_detector(x)

        self.assertEqual(len(detects), 1)
        d = detects[0]

        self.assertFloatTuplesAlmostEqual(x[0:N], y[BUFFER_LEN:BUFFER_LEN + N])
        self.assertEqual(d.offset, BUFFER_LEN)
        self.assertEqual(d.value['sto_int'], (BUFFER_LEN / R) % N)
        self.assertEqual(d.value['cfo_int'], 0)
        self.assertAlmostEqual(d.value['sto_frac'], 0)
        self.assertAlmostEqual(d.value['cfo_frac'], 0)
        self.assertAlmostEqual(d.value['power'], 1, places=6)
Beispiel #3
0
    def test_040_unit_power(self):
        print("test_040_unit_power")

        phi = 0.3
        P = 1
        x = np.concatenate([lora.gen_preamble(SF, R=R), np.zeros(3 * N * R)])
        x = lora.add_cfo(SF, x, phi, R=R)
        y, detects = self._feed_detector(x)

        self.assertEqual(len(detects), 1)
        d = detects[0]

        self.assertEqual(d.offset, BUFFER_LEN)
        self.assertAlmostEqual(d.value['cfo_frac'], phi)
        self.assertAlmostEqual(d.value['power'], P, places=6)
Beispiel #4
0
    def test_022_cfo_int_frac(self):
        print("test_022_cfo_int_frac")
        phi = -3.42
        x = np.concatenate([lora.gen_preamble(SF, R=R), np.zeros(3 * N * R)])
        x = lora.add_cfo(SF, x, phi, R=R)
        y, detects = self._feed_detector(x)

        self.assertEqual(len(detects), 1)
        d = detects[0]

        self.assertEqual(d.value['sto_int'], (BUFFER_LEN / R) % N)
        self.assertEqual(d.value['cfo_int'], -3)
        self.assertAlmostEqual(d.value['sto_frac'], 0)
        self.assertAlmostEqual(d.value['cfo_frac'], -0.42, places=2)
        self.assertAlmostEqual(d.value['power'], 1, places=1)
Beispiel #5
0
    def test_042_strong_power(self):
        print("test_042_strong_power")

        P_dB = 3
        phi = 0.3

        P = 10**(P_dB / 10.0)
        x = np.concatenate([lora.gen_preamble(SF, R=R), np.zeros(3 * N * R)])
        x = np.sqrt(P) * lora.add_cfo(SF, x, phi, R=R)
        y, detects = self._feed_detector(x)

        self.assertEqual(len(detects), 1)
        d = detects[0]

        self.assertEqual(d.offset, BUFFER_LEN)
        self.assertAlmostEqual(d.value['cfo_frac'], phi)
        self.assertAlmostEqual(d.value['power'], P, places=4)
Beispiel #6
0
    def test_013_sto_frac_high(self):
        print("test_013_sto_frac_high")

        sto_frac = 0.68
        x = np.concatenate([[0] * int(sto_frac * R),
                            lora.gen_preamble(SF,
                                              R=R,
                                              sto_frac=np.mod(
                                                  sto_frac, 1.0 / R)),
                            np.zeros(3 * N * R)])
        y, detects = self._feed_detector(x)

        self.assertEqual(len(detects), 1)
        d = detects[0]

        self.assertAlmostEqual(d.value['sto_frac'], round_sto(sto_frac))
        self.assertAlmostEqual(d.value['cfo_frac'], 0)
Beispiel #7
0
    def test_010_sto_int_intrasym(self):
        print("test_010_sto_int_intrasym")

        M = 5
        x = np.concatenate(
            [np.zeros(M * R),
             lora.gen_preamble(SF, R=R),
             np.zeros(3 * N * R)])
        y, detects = self._feed_detector(x)

        self.assertEqual(len(detects), 1)
        d = detects[0]

        k = BUFFER_LEN + M * R
        self.assertEqual(d.offset, k)
        self.assertEqual(d.value['sto_int'], (k / R) % N)
        self.assertEqual(d.value['cfo_int'], 0)
        self.assertAlmostEqual(d.value['sto_frac'], 0)
        self.assertAlmostEqual(d.value['cfo_frac'], 0)
Beispiel #8
0
    def test_014_cfo_int(self):
        print("test_014_cfo_int")

        L_CFO = 30.0

        x = np.concatenate([lora.gen_preamble(SF, R=R), np.zeros(3 * N * R)])

        x = lora.add_cfo(SF, x, L_CFO, R=R)
        y, detects = self._feed_detector(x)

        self.assertEqual(len(detects), 1)
        d = detects[0]

        k = BUFFER_LEN
        self.assertEqual(d.offset, k)
        self.assertEqual(d.value['sto_int'], (k / R) % N)
        self.assertEqual(d.value['cfo_int'], L_CFO)
        self.assertAlmostEqual(d.value['sto_frac'], 0)
        self.assertAlmostEqual(d.value['cfo_frac'], 0, places=5)
Beispiel #9
0
    def _test_cfo_sto(self, CFO, STO):
        CFO_int = np.round(CFO).astype(int)
        CFO_frac = CFO - CFO_int
        STO_int = np.floor(STO).astype(int)
        STO_frac = STO - STO_int

        x = np.concatenate([
            np.zeros(STO_int * R + int(STO_frac * R)),
            lora.gen_preamble(SF, R=R, sto_frac=np.mod(STO_frac, 1.0 / R)),
            np.zeros(3 * N * R)
        ])
        x = lora.add_cfo(SF, x, CFO, R=R)
        y, detects = self._feed_detector(x)

        self.assertEqual(len(detects), 1)
        d = detects[0]

        residual_int = ((d.value['sto_int'] + d.value['cfo_int']) -
                        (STO_int + CFO_int) - N / 4) % N
        self.assertIn(residual_int, (N - 1, 0, 1))
        self.assertAlmostEqual(d.value['cfo_frac'], CFO_frac, places=3)
        self.assertAlmostEqual(d.value['sto_frac'], round_sto(STO_frac))