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.
--- /dev/null
+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
+++ /dev/null
-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