home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast2.iso / c / lpc05b.zip / LPC2.C < prev    next >
C/C++ Source or Header  |  1992-05-22  |  2KB  |  95 lines

  1. /*
  2. *------------------------------------------------------------------------------
  3. *    file:    lpc2.c
  4. *    desct:    finding LPC coefficients with autocorrelation matrix 
  5. *    date:    19 May 1992
  6. *    by:    patrick ko shu pui
  7. *    ver:    v0.1b
  8. *------------------------------------------------------------------------------
  9. */
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include "matrix.h"
  13. #include "lpc.h"
  14.  
  15. /*
  16. *------------------------------------------------------------------------------
  17. *    funct:    normeqn_ac    
  18. *    desct:    create a normal equation with autocorrelation matrix 
  19. *    given:    a1 = allocated matrix (M x M) for autocorrelation matrix
  20. *        a2 = allocated matrix (M x 1)
  21. *        s = signal array
  22. *        nn= number of signal
  23. *    retrn:    nothing
  24. *------------------------------------------------------------------------------
  25. */
  26. int normeqn_ac( A1, A2, s, nn )
  27. MATRIX A1, A2;
  28. double *s;
  29. int nn;
  30. {
  31.     int    i, j, k, n, m;
  32.  
  33.     m = MatCol(A1);
  34.  
  35.     /*
  36.     * create autocorrelation matrix
  37.     */
  38.     for (i=0; i<m; i++)
  39.         {
  40.         A1[0][i] = 0.0;
  41.         for (n=0; n<nn-i; n++)
  42.             {
  43.             A1[0][i] += s[n] * s[n+i];
  44.             }
  45.         }
  46.     for (i=1; i<m; i++)
  47.     for (j=0; j<m; j++)
  48.         {
  49.         A1[i][j] = A1[0][abs(i-j)];
  50.         }
  51.  
  52.     for (k=1; k<m; k++)
  53.         {
  54.         A2[k-1][0] = A1[0][k];
  55.         }
  56.  
  57.     A2[m-1][0] = 0.0;
  58.     for (n=0; n<nn-m; n++)
  59.         {
  60.         A2[m-1][0] += s[n] * s[n+m];
  61.         }
  62. }
  63.  
  64. /*
  65. *------------------------------------------------------------------------------
  66. *    funct:    lpc2 (autocorrelation approach)
  67. *    desct:    lpc on one windows of data
  68. *    given:    A = allocated correlation matrix (M x M) M=order of LPC 
  69. *        B = allocated column vector (M x 1) 
  70. *        P = allocated column vector (M x 1) for PARCOR coefs
  71. *        E = allocated column vector (M+1 x 1) for residue power
  72. *        s = signal array
  73. *        nn = number of signals in s  
  74. *    retrn:    a column matrix of LPC coefficients    
  75. *------------------------------------------------------------------------------
  76. */ 
  77. MATRIX lpc2( A, B, s, nn, P, E )
  78. MATRIX A, B;
  79. double *s;
  80. int nn;
  81. MATRIX P, E;
  82. {
  83.     MATRIX X;
  84.     int i;
  85.  
  86.     normeqn_ac( A, B, s, nn );
  87.  
  88.     X = mat_lsolve_durbin( A, B, P, E );
  89.  
  90.     for (i=0; i<MatRow(X); i++)
  91.         X[i][0] *= -1.0;
  92.  
  93.     return (X);
  94.