I think this is easier than it has been made out to be. Findpeaks won't really work, since it is looking for peaks, and these plateaus are not really constant in value.
The plateaus are regions of the curve here where it has a value of 0, within some tolerance. I lack your data, nor do I know what a reasonable tolerance would be.
Since the plateau appears to be at zero, just do a simple test.
this gives you a logical vector where the curve is in the plateau region. Then, find the locations in that logical vector where a transition is made into the plateau, and then out of it.
Start by adding with zeros (false) at each end, in case a plateau is already in existence at either end.
pbool = [false, pbool, false];
Now just search for the string [0 1]. That will indicate where a plateau starts. And we will find EVERY plateau in the one operation. Searching for the transition out of the plateau is also easy, because we search for [1 0].
pstart = strfind(pbool,[0 1]);
pend = strfind(pbool,[1 0]) - 1;
the elements of pstart are the beginnings of each plateau. And the corresponding elements of pend are the end points for that plateau. I had to subtract 1 from the end points, because of the zero pad.
y = min(0,sin(0:.1:14) - 0.9);
y = y + randn(size(y)) * 0.001;
plot(y)
grid on
Lets try it out. I know a good tolerance, because I know the noise standard deviation was 0.001. 5 sigma should suffice, so 0.005 should be quite adequate. But if you have no a-priori clue as to the noise variance, you could try my estimatenoise code (on the FEX) sqrt(estimatenoise(y))
ans =
0.0012083
So 5 sigma would then be 0.006. Either will be close enough for government work.
tol = 0.005;
pbool = (y >= -tol);
pbool = [false, pbool, false];
pstart = strfind(pbool,[0 1]);
pend = strfind(pbool,[1 0]);
pstart
pstart =
13 75 138
pend
pend =
21 84 141
plot(1:numel(y),y,'-b',pstart,y(pstart),'ro',pend,y(pend),'rx')
grid on
The change in case your nominal plateau level is not actually at zero is trivial to code, as long as you know where to set it. That too would be easily done automatically.