public static double[] lsf2lpc(double[] lsf){
  MathUtils.quickSort(lsf);
  int P=lsf.length;
  int half_order=P / 2;
  int i, j;
  double xf, xx;
  double[] a=new double[P / 2 + 1];
  double[] a1=new double[P / 2 + 1];
  double[] a2=new double[P / 2 + 1];
  double[] b=new double[P / 2 + 1];
  double[] b1=new double[P / 2 + 1];
  double[] b2=new double[P / 2 + 1];
  double[] p=new double[P / 2];
  double[] q=new double[P / 2];
  double[] oneMinusA=new double[P + 1];
  oneMinusA[0]=1.;
  if ((lsf[0] <= 0.0) || (lsf[0] >= 0.5)) {
    throw new IllegalArgumentException("LSFs out of bounds; lsf[0] = " + lsf[0]);
  }
  for (i=1; i < P; i++) {
    if (lsf[i] <= lsf[i - 1])     throw new IllegalArgumentException("nonmonotonic LSFs");
    if ((lsf[i] <= 0.0) || (lsf[i] >= 0.5))     throw new IllegalArgumentException("LSFs out of bounds; lsf[" + i + "] = "+ lsf[i]);
  }
  for (i=0; i < half_order; i++) {
    p[i]=-2 * Math.cos(MathUtils.TWOPI * lsf[2 * i]);
    q[i]=-2 * Math.cos(MathUtils.TWOPI * lsf[2 * i + 1]);
  }
  xf=0.0;
  for (i=0; i <= P; i++) {
    if (i == 0)     xx=1.0;
 else     xx=0.0;
    a[0]=xx + xf;
    b[0]=xx - xf;
    xf=xx;
    for (j=0; j < half_order; j++) {
      a[j + 1]=a[j] + p[j] * a1[j] + a2[j];
      b[j + 1]=b[j] + q[j] * b1[j] + b2[j];
      a2[j]=a1[j];
      a1[j]=a[j];
      b2[j]=b1[j];
      b1[j]=b[j];
    }
    if (i > 0)     oneMinusA[i]=0.5 * (a[half_order] + b[half_order]);
  }
  return oneMinusA;
}

public static double [ ] lsf2lpc ( double [ ] lsf ) { MathUtils . quickSort ( lsf ) ; int P = lsf . length ; int half_order = P / 2 ; int i , j ; double xf , xx ; double [ ] a = new double [ P / 2 + 1 ] ; double [ ] a1 = new double [ P / 2 + 1 ] ; double [ ] a2 = new double [ P / 2 + 1 ] ; double [ ] b = new double [ P / 2 + 1 ] ; double [ ] b1 = new double [ P / 2 + 1 ] ; double [ ] b2 = new double [ P / 2 + 1 ] ; double [ ] p = new double [ P / 2 ] ; double [ ] q = new double [ P / 2 ] ; double [ ] oneMinusA = new double [ P + 1 ] ; oneMinusA [ 0 ] = 1. ; if ( ( lsf [ 0 ] <= 0.0 ) || ( lsf [ 0 ] >= 0.5 ) ) { throw new IllegalArgumentException ( "LSFs out of bounds; lsf[0] = " + lsf [ 0 ] ) ; } for ( i = 1 ; i < P ; i ++ ) { if ( lsf [ i ] <= lsf [ i - 1 ] ) throw new IllegalArgumentException ( "nonmonotonic LSFs" ) ; if ( ( lsf [ i ] <= 0.0 ) || ( lsf [ i ] >= 0.5 ) ) throw new IllegalArgumentException ( "LSFs out of bounds; lsf[" + i + "] = " + lsf [ i ] ) ; } for ( i = 0 ; i < half_order ; i ++ ) { p [ i ] = - 2 * Math . cos ( MathUtils . TWOPI * lsf [ 2 * i ] ) ; q [ i ] = - 2 * Math . cos ( MathUtils . TWOPI * lsf [ 2 * i + 1 ] ) ; } xf = 0.0 ; for ( i = 0 ; i <= P ; i ++ ) { if ( i == 0 ) xx = 1.0 ; else xx = 0.0 ; a [ 0 ] = xx + xf ; b [ 0 ] = xx - xf ; xf = xx ; for ( j = 0 ; j < half_order ; j ++ ) { a [ j + 1 ] = a [ j ] + p [ j ] * a1 [ j ] + a2 [ j ] ; b [ j + 1 ] = b [ j ] + q [ j ] * b1 [ j ] + b2 [ j ] ; a2 [ j ] = a1 [ j ] ; a1 [ j ] = a [ j ] ; b2 [ j ] = b1 [ j ] ; b1 [ j ] = b [ j ] ; } if ( i > 0 ) oneMinusA [ i ] = 0.5 * ( a [ half_order ] + b [ half_order ] ) ; } return oneMinusA ; }
convert lsf frequencies into lpc coefficients . the analysis filter may be reconstructed : a ( z ) = 1 / 2 [ p ( z ) + q ( z ) ]
