home *** CD-ROM | disk | FTP | other *** search
/ Shareware 1 2 the Maxx / sw_1.zip / sw_1 / PROGRAM / LPC05B.ZIP / CEPSTRUM.C next >
C/C++ Source or Header  |  1992-05-22  |  919b  |  46 lines

  1. #include <stdio.h>
  2. #include <math.h>
  3. #include "matrix.h"
  4. #include "lpc.h"
  5.  
  6. /*
  7. *-----------------------------------------------------------------------------
  8. *    funct:    cepstrum
  9. *    desct:    derive LPC cepstrum coefficients from LPC coefficients
  10. *    given:    A = LPC vector of coefficients (n x 1)
  11. *        E = residue power 
  12. *    retrn:    cepstrum matrix (dim n+1 x 1)
  13. *-----------------------------------------------------------------------------
  14. */
  15. MATRIX cepstrum( A, E )
  16. MATRIX A;
  17. double E;
  18. {
  19.     int    i, i1, n, k, k1, ik, kk;
  20.     MATRIX    C;
  21.     double    csum;
  22.  
  23.     n = MatRow(A);
  24.     C = mat_creat( n+1, 1, UNDEFINED );
  25.  
  26.     C[0][0] = 0.5 * log(E);
  27.     C[1][0] = -A[0][0];
  28.  
  29.     for (i=2; i<=n; i++)
  30.         {
  31.         i1 = i + 1;
  32.         kk = i - 1;
  33.         csum = 0.0;
  34.         for (k=1; k<=kk; k++)
  35.             {
  36.             ik = i - k;
  37.             k1 = k + 1;
  38.             csum += k * C[k1-1][0] * A[ik-1][0];
  39.             }
  40.         csum /= i;
  41.         C[i1-1][0] = -(A[i-1][0] + csum);
  42.         }
  43.  
  44.     return (C);
  45. }
  46.