-function changed = detect_change(t, p, threshold = 0.2, min_dist = 10)
+function changed = detect_change(t, p, threshold = 0.03, min_dist = 10)
dp = (p(2:end) - p(1:end - 1)) ./ (t(2:end) - t(1:end - 1));
- dp = dp / max(dp);
- changed = abs(dp) / threshold > 1;
+ dp = abs(dp);
+ pkg load signal;
+ sliding_mean = filtfilt(ones(30) / 30, 1, dp);
+ dp_normalized = dp ./ sliding_mean;
+ changed = dp_normalized / threshold > 1;
for i = (length(changed):-1:1)
j = i - 1;
while (j > 0 && t(j) + min_dist > t(i))
j -= 1;
end
end
+ changed(1:30) = 0;
+ changed(end - 30:end) = 0;
changed = [0 changed];
changed = logical(changed);
end
-function [p_eq, p_after_fill] = get_important_pressure(t, p, graph = 1, threshold = 0.01)
+function [p_eq, p_after_fill] = get_important_pressure(t, p, graph = 1, threshold = 0.03)
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)];
-function [p_eq n] = process_experiment(t, p, V_fill, V_cell, Vvz, T = 298, graph = 1, threshold = 0.1)
+function [p_eq n] = process_experiment(t, p, V_fill, V_cell, Vvz, T = 298, graph = 1, threshold = 0.03)
R = 8.314;
[p_eq, p_fill] = get_important_pressure(t, p, graph, threshold);
p_start = (p_eq(1:(end - 1)) * (V_cell - Vvz) + p_fill * V_fill) / (V_fill + V_cell - Vvz);