From 14896c19dcd49713a1c89259ad962a76905ebc80 Mon Sep 17 00:00:00 2001 From: Johannes Pohl Date: Sun, 5 May 2019 18:23:04 +0200 Subject: [PATCH 1/5] fix ainterpretation parameters --- src/urh/ainterpretation/AutoInterpretation.py | 4 ++-- tests/auto_interpretation/test_additional_signals.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/urh/ainterpretation/AutoInterpretation.py b/src/urh/ainterpretation/AutoInterpretation.py index 598b3e295c..42f052bb5f 100644 --- a/src/urh/ainterpretation/AutoInterpretation.py +++ b/src/urh/ainterpretation/AutoInterpretation.py @@ -148,7 +148,7 @@ def detect_modulation(data: np.ndarray, wavelet_scale=4, median_filter_order=11) var_filtered_mag = np.var(c_auto_interpretation.median_filter(mag_wavlt, k=median_filter_order)) var_filtered_norm_mag = np.var(c_auto_interpretation.median_filter(norm_mag_wavlt, k=median_filter_order)) - if all(v < 0.1 for v in (var_mag, var_norm_mag, var_filtered_mag, var_filtered_norm_mag)): + if all(v < 0.15 for v in (var_mag, var_norm_mag, var_filtered_mag, var_filtered_norm_mag)): return "OOK" if var_mag > 1.5 * var_norm_mag: @@ -157,7 +157,7 @@ def detect_modulation(data: np.ndarray, wavelet_scale=4, median_filter_order=11) return "ASK" else: # FSK or PSK - if var_mag > 10 * var_filtered_mag: + if var_mag > 5 * var_filtered_mag: return "PSK" else: # Now we either have a FSK signal or we a have OOK single pulse diff --git a/tests/auto_interpretation/test_additional_signals.py b/tests/auto_interpretation/test_additional_signals.py index 8dee7c7f4a..33c5cffa8a 100644 --- a/tests/auto_interpretation/test_additional_signals.py +++ b/tests/auto_interpretation/test_additional_signals.py @@ -29,7 +29,7 @@ def test_action(self): self.assertEqual(mod_type, "ASK") self.assertGreaterEqual(bit_length, 400) - self.assertLessEqual(bit_length, 500) + self.assertLessEqual(bit_length, 600) print("noise", noise, "center", center, "bit length", bit_length, "tolerance", tolerance) demodulated = demodulate(data, mod_type, bit_length, center, noise, tolerance) From 696d67c0fc41e9754521956d9bd0f926d9b323ec Mon Sep 17 00:00:00 2001 From: Johannes Pohl Date: Sun, 5 May 2019 18:29:21 +0200 Subject: [PATCH 2/5] fix window size calculation --- src/urh/ainterpretation/AutoInterpretation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/urh/ainterpretation/AutoInterpretation.py b/src/urh/ainterpretation/AutoInterpretation.py index 42f052bb5f..8af8a492b5 100644 --- a/src/urh/ainterpretation/AutoInterpretation.py +++ b/src/urh/ainterpretation/AutoInterpretation.py @@ -213,7 +213,7 @@ def detect_center(rectangular_signal: np.ndarray, max_size=None): num_values = 2 most_common_levels = [] - window_size = max(2, int(0.05*len(y))) + window_size = max(2, int(0.05*len(y)) + 1) def get_elem(arr, index: int, default): if 0 <= index < len(arr): @@ -225,7 +225,7 @@ def get_elem(arr, index: int, default): # check if we have a local maximum in histogram, if yes, append the value if all(y[index] > get_elem(y, index+i, 0) and y[index] > get_elem(y, index-i, 0) - for i in range(1, window_size+1)): + for i in range(1, window_size)): most_common_levels.append(x[index]) if len(most_common_levels) == num_values: From 7ec5e38d036b318af6a5c95272051b54fef0492a Mon Sep 17 00:00:00 2001 From: Johannes Pohl Date: Sun, 5 May 2019 18:55:01 +0200 Subject: [PATCH 3/5] fix unittest --- tests/test_advanced_modulation_settings.py | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/test_advanced_modulation_settings.py b/tests/test_advanced_modulation_settings.py index 6a7fb6472c..b37ea7cd7d 100644 --- a/tests/test_advanced_modulation_settings.py +++ b/tests/test_advanced_modulation_settings.py @@ -2,7 +2,9 @@ from PyQt5.QtWidgets import QApplication from tests.QtTestCase import QtTestCase +from urh.controller.MainController import MainController from urh.controller.dialogs.AdvancedModulationOptionsDialog import AdvancedModulationOptionsDialog +from urh.controller.widgets.SignalFrame import SignalFrame class TestAdvancedModulationSettings(QtTestCase): @@ -15,13 +17,24 @@ def test_pause_threshold(self): self.assertEqual(signal_frame.proto_analyzer.num_messages, 1) def test_message_length_divisor(self): + assert isinstance(self.form, MainController) + self.form.ui.actionAuto_detect_new_signals.setChecked(False) self.add_signal_to_form("pwm.coco") - signal_frame = self.form.signal_tab_controller.signal_frames[0] + signal_frame = self.form.signal_tab_controller.signal_frames[0] # type: SignalFrame + signal_frame.ui.spinBoxNoiseTreshold.setValue(0.0525) signal_frame.ui.cbModulationType.setCurrentText("ASK") + signal_frame.ui.spinBoxCenterOffset.setValue(0.01807) + signal_frame.ui.spinBoxCenterOffset.editingFinished.emit() + signal_frame.ui.spinBoxInfoLen.setValue(2900) + signal_frame.ui.spinBoxInfoLen.editingFinished.emit() + signal_frame.ui.spinBoxTolerance.setValue(2) + signal_frame.ui.spinBoxTolerance.editingFinished.emit() + + protocol = signal_frame.proto_analyzer bits = "1000100010001110100011101000111010001000100011101000111010001110100011101000111010001110111011101" - pauses = [77115, 77113, 58221] + pauses = [77114, 77112, 58221] for i in range(3): self.assertEqual(protocol.plain_bits_str[i], bits, msg=str(i)) self.assertEqual(protocol.messages[i].pause, pauses[i], msg=str(i)) From 77af8101429e5f1624c724d4b629ed1d1af7c762 Mon Sep 17 00:00:00 2001 From: Johannes Pohl Date: Sun, 5 May 2019 18:55:15 +0200 Subject: [PATCH 4/5] catch error and improve value --- src/urh/ainterpretation/AutoInterpretation.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/urh/ainterpretation/AutoInterpretation.py b/src/urh/ainterpretation/AutoInterpretation.py index 8af8a492b5..7e0461abce 100644 --- a/src/urh/ainterpretation/AutoInterpretation.py +++ b/src/urh/ainterpretation/AutoInterpretation.py @@ -148,7 +148,7 @@ def detect_modulation(data: np.ndarray, wavelet_scale=4, median_filter_order=11) var_filtered_mag = np.var(c_auto_interpretation.median_filter(mag_wavlt, k=median_filter_order)) var_filtered_norm_mag = np.var(c_auto_interpretation.median_filter(norm_mag_wavlt, k=median_filter_order)) - if all(v < 0.15 for v in (var_mag, var_norm_mag, var_filtered_mag, var_filtered_norm_mag)): + if all(v < 0.175 for v in (var_mag, var_norm_mag, var_filtered_mag, var_filtered_norm_mag)): return "OOK" if var_mag > 1.5 * var_norm_mag: @@ -206,7 +206,7 @@ def detect_center(rectangular_signal: np.ndarray, max_size=None): try: y, x = np.histogram(rect, bins=np.arange(hist_min, hist_max + hist_step, hist_step)) - except ZeroDivisionError: + except (ZeroDivisionError, ValueError): # For a segment with zero variance (constant line) it is not possible to find a center return None From 1923d52002b274c44d49943e681d9db4f2013b6e Mon Sep 17 00:00:00 2001 From: Johannes Pohl Date: Sun, 5 May 2019 19:37:28 +0200 Subject: [PATCH 5/5] tune value --- src/urh/ainterpretation/AutoInterpretation.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/urh/ainterpretation/AutoInterpretation.py b/src/urh/ainterpretation/AutoInterpretation.py index 7e0461abce..53b37b5dc3 100644 --- a/src/urh/ainterpretation/AutoInterpretation.py +++ b/src/urh/ainterpretation/AutoInterpretation.py @@ -148,7 +148,7 @@ def detect_modulation(data: np.ndarray, wavelet_scale=4, median_filter_order=11) var_filtered_mag = np.var(c_auto_interpretation.median_filter(mag_wavlt, k=median_filter_order)) var_filtered_norm_mag = np.var(c_auto_interpretation.median_filter(norm_mag_wavlt, k=median_filter_order)) - if all(v < 0.175 for v in (var_mag, var_norm_mag, var_filtered_mag, var_filtered_norm_mag)): + if all(v < 0.15 for v in (var_mag, var_norm_mag, var_filtered_mag, var_filtered_norm_mag)): return "OOK" if var_mag > 1.5 * var_norm_mag: