Calculate signal windows which pass specific values
1 view (last 30 days)
Show older comments
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 Comments
Answers (1)
Guillaume
on 13 Jul 2015
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 Comments
See Also
Categories
Find more on AI for Signals in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!