Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/delayEstimate.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 % DELAYESTIMATE estimates the delay between two AOs | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: DELAYESTIMATE returns an estimate of the delay between the two | |
5 % input analysis objects. Different weights in frequency | |
6 % domain can be used. | |
7 % | |
8 % CALL: bs = delayEstimate(a1,a2,pl) | |
9 % | |
10 % INPUTS: a1 - input analysis objects | |
11 % a2 - delayed analysis objects | |
12 % pl - input parameter list | |
13 % | |
14 % OUTPUTS: bs - analysis object with the delay (as cdata) | |
15 % | |
16 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'delayEstimate')">Parameters Description</a> | |
17 % | |
18 % VERSION: $Id: delayEstimate.m,v 1.6 2011/04/08 08:56:15 hewitson Exp $ | |
19 % | |
20 % HISTORY: 15-10-09 M Nofrarias | |
21 % Creation | |
22 % | |
23 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
24 | |
25 | |
26 function varargout = delayEstimate(varargin) | |
27 | |
28 % Check if this is a call for parameters | |
29 if utils.helper.isinfocall(varargin{:}) | |
30 varargout{1} = getInfo(varargin{3}); | |
31 return | |
32 end | |
33 | |
34 import utils.const.* | |
35 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
36 | |
37 % Collect input variable names | |
38 in_names = cell(size(varargin)); | |
39 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
40 | |
41 % Collect all AOs | |
42 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
43 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names); | |
44 | |
45 % Decide on a deep copy or a modify | |
46 bs = copy(as, nargout); | |
47 | |
48 % Combine plists | |
49 pl = parse(pl, getDefaultPlist); | |
50 | |
51 % get frequency weight | |
52 weight = find(pl, 'weight'); | |
53 | |
54 N = len(bs(1)); | |
55 T = bs(1).x(end); | |
56 fs = bs(1).fs; | |
57 % zeropad to avoid circular convolution in ifft | |
58 bs(1).zeropad; | |
59 bs(2).zeropad; | |
60 % compute spectral density, scale applied after to avoid round-off errors | |
61 scale = fs/N; | |
62 Gx11 = conj(fft(bs(1).y)).*fft(bs(1).y); | |
63 Gx11 = Gx11*scale; | |
64 Gx12 = conj(fft(bs(1).y)).*fft(bs(2).y); | |
65 Gx12 = Gx12*scale; | |
66 Gx22 = conj(fft(bs(2).y)).*fft(bs(2).y); | |
67 Gx22 = Gx22*scale; | |
68 % frequencies for two-sided spectrum | |
69 f = linspace(-fs,fs,2*N); | |
70 % select weight | |
71 if strcmp(weight,'roth') | |
72 weight = Gx11; | |
73 elseif strcmp(weight,'scot') | |
74 weight = sqrt(Gx11.* Gx22); | |
75 elseif strcmp(weight,'scc') | |
76 weight = 1; | |
77 elseif strcmp(weight,'phat') | |
78 weight = abs(Gx12); | |
79 elseif strcmp(weight,'eckart') | |
80 weight = 1; | |
81 elseif strcmp(weight,'ML') | |
82 weight = 1; | |
83 else | |
84 error('### Unknown value for ''weight'' parameter ' ) | |
85 end | |
86 % compute unscaled correlation function | |
87 Ru = ifft(Gx12./weight); | |
88 % lag= 0:\deltat*(N-1) | |
89 % n= 1:N/2-1 | |
90 r = linspace(0,T-1/fs,length(Ru)/2-1); | |
91 % scaling to correct zeropad bias | |
92 R = (N./(N-r))'.*Ru(1:length(Ru)/2-1); | |
93 % get maximum | |
94 [m,ind] = max(R); | |
95 del = r(ind); | |
96 % plot if required | |
97 plt = find(pl, 'plot'); | |
98 if plt | |
99 Rxy = ao(xydata(r,R)); | |
100 Rxy.setName(sprintf('Correlation(%s,%s)', ao_invars{1},ao_invars{2})) | |
101 iplot(Rxy) | |
102 end | |
103 | |
104 % create new output cdata | |
105 cd = cdata(del); | |
106 % add unitss | |
107 cd.yunits = 's'; | |
108 % update AO | |
109 c = ao(cd); | |
110 % add error | |
111 % bs(jj).data.dy = dev; | |
112 % Add name | |
113 c.name = sprintf('delayEst(%s,%s)', ao_invars{1},ao_invars{2}); | |
114 % Add history | |
115 c.addHistory(getInfo('None'), pl, [ao_invars(:)], [bs(:).hist]); | |
116 | |
117 % set output | |
118 varargout{1} = c; | |
119 | |
120 end | |
121 | |
122 %-------------------------------------------------------------------------- | |
123 % Get Info Object | |
124 %-------------------------------------------------------------------------- | |
125 function ii = getInfo(varargin) | |
126 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
127 sets = {}; | |
128 pl = []; | |
129 else | |
130 sets = {'Default'}; | |
131 pl = getDefaultPlist; | |
132 end | |
133 % Build info object | |
134 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: delayEstimate.m,v 1.6 2011/04/08 08:56:15 hewitson Exp $', sets, pl); | |
135 end | |
136 | |
137 %-------------------------------------------------------------------------- | |
138 % Get Default Plist | |
139 %-------------------------------------------------------------------------- | |
140 | |
141 function plout = getDefaultPlist() | |
142 persistent pl; | |
143 if exist('pl', 'var')==0 || isempty(pl) | |
144 pl = buildplist(); | |
145 end | |
146 plout = pl; | |
147 end | |
148 | |
149 function pl = buildplist() | |
150 pl = plist(); | |
151 % method | |
152 p = param({'weight',['scaling of output. Choose from:<ul>', ... | |
153 '<li>scc - </li>', ... | |
154 '<li>roth - </li>', ... | |
155 '<li>scot - </li>', ... | |
156 '<li>phat - </li>', ... | |
157 '<li>eckart - </li>', ... | |
158 '<li>ML - </li></ul>']}, {1, {'scc','roth', 'scot','phat','eckart','ML'}, paramValue.SINGLE}); | |
159 pl.append(p); | |
160 % Plot | |
161 p = param({'Plot', 'Plot the correlation function'}, ... | |
162 {2, {'true', 'false'}, paramValue.SINGLE}); | |
163 pl.append(p); | |
164 end | |
165 % END | |
166 |