Find specific points of increase within multiple different data sets
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
pkll201
el 22 de Mayo de 2024
Comentada: Mathieu NOE
el 24 de Mayo de 2024
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
Lindices=find(Lchange);
%Calculate change in L between these indices
figure;
plot(Ldata);
xline(Lindices);
Lpoints=Lindices;
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)];
number=Ldiff>40;
Ldiff(number)=NaN;
indices=~isnan(Ldiff);
Lindices2=Lindices(indices);
Lpoints=Lindices2
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!
0 comentarios
Respuesta aceptada
Mathieu NOE
el 22 de Mayo de 2024
hello
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
load('example_data.mat')
% 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');
plot(xaxis,data,xaxis(locsn),data(locsn),'dk',xaxis(locsp),data(locsp),'dr');
legend('data','start points','end points','Location','NorthEastOutside');
2 comentarios
Más respuestas (0)
Ver también
Categorías
Más información sobre Logical en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!