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;
+ changed = abs(dp) / threshold > 1;
for i = (length(changed):-1:1)
j = i - 1;
while (j > 0 && t(j) + min_dist > t(i))
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)];
+ big_pressure_changes_loginds = detect_change(t, p, threshold);
+ big_pressure_changes_inds = find(big_pressure_changes_loginds == 1);
+ fill_inds = [1 big_pressure_changes_inds(1:2:end) numel(p)];
+ open_inds = [1 big_pressure_changes_inds(2:2:end) numel(p)];
if (graph)
figure()
plot(t, p);
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));
+ p_after_fill(i - 1) = get_equilibrium_pressure(t(fill_inds(i - 1):open_inds(i - 1) - 1), p(fill_inds(i - 1):open_inds(i - 1) - 1));
end
if (graph)
if (i < length(fill_inds))
-function [p_eq n] = process_experiment(t, p, V1, V2, Vvz, T = 298, graph = 1, threshold = 0.01)
+function [p_eq n] = process_experiment(t, p, V1, V2, Vvz, T = 298, graph = 1, threshold = 0.1)
R = 8.314;
[p_eq, p_fill] = get_important_pressure(t, p, graph, threshold);
p_start = (p_eq(1:(end - 1)) * (V2 - Vvz) + p_fill * V1) / (V1 + V2 - Vvz);
n = [0 cumsum(delta_n)];
if (graph)
figure();
- plot(p_eq, n, "-o");
+ plot(p_eq, n, "o");
end
end