Curve Fitting of large Data Measurement?

17 visualizaciones (últimos 30 días)
Hossam Amin
Hossam Amin el 23 de En. de 2022
Comentada: Sebastian el 21 de Ag. de 2023
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.
  2 comentarios
Ahmed raafat
Ahmed raafat el 23 de En. de 2022
I have download your data , and plot the second and third col
the repeating sequence leads to failing the curve fitting like this (Untitled.png)
you need to add another factor
Hossam Amin
Hossam Amin el 23 de En. de 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.

Iniciar sesión para comentar.

Respuesta aceptada

Star Strider
Star Strider el 24 de En. de 2022
Try this —
T1 = readtable('https://www.mathworks.com/matlabcentral/answers/uploaded_files/871405/Measurement%20Data.xlsx', '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);
figure
plot(x,yk,':b', 'LineWidth',1.5)
hold on
plot(xp,fit(s,xp), '--r')
hold off
grid
xlabel('Time')
ylabel('Amplitude')
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')
end
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 =
7.253749849224849e+00
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 =
6.954008038834750e+03
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.)
.
  26 comentarios
Star Strider
Star Strider el 30 de En. de 2022
As always, my pleasure!
Sebastian
Sebastian el 21 de Ag. de 2023
Hello Star Strider,
i´ve also tried to fit my messuered Data with your code. Unfortunately i do not receive any fitted curve. You write that the fit function should be varied. How do you proceed? Is it experience or can you give me an advice? I´ve uploaded my data as well.
Thank you in advance

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Conditional Mean Models en Help Center y File Exchange.

Productos


Versión

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by