From: Lukáš Jiřiště Date: Wed, 11 Dec 2024 09:55:54 +0000 (+0100) Subject: Improve detect_change function X-Git-Url: https://git.ljiriste.work/?a=commitdiff_plain;h=fed64548bfd6aeb498cf0c7e31b41ad22417406d;p=analyse_servo.git Improve detect_change function Opening the valve to cell in two stages introduced a problem with the peak detection (double peaks). For small pressures during desorption measurement the pressure differences were also small and the threshold could not be set so that it recognizes these small peaks without triggering the double peaks. Both seem to be somewhat solved by what I've done. The differences are divided by the mean of differences 15 (arbitrary) sample to both sides. This amplifies the peaks that occur around vacuum much more than others. In other words the difference function is divided by the convolution of differences and a rectangular window (of size 30). The convolution looks like exponentials that roughly follow the pressure that have smeared peaks. By dividing the differences by this convolution, the small peaks are divided by small values while the big peaks are divided by greater values. This maybe worsens the noise-to-signal ratio, but makes the peaks easier to process. --- diff --git a/detect_change.m b/detect_change.m index 3a5f91a..e46c42c 100644 --- a/detect_change.m +++ b/detect_change.m @@ -1,7 +1,10 @@ -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)) @@ -12,6 +15,8 @@ function changed = detect_change(t, p, threshold = 0.2, min_dist = 10) j -= 1; end end + changed(1:30) = 0; + changed(end - 30:end) = 0; changed = [0 changed]; changed = logical(changed); end diff --git a/get_important_pressure.m b/get_important_pressure.m index 9862475..2093515 100644 --- a/get_important_pressure.m +++ b/get_important_pressure.m @@ -1,4 +1,4 @@ -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)]; diff --git a/process_experiment.m b/process_experiment.m index 2b52bbf..7257e8b 100644 --- a/process_experiment.m +++ b/process_experiment.m @@ -1,4 +1,4 @@ -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);