Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_lcohere.m @ 44:409a22968d5e default
Add unit tests
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Tue, 06 Dec 2011 18:42:11 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
43:bc767aaa99a8 | 44:409a22968d5e |
---|---|
1 % UTP_AO_LCOHERE a set of UTPs for the ao/lcohere method | |
2 % | |
3 % M Hewitson 06-08-08 | |
4 % | |
5 % $Id: utp_ao_lcohere.m,v 1.26 2011/07/22 12:29:58 mauro Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The lcohere method of the ao class computes the lcoherence between two | |
11 % time-series AOs on a log frequency axis. | |
12 % | |
13 % </MethodDescription> | |
14 | |
15 function results = utp_ao_lcohere(varargin) | |
16 | |
17 % Check the inputs | |
18 if nargin == 0 | |
19 | |
20 % Some keywords | |
21 class = 'ao'; | |
22 mthd = 'lcohere'; | |
23 | |
24 results = []; | |
25 disp('******************************************************'); | |
26 disp(['**** Running UTPs for ' class '/' mthd]); | |
27 disp('******************************************************'); | |
28 | |
29 % Test AOs | |
30 [at1,at2,at3,at4,at5,at6] = eval(['get_test_objects_' class]); | |
31 | |
32 % Exception list for the UTPs: | |
33 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
34 | |
35 % Get default window from the preferences | |
36 prefs = getappdata(0, 'LTPDApreferences'); | |
37 defaultWinType = char(prefs.getMiscPrefs.getDefaultWindow); | |
38 | |
39 % Run the tests | |
40 results = [results utp_01]; % getInfo call | |
41 results = [results utp_02]; % Vector input (only with two objects) | |
42 results = [results utp_03]; % Matrix input (not possible) | |
43 results = [results utp_04]; % List input (only with two objects) | |
44 results = [results utp_05]; % Test with mixed input (not possible) | |
45 results = [results utp_06]; % Test history is working | |
46 results = [results utp_07]; % Test the modify call works | |
47 results = [results utp_08]; % Test input data shape == output data shape | |
48 results = [results utp_09]; % Test output of the data | |
49 | |
50 results = [results utp_11(mthd, [at1 at1], ple1)]; % Test plotinfo doesn't disappear | |
51 | |
52 results = [results utp_12]; % Test basic symmetry properties of lcohere (C) | |
53 results = [results utp_13]; % Test basic symmetry properties of lcohere (MS) | |
54 results = [results utp_14]; % Test basic symmetry properties of lcohere (C) | |
55 results = [results utp_15]; % Test basic symmetry properties of lcohere (MS) | |
56 results = [results utp_16]; % Test basic relationship (MS) <-> (C) | |
57 results = [results utp_17]; % Test units handling: complex cohere | |
58 results = [results utp_18]; % Test units handling: magnitude-squared cohere | |
59 results = [results utp_30]; % Special cases: same input | |
60 | |
61 disp('Done.'); | |
62 disp('******************************************************'); | |
63 | |
64 elseif nargin == 1 % Check for UTP functions | |
65 if strcmp(varargin{1}, 'isutp') | |
66 results = 1; | |
67 else | |
68 results = 0; | |
69 end | |
70 else | |
71 error('### Incorrect inputs') | |
72 end | |
73 | |
74 %% UTP_01 | |
75 | |
76 % <TestDescription> | |
77 % | |
78 % Tests that the getInfo call works for this method. | |
79 % | |
80 % </TestDescription> | |
81 function result = utp_01 | |
82 | |
83 | |
84 % <SyntaxDescription> | |
85 % | |
86 % Test that the getInfo call works for no sets, all sets, and each set | |
87 % individually. | |
88 % | |
89 % </SyntaxDescription> | |
90 | |
91 try | |
92 % <SyntaxCode> | |
93 % Call for no sets | |
94 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
95 % Call for all sets | |
96 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
97 % Call for each set | |
98 for kk=1:numel(io(2).sets) | |
99 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
100 end | |
101 % </SyntaxCode> | |
102 stest = true; | |
103 catch err | |
104 disp(err.message) | |
105 stest = false; | |
106 end | |
107 | |
108 % <AlgoDescription> | |
109 % | |
110 % 1) Check that getInfo call returned an minfo object in all cases. | |
111 % 2) Check that all plists have the correct parameters. | |
112 % | |
113 % </AlgoDescription> | |
114 | |
115 atest = true; | |
116 if stest | |
117 % <AlgoCode> | |
118 % check we have minfo objects | |
119 if isa(io, 'minfo') | |
120 | |
121 %%% SET 'None' | |
122 if ~isempty(io(1).sets), atest = false; end | |
123 if ~isempty(io(1).plists), atest = false; end | |
124 %%% Check all Sets | |
125 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
126 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
127 %%%%%%%%%% SET 'Default' | |
128 if io(3).plists.nparams ~= 10, atest = false; end | |
129 % Check key | |
130 if ~io(3).plists.isparam('kdes'), atest = false; end | |
131 if ~io(3).plists.isparam('jdes'), atest = false; end | |
132 if ~io(3).plists.isparam('lmin'), atest = false; end | |
133 if ~io(3).plists.isparam('win'), atest = false; end | |
134 if ~io(3).plists.isparam('olap'), atest = false; end | |
135 if ~io(3).plists.isparam('type'), atest = false; end | |
136 if ~io(3).plists.isparam('order'), atest = false; end | |
137 if ~io(3).plists.isparam('psll'), atest = false; end | |
138 if ~io(3).plists.isparam('times'), atest = false; end | |
139 if ~io(3).plists.isparam('split'), atest = false; end | |
140 % Check default value | |
141 if ~isequal(io(3).plists.find('kdes'), 100), atest = false; end | |
142 if ~isequal(io(3).plists.find('jdes'), 1000), atest = false; end | |
143 if ~isequal(io(3).plists.find('lmin'), 0), atest = false; end | |
144 if ~strcmpi(io(3).plists.find('win'), defaultWinType), atest = false; end | |
145 if ~isequal(io(3).plists.find('olap'), -1), atest = false; end | |
146 if ~isequal(io(3).plists.find('type'), 'C'), atest = false; end | |
147 if ~isequal(io(3).plists.find('order'), 0), atest = false; end | |
148 if ~isequal(io(3).plists.find('psll'), 200), atest = false; end | |
149 if ~isEmptyDouble(io(3).plists.find('times')), atest = false; end | |
150 if ~isEmptyDouble(io(3).plists.find('split')), atest = false; end | |
151 % Check options | |
152 if ~isequal(io(3).plists.getOptionsForParam('kdes'), {100}), atest = false; end | |
153 if ~isequal(io(3).plists.getOptionsForParam('jdes'), {1000}), atest = false; end | |
154 if ~isequal(io(3).plists.getOptionsForParam('lmin'), {0}), atest = false; end | |
155 if ~isequal(io(3).plists.getOptionsForParam('win'), specwin.getTypes), atest = false; end | |
156 if ~isequal(io(3).plists.getOptionsForParam('olap'), {-1}), atest = false; end | |
157 if ~isequal(io(3).plists.getOptionsForParam('type'), {'C', 'MS'}), atest = false; end | |
158 if ~isequal(io(3).plists.getOptionsForParam('order'), {-1 0 1 2 3 4 5 6 7 8 9}), atest = false; end | |
159 if ~isequal(io(3).plists.getOptionsForParam('psll'), {200}), atest = false; end | |
160 if ~isequal(io(3).plists.getOptionsForParam('times'), {[]}), atest = false; end | |
161 if ~isequal(io(3).plists.getOptionsForParam('split'), {[]}), atest = false; end | |
162 end | |
163 % </AlgoCode> | |
164 else | |
165 atest = false; | |
166 end | |
167 | |
168 % Return a result structure | |
169 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
170 end % END UTP_01 | |
171 | |
172 %% UTP_02 | |
173 | |
174 % <TestDescription> | |
175 % | |
176 % Tests that the lcohere method works with a vector of AOs as input. (only | |
177 % with two objects in the vector) | |
178 % | |
179 % </TestDescription> | |
180 function result = utp_02 | |
181 | |
182 % <SyntaxDescription> | |
183 % | |
184 % Test that the lcohere method works for a vector of AOs as input. | |
185 % | |
186 % </SyntaxDescription> | |
187 | |
188 try | |
189 % <SyntaxCode> | |
190 avec = [at1 at5]; | |
191 out = lcohere(avec); | |
192 % </SyntaxCode> | |
193 stest = true; | |
194 catch err | |
195 disp(err.message) | |
196 stest = false; | |
197 end | |
198 | |
199 % <AlgoDescription> | |
200 % | |
201 % 1) Check that the number of elements in 'out' is equal to 1. | |
202 % | |
203 % </AlgoDescription> | |
204 | |
205 atest = true; | |
206 if stest | |
207 % <AlgoCode> | |
208 % Check we have the correct number of outputs | |
209 if numel(out) ~= 1, atest = false; end | |
210 % </AlgoCode> | |
211 else | |
212 atest = false; | |
213 end | |
214 | |
215 % Return a result structure | |
216 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
217 end % END UTP_02 | |
218 | |
219 %% UTP_03 | |
220 | |
221 % <TestDescription> | |
222 % | |
223 % Test that the lcohere method doesn't work for a matrix of AOs as input. | |
224 % | |
225 % </TestDescription> | |
226 function result = utp_03 | |
227 | |
228 % <SyntaxDescription> | |
229 % | |
230 % Test that the lcohere method doesn't work for a matrix of AOs as input. | |
231 % | |
232 % </SyntaxDescription> | |
233 | |
234 try | |
235 % <SyntaxCode> | |
236 amat = [at1 at5; at5 at6]; | |
237 out = lcohere(amat); | |
238 % </SyntaxCode> | |
239 stest = false; | |
240 catch err | |
241 stest = true; | |
242 end | |
243 | |
244 % <AlgoDescription> | |
245 % | |
246 % 1) Nothing to check. | |
247 % | |
248 % </AlgoDescription> | |
249 | |
250 atest = true; | |
251 if stest | |
252 % <AlgoCode> | |
253 % </AlgoCode> | |
254 else | |
255 atest = false; | |
256 end | |
257 | |
258 % Return a result structure | |
259 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
260 end % END UTP_03 | |
261 | |
262 %% UTP_04 | |
263 | |
264 % <TestDescription> | |
265 % | |
266 % Tests that the lcohere method works with a list of AOs as input. | |
267 % | |
268 % </TestDescription> | |
269 function result = utp_04 | |
270 | |
271 % <SyntaxDescription> | |
272 % | |
273 % Test that the lcohere method works for a list of AOs as input. | |
274 % | |
275 % </SyntaxDescription> | |
276 | |
277 try | |
278 % <SyntaxCode> | |
279 out = lcohere(at1,at5); | |
280 % </SyntaxCode> | |
281 stest = true; | |
282 catch err | |
283 disp(err.message) | |
284 stest = false; | |
285 end | |
286 | |
287 % <AlgoDescription> | |
288 % | |
289 % 1) Check that the number of elements in 'out' is equal to 1. | |
290 % | |
291 % </AlgoDescription> | |
292 | |
293 atest = true; | |
294 if stest | |
295 % <AlgoCode> | |
296 % Check we have the correct number of outputs | |
297 if numel(out) ~= 1, atest = false; end | |
298 % </AlgoCode> | |
299 else | |
300 atest = false; | |
301 end | |
302 | |
303 % Return a result structure | |
304 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
305 end % END UTP_04 | |
306 | |
307 %% UTP_05 | |
308 | |
309 % <TestDescription> | |
310 % | |
311 % Tests that the lcohere method doesn't work with a mix of different | |
312 % shaped AOs as input. | |
313 % | |
314 % </TestDescription> | |
315 function result = utp_05 | |
316 | |
317 % <SyntaxDescription> | |
318 % | |
319 % Test that the lcohere method doesn't work with an input of matrices | |
320 % and vectors and single AOs. | |
321 % | |
322 % </SyntaxDescription> | |
323 | |
324 try | |
325 % <SyntaxCode> | |
326 out = lcohere(at1,[at5 at6],at5,[at5 at1; at6 at1],at6); | |
327 stest = false; | |
328 % </SyntaxCode> | |
329 catch err | |
330 stest = true; | |
331 end | |
332 | |
333 % <AlgoDescription> | |
334 % | |
335 % 1) Nothing to check. | |
336 % | |
337 % </AlgoDescription> | |
338 | |
339 atest = true; | |
340 if stest | |
341 % <AlgoCode> | |
342 % </AlgoCode> | |
343 else | |
344 atest = false; | |
345 end | |
346 | |
347 % Return a result structure | |
348 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
349 end % END UTP_05 | |
350 | |
351 %% UTP_06 | |
352 | |
353 % <TestDescription> | |
354 % | |
355 % Tests that the lcohere method properly applies history. | |
356 % | |
357 % </TestDescription> | |
358 function result = utp_06 | |
359 | |
360 % <SyntaxDescription> | |
361 % | |
362 % Test that the result of applying the lcohere method can be processed back | |
363 % to an m-file. | |
364 % | |
365 % </SyntaxDescription> | |
366 | |
367 try | |
368 % <SyntaxCode> | |
369 out = lcohere(at5,at6); | |
370 mout = rebuild(out); | |
371 % </SyntaxCode> | |
372 stest = true; | |
373 catch err | |
374 disp(err.message) | |
375 stest = false; | |
376 end | |
377 | |
378 % <AlgoDescription> | |
379 % | |
380 % 1) Check that the last entry in the history of 'out' corresponds to | |
381 % 'lcohere'. | |
382 % 2) Check that the re-built object is the same as 'out'. | |
383 % | |
384 % </AlgoDescription> | |
385 | |
386 atest = true; | |
387 if stest | |
388 % <AlgoCode> | |
389 % Check the last step in the history of 'out' | |
390 if ~strcmp(out.hist.methodInfo.mname, 'lcohere'), atest = false; end | |
391 % Check the re-built object | |
392 if ~eq(mout, out, ple2), atest = false; end | |
393 % </AlgoCode> | |
394 else | |
395 atest = false; | |
396 end | |
397 | |
398 % Return a result structure | |
399 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
400 end % END UTP_06 | |
401 | |
402 %% UTP_07 | |
403 | |
404 % <TestDescription> | |
405 % | |
406 % Tests that the lcohere method can not modify the input AO. | |
407 % | |
408 % </TestDescription> | |
409 function result = utp_07 | |
410 | |
411 % <SyntaxDescription> | |
412 % | |
413 % Test that the lcohere method can not modify the input AO. | |
414 % The method must throw an error for the modifier call. | |
415 % | |
416 % </SyntaxDescription> | |
417 | |
418 try | |
419 % <SyntaxCode> | |
420 % copy at1 to work with | |
421 ain = ao(at1); | |
422 % modify ain | |
423 ain.lcohere(at5); | |
424 % </SyntaxCode> | |
425 stest = false; | |
426 catch err | |
427 stest = true; | |
428 end | |
429 | |
430 % <AlgoDescription> | |
431 % | |
432 % 1) Nothing to check. | |
433 % | |
434 % </AlgoDescription> | |
435 | |
436 atest = true; | |
437 if stest | |
438 % <AlgoCode> | |
439 % </AlgoCode> | |
440 else | |
441 atest = false; | |
442 end | |
443 | |
444 % Return a result structure | |
445 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
446 end % END UTP_07 | |
447 | |
448 %% UTP_08 | |
449 | |
450 % <TestDescription> | |
451 % | |
452 % Test the shape of the output. | |
453 % | |
454 % </TestDescription> | |
455 function result = utp_08 | |
456 | |
457 % <SyntaxDescription> | |
458 % | |
459 % Test that the lcohere method keeps the data shape of the input object. The | |
460 % input AO must be an AO with row data and an AO with column data. | |
461 % | |
462 % </SyntaxDescription> | |
463 | |
464 try | |
465 % <SyntaxCode> | |
466 out1 = lcohere(at5, at6); | |
467 out2 = lcohere(at6, at5); | |
468 % </SyntaxCode> | |
469 stest = true; | |
470 catch err | |
471 disp(err.message) | |
472 stest = false; | |
473 end | |
474 | |
475 % <AlgoDescription> | |
476 % | |
477 % 1) Check that the shpe of the output data doesn't change. | |
478 % | |
479 % </AlgoDescription> | |
480 | |
481 atest = true; | |
482 if stest | |
483 % <AlgoCode> | |
484 % Check the shape of the output data | |
485 if size(out1.data.y, 2) ~= 1, atest = false; end | |
486 if size(out2.data.y, 1) ~= 1, atest = false; end | |
487 % </AlgoCode> | |
488 else | |
489 atest = false; | |
490 end | |
491 | |
492 % Return a result structure | |
493 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
494 end % END UTP_08 | |
495 | |
496 %% UTP_09 | |
497 | |
498 % <TestDescription> | |
499 % | |
500 % Check that the lcohere method pass back the output objects to a list of | |
501 % output variables or to a single variable. | |
502 % | |
503 % </TestDescription> | |
504 function result = utp_09 | |
505 | |
506 % <SyntaxDescription> | |
507 % | |
508 % This test is not longer necessary because the cohere method pass back | |
509 % always only one object. | |
510 % | |
511 % </SyntaxDescription> | |
512 | |
513 try | |
514 % <SyntaxCode> | |
515 % </SyntaxCode> | |
516 stest = true; | |
517 catch err | |
518 disp(err.message) | |
519 stest = false; | |
520 end | |
521 | |
522 % <AlgoDescription> | |
523 % | |
524 % 1) Nothing to check. | |
525 % | |
526 % </AlgoDescription> | |
527 | |
528 atest = true; | |
529 if stest | |
530 % <AlgoCode> | |
531 % </AlgoCode> | |
532 else | |
533 atest = false; | |
534 end | |
535 | |
536 % Return a result structure | |
537 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
538 end % END UTP_09 | |
539 | |
540 %% UTP_12 | |
541 | |
542 % <TestDescription> | |
543 % | |
544 % Tests symmetry properties of complex-coherence: | |
545 % 1) white noise produced from normal pdf, with a given mean value and | |
546 % sigma (distribution's 1st and 2nd orders) | |
547 % 2) white noise produced from normal pdf, with a given mean value and | |
548 % sigma (distribution's 1st and 2nd orders) | |
549 % 3) complex lcoherence of the white noise series | |
550 % 4) compare C(x,y) with conj(C(y,x)) | |
551 % 5) compare C(x,x) and C(y,y) with 1 | |
552 % | |
553 | |
554 % </TestDescription> | |
555 function result = utp_12 | |
556 | |
557 % <SyntaxDescription> | |
558 % | |
559 % 1) Prepare the test tsdata: | |
560 % white noise from normal distribution + offset | |
561 % 2) Assign a random unit | |
562 % 3) Prepare the test tsdata: | |
563 % white noise from normal distribution + offset | |
564 % 4) Assign a random unit | |
565 % 5) complex log-scale coherence of the white noise | |
566 % | |
567 % </SyntaxDescription> | |
568 | |
569 % <SyntaxCode> | |
570 try | |
571 | |
572 % Array of parameters to pick from | |
573 fs_list = [0.1;1;10]; | |
574 nsecs_list = [100:100:10000]'; | |
575 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]'; | |
576 mu_distr_list = [1e-6 2e-3 0.25 1:0.1:10]'; | |
577 | |
578 % Build time-series test data | |
579 | |
580 % Picks the values at random from the list | |
581 fs = utils.math.randelement(fs_list, 1); | |
582 nsecs = utils.math.randelement(nsecs_list, 1); | |
583 sigma_distr = utils.math.randelement(sigma_distr_list, 1); | |
584 mu_distr = utils.math.randelement(mu_distr_list, 1); | |
585 f = [1:5] / 100 * fs; | |
586 A = sigma_distr + sigma_distr*rand(1,1); | |
587 phi = 0 + 2*pi*rand(1,1); | |
588 | |
589 % White noise | |
590 type = 'Normal'; | |
591 a_n1 = ao(plist('waveform', 'noise', ... | |
592 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr)); | |
593 a_n2 = ao(plist('waveform', 'noise', ... | |
594 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr)); | |
595 a_const = ao(mu_distr); | |
596 a_wave = ao(plist('waveform', 'sine-wave', ... | |
597 'fs', fs, 'nsecs', nsecs, 'f', f, 'A', A, 'phi', phi)); | |
598 a_1 = a_n1 + a_const + a_wave; | |
599 a_2 = a_n2 + a_wave; | |
600 | |
601 % Set units and prefix from those supported | |
602 unit_list = unit.supportedUnits; | |
603 % remove the first empty unit '' from the list, because then is it | |
604 % possible that we add a prefix to an empty unit | |
605 unit_list = unit_list(2:end); | |
606 prefix_list = unit.supportedPrefixes; | |
607 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
608 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
609 | |
610 % Evaluate the complex coherence of the time-series data | |
611 win_list = specwin.getTypes; | |
612 win = utils.math.randelement(win_list,1); | |
613 win = win{1}; | |
614 if strcmp(win, 'Kaiser') | |
615 win = specwin(win, 1, find(ao.getInfo('psd').plists, 'psll')); | |
616 else | |
617 win = specwin(win, 1); | |
618 end | |
619 olap = win.rov; | |
620 detrend = 0; | |
621 scale_type = 'C'; | |
622 | |
623 C12 = lcohere(a_1, a_2, ... | |
624 plist('Win', win.type, 'olap', olap, 'order', detrend, 'type', scale_type)); | |
625 C21 = lcohere(a_2, a_1, ... | |
626 plist('Win', win.type, 'olap', olap, 'order', detrend, 'type', scale_type)); | |
627 C21_cc = conj(C21); | |
628 C11 = lcohere(a_1, a_1, ... | |
629 plist('Win', win.type, 'olap', olap, 'order', detrend, 'type', scale_type)); | |
630 C22 = lcohere(a_2, a_2, ... | |
631 plist('Win', win.type, 'olap', olap, 'order', detrend, 'type', scale_type)); | |
632 stest = true; | |
633 | |
634 catch err | |
635 disp(err.message) | |
636 stest = false; | |
637 end | |
638 % </SyntaxCode> | |
639 | |
640 % <AlgoDescription> | |
641 % | |
642 % 1) Check that C(x,y) equals conj(C(y,x)) | |
643 % 2) Check that C(x,x) equals 1 | |
644 % 2) Check that C(y,y) equals 1 | |
645 | |
646 % </AlgoDescription> | |
647 | |
648 % <AlgoCode> | |
649 atest = true; | |
650 tol = 1e-12; | |
651 | |
652 if stest | |
653 if ~eq(C12.data, C21_cc.data, 'dy') || ... | |
654 any(abs(C11.y-ones(size(C11.y))) > tol) || ... | |
655 any(abs(C22.y-ones(size(C22.y))) > tol) | |
656 atest = false; | |
657 end | |
658 else | |
659 atest = false; | |
660 end | |
661 % </AlgoCode> | |
662 | |
663 % Return a result structure | |
664 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
665 end % END UTP_12 | |
666 | |
667 %% UTP_13 | |
668 | |
669 % <TestDescription> | |
670 % | |
671 % Tests symmetry properties of complex-coherence: | |
672 % 1) white noise produced from normal pdf, with a given mean value and | |
673 % sigma (distribution's 1st and 2nd orders) | |
674 % 2) white noise produced from normal pdf, with a given mean value and | |
675 % sigma (distribution's 1st and 2nd orders) | |
676 % 3) magnitude-squared log-scale coherence of the white noise series | |
677 % 4) compare C(x,y) with C(y,x) | |
678 % 5) compare C(x,x) and C(y,y) with 1 | |
679 % | |
680 | |
681 % </TestDescription> | |
682 function result = utp_13 | |
683 | |
684 % <SyntaxDescription> | |
685 % | |
686 % 1) Prepare the test tsdata: | |
687 % white noise from normal distribution + offset | |
688 % 2) Assign a random unit | |
689 % 3) Prepare the test tsdata: | |
690 % white noise from normal distribution + offset | |
691 % 4) Assign a random unit | |
692 % 5) magnitude-squared log-scale coherence of the white noise | |
693 % | |
694 % </SyntaxDescription> | |
695 | |
696 % <SyntaxCode> | |
697 try | |
698 | |
699 % Array of parameters to pick from | |
700 fs_list = [0.1;1;10]; | |
701 nsecs_list = [100:100:10000]'; | |
702 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]'; | |
703 mu_distr_list = [1e-6 2e-3 0.25 1:0.1:10]'; | |
704 | |
705 % Build time-series test data | |
706 | |
707 % Picks the values at random from the list | |
708 fs = utils.math.randelement(fs_list, 1); | |
709 nsecs = utils.math.randelement(nsecs_list, 1); | |
710 sigma_distr = utils.math.randelement(sigma_distr_list, 1); | |
711 mu_distr = utils.math.randelement(mu_distr_list, 1); | |
712 f = [1:5] / 100 * fs; | |
713 A = sigma_distr + sigma_distr*rand(1,1); | |
714 phi = 0 + 2*pi*rand(1,1); | |
715 | |
716 % White noise | |
717 type = 'Normal'; | |
718 a_n1 = ao(plist('waveform', 'noise', ... | |
719 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr)); | |
720 a_n2 = ao(plist('waveform', 'noise', ... | |
721 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr)); | |
722 a_const = ao(mu_distr); | |
723 a_wave = ao(plist('waveform', 'sine-wave', ... | |
724 'fs', fs, 'nsecs', nsecs, 'f', f, 'A', A, 'phi', phi)); | |
725 a_1 = a_n1 + a_const + a_wave; | |
726 a_2 = a_n2 + a_wave; | |
727 | |
728 % Set units and prefix from those supported | |
729 unit_list = unit.supportedUnits; | |
730 % remove the first empty unit '' from the list, because then is it | |
731 % possible that we add a prefix to an empty unit | |
732 unit_list = unit_list(2:end); | |
733 prefix_list = unit.supportedPrefixes; | |
734 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
735 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
736 | |
737 % Evaluate the magnitude-squared coherence of the time-series data | |
738 win_list = specwin.getTypes; | |
739 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1); | |
740 win_type = win_type{1}; | |
741 if strcmp(win_type, 'Kaiser') | |
742 win = specwin(win_type, 1, find(ao.getInfo('psd').plists, 'psll')); | |
743 else | |
744 win = specwin(win_type, 1); | |
745 end | |
746 olap = win.rov; | |
747 detrend = 0; | |
748 scale_type = 'MS'; | |
749 | |
750 C12 = lcohere(a_1, a_2, ... | |
751 plist('Win', win.type, 'olap', olap, 'order', detrend, 'type', scale_type)); | |
752 C21 = lcohere(a_2, a_1, ... | |
753 plist('Win', win.type, 'olap', olap, 'order', detrend, 'type', scale_type)); | |
754 C11 = lcohere(a_1, a_1, ... | |
755 plist('Win', win.type, 'olap', olap, 'order', detrend, 'type', scale_type)); | |
756 C22 = lcohere(a_2, a_2, ... | |
757 plist('Win', win.type, 'olap', olap, 'order', detrend, 'type', scale_type)); | |
758 stest = true; | |
759 | |
760 catch err | |
761 disp(err.message) | |
762 stest = false; | |
763 end | |
764 % </SyntaxCode> | |
765 | |
766 % <AlgoDescription> | |
767 % | |
768 % 1) Check that C(x,y) equals C(y,x) | |
769 % 1) Check that C(x,x) equals 1 | |
770 % 1) Check that C(y,y) equals 1 | |
771 | |
772 % </AlgoDescription> | |
773 | |
774 % <AlgoCode> | |
775 atest = true; | |
776 tol = 1e-12; | |
777 | |
778 if stest | |
779 if ~eq(C12.data, C21.data) || ... | |
780 any(abs(C11.y - ones(size(C11.y))) > tol) || ... | |
781 any(abs(C22.y - ones(size(C22.y))) > tol) | |
782 atest = false; | |
783 end | |
784 else | |
785 atest = false; | |
786 end | |
787 % </AlgoCode> | |
788 | |
789 % Return a result structure | |
790 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
791 end % END UTP_13 | |
792 | |
793 %% UTP_14 | |
794 | |
795 % <TestDescription> | |
796 % | |
797 % Tests symmetry properties of complex-coherence: | |
798 % 1) white noise produced from normal pdf, with a given mean value and | |
799 % sigma (distribution's 1st and 2nd orders) | |
800 % 2) white noise produced from normal pdf, with a given mean value and | |
801 % sigma (distribution's 1st and 2nd orders) | |
802 % 3) complex log-scale coherence of the combination of white noise series | |
803 % 4) compare C(x,y) with 1 | |
804 % | |
805 | |
806 % </TestDescription> | |
807 function result = utp_14 | |
808 | |
809 % <SyntaxDescription> | |
810 % | |
811 % 1) Prepare the test tsdata: | |
812 % white noise from normal distribution + offset | |
813 % 2) Assign a random unit | |
814 % 3) Prepare the test tsdata: | |
815 % white noise from normal distribution + offset | |
816 % 4) Assign a random unit | |
817 % 5) complex log-scale coherence of the combination of noise | |
818 % | |
819 % </SyntaxDescription> | |
820 | |
821 % <SyntaxCode> | |
822 try | |
823 | |
824 % Array of parameters to pick from | |
825 fs_list = [0.1;1;10]; | |
826 nsecs_list = [100:100:10000]'; | |
827 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]'; | |
828 mu_distr_list = [1e-6 2e-3 0.25 1:0.1:10]'; | |
829 | |
830 % Build time-series test data | |
831 | |
832 % Picks the values at random from the list | |
833 fs = utils.math.randelement(fs_list, 1); | |
834 nsecs = utils.math.randelement(nsecs_list, 1); | |
835 sigma_distr = utils.math.randelement(sigma_distr_list, 1); | |
836 mu_distr = utils.math.randelement(mu_distr_list, 1); | |
837 f = [1:5] / 100 * fs; | |
838 A = sigma_distr + sigma_distr*rand(1,1); | |
839 phi = 0 + 2*pi*rand(1,1); | |
840 | |
841 % White noise | |
842 type = 'Normal'; | |
843 a_n = ao(plist('waveform', 'noise', ... | |
844 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr)); | |
845 a_const = ao(mu_distr); | |
846 % Sinusoidal signal | |
847 a_wave = ao(plist('waveform', 'sine-wave', ... | |
848 'fs', fs, 'nsecs', nsecs, 'f', f, 'A', A, 'phi', phi)); | |
849 a_1 = a_n + a_wave; | |
850 % Linear combination (totally correlated time series) | |
851 a_2 = a_1 + a_const; | |
852 | |
853 % Set units and prefix from those supported | |
854 unit_list = unit.supportedUnits; | |
855 % remove the first empty unit '' from the list, because then is it | |
856 % possible that we add a prefix to an empty unit | |
857 unit_list = unit_list(2:end); | |
858 prefix_list = unit.supportedPrefixes; | |
859 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
860 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
861 | |
862 % Evaluate the complex coherence of the time-series data | |
863 win_list = specwin.getTypes; | |
864 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1); | |
865 win_type = win_type{1}; | |
866 if strcmp(win_type, 'Kaiser') | |
867 win = specwin(win_type, 1, find(ao.getInfo('psd').plists, 'psll')); | |
868 else | |
869 win = specwin(win_type, 1); | |
870 end | |
871 olap = win.rov; | |
872 detrend = 0; | |
873 scale_type = 'C'; | |
874 | |
875 C = lcohere(a_1, a_2, ... | |
876 plist('Win', win.type, 'olap', olap, 'order', detrend, 'type', scale_type)); | |
877 stest = true; | |
878 | |
879 catch err | |
880 disp(err.message) | |
881 stest = false; | |
882 end | |
883 % </SyntaxCode> | |
884 | |
885 % <AlgoDescription> | |
886 % | |
887 % 1) Check that the complex coherence equals 1 | |
888 | |
889 % </AlgoDescription> | |
890 | |
891 % <AlgoCode> | |
892 atest = true; | |
893 TOL = 1e-12; | |
894 | |
895 if stest | |
896 if any(abs((C.y - 1)) > TOL) | |
897 atest = false; | |
898 end | |
899 else | |
900 atest = false; | |
901 end | |
902 % </AlgoCode> | |
903 | |
904 % Return a result structure | |
905 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
906 end % END UTP_14 | |
907 | |
908 %% UTP_15 | |
909 | |
910 % <TestDescription> | |
911 % | |
912 % Tests symmetry properties of complex-coherence: | |
913 % 1) white noise produced from normal pdf, with a given mean value and | |
914 % sigma (distribution's 1st and 2nd orders) | |
915 % 2) white noise produced from normal pdf, with a given mean value and | |
916 % sigma (distribution's 1st and 2nd orders) | |
917 % 3) magnitude-squared log-scale coherence of the combination of white noise series | |
918 % 4) compare C(x,y) with 1 | |
919 % | |
920 | |
921 % </TestDescription> | |
922 function result = utp_15 | |
923 | |
924 % <SyntaxDescription> | |
925 % | |
926 % 1) Prepare the test tsdata: | |
927 % white noise from normal distribution + offset | |
928 % 2) Assign a random unit | |
929 % 3) Prepare the test tsdata: | |
930 % white noise from normal distribution + offset | |
931 % 4) Assign a random unit | |
932 % 5) magnitude-squared log-scale coherence of the combination of noise | |
933 % | |
934 % </SyntaxDescription> | |
935 | |
936 % <SyntaxCode> | |
937 try | |
938 | |
939 % Array of parameters to pick from | |
940 fs_list = [0.1;1;10]; | |
941 nsecs_list = [100:100:10000]'; | |
942 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]'; | |
943 mu_distr_list = [1e-6 2e-3 0.25 1:0.1:10]'; | |
944 | |
945 % Build time-series test data | |
946 | |
947 % Picks the values at random from the list | |
948 fs = utils.math.randelement(fs_list, 1); | |
949 nsecs = utils.math.randelement(nsecs_list, 1); | |
950 sigma_distr = utils.math.randelement(sigma_distr_list, 1); | |
951 mu_distr = utils.math.randelement(mu_distr_list, 1); | |
952 f = [1:5] / 100 * fs; | |
953 A = sigma_distr + sigma_distr*rand(1,1); | |
954 phi = 0 + 2*pi*rand(1,1); | |
955 | |
956 % White noise | |
957 type = 'Normal'; | |
958 a_n = ao(plist('waveform', 'noise', ... | |
959 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr)); | |
960 a_const = ao(mu_distr); | |
961 % Sinusoidal signal | |
962 a_wave = ao(plist('waveform', 'sine-wave', ... | |
963 'fs', fs, 'nsecs', nsecs, 'f', f, 'A', A, 'phi', phi)); | |
964 a_1 = a_n + a_wave; | |
965 % Linear combination (totally correlated time series) | |
966 a_2 = a_1 + a_const; | |
967 | |
968 % Set units and prefix from those supported | |
969 unit_list = unit.supportedUnits; | |
970 % remove the first empty unit '' from the list, because then is it | |
971 % possible that we add a prefix to an empty unit | |
972 unit_list = unit_list(2:end); | |
973 prefix_list = unit.supportedPrefixes; | |
974 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
975 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
976 | |
977 % Evaluate the complex coherence of the time-series data | |
978 win_list = specwin.getTypes; | |
979 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1); | |
980 win_type = win_type{1}; | |
981 if strcmp(win_type, 'Kaiser') | |
982 win = specwin(win_type, 1, find(ao.getInfo('psd').plists, 'psll')); | |
983 else | |
984 win = specwin(win_type, 1); | |
985 end | |
986 olap = win.rov; | |
987 detrend = 0; | |
988 scale_type = 'MS'; | |
989 | |
990 C = lcohere(a_1, a_2, ... | |
991 plist('Win', win.type, 'olap', olap, 'order', detrend, 'type', scale_type)); | |
992 stest = true; | |
993 | |
994 catch err | |
995 disp(err.message) | |
996 stest = false; | |
997 end | |
998 % </SyntaxCode> | |
999 | |
1000 % <AlgoDescription> | |
1001 % | |
1002 % 1) Check that the magnitude-squared coherence equals 1 | |
1003 | |
1004 % </AlgoDescription> | |
1005 | |
1006 % <AlgoCode> | |
1007 atest = true; | |
1008 | |
1009 if stest | |
1010 if ~eq(C.y, ones(size(C.y))) | |
1011 atest = false; | |
1012 end | |
1013 else | |
1014 atest = false; | |
1015 end | |
1016 % </AlgoCode> | |
1017 | |
1018 % Return a result structure | |
1019 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
1020 end % END UTP_15 | |
1021 | |
1022 %% UTP_16 | |
1023 | |
1024 % <TestDescription> | |
1025 % | |
1026 % Tests symmetry properties of complex-coherence: | |
1027 % 1) white noise produced from normal pdf, with a given mean value and | |
1028 % sigma (distribution's 1st and 2nd orders) | |
1029 % 2) white noise produced from normal pdf, with a given mean value and | |
1030 % sigma (distribution's 1st and 2nd orders) | |
1031 % 3) magnitude-squared log-scale coherence M of the combination of white noise series | |
1032 % 4) complex log-scale coherence C of the combination of white noise series | |
1033 % 5) compare abs(C)^2 with M | |
1034 % | |
1035 | |
1036 % </TestDescription> | |
1037 function result = utp_16 | |
1038 | |
1039 % <SyntaxDescription> | |
1040 % | |
1041 % 1) Prepare the test tsdata: | |
1042 % white noise from normal distribution + offset | |
1043 % 2) Assign a random unit | |
1044 % 3) Prepare the test tsdata: | |
1045 % white noise from normal distribution + offset | |
1046 % 4) Assign a random unit | |
1047 % 5) magnitude-squared log-scale coherence of the combination of noise | |
1048 % 6) complex log-scale coherence of the combination of noise | |
1049 % | |
1050 % </SyntaxDescription> | |
1051 | |
1052 % <SyntaxCode> | |
1053 try | |
1054 | |
1055 % Array of parameters to pick from | |
1056 fs_list = [0.1;1;10]; | |
1057 nsecs_list = [100:100:10000]'; | |
1058 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]'; | |
1059 mu_distr_list = [1e-6 2e-3 0.25 1:0.1:10]'; | |
1060 | |
1061 % Build time-series test data | |
1062 | |
1063 % Picks the values at random from the list | |
1064 fs = utils.math.randelement(fs_list, 1); | |
1065 nsecs = utils.math.randelement(nsecs_list, 1); | |
1066 sigma_distr = utils.math.randelement(sigma_distr_list, 1); | |
1067 mu_distr = utils.math.randelement(mu_distr_list, 1); | |
1068 f = [1:5] / 100 * fs; | |
1069 A = sigma_distr + sigma_distr*rand(1,1); | |
1070 phi = 0 + 2*pi*rand(1,1); | |
1071 | |
1072 % White noise | |
1073 type = 'Normal'; | |
1074 a_n = ao(plist('waveform', 'noise', ... | |
1075 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr)); | |
1076 a_const = ao(mu_distr); | |
1077 % Sinusoidal signal | |
1078 a_wave = ao(plist('waveform', 'sine-wave', ... | |
1079 'fs', fs, 'nsecs', nsecs, 'f', f, 'A', A, 'phi', phi)); | |
1080 a_1 = a_n + a_wave; | |
1081 % Linear combination (totally correlated time series) | |
1082 a_2 = a_1 + a_const; | |
1083 | |
1084 % Set units and prefix from those supported | |
1085 unit_list = unit.supportedUnits; | |
1086 % remove the first empty unit '' from the list, because then is it | |
1087 % possible that we add a prefix to an empty unit | |
1088 unit_list = unit_list(2:end); | |
1089 prefix_list = unit.supportedPrefixes; | |
1090 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
1091 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
1092 | |
1093 % Evaluate the complex coherence of the time-series data | |
1094 win_list = specwin.getTypes; | |
1095 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1); | |
1096 win_type = win_type{1}; | |
1097 if strcmp(win_type, 'Kaiser') | |
1098 win = specwin(win_type, 1, find(ao.getInfo('psd').plists, 'psll')); | |
1099 else | |
1100 win = specwin(win_type, 1); | |
1101 end | |
1102 olap = win.rov; | |
1103 detrend = 0; | |
1104 | |
1105 M = lcohere(a_1, a_2, ... | |
1106 plist('Win', win.type, 'olap', olap, 'order', detrend, 'type', 'MS')); | |
1107 C = lcohere(a_1, a_2, ... | |
1108 plist('Win', win.type, 'olap', olap, 'order', detrend, 'type', 'C')); | |
1109 stest = true; | |
1110 | |
1111 catch err | |
1112 disp(err.message) | |
1113 stest = false; | |
1114 end | |
1115 % </SyntaxCode> | |
1116 | |
1117 % <AlgoDescription> | |
1118 % | |
1119 % 1) Check that the magnitude-squared coherence equals the square | |
1120 % modulus of the complex coherence | |
1121 | |
1122 % </AlgoDescription> | |
1123 | |
1124 % <AlgoCode> | |
1125 atest = true; | |
1126 TOL = 1e-15; | |
1127 | |
1128 if stest | |
1129 if any(abs(M.y - abs(C.y).^2) > TOL) | |
1130 atest = false; | |
1131 end | |
1132 else | |
1133 atest = false; | |
1134 end | |
1135 % </AlgoCode> | |
1136 | |
1137 % Return a result structure | |
1138 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
1139 end % END UTP_16 | |
1140 | |
1141 %% UTP_17 | |
1142 | |
1143 % <TestDescription> | |
1144 % | |
1145 % Tests handling of units: | |
1146 % 1) white noise produced from normal pdf, with a given mean value and | |
1147 % sigma (distribution's 1st and 2nd orders) | |
1148 % 2) white noise produced from normal pdf, with a given mean value and | |
1149 % sigma (distribution's 1st and 2nd orders) | |
1150 % 3) complex log-scale coherence of the white noise series | |
1151 % 4) compares the units of the input and output | |
1152 % | |
1153 | |
1154 % </TestDescription> | |
1155 function result = utp_17 | |
1156 | |
1157 % <SyntaxDescription> | |
1158 % | |
1159 % 1) Prepare the test tsdata: | |
1160 % white noise from normal distribution + offset | |
1161 % 2) Assign a random unit | |
1162 % 3) Prepare the test tsdata: | |
1163 % white noise from normal distribution + offset | |
1164 % 4) Assign a random unit | |
1165 % 5) complex cohere of the white noise | |
1166 % | |
1167 % </SyntaxDescription> | |
1168 | |
1169 % <SyntaxCode> | |
1170 try | |
1171 | |
1172 % Build time-series test data | |
1173 fs = 1; | |
1174 nsecs = 86400; | |
1175 sigma_distr_1 = 4.69e-12; | |
1176 mu_distr_1 = -5.11e-14; | |
1177 sigma_distr_2 = 6.04e-9; | |
1178 mu_distr_2 = 1.5e-10; | |
1179 | |
1180 % White noise | |
1181 type = 'Normal'; | |
1182 | |
1183 a_n = ao(plist('waveform', 'noise', ... | |
1184 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_1)); | |
1185 a_const = ao(mu_distr_1); | |
1186 a_1 = a_n + a_const; | |
1187 | |
1188 a_n = ao(plist('waveform', 'noise', ... | |
1189 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_2)); | |
1190 a_const = ao(mu_distr_2); | |
1191 a_2 = a_n + a_const; | |
1192 | |
1193 % Set units and prefix from those supported | |
1194 unit_list = unit.supportedUnits; | |
1195 % remove the first empty unit '' from the list, because then is it | |
1196 % possible that we add a prefix to an empty unit | |
1197 unit_list = unit_list(2:end); | |
1198 prefix_list = unit.supportedPrefixes; | |
1199 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
1200 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
1201 | |
1202 % Evaluate the log-scale coherence of the time-series data | |
1203 win = specwin('BH92'); | |
1204 olap = win.rov; | |
1205 detrend = 0; | |
1206 scale_type = 'C'; | |
1207 | |
1208 C = lcohere(a_1, a_2, plist('Win', win.type, 'olap', olap, 'order', detrend, 'type', scale_type)); | |
1209 | |
1210 stest = true; | |
1211 | |
1212 catch err | |
1213 disp(err.message) | |
1214 stest = false; | |
1215 end | |
1216 % </SyntaxCode> | |
1217 | |
1218 % <AlgoDescription> | |
1219 % | |
1220 % 1) Check that (complex coherence yunits) equals [1] | |
1221 % 2) Check that (complex coherence xunits) equals [Hz] | |
1222 | |
1223 % </AlgoDescription> | |
1224 | |
1225 % <AlgoCode> | |
1226 atest = true; | |
1227 | |
1228 if stest | |
1229 if ne(C.yunits, unit('')) || ne(C.xunits, unit('Hz')) | |
1230 atest = false; | |
1231 end | |
1232 else | |
1233 atest = false; | |
1234 end | |
1235 % </AlgoCode> | |
1236 | |
1237 % Return a result structure | |
1238 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
1239 end % END UTP_17 | |
1240 | |
1241 %% UTP_18 | |
1242 | |
1243 % <TestDescription> | |
1244 % | |
1245 % Tests handling of units: | |
1246 % 1) white noise produced from normal pdf, with a given mean value and | |
1247 % sigma (distribution's 1st and 2nd orders) | |
1248 % 2) white noise produced from normal pdf, with a given mean value and | |
1249 % sigma (distribution's 1st and 2nd orders) | |
1250 % 3) magnitude-squared log-scale coherence of the white noise series | |
1251 % 4) compares the units of the input and output | |
1252 % | |
1253 | |
1254 % </TestDescription> | |
1255 function result = utp_18 | |
1256 | |
1257 % <SyntaxDescription> | |
1258 % | |
1259 % 1) Prepare the test tsdata: | |
1260 % white noise from normal distribution + offset | |
1261 % 2) Assign a random unit | |
1262 % 3) Prepare the test tsdata: | |
1263 % white noise from normal distribution + offset | |
1264 % 4) Assign a random unit | |
1265 % 5) magnitude-squared cohere of the white noise | |
1266 % | |
1267 % </SyntaxDescription> | |
1268 | |
1269 % <SyntaxCode> | |
1270 try | |
1271 | |
1272 % Build time-series test data | |
1273 fs = 1; | |
1274 nsecs = 86400; | |
1275 sigma_distr_1 = 4.69e-12; | |
1276 mu_distr_1 = -5.11e-14; | |
1277 sigma_distr_2 = 6.04e-9; | |
1278 mu_distr_2 = 1.5e-10; | |
1279 | |
1280 % White noise | |
1281 type = 'Normal'; | |
1282 | |
1283 a_n = ao(plist('waveform', 'noise', ... | |
1284 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_1)); | |
1285 a_const = ao(mu_distr_1); | |
1286 a_1 = a_n + a_const; | |
1287 | |
1288 a_n = ao(plist('waveform', 'noise', ... | |
1289 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_2)); | |
1290 a_const = ao(mu_distr_2); | |
1291 a_2 = a_n + a_const; | |
1292 | |
1293 % Set units and prefix from those supported | |
1294 unit_list = unit.supportedUnits; | |
1295 % remove the first empty unit '' from the list, because then is it | |
1296 % possible that we add a prefix to an empty unit | |
1297 unit_list = unit_list(2:end); | |
1298 prefix_list = unit.supportedPrefixes; | |
1299 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
1300 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
1301 | |
1302 % Evaluate the log-scale coherence of the time-series data | |
1303 win = specwin('BH92'); | |
1304 olap = win.rov; | |
1305 detrend = 0; | |
1306 scale_type = 'MS'; | |
1307 | |
1308 C = lcohere(a_1, a_2, plist('Win', win.type, 'olap', olap, 'order', detrend, 'type', scale_type)); | |
1309 | |
1310 stest = true; | |
1311 | |
1312 catch err | |
1313 disp(err.message) | |
1314 stest = false; | |
1315 end | |
1316 % </SyntaxCode> | |
1317 | |
1318 % <AlgoDescription> | |
1319 % | |
1320 % 1) Check that (magnitude-squared coherence yunits) equals [1] | |
1321 % 2) Check that (magnitude-squared coherence xunits) equals [Hz] | |
1322 | |
1323 % </AlgoDescription> | |
1324 | |
1325 % <AlgoCode> | |
1326 atest = true; | |
1327 | |
1328 if stest | |
1329 if ne(C.yunits, unit('')) || ne(C.xunits, unit('Hz')) | |
1330 atest = false; | |
1331 end | |
1332 else | |
1333 atest = false; | |
1334 end | |
1335 % </AlgoCode> | |
1336 | |
1337 % Return a result structure | |
1338 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
1339 end % END UTP_18 | |
1340 | |
1341 %% UTP_30 | |
1342 | |
1343 % <TestDescription> | |
1344 % | |
1345 % Tests handling of special cases: | |
1346 % 1) white noise produced from normal pdf, with a given mean value and | |
1347 % sigma (distribution's 1st and 2nd orders) | |
1348 % 2) the same noise series | |
1349 % 3) lcohere of the white noise series | |
1350 % 4) compares the output to unity | |
1351 % | |
1352 | |
1353 % </TestDescription> | |
1354 function result = utp_30 | |
1355 | |
1356 % <SyntaxDescription> | |
1357 % | |
1358 % 1) Prepare the test tsdata: | |
1359 % white noise from normal distribution + offset | |
1360 % 2) Assign a random unit | |
1361 % 3) Prepare the test tsdata: | |
1362 % the same data as 1) and 2) | |
1363 % 4) lcohere of the series | |
1364 % | |
1365 % </SyntaxDescription> | |
1366 | |
1367 % <SyntaxCode> | |
1368 try | |
1369 | |
1370 % Build time-series test data | |
1371 fs = 1; | |
1372 nsecs = 86400; | |
1373 sigma_distr_1 = 4.69e-12; | |
1374 mu_distr_1 = -5.11e-14; | |
1375 | |
1376 % White noise | |
1377 type = 'Normal'; | |
1378 | |
1379 a_n = ao(plist('waveform', 'noise', ... | |
1380 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_1)); | |
1381 a_const = ao(mu_distr_1); | |
1382 a_1 = a_n + a_const; | |
1383 | |
1384 % Set units and prefix from those supported | |
1385 unit_list = unit.supportedUnits; | |
1386 % remove the first empty unit '' from the list, because then is it | |
1387 % possible that we add a prefix to an empty unit | |
1388 unit_list = unit_list(2:end); | |
1389 prefix_list = unit.supportedPrefixes; | |
1390 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))])); | |
1391 | |
1392 % Build the second object as a copy of the first | |
1393 a_2 = a_1; | |
1394 | |
1395 % Evaluate the lcohere of the time-series data | |
1396 win = specwin('BH92'); | |
1397 olap = win.rov; | |
1398 detrend = 0; | |
1399 scale_type = 'C'; | |
1400 | |
1401 C = lcohere(a_1, a_2, ... | |
1402 plist('Win', win.type, 'order', detrend, 'type', scale_type, 'olap', olap)); | |
1403 | |
1404 stest = true; | |
1405 | |
1406 catch err | |
1407 disp(err.message) | |
1408 stest = false; | |
1409 end | |
1410 % </SyntaxCode> | |
1411 | |
1412 % <AlgoDescription> | |
1413 % | |
1414 % 1) Check that calculated lcohere equals 1 | |
1415 | |
1416 % </AlgoDescription> | |
1417 | |
1418 % <AlgoCode> | |
1419 atest = true; | |
1420 | |
1421 if stest | |
1422 if sum(ne(C.y, 1)) | |
1423 atest = false; | |
1424 end | |
1425 else | |
1426 atest = false; | |
1427 end | |
1428 % </AlgoCode> | |
1429 | |
1430 % Return a result structure | |
1431 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
1432 end % END UTP_30 | |
1433 | |
1434 end |