Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix parameters of auto interpretation for better PSK detection #649

Merged
merged 5 commits into from
May 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions src/urh/ainterpretation/AutoInterpretation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down Expand Up @@ -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):
Expand All @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/auto_interpretation/test_additional_signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 15 additions & 2 deletions tests/test_advanced_modulation_settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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))
Expand Down