MATLAB: Damped cosine features in a exponential decay

@ star striderdamped cosine decay

Hi Guys,
I am trying to fit a decay curve which has some oscillatory feature in the decay. I tried to fit the data with the sum of a exponential with cosine function but didn't succed. Any help would be appreciated. I attached file here (column 1 is time and column 2 is the corresponding intensities).
Thanks and regards,

Best Answer

This produces a reasonable approximation, however the signal appears to be changing its frequency toward the end:
D = load('Ampf.mat');
t = D.Ampf(:,1);
s = D.Ampf(:,2);
s = detrend(s,7);
yu = max(s);
yl = min(s);
yr = (yu-yl); % Range of ‘y’
yz = s-yu+(yr/2);
zt = t(yz(:) .* circshift(yz(:),[1 0]) <= 0); % Find zero-crossings
per = 2*mean(diff(zt)); % Estimate period
ym = mean(s); % Estimate offset
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,t) - s); % Least-Squares cost function
B = fminsearch(fcn, [yr; -1; per; -1; ym]) % Minimise Least-Squares
xp = linspace(min(t),max(t));
yp = fit(B,xp);
figure
plot(t, s, '-p')
hold on
plot(xp, yp, '-r')
hold off
grid
It may be necessary to change ‘fit’ to something more closely approximating the process that produced your data. Retain the detrending step in the code.