Fit Underdamped oscillator to data
12 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I have been trying to fit a under-damped oscillator equation to some data that I have. I have tried most of the online examples I can find with little success. My data can be visualized below and I have attached a file with the raw data as well.
0 comentarios
Respuestas (1)
Star Strider
el 2 de Dic. de 2015
This is not perfect but the best I can do:
D = load('matheu Broom rate0.2.mat');
t = D.t;
x = D.x;
[xu,ixu] = max(x);
[xl,ixl] = min(x);
xr = (xu-xl); % Range of ‘x’
xm = mean(x); % Estimate d-c offset
xz = x - xm; % Subtract d-c Offset
zt = t(xz .* circshift(xz,[-1 0]) <= 0); % Find zero-crossings
per = 2*mean(diff(zt)); % Estimate period
objfcn = @(b,x) b(1).*exp(b(2).*x).*(sin(2*pi*x./b(3) + 2*pi/b(4))) + b(5); % Function to fit
ssecf = @(b) sum((objfcn(b,t) - x).^2); % Sum-Of-Squares cost function
init_est = [xr; -0.01; per; t(ixl)/per; xm]; % Initial Parameter Estimates
[s,sse] = fminsearch(ssecf, init_est) % Minimise Sum-Of-Squares
tp = linspace(min(t),max(t), 250);
figure(1)
plot(t,x,'b', tp,objfcn(s,tp), 'r')
grid
axis([xlim 0.3 0.7])
text(0.006, 0.62, sprintf('x(t) = %.3f\\cdote^{%.3f\\cdott}\\cdotsin(2\\pit\\cdot%.3f + %.3f) + %.3f', s(1:2), 1/s(3), 2*pi/s(4), s(5)))
2 comentarios
Ver también
Categorías
Más información sobre Get Started with Curve Fitting Toolbox en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!