Counting number of bursts

13 ビュー (過去 30 日間)
Antonio Morales
Antonio Morales 2016 年 8 月 9 日
コメント済み: Image Analyst 2017 年 1 月 16 日
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

採用された回答

Image Analyst
Image Analyst 2016 年 8 月 9 日
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)
  4 件のコメント
Antonio Morales
Antonio Morales 2017 年 1 月 16 日
No, if a span is not long enough at first, it should not be counted as span even if after getting rid of zeros between spans it becomes long enough. How could that be worked around?
Thank you.
Image Analyst
Image Analyst 2017 年 1 月 16 日
Try this:
EMG_signal = [1 1 2 4 2 0 0 2 2 0 2 0 2 2 2 0 4 4 4 4 1] % 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])
% Specify the max number of zeros 0's there are that should be filled in.
maxHoleSize = 4;
holes = bwareafilt(~isLongEnough, [0, maxHoleSize])
% Don't take any holes if they are on the front or end of the vector
% because they are not bounded by spans on each side.
firstZero = find(holes, 1, 'first')
lastZero = find(holes, 1, 'last')
holes(1:firstZero) = 0;
holes(lastZero:end) = 0
% Now fill in the hoels by ORing:
isLongEnough = isLongEnough | holes;
% Count the number of spans (bursts) that are long enough.
[labeledSpans, numberOfBursts] = bwlabel(isLongEnough)
% Find the lengths of all the spans
props = regionprops(labeledSpans, 'Area');
allLengths = [props.Area]

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeMeasurements and Spatial Audio についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by