Clear Filters
Clear Filters

Find specific points of increase within multiple different data sets

19 views (last 30 days)
I am trying to write a function to identify the points as shown on this graph (not ones crossed with red).
However, I can't seem to get it to only identify the start and finish of the increase of data. Most of them are identifying points in between which are not wanted (but not at every point). This is what I have written so far:
function [Lpoints] = findpoints(Ldata)
%Calculate the point of abrupt changes in Ldata
Lchange = ischange(Ldata,'linear','Threshold',500);
%Find indices of changes
%Calculate change in L between these indices
I have tried to exclude the central points by adding this (and adjusting the Ldiff>x parameter) to only get the start of the increase but this seems to eliminate the more subtle increases, and it would be preferred to get both points.
Lvalues = Ldata(Lindices);
Ldiff = [0; diff(Lvalues)];
I have attached a selection of sample data, and it would be ideal to get something that works across the board. I may be taking the wrong approach, so any suggestions of how to go about this would be great!

Accepted Answer

Mathieu NOE
Mathieu NOE on 22 May 2024 at 15:35
try this... hope it helps - though I did not draw vertical lines but you have to start and ending points coordinates.
I tested the code on the 10 examples data provided
% whos
% Name Size Bytes Class Attributes
% example1 1096x1 8768 double
% example10 486x1 3888 double
% example2 1327x1 10616 double
% example3 1116x1 8928 double
% example4 690x1 5520 double
% example5 642x1 5136 double
% example6 720x1 5760 double
% example7 834x1 6672 double
% example8 655x1 5240 double
% example9 790x1 6320 double
data = example1;
% high pass filter the data first
[b,a] = butter(2,0.01,'high');
datad = filtfilt(b,a,data);
% find start , end points = positive and negative peaks of the high pass
% filtered data (with islocalmax)
minpeakdist = 50;
min_amplitude= max(abs(datad))/10;
tf=islocalmax(datad,'MinSeparation',minpeakdist, 'MinProminence', 1);
locsp = find(tf);
locsp = locsp(datad(locsp)>min_amplitude);
tf=islocalmax(-datad,'MinSeparation',minpeakdist, 'MinProminence', 1);
locsn = find(tf);
locsn = locsn(datad(locsn)<-min_amplitude);
locsn(locsn>locsp(end)) = []; % remove "start" point wich is now followed by "end" point at the end of the data
% plot
xaxis = 1:numel(data);
% plot(xaxis,datad,xaxis(locsn),datad(locsn),'dk',xaxis(locsp),datad(locsp),'dr');
legend('data','start points','end points','Location','NorthEastOutside');

More Answers (0)




Community Treasure Hunt

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

Start Hunting!