]> Creatis software - CreaPhase.git/blob - octave_packages/tsa-4.2.4/ar2rc.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / tsa-4.2.4 / ar2rc.m
1 function [MX,res,arg3] = ar2rc(ar);
2 % converts autoregressive parameters into reflection coefficients 
3 % with the Durbin-Levinson recursion for multiple channels
4 % function  [AR,RC,PE] = ar2rc(AR);
5 % function  [MX,PE] = ar2rc(AR);
6 %
7 %  INPUT:
8 % AR    autoregressive model parameter  
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 %        AR = 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 RC2AR 
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: ar2rc.m 5090 2008-06-05 08:12:04Z schloegl $
30 %       Copyright (C) 1998-2002,2008 by Alois Schloegl <a.schloegl@ieee.org>
31 %
32 %    This program is free software: you can redistribute it and/or modify
33 %    it under the terms of the GNU General Public License as published by
34 %    the Free Software Foundation, either version 3 of the License, or
35 %    (at your option) any later version.
36 %
37 %    This program 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
40 %    GNU General Public License for more details.
41 %
42 %    You should have received a copy of the GNU General Public License
43 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
44
45 % Inititialization
46 [lr,lc]=size(ar);
47 res=[ones(lr,1) zeros(lr,lc)];
48
49 if nargout<3         % needs O(p^2) memory 
50         MX=zeros(lr,lc*(lc+1)/2);   
51         MX(:,lc*(lc-1)/2+(1:lc))=ar;
52         
53         % Durbin-Levinson Algorithm
54         idx=lc*(lc-1)/2;
55         for K=lc:-1:2; 
56                 %idx=K*(K-1)/2;  %see below
57                 MX(:,(K-2)*(K-1)/2+(1:K-1)) = (MX(:,idx+(1:K-1)) + MX(:,(idx+K)*ones(K-1,1)).*MX(:,idx+(K-1:-1:1)))./((ones(lr,1)-abs(MX(:,idx+K)).^2)*ones(1,K-1));
58                 idx=idx-K+1;
59         end;
60         for K=1:lc
61                 idx=K*(K-1)/2;  %see below
62                 res(:,K+1) = res(:,K).*(1-abs(MX(:,idx+K)).^2);
63         end;
64             
65         %arp=MX(:,K*(K-1)/2+(1:K));
66         %rc =MX(:,(1:K).*(2:K+1)/2);
67
68 else            % needs O(p) memory 
69         
70         %ar=zeros(lr,lc);
71         rc=zeros(lr,lc);
72         rc(:,lc)=ar(:,lc);
73         MX=ar; % assign output
74         
75         % Durbin-Levinson Algorithm
76         for K=lc-1:-1:1,
77                 ar(:,1:K)=(ar(:,1:K)+ar(:,(K+1)*ones(K,1)).*ar(:,K:-1:1))./((ones(lr,1)-abs(ar(:,K+1)).^2)*ones(1,K));
78                 rc(:,K)=ar(:,K);
79         end;
80         
81         for K=1:lc,
82                 res(:,K+1) = res(:,K) .* (1-abs(ar(:,K)).^2);
83         end;
84         
85         % assign output arguments
86         arg3=res;
87         res=rc;
88         %MX=ar;
89 end; %if