MATLAB: How to segment the signal based on amplitude change.

MATLABsignal segmentation

Attached herewith a signal image and dataset (.mat file). I have to segment the signal with respect to amplitue and extract the time duration of each segment.
Your help will be highly appreciated.
Thank you. data-graph.JPG

Best Answer

Use the findchangepts (link) function (introduced in R2016a):
D = load('t1.mat');
t1 = double(D.t1);
[cp,res] = findchangepts(t1(:,3), 'MaxNumChanges',2, 'Statistic','std');
figure
plot(t1(:,1), t1(:,3))
hold on
plot(repmat(t1(cp,1),1,2)', repmat(ylim',1,numel(cp)), 'LineWidth',2)
hold off
grid
See the documentation for the function for detailks on the various options.