From eae8e4dd8602cb1f33bb329b586b0976f2c442e6 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Ji=C5=99i=C5=A1t=C4=9B?= Date: Mon, 20 May 2024 16:03:21 +0200 Subject: [PATCH] Change detect_open to detect_change Positive threshold behaves the same way it behaved before. With negative threshold the function only detects values (derivatives) lower (bigger in absolute value) than that. --- detect_change.m | 17 +++++++++++++++++ detect_open.m | 17 ----------------- 2 files changed, 17 insertions(+), 17 deletions(-) create mode 100644 detect_change.m delete mode 100644 detect_open.m diff --git a/detect_change.m b/detect_change.m new file mode 100644 index 0000000..0c71010 --- /dev/null +++ b/detect_change.m @@ -0,0 +1,17 @@ +function changed = detect_change(t, p, threshold = 0.2, min_dist = 10) + dp = (p(2:end) - p(1:end - 1)) ./ (t(2:end) - t(1:end - 1)); + dp = dp / max(dp); + changed = dp / threshold > 1; + for i = (length(changed):-1:1) + j = i - 1; + while (j > 0 && t(j) + min_dist > t(i)) + if (changed(j) == 1) + changed(i) = 0; + break; + end + j -= 1; + end + end + changed = [0 changed]; + changed = logical(changed); +end diff --git a/detect_open.m b/detect_open.m deleted file mode 100644 index 4c20f01..0000000 --- a/detect_open.m +++ /dev/null @@ -1,17 +0,0 @@ -function opened = detect_open(t, p, threshold = 0.2, min_dist = 10) - dp = (p(2:end) - p(1:end - 1)) ./ (t(2:end) - t(1:end - 1)); - dp = dp / max(dp); - opened = dp > threshold; - for i = (length(opened):-1:1) - j = i - 1; - while (j > 0 && t(j) + min_dist > t(i)) - if (opened(j) == 1) - opened(i) = 0; - break; - end - j -= 1; - end - end - opened = [0 opened]; - opened = logical(opened); -end -- 2.30.2