Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/cov.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % COV estimate covariance of data streams. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: COV estimate covariance of data streams. | |
5 % | |
6 % CALL: c = cov(a,b, pl) | |
7 % | |
8 % INPUTS: pl - a parameter list | |
9 % a,b - input analysis object | |
10 % | |
11 % OUTPUTS: c - output analysis object containing the covariance matrix. | |
12 % | |
13 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'cov')">Parameters Description</a> | |
14 % | |
15 % VERSION: $Id: cov.m,v 1.18 2011/04/08 08:56:12 hewitson Exp $ | |
16 % | |
17 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
18 | |
19 function varargout = cov(varargin) | |
20 | |
21 % Check if this is a call for parameters | |
22 if utils.helper.isinfocall(varargin{:}) | |
23 varargout{1} = getInfo(varargin{3}); | |
24 return | |
25 end | |
26 | |
27 import utils.const.* | |
28 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
29 | |
30 % Collect input variable names | |
31 in_names = cell(size(varargin)); | |
32 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
33 | |
34 % Collect all AOs and plists | |
35 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
36 | |
37 if nargout == 0 | |
38 error('### cov cannot be used as a modifier. Please give an output variable.'); | |
39 end | |
40 | |
41 if numel(as) < 2 | |
42 error('### cov requires at least two input AOs to work.'); | |
43 end | |
44 | |
45 % Convolute the data | |
46 smat = []; | |
47 inunits = unit; | |
48 name = ''; | |
49 desc = ''; | |
50 for jj=1:numel(as) | |
51 smat = [smat as(jj).data.getY]; | |
52 inunits = inunits .* as(jj).data.yunits; | |
53 name = strcat(name, [',' ao_invars{jj}]); | |
54 desc = strcat(desc, [' ' as(jj).description]); | |
55 end | |
56 desc = strtrim(desc); | |
57 plotinfo = [as(:).plotinfo]; | |
58 if ~isempty(plotinfo) | |
59 plotinfo = combine(plotinfo); | |
60 end | |
61 | |
62 bs = ao(cdata(cov(smat))); | |
63 bs.name = sprintf('cov(%s)', name(2:end)); | |
64 bs.description = desc; | |
65 bs.plotinfo = plotinfo; | |
66 bs.data.setYunits(inunits); | |
67 bs.addHistory(getInfo('None'), getDefaultPlist, ao_invars, [as(:).hist]); | |
68 | |
69 % Set output | |
70 if nargout == numel(bs) | |
71 % List of outputs | |
72 for ii = 1:numel(bs) | |
73 varargout{ii} = bs(ii); | |
74 end | |
75 else | |
76 % Single output | |
77 varargout{1} = bs; | |
78 end | |
79 end | |
80 | |
81 %-------------------------------------------------------------------------- | |
82 % Get Info Object | |
83 %-------------------------------------------------------------------------- | |
84 function ii = getInfo(varargin) | |
85 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
86 sets = {}; | |
87 pls = []; | |
88 else | |
89 sets = {'Default'}; | |
90 pls = getDefaultPlist; | |
91 end | |
92 % Build info object | |
93 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: cov.m,v 1.18 2011/04/08 08:56:12 hewitson Exp $', sets, pls); | |
94 ii.setModifier(false); | |
95 ii.setArgsmin(2); | |
96 end | |
97 | |
98 %-------------------------------------------------------------------------- | |
99 % Get Default Plist | |
100 %-------------------------------------------------------------------------- | |
101 | |
102 | |
103 function plout = getDefaultPlist() | |
104 persistent pl; | |
105 if exist('pl', 'var')==0 || isempty(pl) | |
106 pl = buildplist(); | |
107 end | |
108 plout = pl; | |
109 end | |
110 | |
111 function pl_default = buildplist() | |
112 pl_default = plist.EMPTY_PLIST; | |
113 end | |
114 |