function pacf = pacfcomp(acf)
% PACFCOMP computes partial autocorrelation function
% PACFCOMP(ACF) computes the pacf corresponding to the input
%   ACF by using the Cholesky decomposition of the R matrix.
% ACF should be column vector of 1, rho(1), rho(2), ..., rho(n).

[n m] = size(acf);
acf1 = acf(2:n);
n = n-1;
[t,p] = chol(toeplitz(acf(1:n)));
if p>0
   q=p-1;
else 
   q=n; 
end
r = acf1(1:q);
for k=1:q
   r(k) = r(k)/t(k,k);
   if k<q 
      r((k+1):q) = r((k+1):q) - t(k,(k+1):q)'*r(k); 
   end
end
pacf = r./diag(t);
if p>0 pacf((q+1):n) = zeros((n-q),1); end