#This work is licensed under the
#Creative Commons Attribution-Share Alike 3.0 United States License.
#To view a copy of this license, visit
#http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter to
#Creative Commons,
#171 Second Street, Suite 300,
#San Francisco, California, 94105, USA.

INPUT autocorrelated, max_LPC;
OUTPUT "a list of LP coefficient lists, a list of error values";
VAR autocorrelated "autocorrelated";
VAR max_LPC "maximum LPC order";
VAR LP_coeff "LP coefficient";
VAR error "error";
k[0] <- autocorrelated[1] / autocorrelated[0];
LP_coeff[0][0] <- k[0];
error[0] <- autocorrelated[0] * (1 - k[0] ^ 2);
for i <- 1 to max_LPC {
    q[i] <- autocorrelated[i + 1] -
            sum j <- 0 to i - 1 {LP_coeff[(i - 1)][j] * autocorrelated[i - j]};
    k[i] <- q[i] / error[i - 1];
    for j <- 0 to i {
        LP_coeff[i][j] <- LP_coeff[(i - 1)][j] - (k[i] * LP_coeff[(i - 1)][(i - j - 1)]);
    }
    LP_coeff[i][i] <- k[i];
    error[i] <- error[i - 1] * (1 - k[i] ^ 2);
}
return LP_coeff,error;
