D = load('signals (1).mat');
Signal = D.Signal;
N = length(Signal);
t = linspace(0, 1, N) * N;
[pk,loc] = findpeaks(Signal, 'MinPeakHeight',1);
[trofs,trlocs] = findpeaks(-Signal);
ltidx = find(trlocs < loc, 1, 'last');
gtidx = find(trlocs > loc, 1, 'first');
Out{1} = {Signal(1:trlocs(ltidx)); Signal(trlocs(ltidx)+1:trlocs(gtidx)-1); Signal(trlocs(gtidx):end)};
Out{2} = {t(1:trlocs(ltidx)); t(trlocs(ltidx)+1:trlocs(gtidx)-1); t(trlocs(gtidx):N)};
figure
plot(Out{2}{1}, Out{1}{1}, 'r')
hold on
plot(Out{2}{2}, Out{1}{2}, 'g')
plot(Out{2}{3}, Out{1}{3}, 'b')
hold off
grid
Best Answer