Fit Underdamped oscillator to data

12 次查看(过去 30 天)
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.

回答(1 个)

Star Strider
Star Strider 2015-12-2
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 个评论
matheu Broom
matheu Broom 2015-12-2
WOW thank you so much I was pulling my hair out over this problem. This will help me so much :)
Star Strider
Star Strider 2015-12-2
My pleasure!
If it solved your problem, please Accept my Answer

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Get Started with Curve Fitting Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by