diff --git a/src/urh/ainterpretation/AutoInterpretation.py b/src/urh/ainterpretation/AutoInterpretation.py index 598b3e295c..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.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 @@ -206,14 +206,14 @@ 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 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: 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) 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))