LINE Solver
MATLAB API documentation
Loading...
Searching...
No Matches
trace_gamma.m
1function [GAMMA, RHO0, RESIDUALS] = trace_gamma(T, limit)
2% Estimates the auto-correlation decay rate of a trace.
3% Input:
4% - T: the trace
5% - limit: maximum lag considered (optional, default = 1000)
6% Output:
7% - GAMMA: autocorrelation decay rate
8
9if nargin < 2
10 limit = 1000;
11end
12
13M1 = mean(T);
14M2 = mean(T.^2);
15
16lag = 1:min(limit,length(T));
17rho = trace_acf(T, lag);
18VAR = M2-M1^2;
19SCV = VAR/M1^2;
20RHO0 = 1/2 * (1 - 1/SCV);
21
22opt = statset('nlinfit');
23opt.MaxIter = 1e5;
24opt.Display = 'off';
25opt.RobustWgtFun = 'fair';
26try
27 [GAMMA,RESIDUALS] = nlinfit(lag, rho, @geometric, 0.99, opt);
28catch err
29 warning('Non linear regression for ACF decay rate failed, trying lsqcurvefit');
30 GAMMA = lsqcurvefit(@geometric, 0.99, lag, rho, -1, 1);
31end
32
33 function rhok = geometric(gamma,k)
34 rhok = (RHO0 * gamma.^k)';
35 end
36
37end