Calculate signal windows which pass specific values
2 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/152124/image.jpeg)
I want to calculate the three windows when my signal pass through these values.
0 commentaires
Réponses (1)
Guillaume
le 13 Juil 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 commentaires
Voir également
Catégories
En savoir plus sur Multirate Signal Processing dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!