--- /dev/null
+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)];
+ 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);
+ if (graph)
+ if (i < length(inds))
+ plot([t(inds(i) - 5) t(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");
+ end
+ if (i > 2)
+ plot([t(inds(i - 1) - 4) t(inds(i - 1) + 5)], p_after_open(i - 1) .* [1 1], "green");
+ end
+ end
+ end
+ p_after_open(1) = [];
+end
+
+function [p_eq p_after_open] = process_single(t, p)
+ p_after_open = max(p);
+ weights = ((t - t(1)) / (t(end) - t(1))) .^ 10;
+ p_eq = weighted_mean(p, weights);
+end
for i = ceil(t_open)
p2 = (p(i + 1) * (V2 - Vvz) + p1 * V1) / (V1 + V2 - Vvz);
peq += 0.7 * (p2 - peq);
- p(i + 1:end) = (p2 - peq) * exp((-(i + 1:length(p)) + i + 1) / 10) + peq;
+ p(i + 1:end) = (p2 - peq) * exp((-((i + 1):length(p)) + i + 1) / 10) + peq;
end
p += rand(size(t)) * p1 / 100;
end
--- /dev/null
+function res = weighted_mean(values, weights)
+ weighted_sum = sum(values .* weights);
+ res = weighted_sum / sum(weights);
+end