How to group and code 2 different parts of a graph.

4 views (last 30 days)
Hey,
I have a graph that repeats the same pattern over and over. In each 'period', there are 2 main parts to the graph, and I would like to compile a code that would allow me to separate these two parts so that I can then just call the name and work with that part of the graph. It's easier to explain using a picture, so here it is:
This repeats itself a bunch of times- here you can only see it repeat twice, but basically each 'period' has a phase 1 (black part) and a phase 2 (red part) and I'm just trying to separate the two so that I can then just call out 'phase 1' or 'phase 2' and it will refer to that part. One of the things I would like to find is the time (x axis) duration of each phase.
The actual graph looks like the second attached file (single red line on MATLAB), so you can see that for example using the gradient- positive or negative for the 2 phases, it might not work as phase 2 can sometimes have a small positive gradient.
Thank you very much!

Answers (1)

jonas
jonas on 24 Jul 2018
I happen to have your data from a previous question, so here is my suggestion:
I know that you already have the start value of the first change in slope, so you should remove the part of the signal prior to this point. Then you can use findpeaks to locate the peaks and throughs.
[~,p]=findpeaks(y,'MinPeakProminence',30);
[~,t]=findpeaks(y*-1,'MinPeakProminence',30);
figure;hold on
plot(x,y,'-',...
x(p),y(p),'o',...
x(t),y(t),'x');
Then you can just take the segments between each peak and through and structure this data however you wish.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!