Modify get_important_pressure
authorLukáš Jiřiště <jiriste@icpf.cas.cz>
Mon, 20 May 2024 14:07:22 +0000 (16:07 +0200)
committerLukáš Jiřiště <jiriste@icpf.cas.cz>
Mon, 20 May 2024 14:07:22 +0000 (16:07 +0200)
This function now handles the correct experiment.

get_important_pressure.m

index 7e546f2de86ebfd0de45050b37479bbbe2a8f198..153ca6bc14f93ff73c85e52256d718519912ae7d 100644 (file)
@@ -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