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))
def system_mu(self, STO, CFO): print "test_system_mu ", STO, CFO self.maxDiff = None P1_dB = -12 #too high power leads to false detection P2_dB = -9 tau = int(15 * R * N + STO * R) S1 = (5, 10, 20, 30, 40, 50, 60, 70) * 3 S2 = (42, 101, 89, 15, 127, 0, 74, 94) * 3 p1 = lora.gen_packet(SF, S1, R=R) p2 = lora.gen_packet(SF, S2, R=R) x1 = np.sqrt(10**(P1_dB / 10.0)) * np.concatenate( [np.zeros(0), p1, np.zeros(tau)]) x2 = np.sqrt(10**(P2_dB / 10.0)) * np.concatenate( [np.zeros(tau), p2, np.zeros(0)]) x2 = lora.add_cfo(SF, x2, CFO, R=R) x = np.concatenate([x1 + x2, np.zeros(20 * N * R)]) S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1)) self.assertEqual(S1, S1_out) self.assertEqual(S2, S2_out)
def test_043_strong_source(self): print("test_043_strong_source") P_dB = 9 phi = 0.3 P = 10**(P_dB / 10.0) n = np.tile(np.arange(0, N * R), 14) x = np.exp(1j * 2 * np.pi * n / (N * R)) x = np.sqrt(P) * lora.add_cfo(SF, x, phi, R=R) y, detects = self._feed_detector(x) self.assertEqual(len(detects), 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)
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)
def test_002_system_su_cfo(self): print("test_002_system_su_cfo") R = 8 S1 = (0, 10, 20, 30, 40, 50, 60, 70, 80) cfo = 10.5 # Should trigger an integer offset of 1 in the detection bock x = np.concatenate( [lora.gen_packet(SF, S1, R=R), np.zeros(15 * N * R)]) x = lora.add_cfo(SF, x, cfo, R=R) S1_out, S2_out = self._feed_system(x, R=R, Nsyms=len(S1)) self.assertEqual(S1, S1_out) self.assertEqual(len(S2_out), 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)
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)
def test_003_half_payloads_cfo(self): print("test_003_half_payloads_cfo") Su, Si1, Si2 = 21, 0, 10 Pu, Pi = 1.0, 0.5 delta_cfo = -3.5 x_u = np.sqrt(Pu) * lora.gen_sym(SF, Su) x_i = np.sqrt(Pi) * np.concatenate( [lora.gen_sym(SF, Si1)[N / 2:N], lora.gen_sym(SF, Si2)[0:N / 2]]) x = x_u + lora.add_cfo(SF, x_i, delta_cfo) win_tags = { 0: ('new_window', { 'power1': Pu, 'power2': Pi, 'win_len': N, 'tau': N / 2.0, 'delta_cfo': delta_cfo, 'Tu': SYNC_TYPE_PAYLOAD, 'Ti1': SYNC_TYPE_PAYLOAD, 'Ti2': SYNC_TYPE_PAYLOAD }) } y, tags = self._feed_demod(x, win_tags, id=0) self.assertEqual(len(y), 1) self.assertEqual(len(tags), 1) demod = tags[0].value self.assertEqual(demod['Su'], Su) self.assertAlmostEqual(demod['Mu'], np.sqrt(Pu), places=2) self.assertEqual(demod['Si1'], Si1) self.assertAlmostEqual(demod['Mi1'], np.sqrt(Pi) / 2, places=2) self.assertEqual(demod['Si2'], Si2) self.assertAlmostEqual(demod['Mi2'], np.sqrt(Pi) / 2, places=2) self.assertAlmostEqual(y, i0(Pu) * i0(Pi / 2) * i0(Pi / 2), places=2)
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))