How do i find points where slope is zero.

28 views (last 30 days)
I dealing with data from an experiment and i need to find local equivalents or the points where slope is zero.
I tried it in the code as you can see in graph (the red circles), I could find a couple, but the rest dont have the slope exactly zero.
So anyone know if its possible to find the top point or the equivalents.
clc
gogn = xlsread(fullfile('C:\Users\ebben\Dropbox\HR\Eðlisfræði\Verklegt\Top','TOP_gogn.xlsx'));
angle = gogn(:,3); % Exstracting data from excel doc
time = gogn(:,4);
scl = find(angle==min(angle));
time = time(scl:numel(time)); % deleting data in beginning thats not important
angle = angle(scl:numel(angle));
stilling = angle(numel(angle)); % Adjusting to fit x-axis = 0
angle = angle + abs(stilling);
plot(time,angle,'Linewidth',1.5) % plotting and designing graph
xlabel('Time[sec]');
ylabel('Angle[rad]');
grid
hold on
dx_time1 = mean(diff(time)); % trying to find where slope is zero
dy_angle = gradient(angle,dx_time1);
n=1;
slope_angle = dy_angle(1)
for i=1:numel(time)
slope_angle = dy_angle(i);
if slope_angle == 0
inti(n)=i;
n=n+1;
end
end
for i=1:numel(vec)
% for lykkja sem plottar upp punktana á graf
plot(time(vec(i)),angle(vec(i)),'rO','markersize',10)
hold on
end
Capture.JPG

Accepted Answer

Star Strider
Star Strider on 14 Oct 2019
If you want to use the gradient function to find the inflection points, and since you are dealing with finite-precision values, one approach would be to use linspace and interp1 to create a much higher resolution ‘time’ vector, and then interpolate the ‘angle’ vector to it.
Also, using a tolerance rather than a specific value here:
if slope_angle <= 1E-4
or something similar, might be more appropriate.
However, since you want to find the maxima and minima, the easiest approach would be to use the findpeaks function on the signal and its negative value (to find the minima), or the islocalmax and islocalmin functions to do the same.
It depends on what approach you want to take, and the constraints of your data and data processing.
  2 Comments
Eirikur Bernharðsson
Eirikur Bernharðsson on 15 Oct 2019
MVP. didnt know about the findpeaks function.
Star Strider
Star Strider on 15 Oct 2019
Neither did I a few years ago!

Sign in to comment.

More Answers (0)

Categories

Find more on Preprocessing Data in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!