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);
yz = s-yu+(yr/2);
zt = t(yz(:) .* circshift(yz(:),[1 0]) <= 0);
per = 2*mean(diff(zt));
ym = mean(s);
fit = @(b,x) b(1) .* exp(b(2).*x) .* (sin(2*pi*x./b(3) + 2*pi/b(4))) + b(5);
fcn = @(b) norm(fit(b,t) - s);
B = fminsearch(fcn, [yr; -1; per; -1; ym])
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.
Best Answer