From 1442dc09b5f0978cab5dffc0cef51b4caade2b0b 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:07:22 +0200 Subject: [PATCH] Modify get_important_pressure This function now handles the correct experiment. --- get_important_pressure.m | 32 ++++++++++++++++++-------------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/get_important_pressure.m b/get_important_pressure.m index 7e546f2..153ca6b 100644 --- a/get_important_pressure.m +++ b/get_important_pressure.m @@ -1,31 +1,35 @@ -function [p_eq, p_after_open] = get_important_pressure(t, p, graph = 1, threshold = 0.05) - log_inds = detect_open(t, p, threshold); - inds = [1 find(log_inds == 1) length(p)]; +function [p_eq, p_after_fill] = get_important_pressure(t, p, graph = 1, threshold = 0.01) + fill_loginds = detect_change(t, p, threshold); + fill_inds = [1 find(fill_loginds == 1) length(p)]; + open_loginds = detect_change(t, p, -threshold); + open_inds = [1 find(open_loginds == 1) length(p)]; if (graph) figure() plot(t, p); hold on; end - for i = 2:length(inds) - t_single = t(inds(i - 1):(inds(i) - 1)); - p_single = p(inds(i - 1):(inds(i) - 1)); - [p_eq(i - 1) p_after_open(i - 1)] = process_single(t_single, p_single); + for i = 2:length(fill_inds) + t_single = t(open_inds(i - 1):(fill_inds(i) - 1)); + p_single = p(open_inds(i - 1):(fill_inds(i) - 1)); + p_eq(i - 1) = get_equilibrium_pressure(t_single, p_single); + if (i > 2) + p_after_fill(i - 1) = mean(p(fill_inds(i - 1):open_inds(i - 1) - 1)); + end if (graph) - if (i < length(inds)) - plot([t(inds(i) - 5) t(inds(i) + 4)], p_eq(i - 1) .* [1 1], "red"); + if (i < length(fill_inds)) + plot([t(fill_inds(i) - 5) t(fill_inds(i) + 4)], p_eq(i - 1) .* [1 1], "red"); else - plot([t(inds(i) - 5) t(end)], p_eq(i - 1) .* [1 1], "red"); + plot([t(fill_inds(i) - 5) t(end)], p_eq(i - 1) .* [1 1], "red"); end if (i > 2) - plot([t(inds(i - 1) - 4) t(inds(i - 1) + 5)], p_after_open(i - 1) .* [1 1], "green"); + plot([(t(fill_inds(i - 1)) - 5) (t(open_inds(i - 1)) + 4)], p_after_fill(i - 1) .* [1 1], "green"); end end end - p_after_open(1) = []; + p_after_fill(1) = []; end -function [p_eq p_after_open] = process_single(t, p) - p_after_open = max(p); +function p_eq = get_equilibrium_pressure(t, p) weights = ((t - t(1)) / (t(end) - t(1))) .^ 10; p_eq = weighted_mean(p, weights); end -- 2.30.2