]> Creatis software - CreaPhase.git/blob - octave_packages/tsa-4.2.4/rc2ar.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / tsa-4.2.4 / rc2ar.m
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
29 %       $Id: rc2ar.m 5090 2008-06-05 08:12:04Z schloegl $
30 %       Copyright (c) 1996-2002,2007,2008 by Alois Schloegl <a.schloegl@ieee.org>
31 %       This function is part of the TSA-toolbox
32 %       http://www.dpmi.tu-graz.ac.at/~schloegl/matlab/tsa/
33 %
34 %    This program is free software: you can redistribute it and/or modify
35 %    it under the terms of the GNU General Public License as published by
36 %    the Free Software Foundation, either version 3 of the License, or
37 %    (at your option) any later version.
38 %
39 %    This program is distributed in the hope that it will be useful,
40 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
41 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42 %    GNU General Public License for more details.
43 %
44 %    You should have received a copy of the GNU General Public License
45 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
46
47
48 % Inititialization
49 [lr,lc]=size(rc);
50 res=[ones(lr,1) zeros(lr,lc)];
51 if nargout<3         % needs O(p^2) memory 
52         MX=zeros(lr,lc*(lc+1)/2);   
53         idx=0;
54         
55         % Durbin-Levinson Algorithm
56         for K=1:lc,
57                 MX(:,idx+K)=rc(:,K);%(AutoCov(:,K+1)-d)./res(:,K);
58                 %rc(:,K)=arp(:,K);
59                 if K>1   %for compatibility with OCTAVE 2.0.13
60                         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));
61                 end;   
62                 res(:,K+1) = res(:,K).*(1-abs(MX(:,idx+K)).^2);
63                 idx=idx+K;
64         end;
65         %arp=MX(:,K*(K-1)/2+(1:K));
66         %rc =MX(:,(1:K).*(2:K+1)/2);
67         ACF=cumprod(ones(lr,lr)-rc.^2,2);
68
69 else            % needs O(p) memory 
70         ar=zeros(lr,lc);
71         acf=[ones(lr,1),zeros(lr,lc)];
72         %rc=RC; %zeros(lr,lc-1);
73         
74         % Durbin-Levinson Algorithm
75         for K=1:lc,
76                 acf(:,K) = -sum(acf(:,K:-1:1).*ar(:,1:K),2);        
77                 ar(:,K) = rc(:,K);
78                 if K>1, %for compatibility with OCTAVE 2.0.13
79                         ar(:,1:K-1) = ar(:,1:K-1) - ar(:,K*ones(K-1,1)) .* ar(:,K-1:-1:1);
80                 end;
81                 res(:,K+1) = res(:,K) .* (1-abs(ar(:,K)).^2);
82         end;
83         
84         ACF=cumprod(ones(lr,lc)-rc.^2,2);
85
86         % assign output arguments
87         arg3=res;
88         res=rc;
89         MX=ar;
90 end; %if
91