Effacer les filtres
Effacer les filtres

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

4 vues (au cours des 30 derniers jours)
Elias Kerstein
Elias Kerstein le 17 Avr 2024
Commenté : Mathieu NOE le 19 Avr 2024
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!

Réponse acceptée

Mathieu NOE
Mathieu NOE le 18 Avr 2024
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 commentaires
Elias Kerstein
Elias Kerstein le 19 Avr 2024
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!
Mathieu NOE
Mathieu NOE le 19 Avr 2024
ok, tx for the explanation
all the best

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Fit Postprocessing dans Help Center et File Exchange

Produits


Version

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by