public static void calculateFromPrior ( LPC lpc , long [ ] R , LPC priorLPC ) { int coeffCount = lpc . order ; //calculate first iteration directly double [ ] A = lpc . rawCoefficients ; for ( int i = 0 ; i < coeffCount + 1 ; i ++ ) A [ i ] = 0.0 ; A [ 0 ] = 1 ; double E = R [ 0 ] ; int startIter = 0 ; if ( priorLPC != null && priorLPC . order < lpc . order ) { startIter = priorLPC . order ; E = priorLPC . rawError ; System . arraycopy ( priorLPC . rawCoefficients , 0 , A , 0 , startIter + 1 ) ; } //calculate remaining iterations if ( R [ 0 ] == 0 ) { for ( int i = 0 ; i < coeffCount + 1 ; i ++ ) A [ i ] = 0.0 ; } else { double [ ] ATemp = lpc . tempCoefficients ; for ( int i = 0 ; i < coeffCount + 1 ; i ++ ) ATemp [ i ] = 0.0 ; for ( int k = startIter ; k < coeffCount ; k ++ ) { double lambda = 0.0 ; double temp = 0.0 ; for ( int j = 0 ; j <= k ; j ++ ) { temp -= A [ j ] * R [ k - j + 1 ] ; } lambda = temp / E ; for ( int i = 0 ; i <= k + 1 ; i ++ ) { ATemp [ i ] = A [ i ] + lambda * A [ k + 1 - i ] ; } System . arraycopy ( ATemp , 0 , A , 0 , coeffCount + 1 ) ; E = ( 1 - lambda * lambda ) * E ; } } lpc . rawError = E ; }
Calculate an LPC using a prior order LPC s values to save calculations .