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!