invert.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. /*
  2. $Log$
  3. Revision 1.15 2004/06/26 03:50:14 markster
  4. Merge source cleanups (bug #1911)
  5. Revision 1.14 2003/02/12 13:59:15 matteo
  6. mer feb 12 14:56:57 CET 2003
  7. Revision 1.1.1.1 2003/02/12 13:59:15 matteo
  8. mer feb 12 14:56:57 CET 2003
  9. Revision 1.2 2000/01/05 08:20:39 markster
  10. Some OSS fixes and a few lpc changes to make it actually work
  11. * Revision 1.1 1996/08/19 22:32:00 jaf
  12. * Initial revision
  13. *
  14. */
  15. /* -- translated by f2c (version 19951025).
  16. You must link the resulting object file with the libraries:
  17. -lf2c -lm (in that order)
  18. */
  19. #include "f2c.h"
  20. #ifdef P_R_O_T_O_T_Y_P_E_S
  21. extern int invert_(integer *order, real *phi, real *psi, real *rc);
  22. #endif
  23. /* **************************************************************** */
  24. /* INVERT Version 45G */
  25. /* $Log$
  26. * Revision 1.15 2004/06/26 03:50:14 markster
  27. * Merge source cleanups (bug #1911)
  28. *
  29. * Revision 1.14 2003/02/12 13:59:15 matteo
  30. * mer feb 12 14:56:57 CET 2003
  31. *
  32. * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
  33. * mer feb 12 14:56:57 CET 2003
  34. *
  35. * Revision 1.2 2000/01/05 08:20:39 markster
  36. * Some OSS fixes and a few lpc changes to make it actually work
  37. *
  38. * Revision 1.1 1996/08/19 22:32:00 jaf
  39. * Initial revision
  40. * */
  41. /* Revision 1.3 1996/03/18 20:52:47 jaf */
  42. /* Just added a few comments about which array indices of the arguments */
  43. /* are used, and mentioning that this subroutine has no local state. */
  44. /* Revision 1.2 1996/03/13 16:51:32 jaf */
  45. /* Comments added explaining that none of the local variables of this */
  46. /* subroutine need to be saved from one invocation to the next. */
  47. /* Eliminated a comment from the original, describing a local array X */
  48. /* that appeared nowhere in the code. */
  49. /* Revision 1.1 1996/02/07 14:47:20 jaf */
  50. /* Initial revision */
  51. /* **************************************************************** */
  52. /* Invert a covariance matrix using Choleski decomposition method. */
  53. /* Input: */
  54. /* ORDER - Analysis order */
  55. /* PHI(ORDER,ORDER) - Covariance matrix */
  56. /* Indices (I,J) read, where ORDER .GE. I .GE. J .GE. 1.*/
  57. /* All other indices untouched. */
  58. /* PSI(ORDER) - Column vector to be predicted */
  59. /* Indices 1 through ORDER read. */
  60. /* Output: */
  61. /* RC(ORDER) - Pseudo reflection coefficients */
  62. /* Indices 1 through ORDER written, and then possibly read.
  63. */
  64. /* Internal: */
  65. /* V(ORDER,ORDER) - Temporary matrix */
  66. /* Same indices written as read from PHI. */
  67. /* Many indices may be read and written again after */
  68. /* initially being copied from PHI, but all indices */
  69. /* are written before being read. */
  70. /* NOTE: Temporary matrix V is not needed and may be replaced */
  71. /* by PHI if the original PHI values do not need to be preserved. */
  72. /* Subroutine */ int invert_(integer *order, real *phi, real *psi, real *rc)
  73. {
  74. /* System generated locals */
  75. unsigned i__2;
  76. integer phi_dim1, phi_offset, i__1, i__3;
  77. real r__1, r__2;
  78. /* Local variables */
  79. real save;
  80. integer i__, j, k;
  81. real v[100] /* was [10][10] */;
  82. /* Arguments */
  83. /* $Log$
  84. * Revision 1.15 2004/06/26 03:50:14 markster
  85. * Merge source cleanups (bug #1911)
  86. *
  87. * Revision 1.14 2003/02/12 13:59:15 matteo
  88. * mer feb 12 14:56:57 CET 2003
  89. *
  90. * Revision 1.1.1.1 2003/02/12 13:59:15 matteo
  91. * mer feb 12 14:56:57 CET 2003
  92. *
  93. * Revision 1.2 2000/01/05 08:20:39 markster
  94. * Some OSS fixes and a few lpc changes to make it actually work
  95. *
  96. * Revision 1.1 1996/08/19 22:32:00 jaf
  97. * Initial revision
  98. * */
  99. /* Revision 1.3 1996/03/29 22:03:47 jaf */
  100. /* Removed definitions for any constants that were no longer used. */
  101. /* Revision 1.2 1996/03/26 19:34:33 jaf */
  102. /* Added comments indicating which constants are not needed in an */
  103. /* application that uses the LPC-10 coder. */
  104. /* Revision 1.1 1996/02/07 14:43:51 jaf */
  105. /* Initial revision */
  106. /* LPC Configuration parameters: */
  107. /* Frame size, Prediction order, Pitch period */
  108. /* Parameters/constants */
  109. /* Local variables that need not be saved */
  110. /* Decompose PHI into V * D * V' where V is a triangular matrix whose */
  111. /* main diagonal elements are all 1, V' is the transpose of V, and */
  112. /* D is a vector. Here D(n) is stored in location V(n,n). */
  113. /* Parameter adjustments */
  114. --rc;
  115. --psi;
  116. phi_dim1 = *order;
  117. phi_offset = phi_dim1 + 1;
  118. phi -= phi_offset;
  119. /* Function Body */
  120. i__1 = *order;
  121. for (j = 1; j <= i__1; ++j) {
  122. i__2 = *order;
  123. for (i__ = j; i__ <= i__2; ++i__) {
  124. v[i__ + j * 10 - 11] = phi[i__ + j * phi_dim1];
  125. }
  126. i__2 = j - 1;
  127. for (k = 1; k <= i__2; ++k) {
  128. save = v[j + k * 10 - 11] * v[k + k * 10 - 11];
  129. i__3 = *order;
  130. for (i__ = j; i__ <= i__3; ++i__) {
  131. v[i__ + j * 10 - 11] -= v[i__ + k * 10 - 11] * save;
  132. }
  133. }
  134. /* Compute intermediate results, which are similar to RC's */
  135. if ((r__1 = v[j + j * 10 - 11], abs(r__1)) < 1e-10f) {
  136. goto L100;
  137. }
  138. rc[j] = psi[j];
  139. i__2 = j - 1;
  140. for (k = 1; k <= i__2; ++k) {
  141. rc[j] -= rc[k] * v[j + k * 10 - 11];
  142. }
  143. v[j + j * 10 - 11] = 1.f / v[j + j * 10 - 11];
  144. rc[j] *= v[j + j * 10 - 11];
  145. /* Computing MAX */
  146. /* Computing MIN */
  147. r__2 = rc[j];
  148. r__1 = min(r__2,.999f);
  149. rc[j] = max(r__1,-.999f);
  150. }
  151. return 0;
  152. /* Zero out higher order RC's if algorithm terminated early */
  153. L100:
  154. i__1 = *order;
  155. for (i__ = j; i__ <= i__1; ++i__) {
  156. rc[i__] = 0.f;
  157. }
  158. /* Back substitute for PC's (if needed) */
  159. /* 110 DO J = ORDER,1,-1 */
  160. /* PC(J) = RC(J) */
  161. /* DO I = 1,J-1 */
  162. /* PC(J) = PC(J) - PC(I)*V(J,I) */
  163. /* END DO */
  164. /* END DO */
  165. return 0;
  166. } /* invert_ */