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

  1. /*
  2. *------------------------------------------------------------------------------
  3. *    file:    lpc1.c
  4. *    desct:    finding LPC coefficients with covariance method
  5. *    date:    18 May 1992
  6. *    by:    patrick ko shu pui
  7. *    ver:    v0.1b
  8. *------------------------------------------------------------------------------
  9. */
  10. #include <stdio.h>
  11. #include "matrix.h"
  12. #include "lpc.h"
  13.  
  14.  
  15. /*
  16. *------------------------------------------------------------------------------
  17. *    funct:    normeqn_cv    
  18. *    desct:    create a normal equation for LPC eqn solving
  19. *    given:    a1 = allocated matrix (M x M)
  20. *        a2 = allocated matrix (M x 1)
  21. *        s = signal array
  22. *        nn= number of signal
  23. *    retrn:    nothing
  24. *------------------------------------------------------------------------------
  25. */
  26. int normeqn_cv( A1, A2, s, nn )
  27. MATRIX A1, A2;
  28. double *s;
  29. int nn;
  30. {
  31.     int    j, k, n, m;
  32.     double    temp;
  33.  
  34.     m = MatCol(A1);
  35.  
  36.     for (k=1; k<=m; k++)
  37.         {
  38.         for (j=0; j<=k; j++)
  39.         {
  40.         temp = 0.0;
  41.         for (n=0; n<nn; n++)
  42.             {
  43.             if (n-j < 0)
  44.                 continue;    
  45.             temp += s[n-j]*s[n-k];
  46.             }
  47.         if (j==0)
  48.             A2[k-1][0] = temp * -1.0;
  49.         else
  50.             A1[j-1][k-1] = A1[k-1][j-1] = temp;    
  51.         }
  52.         }
  53. }
  54.  
  55. /*
  56. *------------------------------------------------------------------------------
  57. *    funct:    lpc1
  58. *    desct:    lpc on one windows of data
  59. *    given:    A = allocated correlation matrix (M x M) M=order of LPC 
  60. *        B = allocated column vector (M x 1) 
  61. *        s = signal array
  62. *        nn = number of signals in s  
  63. *    retrn:    a column matrix of LPC coefficients    
  64. *------------------------------------------------------------------------------
  65. */ 
  66. MATRIX lpc1( A, B, s, nn )
  67. MATRIX A, B;
  68. double *s;
  69. int nn;
  70. {
  71.     normeqn_cv( A, B, s, nn );
  72.     return (mat_lsolve( A, B ));
  73.