Obtain Values Greater Than Threshold For a Duration

5 views (last 30 days)
I have EMG data where I would like to see where the EMG is considered "Active". In order to be "Active" the signal must be above some threshold 'X' for 'Y' time points to be considered. (Ex. Above threshold value of 10 for at least 0.1 seconds). How may I find the indicies of values that are above the threshold for at least some given period of time.

Accepted Answer

Walter Roberson
Walter Roberson on 20 Sep 2022
%Fs is sampling frequency, use your actual frequency instead of the
%hard-coded one I give here
Fs = 24000;
threshold_duration = 0.1;
threshold_number_samples = ceil(threshold_duration * Fs);
mask = X(:).' > threshold;
mask2 = true(1, threshold_number_samples);
starts = strfind([false, mask], [false, mask2]);
stops = strfind([mask, false], [mask2, false]);
%now each starts(K) : stops(K) is indices of data above the threshold for
%sufficiently long

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!