Global Index (all files) (short | long) | Local Index (files in subdir) (short | long)
[alpha, Alpha] = partial_autocorr(x, nest);
alpha = partial_autocorr(x, lags); Inputs: x is the time series lags is 0:length(x) unless otherwise specified (I suggest lags = [0:20], or this will take a while) Outputs: alpha is the partial autocorrelation vector
function [alpha, Alpha] = partial_autocorr(x, nest); if ~all([length(size(x))==2 , ismember(1, size(x))]); error('x must be a vector'); end if nargin == 1; nest = (length(x)); end nest = nest(nest >= 0); nest = length(nest)-1; x = x(:); ntim = length(x); fi = repmat(NaN, [nest+1 1]); for i = 1:(nest+1); % size(x(1:(end-i+1))) % size(x((1+i-1):end)) fi(i) = x(1:(end-i+1))'*x((1+i-1):end)/(ntim-i); end alph = zeros(nest); alph(1,1) = fi(2)/fi(1); for i = 2:nest; alph(i,i) = fi(i+1)/fi(1) - alph(i-1,1:(i-1))*fi((i):-1:2)/fi(1); alph(i,i) = alph(i,i)/(1-alph(i-1,((i-1):-1:1))*fi((i):-1:2)/fi(1)); for j = 1:(i-1); alph(i,j) = alph(i-1,j)-alph(i,i)*alph(i-1,i-j); end; end; alpha = [1 diag(alph)']; if nargout == 2; Alpha = alph; end