How to plot an inflection point from a temperature profile data source?
9 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Robin Patel
le 13 Déc 2020
Commenté : Mathieu NOE
le 15 Déc 2020
Hello everyone,
I have been trying to plot a tangent to a curve. My data source is a temperature profile from a TCL (temperature control lab). It has two heaters and the data from the arduino Leonardo is collected every second. I have a set of 2000 data points from the curve. While plotting the inflection point, I am not able to get the tangent to the curve. I tried to smooth the curve but no proper tangent could be found. I have the file attached. Can anyone please help me?
0 commentaires
Réponse acceptée
Mathieu NOE
le 13 Déc 2020
hello
here you are
enjoy it !
% sliding avg method
temp_out = myslidingavg(temp, 50);
figure(1),
semilogx(time,temp,'b',time,temp_out,'r','linewidth',2);
% first derivative
dx = mean(diff(time));
dy = [0; diff(temp_out)./dx];
dy_out = myslidingavg(dy, 25);
figure(2),
plot(time,dy,'b',time,dy_out,'r','linewidth',2);
% point of inflection = fin peak of first derivative (but not the first
% sample transient)
ind = find(time>time(1)+5 & time<time(1)+200);
[peak,loc] = max(dy_out(ind));
time_inflection = time(ind(loc));
y_inflection = temp_out(ind(loc));
dy_inflection = dy_out(ind(loc));
% tangent equation
temp_tang = y_inflection+dy_inflection*(time-time_inflection);
figure(3),
plot(time,temp,'b',time,temp_out,'r',time(ind),temp_tang(ind),'--k','linewidth',2);
legend('raw temp','smoothed','tangent at inlection point');
4 commentaires
Mathieu NOE
le 15 Déc 2020
hello
so this is a modified code
I noticed that your time vector was not evenly sampled (diff(time) fluctuates with values between 0 and 1)
so first thing is resampling
then I add a bit of smoothing
and I prefered not to use the second derivative (data must be super smooth to use second derivative), but simply use the fact that the inflection point is the peak of the first derivative
code below :
clc
clear all
load data.mat
h1 = diff(temp,2);
K = temp(end);
% resample data because of uneven time samples (sometimes diff(time)
% contains zeros)
dt = 1;
t = min(time):dt:max(time);
temp = interp1(time,temp,t);
temp = myslidingavg(temp, 10);% smoothing
time = t;
%%%%%
L_index = find(temp>=0.1*K,1);
L = time(L_index);
T_index = find(time>=(1-exp(-1))*K,1);
T = time(T_index);
D = diff(temp)./dt;
D = myslidingavg(D, 10); % smoothing
figure,plot(D)
% inflex = find((diff(D)/dt)<0.5,1);
[peak,inflex] = max(D); % inflection point defined as max value of first derivative
% return
A = D(inflex)*time(inflex)-temp(inflex);
tangent = D(inflex)*time - A;
plot(time,temp);
hold on;
plot(time,tangent);
hold on;
plot(L,temp(L_index),'*');
plot(T,temp(T_index),'o')
plot(time,temp);
hold off;
xlim([0 max(time)])
ylim([30 max(temp)])
Plus de réponses (0)
Voir également
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!