Find specific points of increase within multiple different data sets

5 次查看(过去 30 天)
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!

采纳的回答

Mathieu NOE
Mathieu NOE 2024-5-22
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');

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Multirate Signal Processing 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by