MATLAB: How to find the index when both signals are high

indexingMATLABsignal

I have two signals. I want to find out indexes on which both signals are high. Both signals have the amplitude (0 & 1). Blue signal is shifted at y=1. Please help me. Thanks

Best Answer

Assuming your signal are binary vectors of the same size b and r
both = min(b,r);
d = diff([0; both(:); 0]);
upidx = find(d==1) % index where both become high, a & c
downidx = find(d==-1) % index where any of b/r becomes low (so both is no longer high), b & d
lgt = downidx-upidx % (b-a) and (d-c)