Fit Underdamped oscillator to data

13 views (last 30 days)
matheu Broom
matheu Broom on 2 Dec 2015
Commented: Star Strider on 2 Dec 2015
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.

Answers (1)

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

Sign in to comment.

Categories

Find more on Get Started with Curve Fitting Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!