function [times, labels] = naive_threshold(x, fs, training) % Deliberately weak floor: detect where the smoothed amplitude envelope % peaks above a threshold, and classify every event by its duration alone % (time the envelope stays above a fraction of the peak), nearest to the % mean duration of each training type. Scores from this baseline are the % floor real methods should clear. nTypes = numel(training.snips); L = size(training.snips{1}, 1); w = round(0.005 * fs); kern = ones(w, 1) / w; env = conv(abs(x), kern, 'same'); n = numel(env); thr = max(8 * median(env), 0.05 * max(env)); refr = round(L / 2); % mean above-threshold duration per type, from the training snippets durs = zeros(nTypes, 1); for k = 1:nTypes S = training.snips{k}; dk = 0; for j = 1:size(S, 2) ev = conv(abs(S(:, j)), kern, 'same'); dk = dk + sum(ev > 0.2 * max(ev)); end durs(k) = dk / max(size(S, 2), 1); end times = zeros(0, 1); labels = zeros(0, 1); i = 2; while i < n if env(i) > thr && env(i-1) <= thr j2 = min(n, i + refr - 1); [pk, rel] = max(env(i:j2)); p = i + rel - 1; j3 = min(n, i + L - 1); dur = sum(env(i:j3) > 0.2 * pk); [~, lab] = min(abs(durs - dur)); times(end+1, 1) = (i - 1) / fs; labels(end+1, 1) = lab; i = p + refr; else i = i + 1; end end end