## Copyright (C) 2013 Leonardo Araujo
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see .
## -*- texinfo -*-
## @deftypefn {Function File} {[@var{a}, @var{g}] = } lpc (@var{x}, @var{p})
## @deftypefnx {Function File} {[@var{a}, @var{g}] = } lpc (@var{x})
## @deftypefnx {Function File} {@var{a} = } lpc (@var{x}, @var{p})
## @deftypefnx {Function File} {@var{a} = } lpc (@var{x})
##
## Determines the forward linear predictor by minimizing the prediction error
## in the least squares sense. Use the Durbin-Levinson algorithm to solve
## the Yule-Walker equations obtained by the autocorrelation of the input
## signal.
##
## @var{x} is a data vector used to estimate the lpc model of @var{p}-th order,
## given by the prediction polynomial @code{@var{a} = [1 @var{a}(2) ...
## @var{a}(@var{p}+1)]}. If @var{p} is not provided, @code{length(@var{p}) - 1}
## is used as default.
##
## @var{x} might also be a matrix, in which case each column is regarded as a
## separate signal. @code{lpc} will return a model estimate for each column of
## @var{x}.
##
## @var{g} is the variance (power) of the prediction error for each signal in
## @var{x}.
##
## @end deftypefn
## @seealso{aryule,levinson}
function [a, g] = lpc (x, p)
if (nargin < 1 || nargin > 2)
print_usage;
elseif (! isrow (x) && rows (x) < 2)
error( "lpc: rows(X) must be >1" );
elseif (nargin == 2 && (! isscalar (p) || fix (p) != p || p > length (x) - 1
|| p < 1))
error( "lpc: P must be an integer >0 and