]> Creatis software - CreaPhase.git/blob - octave_packages/tsa-4.2.4/invest0.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / tsa-4.2.4 / invest0.m
1 function [AutoCov,AutoCorr,MX,E,NC]=invest0(Y,Pmax,Mode);
2 % First Investigation of a signal (time series) - automated part
3 % [AutoCov,AutoCorr,ARPMX,E,ACFsd,NC]=invest0(Y,Pmax);
4 %
5 % [AutoCov,AutoCorr,ARPMX,E,ACFsd,NC]=invest0(AutoCov,Pmax,Mode);
6
7 %
8 % Y     time series
9 % Pmax  maximal order (optional)
10 %
11 % AutoCov       Autocorrelation 
12 % AutoCorr      normalized Autocorrelation
13 % PartACF       Partial Autocorrelation
14 % ARPMX     Autoregressive Parameter for order Pmax-1
15 % E             Error function E(p)
16 % NC            Number of values (length-missing values)
17 %
18 % REFERENCES:
19 %  P.J. Brockwell and R.A. Davis "Time Series: Theory and Methods", 2nd ed. Springer, 1991.
20 %  M.S. Grewal and A.P. Andrews "Kalman Filtering" Prentice Hall, 1993. 
21 %  S. Haykin "Adaptive Filter Theory" 3ed. Prentice Hall, 1996.
22 %  M.B. Priestley "Spectral Analysis and Time Series" Academic Press, 1981. 
23 %  W.S. Wei "Time Series Analysis" Addison Wesley, 1990.
24
25 %       $Id: invest0.m 7687 2010-09-08 18:39:23Z schloegl $
26 %       Copyright (C) 1998-2003,2008,2010 by Alois Schloegl <a.schloegl@ieee.org>       
27 %       This is part of the TSA-toolbox. See also 
28 %       http://biosig-consulting.com/matlab/tsa/
29 %
30 %    This program is free software: you can redistribute it and/or modify
31 %    it under the terms of the GNU General Public License as published by
32 %    the Free Software Foundation, either version 3 of the License, or
33 %    (at your option) any later version.
34 %
35 %    This program is distributed in the hope that it will be useful,
36 %    but WITHOUT ANY WARRANTY; without even the implied warranty of
37 %    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
38 %    GNU General Public License for more details.
39 %
40 %    You should have received a copy of the GNU General Public License
41 %    along with this program.  If not, see <http://www.gnu.org/licenses/>.
42
43 if nargin<3
44    Mode=0;
45 else
46    Mode=1;
47 end;    
48
49 [nr,nc]=size(Y);
50 NC = sumskipnan(real(~isnan(Y)),2);             % number of valid components (data points)
51
52 if Mode==0
53         if nargin<2, Pmax = min([100 nc/3]); end;
54         M = min(Pmax,nc-1);
55         AutoCov = acovf(Y,M);
56 else
57         AutoCov=Y;
58         M  = min(Pmax,nc-1);
59         nc = Pmax;
60         %M=size(AutoCov,2)-1;
61 end;
62
63 AutoCorr = AutoCov(:,2:M+1)./AutoCov(:,ones(M,1));
64
65 if 1,Pmax<100; % this needs change of sinvest1
66         K=M-1;
67         [MX,E]=lattice(Y,Pmax);
68         %[MX,E]=ulsar(Y,Pmax);
69         %[MX,E]=durlev(AutoCov);
70 %       ARP=MX(:,K*(K-1)/2+(1:K));
71 %       PartACF =MX(:,(1:K).*(2:K+1)/2);
72 else %if nargout > 2
73         [ARP,RC,E]=lattice(Y,Pmax);
74         %[ARP,PartACF,E]=durlev(AutoCov);
75         %MX=[ARP,RC];        
76 end;
77
78
79
80                     
81                     
82                     
83                     
84                     
85