Curve Fitting of large Data Measurement?

20 views (last 30 days)
I have a measurement data which I have uploded, and I am trying to utilize a function to fit the measurement with a damping sinusoidal order of the measurement dataset. But without success. Can anyone please point me in the right direction? The curve fitting app in matlab is unable to make it. I tried a damping function in it, it didn't work. Also the lsqcurvefit nothing is working. I tried a sine function with not success too.
Thanks in advance.
Hossam Amin
Hossam Amin on 23 Jan 2022
Maybe I forgot to mention. The data is composed of speed and torque measurements.
You would need to add the x-axis at time using linspace command.

Sign in to comment.

Accepted Answer

Star Strider
Star Strider on 24 Jan 2022
Try this —
T1 = readtable('', 'VariableNamingRule','preserve');
format longE
x = T1.Time;
yc(:,1) = T1.('Torque[Nm]');
yc(:,1) = smoothdata(yc(:,1), 'sgolay', 250); % Remove Some Noise To Make The Fit Easier
yc(:,2) = T1.('RPM[1/min]');
for k = 1:size(yc,2)
yk = yc(:,k);
y = yk;
% y = detrend(y);
ym = mean(y); % Estimate offset
y = y - ym;
yu = max(y);
yl = min(y);
yr = (yu-yl); % Range of ‘y’
yz = y-yu+(yr/2);
zci = @(v) find(diff(sign(v))); % Returns Approximate Zero-Crossing Indices Of Argument Vector
zt = x(zci(y));
per = 2*mean(diff(zt)); % Estimate period
fit = @(b,x) b(1) .* exp(b(2).*x) .* (sin(2*pi*x./b(3) + 2*pi/b(4))) + b(5); % Objective Function to fit
fcn = @(b) norm(fit(b,x) - yk); % Least-Squares cost function
[s,nmrs] = fminsearch(fcn, [yr; -10; per; -1; ym]) % Minimise Least-Squares
xp = linspace(min(x),max(x), 500);
plot(x,yk,':b', 'LineWidth',1.5)
hold on
plot(xp,fit(s,xp), '--r')
hold off
legend('Original Data', 'Fitted Curve')
text(0.1*max(xlim),0.7*min(ylim), sprintf('$y = %.3f\\cdot e^{%.3E\\cdot x}\\cdot sin(2\\pi\\cdot x\\cdot %.3E%+.3f) %+.4f$', [s(1:2); 1./s(3:4); s(5)]), 'Interpreter','latex')
Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 7.253750
s = 5×1
1.0e+00 * 2.054070381848720e-01 -1.211851657300356e-04 3.381604644061252e+03 -1.273801702648572e+00 -6.517492492161443e-03
nmrs =
Exiting: Maximum number of function evaluations has been exceeded - increase MaxFunEvals option. Current function value: 6954.008039
s = 5×1
1.0e+00 * 5.565560752001775e+02 -3.434517388063775e-04 3.862185655766382e+03 -6.747881574969156e-01 3.384702768264112e+02
nmrs =
Because it uses the least-square approach, the fit is dominated by the highest peaks, and fits them preferentially. Experiment with tweaking ‘fit’ to get different results. (This uses a slightly-modified version of my original code to process and fit the data.)

Sign in to comment.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!