def test_auto_interpretation_elektromaten(self): data = Signal(get_path_for_data_file("elektromaten.coco"), "").data result = AutoInterpretation.estimate(data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "ASK") self.assertEqual(bit_length, 600) demodulated = demodulate(data, mod_type, bit_length, center, noise, tolerance, pause_threshold=8) self.assertEqual(len(demodulated), 11) for i in range(11): self.assertTrue(demodulated[i].startswith("8")) # Test with added 20% noise np.random.seed(5) noise = np.random.normal(loc=0, scale=1, size=2 * len(data)).astype(np.float32).view(np.complex64) noised_data = data + 0.2 * np.mean(np.abs(data)) * noise result = AutoInterpretation.estimate(noised_data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "ASK") self.assertEqual(bit_length, 600) demodulated = demodulate(noised_data, mod_type, bit_length, center, noise, tolerance, pause_threshold=8) self.assertEqual(len(demodulated), 11) for i in range(11): self.assertTrue(demodulated[i].startswith("8"))
def test_brennenstuhl(self): path = self.get_path("brennenstuhl_signal_ABCD_onoff.coco") if not path: return data = Signal(path, "").iq_array result = AutoInterpretation.estimate(data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result[ "tolerance"] self.assertEqual(mod_type, "ASK") self.assertEqual(bit_length, 300) print("noise", noise, "center", center, "bit length", bit_length, "tolerance", tolerance) demodulated = demodulate(data, mod_type, bit_length, center, noise, tolerance, pause_threshold=8) print(demodulated) self.assertEqual(len(demodulated), 64) for i in range(64): self.assertTrue(demodulated[i].startswith("88888888888")) self.assertEqual(len(demodulated[i]), len(demodulated[0]))
def auto_detect(self, emit_update=True, detect_modulation=True, detect_noise=False) -> bool: kwargs = {"noise": None if detect_noise else self.noise_threshold, "modulation": None if detect_modulation else "OOK" if self.__modulation_order == 2 and self.__modulation_type == 0 else self.modulation_type_str} estimated_params = AutoInterpretation.estimate(self.data, **kwargs) if estimated_params is None: return False orig_block = self.block_protocol_update self.block_protocol_update = True if detect_noise: self.noise_threshold = estimated_params["noise"] if detect_modulation: self.modulation_type_str = estimated_params["modulation_type"] self.qad_center = estimated_params["center"] self.tolerance = estimated_params["tolerance"] self.bit_len = estimated_params["bit_length"] self.block_protocol_update = orig_block if emit_update and not self.block_protocol_update: self.protocol_needs_update.emit() return True
def auto_detect(self, emit_update=True, detect_modulation=True, detect_noise=False): kwargs = { "noise": None if detect_noise else self.noise_threshold, "modulation": None if detect_modulation else "OOK" if self.__modulation_order == 2 and self.__modulation_type == 0 else self.modulation_type_str } estimated_params = AutoInterpretation.estimate(self.data, **kwargs) if estimated_params is None: return orig_block = self.block_protocol_update self.block_protocol_update = True if detect_noise: self.noise_threshold = estimated_params["noise"] if detect_modulation: self.modulation_type_str = estimated_params["modulation_type"] self.qad_center = estimated_params["center"] self.tolerance = estimated_params["tolerance"] self.bit_len = estimated_params["bit_length"] self.block_protocol_update = orig_block if emit_update and not self.block_protocol_update: self.protocol_needs_update.emit()
def auto_detect(self, emit_update=True, detect_modulation=True, detect_noise=False) -> bool: kwargs = { "noise": None if detect_noise else self.noise_threshold, "modulation": None if detect_modulation else "OOK" if self.bits_per_symbol == 1 and self.modulation_type == "ASK" else self.modulation_type } estimated_params = AutoInterpretation.estimate(self.iq_array, **kwargs) if estimated_params is None: return False orig_block = self.block_protocol_update self.block_protocol_update = True if detect_noise: self.noise_threshold = estimated_params["noise"] if detect_modulation: self.modulation_type = estimated_params["modulation_type"] self.center = estimated_params["center"] self.tolerance = estimated_params["tolerance"] self.samples_per_symbol = estimated_params["bit_length"] self.block_protocol_update = orig_block if emit_update and not self.block_protocol_update: self.protocol_needs_update.emit() return True
def test_audi(self): path = self.get_path("audi_auf_sr5m.coco") if not path: return data = Signal(path, "").iq_array result = AutoInterpretation.estimate(data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result[ "tolerance"] self.assertEqual(mod_type, "ASK") self.assertGreaterEqual(bit_length, 2400) self.assertLessEqual(bit_length, 2500) self.assertGreaterEqual(center, 0.005) self.assertLessEqual(center, 0.32) print("noise", noise, "center", center, "bit length", bit_length, "tolerance", tolerance) demodulated = demodulate(data, mod_type, bit_length, center, noise, tolerance) print(demodulated) self.assertEqual(len(demodulated), 1) self.assertTrue(demodulated[0].startswith( "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) self.assertTrue(demodulated[0].endswith("cad4c"))
def test_auto_interpretation_elektromaten(self): data = Signal(get_path_for_data_file("elektromaten.coco"), "").iq_array result = AutoInterpretation.estimate(data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result[ "tolerance"] self.assertEqual(mod_type, "ASK") self.assertEqual(bit_length, 600) demodulated = demodulate(data, mod_type, bit_length, center, noise, tolerance, pause_threshold=8) self.assertEqual(len(demodulated), 11) for i in range(11): self.assertTrue(demodulated[i].startswith("8")) # Test with added 20% noise np.random.seed(5) noise = np.random.normal(loc=0, scale=1, size=2 * len(data)).astype( np.float32).view(np.complex64) noised_data = data.as_complex64() + 0.2 * np.mean( data.magnitudes) * noise result = AutoInterpretation.estimate(noised_data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result[ "tolerance"] self.assertEqual(mod_type, "ASK") self.assertEqual(bit_length, 600) demodulated = demodulate(noised_data, mod_type, bit_length, center, noise, tolerance, pause_threshold=8) self.assertEqual(len(demodulated), 11) for i in range(11): self.assertTrue(demodulated[i].startswith("8"))
def test_auto_interpretation_ask(self): ask_signal = np.fromfile(get_path_for_data_file("ask.complex"), dtype=np.complex64) result = AutoInterpretation.estimate(ask_signal) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "ASK") self.assertEqual(bit_length, 300) self.assertGreater(tolerance, 0) self.assertLessEqual(tolerance, 6) self.assertEqual(demodulate(ask_signal, mod_type, bit_length, center, noise, tolerance)[0], "b25b6db6c80")
def test_auto_interpretation_ask(self): ask_signal = np.fromfile(get_path_for_data_file("ask.complex"), dtype=np.float32) result = AutoInterpretation.estimate(ask_signal) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "ASK") self.assertEqual(bit_length, 300) self.assertGreater(tolerance, 0) self.assertLessEqual(tolerance, 6) self.assertEqual(demodulate(ask_signal, mod_type, bit_length, center, noise, tolerance)[0], "b25b6db6c80")
def test_auto_interpretation_fsk(self): fsk_signal = np.fromfile(get_path_for_data_file("fsk.complex"), dtype=np.complex64) result = AutoInterpretation.estimate(fsk_signal) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "FSK") self.assertEqual(bit_length, 100) self.assertGreater(tolerance, 0) self.assertLessEqual(tolerance, 5) self.assertEqual(demodulate(fsk_signal, mod_type, bit_length, center, noise, tolerance)[0], "aaaaaaaac626c626f4dc1d98eef7a427999cd239d3f18")
def test_auto_interpretation_fsk(self): fsk_signal = np.fromfile(get_path_for_data_file("fsk.complex"), dtype=np.float32) result = AutoInterpretation.estimate(fsk_signal) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "FSK") self.assertEqual(bit_length, 100) self.assertGreater(tolerance, 0) self.assertLessEqual(tolerance, 5) self.assertEqual(demodulate(fsk_signal, mod_type, bit_length, center, noise, tolerance)[0], "aaaaaaaac626c626f4dc1d98eef7a427999cd239d3f18")
def test_auto_interpretation_xavax(self): signal = Signal(get_path_for_data_file("xavax.coco"), "") result = AutoInterpretation.estimate(signal.data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "FSK") self.assertEqual(bit_length, 100) demod = demodulate(signal.data, mod_type, bit_length, center, noise, tolerance) self.assertGreaterEqual(len(demod), 5) for i in range(1, len(demod)): self.assertTrue(demod[i].startswith("aaaaaaaa"))
def test_auto_interpretation_xavax(self): signal = Signal(get_path_for_data_file("xavax.coco"), "") result = AutoInterpretation.estimate(signal.iq_array.data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "FSK") self.assertEqual(bit_length, 100) demod = demodulate(signal.iq_array.data, mod_type, bit_length, center, noise, tolerance) self.assertGreaterEqual(len(demod), 5) for i in range(1, len(demod)): self.assertTrue(demod[i].startswith("aaaaaaaa"))
def test_auto_interpretation_elektromaten(self): data = Signal(get_path_for_data_file("elektromaten.complex16s"), "").iq_array result = AutoInterpretation.estimate(data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "ASK") self.assertEqual(bit_length, 600) demodulated = demodulate(data, mod_type, bit_length, center, noise, tolerance, pause_threshold=8) self.assertEqual(len(demodulated), 11) for i in range(11): self.assertTrue(demodulated[i].startswith("8"))
def test_auto_interpretation_homematic(self): data = Signal(get_path_for_data_file("homematic.complex32s"), "").iq_array result = AutoInterpretation.estimate(data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "FSK") self.assertEqual(bit_length, 100) demodulated = demodulate(data, mod_type, bit_length, center, noise, tolerance) self.assertEqual(len(demodulated), 2) for i in range(2): self.assertTrue(demodulated[i].startswith("aaaaaaaa"))
def test_auto_interpretation_homematic(self): data = Signal(get_path_for_data_file("homematic.coco"), "").data result = AutoInterpretation.estimate(data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "FSK") self.assertEqual(bit_length, 100) demodulated = demodulate(data, mod_type, bit_length, center, noise, tolerance) self.assertEqual(len(demodulated), 2) for i in range(2): self.assertTrue(demodulated[i].startswith("aaaaaaaa"))
def test_auto_interpretation_enocean(self): enocean_signal = np.fromfile(get_path_for_data_file("enocean.complex"), dtype=np.float32) result = AutoInterpretation.estimate(enocean_signal) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "ASK") self.assertGreaterEqual(center, 0.0077) self.assertLessEqual(center, 0.0465) self.assertLessEqual(tolerance, 5) self.assertEqual(bit_length, 40) demod = demodulate(enocean_signal, mod_type, bit_length, center, noise, tolerance, decoding=Encoding(["WSP", settings.DECODING_ENOCEAN])) self.assertEqual(len(demod), 3) self.assertEqual(demod[0], demod[2]) self.assertEqual(demod[0], "aa9610002c1c024b")
def test_auto_interpretation_enocean(self): enocean_signal = np.fromfile(get_path_for_data_file("enocean.complex"), dtype=np.complex64) result = AutoInterpretation.estimate(enocean_signal) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "ASK") self.assertGreaterEqual(center, 0.04) self.assertLessEqual(center, 0.066) self.assertLessEqual(tolerance, 5) self.assertEqual(bit_length, 40) demod = demodulate(enocean_signal, mod_type, bit_length, center, noise, tolerance, decoding=Encoding(["WSP", constants.DECODING_ENOCEAN])) self.assertEqual(len(demod), 3) self.assertEqual(demod[0], demod[2]) self.assertEqual(demod[0], "aa9610002c1c024b")
def test_vw(self): path = self.get_path("vw_auf.complex") if not path: return data = Signal(path, "").data result = AutoInterpretation.estimate(data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "ASK") self.assertGreaterEqual(bit_length, 2000) self.assertLessEqual(bit_length, 3000) demodulated = demodulate(data, mod_type, bit_length, center, noise, tolerance) print(demodulated) self.assertEqual(len(demodulated), 1) self.assertTrue(demodulated[0].startswith("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))
def test_esaver(self): path = self.get_path("esaver_test4on.complex") if not path: return data = Signal(path, "").data result = AutoInterpretation.estimate(data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] print(center, noise) self.assertEqual(mod_type, "FSK") self.assertEqual(bit_length, 100) print("noise", noise, "center", center, "bit length", bit_length, "tolerance", tolerance) demodulated = demodulate(data, mod_type, bit_length, center, noise, tolerance) print(demodulated) self.assertEqual(len(demodulated), 12) for i in range(12): self.assertTrue(demodulated[i].startswith("aaaaaaaa"))
def test_brennenstuhl(self): path = self.get_path("brennenstuhl_signal_ABCD_onoff.coco") if not path: return data = Signal(path, "").data result = AutoInterpretation.estimate(data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "ASK") self.assertEqual(bit_length, 300) print("noise", noise, "center", center, "bit length", bit_length, "tolerance", tolerance) demodulated = demodulate(data, mod_type, bit_length, center, noise, tolerance, pause_threshold=8) print(demodulated) self.assertEqual(len(demodulated), 64) for i in range(64): self.assertTrue(demodulated[i].startswith("88888888888")) self.assertEqual(len(demodulated[i]), len(demodulated[0]))
def test_action(self): path = self.get_path("action_FB_A_B_C_D.coco") if not path: return data = Signal(path, "").data result = AutoInterpretation.estimate(data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "ASK") self.assertGreaterEqual(bit_length, 400) self.assertLessEqual(bit_length, 500) print("noise", noise, "center", center, "bit length", bit_length, "tolerance", tolerance) demodulated = demodulate(data, mod_type, bit_length, center, noise, tolerance) print(demodulated) self.assertEqual(len(demodulated), 19) for i in range(2): self.assertTrue(demodulated[i].startswith("8e8eeeeeee8"))
def test_scislo(self): path = self.get_path("scislo.complex") if not path: return data = Signal(path, "").data result = AutoInterpretation.estimate(data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "FSK") self.assertEqual(bit_length, 200) self.assertGreaterEqual(noise, 0.0120) print("noise", noise, "center", center, "bit length", bit_length, "tolerance", tolerance) demodulated = demodulate(data, mod_type, bit_length, center, noise, tolerance) print(demodulated) self.assertEqual(len(demodulated), 8) for i in range(8): self.assertTrue(demodulated[i].startswith("000000000000aaaaaa"))
def test_audi(self): path = self.get_path("audi_auf_sr5m.coco") if not path: return data = Signal(path, "").data result = AutoInterpretation.estimate(data) mod_type, bit_length = result["modulation_type"], result["bit_length"] center, noise, tolerance = result["center"], result["noise"], result["tolerance"] self.assertEqual(mod_type, "ASK") self.assertGreaterEqual(bit_length, 2400) self.assertLessEqual(bit_length, 2500) self.assertGreaterEqual(center, 0.005) self.assertLessEqual(center, 0.32) print("noise", noise, "center", center, "bit length", bit_length, "tolerance", tolerance) demodulated = demodulate(data, mod_type, bit_length, center, noise, tolerance) print(demodulated) self.assertEqual(len(demodulated), 1) self.assertTrue(demodulated[0].startswith("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa")) self.assertTrue(demodulated[0].endswith("cad4c"))
def test_auto_interpretation_overshoot_ook(self): data = Signal(get_path_for_data_file("ook_overshoot.coco"), "").iq_array result = AutoInterpretation.estimate(data) self.assertEqual(result["modulation_type"], "ASK") self.assertEqual(result["bit_length"], 500)
def test_auto_interpretation_overshoot_ook(self): data = Signal(get_path_for_data_file("ook_overshoot.coco"), "").data result = AutoInterpretation.estimate(data) self.assertEqual(result["modulation_type"], "ASK") self.assertEqual(result["bit_length"], 500)