]> Creatis software - CreaPhase.git/blob - octave_packages/nan-2.5.5/decovm.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / nan-2.5.5 / decovm.m
1 function [mu,sd,COV,xc,M,R2]=decovm(XCN,NN)
2 % decompose extended covariance matrix into mean (mu), 
3 % standard deviation, the (pure) Covariance (COV), 
4 % correlation (xc) matrix and the correlation coefficients R2.
5 % NaN's are condsidered as missing values. 
6 % [mu,sd,COV,xc,N,R2]=decovm(ECM[,NN])
7 %
8 % ECM   is the extended covariance matrix
9 % NN    is the number of elements, each estimate (in ECM) is based on 
10 %
11 % see also: MDBC, COVM, R2
12
13 %       $Id: decovm.m 2140 2009-07-02 12:03:55Z schloegl $
14 %       Copyright (c) 1999-2002,2009 by  Alois Schloegl
15 %       This function is part of the NaN-toolbox
16 %       http://pub.ist.ac.at/~schloegl/matlab/NaN/
17
18 % This program is free software; you can redistribute it and/or
19 % modify it under the terms of the GNU General Public License
20 % as published by the Free Software Foundation; either version 3
21 % of the  License, or (at your option) any later version.
22
23 % This program is distributed in the hope that it will be useful,
24 % but WITHOUT ANY WARRANTY; without even the implied warranty of
25 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
26 % GNU General Public License for more details.
27
28 % You should have received a copy of the GNU General Public License
29 % along with this program; if not, write to the Free Software
30 % Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
31
32 [r,c]=size(XCN);
33 if r~=c,
34         fprintf(2,'Warning DECOVM: input argument is not a square matrix\n');
35         XCN = ecovm(XCN);
36         c = c + 1;
37 else
38         M = XCN(1,1);
39         if nargin<2,
40                 XCN = XCN/(XCN(1,1));
41         else %if nargin==2
42                 XCN = XCN./(NN);
43         end;
44
45         if any(isnan(XCN(:))),
46                 warning('DECOVM: Extended Covariance Matrix should not contain NaN''s');
47         end;
48         if 0, %det(XCN)<0; % check removed for performance reasons
49                 warning('DECOVM: Extended Covariance Matrix must be non-negative definite');
50         end;
51 end;
52
53 mu  = XCN(1,2:c);
54 COV = XCN(2:c,2:c) - mu'*mu;
55 sd  = sqrt(diag(COV))';
56 if nargout<4, return; end; 
57 xc  = COV./(sd'*sd);
58 M   = XCN(1,1);
59 if nargout<6, return; end; 
60 R2  = xc.*xc;
61
62 return;
63         
64 mu=XCN(2:N,1)/XCN(1,1);
65 COV=(XCN(2:N,2:N)/XCN(1,1)-XCN(2:N,1)*XCN(1,2:N)/XCN(1,1)^2);
66 sd=sqrt(diag(COV));
67 xc=COV./(sd*sd');
68
69 % function [ECM] = ecovm(signal);
70 % Generates extended Covariance matrix, 
71 % ECM= [l signal]'*[l signal]; % l is a matching column of 1's
72 % ECM is additive, i.e. it can be applied to subsequent blocks and summed up afterwards
73 % [ECM1] = ecovm(s1);
74 % [ECM2] = ecovm(s1);
75 % [ECM]  = ecovm([s1;s2]);
76 % ECM1+ECM2==ECM;
77 %
78 % SS=sum(signal); ECM=[[size(signal,1),SS];[SS',signal'*signal]];