Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/cohere.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children | bc767aaa99a8 |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % COHERE estimates the coherence between time-series objects | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: COHERE estimates the coherence between the | |
5 % time-series objects in the input analysis objects. | |
6 % The estimate is done by taking | |
7 % the ratio of the CPSD between the two inputs, Sxy, divided by | |
8 % the product of the PSDs of the inputs, Sxx and Syy, | |
9 % and is either magnitude-squared: (abs(Sxy))^2 / (Sxx * Syy) | |
10 % or complex value: Sxy / sqrt(Sxx * Syy) | |
11 % Here x is the first input, y is the second input | |
12 % | |
13 % CALL: b = cohere(a1,a2,pl) | |
14 % | |
15 % INPUTS: a1 - input analysis object | |
16 % a2 - input analysis object | |
17 % pl - input parameter list | |
18 % | |
19 % OUTPUTS: b - output analysis object | |
20 % | |
21 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'cohere')">Parameters Description</a> | |
22 % | |
23 % VERSION: $Id: cohere.m,v 1.43 2011/04/08 08:56:16 hewitson Exp $ | |
24 % | |
25 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
26 | |
27 function varargout = cohere(varargin) | |
28 | |
29 % Check if this is a call for parameters | |
30 if utils.helper.isinfocall(varargin{:}) | |
31 varargout{1} = getInfo(varargin{3}); | |
32 return | |
33 end | |
34 | |
35 import utils.const.* | |
36 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
37 | |
38 if nargout == 0 | |
39 error('### cohere cannot be used as a modifier. Please give an output variable.'); | |
40 end | |
41 | |
42 % Collect input variable names | |
43 in_names = cell(size(varargin)); | |
44 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
45 | |
46 % Collect all AOs | |
47 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
48 | |
49 % Apply defaults to plist | |
50 pl = applyDefaults(getDefaultPlist, varargin{:}); | |
51 | |
52 % Throw an error if input is not two AOs | |
53 if numel(as) ~= 2 | |
54 error('### cohere only accepts two inputs AOs.'); | |
55 end | |
56 | |
57 % Compute coherence with xspec | |
58 scale_type = find(pl, 'Type'); | |
59 switch lower(scale_type) | |
60 case 'c' | |
61 bs = xspec(as, pl, 'cohere', getInfo, ao_invars); | |
62 case 'ms' | |
63 bs = xspec(as, pl, 'mscohere', getInfo, ao_invars); | |
64 otherwise | |
65 error(['### Unknown coherence type: [' scale_type ']']); | |
66 end | |
67 | |
68 % Set output | |
69 varargout{1} = bs; | |
70 | |
71 end | |
72 | |
73 %-------------------------------------------------------------------------- | |
74 % Get Info Object | |
75 %-------------------------------------------------------------------------- | |
76 function ii = getInfo(varargin) | |
77 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
78 sets = {}; | |
79 pl = []; | |
80 else | |
81 sets = {'Default'}; | |
82 pl = getDefaultPlist(); | |
83 end | |
84 % Build info object | |
85 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: cohere.m,v 1.43 2011/04/08 08:56:16 hewitson Exp $', sets, pl); | |
86 ii.setModifier(false); | |
87 ii.setArgsmin(2); | |
88 end | |
89 | |
90 %-------------------------------------------------------------------------- | |
91 % Get Default Plist | |
92 %-------------------------------------------------------------------------- | |
93 | |
94 function plout = getDefaultPlist() | |
95 persistent pl; | |
96 if ~exist('pl', 'var') || isempty(pl) | |
97 pl = buildplist(); | |
98 end | |
99 plout = pl; | |
100 end | |
101 | |
102 function pl = buildplist() | |
103 | |
104 % General plist for Welch-based, linearly spaced spectral estimators | |
105 pl = plist.WELCH_PLIST; | |
106 | |
107 % Type | |
108 p = param({'Type',['type of output scaling. Choose from:<ul>', ... | |
109 '<li>MS - Magnitude-Squared Coherence:<br><tt>(abs(Sxy))^2 / (Sxx * Syy)</tt></li>', ... | |
110 '<li>C - Complex Coherence:<br><tt>Sxy / sqrt(Sxx * Syy)</tt></li></ul>']}, {1, {'C', 'MS'}, paramValue.SINGLE}); | |
111 pl.append(p); | |
112 | |
113 end | |
114 |