PageRenderTime 46ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/tags/R2008-02-16/extra/tsa/inst/rc2ar.m

#
MATLAB | 91 lines | 31 code | 10 blank | 50 comment | 5 complexity | 92ce0f013f5f3e22f445c53756c7f580 MD5 | raw file
Possible License(s): GPL-2.0, BSD-3-Clause, LGPL-2.1, GPL-3.0, LGPL-3.0
  1. function [MX,res,arg3,acf] = rc2ar(rc);
  2. % converts reflection coefficients into autoregressive parameters
  3. % uses the Durbin-Levinson recursion for multiple channels
  4. % function [AR,RC,PE,ACF] = rc2ar(RC);
  5. % function [MX,PE] = rc2ar(RC);
  6. %
  7. % INPUT:
  8. % RC reflection coefficients
  9. %
  10. % OUTPUT
  11. % AR autoregressive model parameter
  12. % RC reflection coefficients (= -PARCOR coefficients)
  13. % PE remaining error variance (relative to PE(1)=1)
  14. % MX transformation matrix between ARP and RC (Attention: needs O(p^2) memory)
  15. % arp=MX(:,K*(K-1)/2+(1:K));
  16. % rc =MX(:,(1:K).*(2:K+1)/2);
  17. %
  18. % All input and output parameters are organized in rows, one row
  19. % corresponds to the parameters of one channel
  20. %
  21. % see also ACOVF ACORF DURLEV AR2RC
  22. %
  23. % REFERENCES:
  24. % P.J. Brockwell and R. A. Davis "Time Series: Theory and Methods", 2nd ed. Springer, 1991.
  25. % S. Haykin "Adaptive Filter Theory" 3rd ed. Prentice Hall, 1996.
  26. % M.B. Priestley "Spectral Analysis and Time Series" Academic Press, 1981.
  27. % W.S. Wei "Time Series Analysis" Addison Wesley, 1990.
  28. % $Id: rc2ar.m 4585 2008-02-04 13:47:45Z adb014 $
  29. % Copyright (c) 1996-2002,2007 by Alois Schloegl <a.schloegl@ieee.org>
  30. % This function is part of the TSA-toolbox
  31. % http://www.dpmi.tu-graz.ac.at/~schloegl/matlab/tsa/
  32. % This library is free software; you can redistribute it and/or
  33. % modify it under the terms of the GNU Library General Public
  34. % License as published by the Free Software Foundation; either
  35. % Version 2 of the License, or (at your option) any later version.
  36. %
  37. % This library is distributed in the hope that it will be useful,
  38. % but WITHOUT ANY WARRANTY; without even the implied warranty of
  39. % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  40. % Library General Public License for more details.
  41. %
  42. % You should have received a copy of the GNU Library General Public
  43. % License along with this library; If not, see <http://www.gnu.org/licenses/>.
  44. % Inititialization
  45. [lr,lc]=size(rc);
  46. res=[ones(lr,1) zeros(lr,lc)];
  47. if nargout<3 % needs O(p^2) memory
  48. MX=zeros(lr,lc*(lc+1)/2);
  49. idx=0;
  50. % Durbin-Levinson Algorithm
  51. for K=1:lc,
  52. MX(:,idx+K)=rc(:,K);%(AutoCov(:,K+1)-d)./res(:,K);
  53. %rc(:,K)=arp(:,K);
  54. if K>1 %for compatibility with OCTAVE 2.0.13
  55. MX(:,idx+(1:K-1))=MX(:,(K-2)*(K-1)/2+(1:K-1))-MX(:,(idx+K)*ones(K-1,1)).*MX(:,(K-2)*(K-1)/2+(K-1:-1:1));
  56. end;
  57. res(:,K+1) = res(:,K).*(1-abs(MX(:,idx+K)).^2);
  58. idx=idx+K;
  59. end;
  60. %arp=MX(:,K*(K-1)/2+(1:K));
  61. %rc =MX(:,(1:K).*(2:K+1)/2);
  62. ACF=cumprod(ones(lr,lr)-rc.^2,2);
  63. else % needs O(p) memory
  64. ar=zeros(lr,lc);
  65. acf=[ones(lr,1),zeros(lr,lc)];
  66. %rc=RC; %zeros(lr,lc-1);
  67. % Durbin-Levinson Algorithm
  68. for K=1:lc,
  69. acf(:,K) = -sum(acf(:,K:-1:1).*ar(:,1:K),2);
  70. ar(:,K) = rc(:,K);
  71. if K>1, %for compatibility with OCTAVE 2.0.13
  72. ar(:,1:K-1) = ar(:,1:K-1) - ar(:,K*ones(K-1,1)) .* ar(:,K-1:-1:1);
  73. end;
  74. res(:,K+1) = res(:,K) .* (1-abs(ar(:,K)).^2);
  75. end;
  76. ACF=cumprod(ones(lr,lc)-rc.^2,2);
  77. % assign output arguments
  78. arg3=res;
  79. res=rc;
  80. MX=ar;
  81. end; %if