Fit Underdamped oscillator to data

조회 수: 12 (최근 30일)
matheu Broom
matheu Broom 2015년 12월 2일
댓글: Star Strider 2015년 12월 2일
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