MATLAB: Counting number of bursts

emgImage Processing Toolboxsignal processing

How can I count the number of periods of activity above a certain threshold?
I have an EMG signal with some bursts of activity above baseline. I have used the following code to identify those periods of activity (at least 200 points) above a predetermined threshold value that I have chosen:
above_threshold = (EMG_signal > threshold);
spanLocs = bwlabel(above_threshold);
spanLength = regionprops(spanLocs, 'area');
spanLength = [spanLength.Area];
goodSpans = find(spanLength>=200);
allInSpans = find(ismember(spanLocs, goodSpans));
Now I would like to count the number of bursts that have been identified above (i.e. see image attached. In this example, in red are shown the bursts identified).
Any help is much appreciated. Thanks a lot. Antonio

Best Answer

Simply call bwareafilt and bwlabel. So get rid of all that and just simply have this:
EMG_signal = [1 2 4 2 0 0 2 2 0 2 0 2 2 2] % Sample signal with 2 bursts
threshold = 1.5
above_threshold = (EMG_signal > threshold)
minAcceptableLength = 3; % or 200 or whatever.
% Find spans that are long enough.
isLongEnough = bwareafilt(above_threshold, [minAcceptableLength, inf])
% Count the number of spans (bursts) that are long enough.
[labeledSpans, numberOfBursts] = bwlabel(isLongEnough)