Improve detect_change function
authorLukáš Jiřiště <jiriste@icpf.cas.cz>
Wed, 11 Dec 2024 09:55:54 +0000 (10:55 +0100)
committerLukáš Jiřiště <jiriste@icpf.cas.cz>
Wed, 11 Dec 2024 10:27:41 +0000 (11:27 +0100)
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.

detect_change.m
get_important_pressure.m
process_experiment.m

index 3a5f91a70d629410d008dbad815759887d559368..e46c42c5052980e6a70614d24ad8460f5ac8b315 100644 (file)
@@ -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
index 98624757e25176500299bacc1ec5cf7366a8492f..2093515a089b585cdaad45067e16bf42fb9e4bf9 100644 (file)
@@ -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)];
index 2b52bbf494b9bd814ed55f4dfa9334ac48d8c2c0..7257e8b67d89e7424790568f1eb92400851ff1ac 100644 (file)
@@ -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);