-
Notifications
You must be signed in to change notification settings - Fork 16
/
gsdffit.m
65 lines (55 loc) · 1.61 KB
/
gsdffit.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
function [para,resnorm,residual, exitflag] = gsdffit(xcor,lagtime,freq,nfit)
% Matlab function that does similar stuff as gsdf_fit.c. Fitting the narrow-banded cross-correlation
% function with a five - parameter wavelet
% A=para(1); is the amplitude
% w=para(2); is the oemga, 2*pi/T
% sigma=para(3); is the frequency band width
% tp=para(4); is the phase delay
% tg=para(5); is the group delay
% Written by Ge Jin
% Lamont, Colubmia University
% April, 2012
% Modified by Ge Jin for industry data
% Conocophillips
% June, 2012
xcor = xcor(:);
lagtime = lagtime(:);
T=1/freq;
N=length(xcor);
N=ceil(N/2);
maxi=find(xcor==max(xcor),1);
delta=lagtime(2)-lagtime(1);
fitN=round(nfit*T/delta);
if maxi-fitN <= 0 || maxi+fitN > length(xcor)
para = zeros(5,1);
resnorm = 0;
residual = 0;
exitflag = -8;
return;
end
cutxcor = xcor(maxi-fitN:maxi+fitN);
taxis = lagtime(maxi-fitN:maxi+fitN);
w = 2*pi/T;
maxi=find(cutxcor==max(cutxcor),1);
t0=taxis(maxi);
amp0=cutxcor(maxi);
cutxcor_norm=cutxcor./amp0;
para0=[1,w,w*.1,t0,t0];
paraL=[0.5,w*.5,0,t0-T,taxis(1)];
paraH=[2,w*2,w*.1*10,t0+T,taxis(end)];
options=optimset('Display','off');
[para,resnorm,residual, exitflag] = lsqcurvefit(@gsdfwavelet,para0, ...
taxis,cutxcor_norm,paraL,paraH,options);
% [para,resnorm,residual, exitflag] = lsqcurvefit(@gsdfwavelet,para0,taxis,cutxcor_norm);
para(1)=para(1)*amp0;
resnorm = resnorm*amp0^2;
residual = residual*amp0;
%
% figure(99)
% clf
% hold on
% plot(taxis,cutxcor);
% plot(taxis,gsdfwavelet(para,taxis),'r--')
% pause;
end