comparison m-toolbox/classes/@ao/lcohere.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 % LCOHERE implement magnitude-squadred coherence estimation on a log frequency axis.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: LCOHERE implement coherence estimation on a log frequency axis.
5 % The estimate is done by taking
6 % the ratio of the CPSD between the two inputs, Sxy, divided by
7 % the product of the PSDs of the inputs, Sxx and Syy,
8 % and is either magnitude-squared: (abs(Sxy))^2 / (Sxx * Syy)
9 % or complex value: Sxy / sqrt(Sxx * Syy)
10 % Here x is the first input, y is the second input
11 %
12 % CALL: b = lcohere(a1,a2,pl)
13 %
14 % INPUTS: a1 - input analysis object
15 % a2 - input analysis object
16 % pl - input parameter list
17 %
18 % OUTPUTS: b - output analysis object
19 %
20 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'lcohere')">Parameters Description</a>
21 %
22 % VERSION: $Id: lcohere.m,v 1.30 2011/04/08 08:56:18 hewitson Exp $
23 %
24 % References: "Improved spectrum estimation from digitized time series
25 % on a logarithmic frequency axis", Michael Troebs, Gerhard Heinzel,
26 % Measurement 39 (2006) 120-129.
27 %
28 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
29
30 function varargout = lcohere(varargin)
31
32 % Check if this is a call for parameters
33 if utils.helper.isinfocall(varargin{:})
34 varargout{1} = getInfo(varargin{3});
35 return
36 end
37
38 import utils.const.*
39 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
40
41 if nargout == 0
42 error('### lcohere cannot be used as a modifier. Please give an output variable.');
43 end
44
45 % Collect input variable names
46 in_names = cell(size(varargin));
47 for ii = 1:nargin,in_names{ii} = inputname(ii);end
48
49 % Collect all AOs
50 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
51
52 % Apply defaults to plist
53 pl = applyDefaults(getDefaultPlist, varargin{:});
54
55 % Throw an error if input is not two AOs
56 if numel(as) ~= 2
57 error('### lcohere only accepts two inputs AOs.');
58 end
59
60 % Compute coherence with lxspec
61 scale_type = find(pl, 'Type');
62 switch lower(scale_type)
63 case 'c'
64 bs = ao.lxspec(as, pl, 'cohere', getInfo, ao_invars);
65 case 'ms'
66 bs = ao.lxspec(as, pl, 'mscohere', getInfo, ao_invars);
67 otherwise
68 error(['### Unknown coherence type: [' scale_type ']']);
69 end
70
71 % Set output
72 varargout{1} = bs;
73
74 end
75
76 %--------------------------------------------------------------------------
77 % Get Info Object
78 %--------------------------------------------------------------------------
79 function ii = getInfo(varargin)
80 if nargin == 1 && strcmpi(varargin{1}, 'None')
81 sets = {};
82 pl = [];
83 else
84 sets = {'Default'};
85 pl = getDefaultPlist();
86 end
87 % Build info object
88 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: lcohere.m,v 1.30 2011/04/08 08:56:18 hewitson Exp $', sets, pl);
89 ii.setModifier(false);
90 ii.setArgsmin(2);
91 end
92
93 %--------------------------------------------------------------------------
94 % Get Default Plist
95 %--------------------------------------------------------------------------
96
97 function plout = getDefaultPlist()
98 persistent pl;
99 if ~exist('pl', 'var') || isempty(pl)
100 pl = buildplist();
101 end
102 plout = pl;
103 end
104
105 function pl = buildplist()
106
107 % General plist for Welch-based, log-scale spaced spectral estimators
108 pl = plist.LPSD_PLIST;
109
110 % Type
111 p = param({'Type',['type of output scaling. Choose from:<ul>', ...
112 '<li>MS - Magnitude-Squared Coherence:<br><tt>(abs(Sxy))^2 / (Sxx * Syy)</tt></li>', ...
113 '<li>C - Complex Coherence:<br><tt>Sxy / sqrt(Sxx * Syy)</tt></li></ul>']}, {1, {'C', 'MS'}, paramValue.SINGLE});
114 pl.append(p);
115
116 end
117
118 % PARAMETERS:
119 %
120 % 'Kdes' - desired number of averages [default: 100]
121 % 'Jdes' - number of spectral frequencies to compute [default: 1000]
122 % 'Lmin' - minimum segment length [default: 0]
123 % 'Win' - the window to be applied to the data to remove the
124 % discontinuities at edges of segments. [default: taken from
125 % user prefs]
126 % Only the design parameters of the window object are
127 % used. Enter either:
128 % - a specwin window object OR
129 % - a string value containing the window name
130 % e.g., plist('Win', 'Kaiser', 'psll', 200)
131 % 'Olap' - segment percent overlap [default: -1, (taken from window function)]
132 % 'Type' - type of output scaling. Choose from:
133 % MS - Magnitude-Squared Coherence (abs(Sxy))^2 / (Sxx * Syy)
134 % C - Complex Coherence Sxy / sqrt(Sxx * Syy) [default]
135 % 'Order' - order of segment detrending
136 % -1 - no detrending
137 % 0 - subtract mean [default]
138 % 1 - subtract linear fit
139 % N - subtract fit of polynomial, order N