How to plot an inflection point from a temperature profile data source?

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?

 Risposta accettata

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 Commenti

Thank you very much for your response. I checked the file and is pretty much what I wanted.
I tried by taking the second derivative of the "temp" file and then using fzero command to find which point the slope is zero. I get a set of repeated values since it is the second derivative (mostly zero)s. I used this video as a reference "https://www.youtube.com/watch?v=s-tF_iO4CzU&t=1375s". I figured out the logic used but seems that it is not working since I have a temperature profile which is not a smooth curve.
I want to learn the tangent method used for calculating the transfer function of a PT-2 system. So, I want the tangent to touch the x-axis so that I can find the time constants and hence compute the transfer function of the system. I have recalculated the trial and computed the new data. Can you please guide me how can I do this?
hello
this is a new code
I used the second part of the curve to compute the time constant
it is based on the slope measured at the inflection point, and divided by the delta of temperature (final - initial)
I am not sure what you want to do with the tangent crossing the y axis (at y = 0)
load('data.mat')
% sliding avg method
temp_out = myslidingavg(temp, 25);
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)+500 & time<time(1)+700);
[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);
% find time point where tangent crosses the y axis (y = 0)
% 0 = y_inflection+dy_inflection*(time_zero-time_inflection);
time_zero = round(time_inflection - y_inflection/dy_inflection);
ind2 = find(time>time_zero & time<time(1)+700);
figure(3),
plot(time,temp,'b',time,temp_out,'r',time(ind2),temp_tang(ind2),'--k','linewidth',2);
legend('raw temp','smoothed','tangent at inlection point');
%% time constant computation
% NB : input step amplitude is unknown but we can scale the data
% second step has a temperature amplitude of 61° - 36.5° = 24.5 °
% so time constant = computed slope (dy) at inflection point divided by temperature amplitude
Tc = dy_inflection/(61 - 36.5) % unit : 1/s
Thank you for your response once again!
I checked the code and it seems pretty well to what I wanted. I tried with new data file as data.mat and the following code with Code.txt file but I can not figure out how can I let the tangent to the x-axis. I think there is some small mistake which I cannot figure out. Can you please help me?
Thank you for the help in advance.
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)])

Accedi per commentare.

Più risposte (0)

Prodotti

Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by