How can I smooth this data before assigning a spline to it?

3 次查看(过去 30 天)
I am attempting to fit a cubic spline to rheological data which can be found in the attached excel file. I need to smooth the data so that when plotting the derivative of the function, the curve does not jump up and down. I guess I am tryin to remove noise and smooth into a better looking line. The code and generated figures are below:
clc;
clear all;
%% --Variable Assignment--
osc_strain = xlsread("ag_gel_data.xlsx",1,'A31:A51');
stor_mod = xlsread("ag_gel_data.xlsx",1,'K31:K51');
loss_mod = xlsread("ag_gel_data.xlsx",1,'L31:L51');
tb1 = table(osc_strain,stor_mod,loss_mod);
%% --Fit: Cubic Spline Interpolant--
[xData, yData] = prepareCurveData( osc_strain, stor_mod );
%% --Plotting-- (Figure 1)
lg1 = loglog(tb1,"osc_strain","stor_mod",'LineWidth',1);
hold on;
lg2 = loglog(tb1,"osc_strain","loss_mod",'LineWidth',1);
% Plot fit with data on a log-log scale.
xup = linspace(xData(1) , xData(end),1e4);
yup = interp1(xData,yData,xup,'pchip');
s = plot(xup,yup ,'--');
%% --Figure Stylization--
lg1.LineStyle = "-";
lg1.Color = "magenta";
lg1.Marker = ".";
lg1.MarkerSize = 16;
lg2.LineStyle = "-";
lg2.Color = "magenta";
lg2.Marker = "o";
lg2.MarkerSize = 4;
s.LineStyle = "--";
s.Color = "black";
xlabel('Oscillation Stress, \gamma (%)')
ylabel("G',G'' (Pa)")
legend('Storage Modulus','Loss Modulus','Cubic Spline','Location','NW')
%% --Plotting-- (Figure 2)
figure;
semilogx( xup,gradient(yup,xup),'-.','color',"black")
xlabel('Oscillation Stress, \gamma (%)')
ylabel("Differential Modulus, K (Pa)")
%% --Tabulate Differential Modulus--
K = gradient(yup,xup);
Ktable0 = [xup; K].';
Ktable = Ktable0(K>=0,:);
Figure 1:
The data I would like to smooth are both pink curves.
Figure 2:
Smoothing the pink curves would result in a smoother curve of the derivative which is plotted above.
Any suggestions? Thank you!

采纳的回答

Mathieu NOE
Mathieu NOE 2024-4-18
hello
you could do this
just using basic interpolation (in log scale) and the regular smoothdata (use your own spline smoother if you prefer)
%% --Variable Assignment--
osc_strain = xlsread("ag_gel_data.xlsx",1,'A31:A51');
stor_mod = xlsread("ag_gel_data.xlsx",1,'K31:K51');
loss_mod = xlsread("ag_gel_data.xlsx",1,'L31:L51');
% log scale interpolate and smooth the data
Npoints = 200;
osc_strain2 = logspace(log10(min(osc_strain)),log10(max(osc_strain)),Npoints);
Nsmooth = 40;
method = 'lowess';
stor_mod2 = interp1(log(osc_strain),log(stor_mod),log(osc_strain2));
stor_mod2 = smoothdata(stor_mod2,method,Nsmooth);
stor_mod2 = exp(stor_mod2);
loss_mod2 = interp1(log(osc_strain),log(loss_mod),log(osc_strain2));
loss_mod2 = smoothdata(loss_mod2,method,Nsmooth);
loss_mod2 = exp(loss_mod2);
%% --Plotting-- (Figure 1)
loglog(osc_strain,stor_mod,'*-','LineWidth',2);
hold on
loglog(osc_strain2,stor_mod2,'*-','LineWidth',1);
loglog(osc_strain,loss_mod,'*-','LineWidth',2);
loglog(osc_strain2,loss_mod2,'*-','LineWidth',1);
hold off
  6 个评论
Elias Kerstein
Elias Kerstein 2024-4-19
prepareCurveData is not a function I have written and I do not have a file in the folder named as such for MATLAB to call. I believe it is a built in function into the software or at least Curve Fitter application. Anyway, thank you for your help!

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Fit Postprocessing 的更多信息

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by