Calculate signal windows which pass specific values
조회 수: 1 (최근 30일)
이전 댓글 표시
I have a signal over time which takes values between 0-1. I have calculate the time windows when the signal takes values between 0.25, 0.50 and 0.75. I want to calculate when the three condition are met. Windows when the signal through pass through these values(both when ascending and descending). For example my signal is look like:

I want to calculate the three windows when my signal pass through these values.
댓글 수: 0
답변 (1개)
Guillaume
2015년 7월 13일
Note that the middle number is irrelevant. If it goes from 0.25 to 0.75 it obviously goes through 0.5.
The way I'd do it is find all the runs where the signal is above 0.25 and discard those runs where the signal does not go above .75.
There are plenty of answers already on how to find start and end of runs (search run length encoding). One way to do it:
thresholds = [0.25, 0.75];
runs = signal > thresholds(1);
druns = diff([0 runs 0]); %start of runs are 1, end of runs are just before -1
startruns = find(druns == 1);
endruns = find(druns == -1) - 1;
From there it's simple to check which one also go above 0.75:
validruns = arrayfun(@(s, e) any(signal(s:e) > threshold(2)), startruns, endruns);
startruns = startruns(validruns);
endruns = endruns(validruns);
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 AI for Signals에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!