function a = linpred( x, N );
% function a = linpred( x, N );
% 
% Linear Prediction Coefficients by Autocorrelation Method 
%
% x(k)  ~  a(1) * x(k-1) + a(2) * x(k-2) + ... + a(N) * x(k-N)
%
% Author:  Markus Hauenstein
% Date:    01.01.2002
% Contact: www.markus-hauenstein.de

x = x(:);
L = length( x );

if N > L,
  error( 'linpred: input signal too short' )
end

autoCorr = zeros(N+1,1);

for i = 0:N,
  autoCorr(i+1) = x(1:L-i)' * x(1+i:L);
end

r0 = autoCorr(2:N+1);
R = toeplitz( autoCorr(1:N) );

% Levinson-Durbin Recursion only efficient for high-order predictors

a = inv(R) * r0;
 