comparison testing/utp_1.1/utps/ao/utp_ao_tfe.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_TFE a set of UTPs for the ao/tfe method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_tfe.m,v 1.35 2011/07/22 12:29:58 mauro Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The tfe method of the ao class computes the transfer function between two
11 % time-series AOs.
12 %
13 % </MethodDescription>
14
15 function results = utp_ao_tfe(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 class = 'ao';
22 mthd = 'tfe';
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 results = [results utp_10]; % Test the basic usage against MATLAB's tfestimate
50
51 results = [results utp_11(mthd, [at1 at1], ple1)]; % Test plotinfo doesn't disappear
52
53 results = [results utp_12]; % Test data lengths
54 results = [results utp_17]; % Test units handling: tfe
55 results = [results utp_21]; % Test number of averages: requested/obtained
56 results = [results utp_22]; % Test number of averages: correct number
57 results = [results utp_23]; % Test number of averages: syntax
58 results = [results utp_25]; % Test Kaiser win and olap: tfe
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 ~= 8, atest = false; end
129 % Check key
130 if ~io(3).plists.isparam('nfft'), atest = false; end
131 if ~io(3).plists.isparam('win'), atest = false; end
132 if ~io(3).plists.isparam('olap'), atest = false; end
133 if ~io(3).plists.isparam('order'), atest = false; end
134 if ~io(3).plists.isparam('navs'), atest = false; end
135 if ~io(3).plists.isparam('times'), atest = false; end
136 if ~io(3).plists.isparam('split'), atest = false; end
137 if ~io(3).plists.isparam('psll'), atest = false; end
138 % Check default value
139 if ~isequal(io(3).plists.find('nfft'), -1), atest = false; end
140 if ~strcmpi(io(3).plists.find('win'), defaultWinType), atest = false; end
141 if ~isequal(io(3).plists.find('olap'), -1), atest = false; end
142 if ~isequal(io(3).plists.find('order'), 0), atest = false; end
143 if ~isequal(io(3).plists.find('navs'), -1), atest = false; end
144 if ~isEmptyDouble(io(3).plists.find('times')), atest = false; end
145 if ~isEmptyDouble(io(3).plists.find('split')), atest = false; end
146 if ~isequal(io(3).plists.find('psll'), 200), atest = false; end
147 % Check options
148 if ~isequal(io(3).plists.getOptionsForParam('nfft'), {-1}), atest = false; end
149 if ~isequal(io(3).plists.getOptionsForParam('win'), specwin.getTypes), atest = false; end
150 if ~isequal(io(3).plists.getOptionsForParam('olap'), {-1}), atest = false; end
151 if ~isequal(io(3).plists.getOptionsForParam('order'), {-1 0 1 2 3 4 5 6 7 8 9}), atest = false; end
152 if ~isequal(io(3).plists.getOptionsForParam('navs'), {-1}), atest = false; end
153 if ~isequal(io(3).plists.getOptionsForParam('times'), {[]}), atest = false; end
154 if ~isequal(io(3).plists.getOptionsForParam('split'), {[]}), atest = false; end
155 if ~isequal(io(3).plists.getOptionsForParam('psll'), {200}), atest = false; end
156 end
157 % </AlgoCode>
158 else
159 atest = false;
160 end
161
162 % Return a result structure
163 result = utp_prepare_result(atest, stest, dbstack, mfilename);
164 end % END UTP_01
165
166 %% UTP_02
167
168 % <TestDescription>
169 %
170 % Tests that the tfe method works with a vector of AOs as input. (only
171 % with two objects in the vector)
172 %
173 % </TestDescription>
174 function result = utp_02
175
176 % <SyntaxDescription>
177 %
178 % Test that the tfe method works for a vector of AOs as input.
179 %
180 % </SyntaxDescription>
181
182 try
183 % <SyntaxCode>
184 avec = [at1 at5];
185 out = tfe(avec);
186 % </SyntaxCode>
187 stest = true;
188 catch err
189 disp(err.message)
190 stest = false;
191 end
192
193 % <AlgoDescription>
194 %
195 % 1) Check that the number of elements in 'out' is equal to 1.
196 %
197 % </AlgoDescription>
198
199 atest = true;
200 if stest
201 % <AlgoCode>
202 % Check we have the correct number of outputs
203 if numel(out) ~= 1, atest = false; end
204 % </AlgoCode>
205 else
206 atest = false;
207 end
208
209 % Return a result structure
210 result = utp_prepare_result(atest, stest, dbstack, mfilename);
211 end % END UTP_02
212
213 %% UTP_03
214
215 % <TestDescription>
216 %
217 % Test that the tfe method doesn't work for a matrix of AOs as input.
218 %
219 % </TestDescription>
220 function result = utp_03
221
222 % <SyntaxDescription>
223 %
224 % Test that the tfe method doesn't work for a matrix of AOs as input.
225 %
226 % </SyntaxDescription>
227
228 try
229 % <SyntaxCode>
230 amat = [at1 at5 at6; at5 at6 at1];
231 out = tfe(amat);
232 % </SyntaxCode>
233 stest = false;
234 catch err
235 stest = true;
236 end
237
238 % <AlgoDescription>
239 %
240 % 1) Nothing to check.
241 %
242 % </AlgoDescription>
243
244 atest = true;
245 if stest
246 % <AlgoCode>
247 % </AlgoCode>
248 else
249 atest = false;
250 end
251
252 % Return a result structure
253 result = utp_prepare_result(atest, stest, dbstack, mfilename);
254 end % END UTP_03
255
256 %% UTP_04
257
258 % <TestDescription>
259 %
260 % Tests that the tfe method works with a list of AOs as input.
261 %
262 % </TestDescription>
263 function result = utp_04
264
265 % <SyntaxDescription>
266 %
267 % Test that the tfe method works for a list of AOs as input.
268 %
269 % </SyntaxDescription>
270
271 try
272 % <SyntaxCode>
273 out = tfe(at1,at5);
274 % </SyntaxCode>
275 stest = true;
276 catch err
277 disp(err.message)
278 stest = false;
279 end
280
281 % <AlgoDescription>
282 %
283 % 1) Check that the number of elements in 'out' is equal to 1.
284 %
285 % </AlgoDescription>
286
287 atest = true;
288 if stest
289 % <AlgoCode>
290 % Check we have the correct number of outputs
291 if numel(out) ~= 1, atest = false; end
292 % </AlgoCode>
293 else
294 atest = false;
295 end
296
297 % Return a result structure
298 result = utp_prepare_result(atest, stest, dbstack, mfilename);
299 end % END UTP_04
300
301 %% UTP_05
302
303 % <TestDescription>
304 %
305 % Tests that the tfe method doesn't work with a mix of different shaped
306 % AOs as input.
307 %
308 % </TestDescription>
309 function result = utp_05
310
311 % <SyntaxDescription>
312 %
313 % Test that the tfe method doesn't work with an input of matrices and
314 % vectors and single AOs.
315 %
316 % </SyntaxDescription>
317
318 try
319 % <SyntaxCode>
320 out = tfe(at1,[at5 at6],at5,[at5 at1; at6 at1],at6);
321 stest = false;
322 % </SyntaxCode>
323 catch err
324 stest = true;
325 end
326
327 % <AlgoDescription>
328 %
329 % 1) Nothing to check
330 %
331 % </AlgoDescription>
332
333 atest = true;
334 if stest
335 % <AlgoCode>
336 % </AlgoCode>
337 else
338 atest = false;
339 end
340
341 % Return a result structure
342 result = utp_prepare_result(atest, stest, dbstack, mfilename);
343 end % END UTP_05
344
345 %% UTP_06
346
347 % <TestDescription>
348 %
349 % Tests that the tfe method properly applies history.
350 %
351 % </TestDescription>
352 function result = utp_06
353
354 % <SyntaxDescription>
355 %
356 % Test that the result of applying the tfe method can be processed back
357 % to an m-file.
358 %
359 % </SyntaxDescription>
360
361 try
362 % <SyntaxCode>
363 out = tfe(at5,at6);
364 mout = rebuild(out);
365 % </SyntaxCode>
366 stest = true;
367 catch err
368 disp(err.message)
369 stest = false;
370 end
371
372 % <AlgoDescription>
373 %
374 % 1) Check that the last entry in the history of 'out' corresponds to
375 % 'tfe'.
376 % 2) Check that the re-built object is the same as 'out'.
377 %
378 % </AlgoDescription>
379
380 atest = true;
381 if stest
382 % <AlgoCode>
383 % Check the last step in the history of 'out'
384 if ~strcmp(out.hist.methodInfo.mname, 'tfe'), atest = false; end
385 % Check the re-built object
386 if ~eq(mout, out, ple2), atest = false; end
387 % </AlgoCode>
388 else
389 atest = false;
390 end
391
392 % Return a result structure
393 result = utp_prepare_result(atest, stest, dbstack, mfilename);
394 end % END UTP_06
395
396 %% UTP_07
397
398 % <TestDescription>
399 %
400 % Tests that the tfe method can not modify the input AO.
401 %
402 % </TestDescription>
403 function result = utp_07
404
405 % <SyntaxDescription>
406 %
407 % Test that the tfe method can not modify the input AO.
408 % The method must throw an error for the modifier call.
409 %
410 % </SyntaxDescription>
411
412 try
413 % <SyntaxCode>
414 % copy at1 to work with
415 ain = ao(at1);
416 % modify ain
417 ain.tfe(at5);
418 % </SyntaxCode>
419 stest = false;
420 catch err
421 stest = true;
422 end
423
424 % <AlgoDescription>
425 %
426 % 1) Nothing to check.
427 %
428 % </AlgoDescription>
429
430 atest = true;
431 if stest
432 % <AlgoCode>
433 % </AlgoCode>
434 else
435 atest = false;
436 end
437
438 % Return a result structure
439 result = utp_prepare_result(atest, stest, dbstack, mfilename);
440 end % END UTP_07
441
442 %% UTP_08
443
444 % <TestDescription>
445 %
446 % Test the shape of the output.
447 %
448 % </TestDescription>
449 function result = utp_08
450
451 % <SyntaxDescription>
452 %
453 % Test that the tfe method keeps the data shape of the input object. The
454 % input AO must be an AO with row data and an AO with column data.
455 %
456 % </SyntaxDescription>
457
458 try
459 % <SyntaxCode>
460 out1 = tfe(at5, at6);
461 out2 = tfe(at6, at5);
462 % </SyntaxCode>
463 stest = true;
464 catch err
465 disp(err.message)
466 stest = false;
467 end
468
469 % <AlgoDescription>
470 %
471 % 1) Check that the shpe of the output data doesn't change.
472 %
473 % </AlgoDescription>
474
475 atest = true;
476 if stest
477 % <AlgoCode>
478 % Check the shape of the output data
479 if size(out1.data.y, 2) ~= 1, atest = false; end
480 if size(out2.data.y, 1) ~= 1, atest = false; end
481 % </AlgoCode>
482 else
483 atest = false;
484 end
485
486 % Return a result structure
487 result = utp_prepare_result(atest, stest, dbstack, mfilename);
488 end % END UTP_08
489
490 %% UTP_09
491
492 % <TestDescription>
493 %
494 % Check that the tfe method pass back the output objects to a list of
495 % output variables or to a single variable.
496 %
497 % </TestDescription>
498 function result = utp_09
499
500 % <SyntaxDescription>
501 %
502 % This test is not longer necessary because the tfe method pass back
503 % always only one object.
504 %
505 % </SyntaxDescription>
506
507 try
508 % <SyntaxCode>
509 % </SyntaxCode>
510 stest = true;
511 catch err
512 disp(err.message)
513 stest = false;
514 end
515
516 % <AlgoDescription>
517 %
518 % 1) Nothing to check.
519 %
520 % </AlgoDescription>
521
522 atest = true;
523 if stest
524 % <AlgoCode>
525 % </AlgoCode>
526 else
527 atest = false;
528 end
529
530 % Return a result structure
531 result = utp_prepare_result(atest, stest, dbstack, mfilename);
532 end % END UTP_09
533
534 %% UTP_10
535
536 % <TestDescription>
537 %
538 % Tests that the tfe method agrees with MATLAB's tfestimate when
539 % configured to use the same parameters.
540 %
541 % </TestDescription>
542 function result = utp_10
543
544 % <SyntaxDescription>
545 %
546 % Test that applying tfe works on two AOs.
547 %
548 % </SyntaxDescription>
549
550 try
551 % <SyntaxCode>
552 % Construct two test AOs
553 nsecs = 10;
554 fs = 1000;
555 pl = plist('nsecs', nsecs, 'fs', fs, 'tsfcn', 'randn(size(t))');
556 a1 = ao(pl); a2 = ao(pl);
557 % Filter one time-series
558 f2 = miir(plist('type', 'bandpass', 'fs', fs, 'order', 3, 'fc', [50 250]));
559 a1f = filter(a1, plist('filter', f2));
560 % make some cross-power
561 a4 = a1f+a2; a4.setName;
562 % Compute transfer function
563 Nfft = 2*fs;
564 win = specwin('Hanning', Nfft);
565 pl = plist('Nfft', Nfft, 'Win', win.type, 'order', -1);
566 out = tfe(a4,a1,pl);
567 % </SyntaxCode>
568 stest = true;
569 catch err
570 disp(err.message)
571 stest = false;
572 end
573
574 % <AlgoDescription>
575 %
576 % 1) Check that output agrees with the output of MATLAB's tfestimate.
577 %
578 % </AlgoDescription>
579
580 atest = true;
581 if stest
582 % <AlgoCode>
583 % Compute transfer function using MATLAB's tfestimate
584 [cxy, f] = tfestimate(a4.y, a1.y, win.win, Nfft/2, Nfft, a1.fs);
585 if ne(cxy, out.y), atest = false; end
586 if ne(f, out.x), atest = false; end
587 % </AlgoCode>
588 else
589 atest = false;
590 end
591
592 % Return a result structure
593 result = utp_prepare_result(atest, stest, dbstack, mfilename);
594 end % END UTP_10
595
596 %% UTP_12
597
598 % <TestDescription>
599 %
600 % Tests that differently sized data sets are treated properly
601 %
602 % </TestDescription>
603 function result = utp_12
604
605 % <SyntaxDescription>
606 %
607 % Test that applying tfe works on two AOs.
608 %
609 % </SyntaxDescription>
610
611 try
612 % <SyntaxCode>
613 % Construct two test AOs
614 nsecs = [10000:1:20000];
615 fs = 1;
616 pl = plist('fs', fs, 'tsfcn', 'randn(size(t))');
617 a1 = ao(pl.pset('nsecs', utils.math.randelement(nsecs, 1)));
618 a2 = ao(pl.pset('nsecs', utils.math.randelement(nsecs, 1)));
619 len_1 = a1.len;
620 len_2 = a2.len;
621 % Filter one time-series
622 f2 = miir(plist('type', 'bandpass', 'fs', fs, 'order', 3, 'fc', [.050 .25]));
623 a1f = filter(a1, plist('filter', f2));
624 % Compute tfe
625 Nfft = -1;
626 win = 'Hanning';
627 pl = plist('Nfft', Nfft, 'Win', win, 'order', -1);
628 out = tfe(a2,a1f,pl);
629 % </SyntaxCode>
630 stest = true;
631 catch err
632 disp(err.message)
633 stest = false;
634 end
635
636 % <AlgoDescription>
637 %
638 % 1) Check that tfe used the length of the shortest ao.
639 %
640 % </AlgoDescription>
641
642 atest = true;
643 if stest
644 % <AlgoCode>
645 % Compare the nfft with the length of the input data
646
647 if out.x(2) ~= 1/min(len_1,len_2)
648 atest = false;
649 end
650 % </AlgoCode>
651 else
652 atest = false;
653 end
654
655 % Return a result structure
656 result = utp_prepare_result(atest, stest, dbstack, mfilename);
657 end % END UTP_12
658
659 %% UTP_17
660
661 % <TestDescription>
662 %
663 % Tests handling of units:
664 % 1) white noise produced from normal pdf, with a given mean value and
665 % sigma (distribution's 1st and 2nd orders)
666 % 2) white noise produced from normal pdf, with a given mean value and
667 % sigma (distribution's 1st and 2nd orders)
668 % 3) tfe of the white noise series
669 % 4) compares the units of the input and output
670 %
671
672 % </TestDescription>
673 function result = utp_17
674
675 % <SyntaxDescription>
676 %
677 % 1) Prepare the test tsdata:
678 % white noise from normal distribution + offset
679 % 2) Assign a random unit
680 % 3) Prepare the test tsdata:
681 % white noise from normal distribution + offset
682 % 4) Assign a random unit
683 % 5) tfe of the white noise
684 %
685 % </SyntaxDescription>
686
687 % <SyntaxCode>
688 try
689
690 % Build time-series test data
691 fs = 1;
692 nsecs = 86400;
693 sigma_distr_1 = 4.69e-12;
694 mu_distr_1 = -5.11e-14;
695 sigma_distr_2 = 6.04e-9;
696 mu_distr_2 = 1.5e-10;
697
698 % White noise
699 type = 'Normal';
700
701 a_n = ao(plist('waveform', 'noise', ...
702 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_1));
703 a_const = ao(mu_distr_1);
704 a_1 = a_n + a_const;
705
706 a_n = ao(plist('waveform', 'noise', ...
707 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_2));
708 a_const = ao(mu_distr_2);
709 a_2 = a_n + a_const;
710
711 % Set units and prefix from those supported
712 unit_list = unit.supportedUnits;
713 % remove the first empty unit '' from the list, because then is it
714 % possible that we add a prefix to an empty unit
715 unit_list = unit_list(2:end);
716 prefix_list = unit.supportedPrefixes;
717 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
718 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
719
720 % Evaluate the tfe of the time-series data
721 win = specwin('BH92');
722 olap = win.rov;
723 detrend = 0;
724 n_pts = nsecs*fs/10;
725
726 T = tfe(a_1,a_2,plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend));
727
728 stest = true;
729
730 catch err
731 disp(err.message)
732 stest = false;
733 end
734 % </SyntaxCode>
735
736 % <AlgoDescription>
737 %
738 % 1) Check that (calculated tfe yunits) equals [1/Hz]
739
740 % </AlgoDescription>
741
742 % <AlgoCode>
743 atest = true;
744
745 if stest
746 if ne(T.yunits, a_2.yunits ./ a_1.yunits) || ne(T.xunits, unit('Hz'))
747 atest = false;
748 end
749 else
750 atest = false;
751 end
752 % </AlgoCode>
753
754 % Return a result structure
755 result = utp_prepare_result(atest, stest, dbstack, mfilename);
756 end % END UTP_17
757
758
759 %% UTP_21
760
761 % <TestDescription>
762 %
763 % Tests the possibility to set the number of averages rather than setting the Nfft:
764 % 1) white noise produced from normal pdf, with:
765 % a given mean value and sigma (distribution's 1st and 2nd order)
766 % 2) tfe of the 2 series, without detrending, random window, set number of
767 % averages
768 % 3) check the effective number of averages
769 %
770
771 % </TestDescription>
772 function result = utp_21
773
774 % <SyntaxDescription>
775 %
776 % 1) Prepare the test tsdata:
777 % white noise from normal distribution + offset
778 % 2) tfe of the 2 series, without detrending, random window, set number of
779 % averages
780 %
781 % </SyntaxDescription>
782
783 % <SyntaxCode>
784 try
785 % Array of parameters to pick from
786 fs_list = [0.1;1;2;5;10];
787 nsecs_list = [2000:1000:10000]';
788 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
789 trend_0_list = [1e-6 2e-3 0.25 1:0.1:10]';
790
791 % Build time-series test data
792
793 % Picks the values at random from the list
794 fs = utils.math.randelement(fs_list, 1);
795 nsecs = utils.math.randelement(nsecs_list, 1);
796 sigma_distr = utils.math.randelement(sigma_distr_list, 1);
797 trend_0 = utils.math.randelement(trend_0_list, 1);
798
799 % White noise
800 type = 'Normal';
801 a_n1 = ao(plist('waveform', 'noise', ...
802 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
803 a_n2 = ao(plist('waveform', 'noise', ...
804 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
805
806 % Constant signal
807 a_c = ao(trend_0);
808
809 % Total signals
810 a1 = a_n1 + a_c;
811 a2 = a_n2 + a_c;
812
813 % Evaluate the tfe of the white noise time-series data
814 win_list = specwin.getTypes;
815 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1);
816 win_type = win_type{1};
817 switch win_type
818 case 'Kaiser'
819 win = specwin(win_type, 1, find(ao.getInfo('tfe').plists, 'psll'));
820 otherwise
821 win = specwin(win_type, 1);
822 end
823
824 olap = win.rov;
825 detrend = 0;
826 n_pts = -1;
827 navs = utils.math.randelement([1:100],1);
828
829 % Evaluates the tfe asking for the number of averages
830 T = tfe(a1, a2, plist('Win', win.type, 'olap', olap, ...
831 'Nfft', n_pts, 'order', detrend, 'navs', navs));
832
833 stest = true;
834
835 catch err
836 disp(err.message)
837 stest = false;
838 end
839 % </SyntaxCode>
840
841 % <AlgoDescription>
842 %
843 % 1) Check that calculated navs are identical to those requested
844 %
845 % </AlgoDescription>
846
847 % <AlgoCode>
848 atest = true;
849
850 if stest
851 % Compare the navs written in the output object with the requested one
852 if ne(navs, T.data.navs)
853 if ne(find(T.hist.plistUsed, 'navs'), T.data.navs)
854 atest = false;
855 end
856 end
857 else
858 atest = false;
859 end
860 % </AlgoCode>
861
862 % Return a result structure
863 result = utp_prepare_result(atest, stest, dbstack, mfilename);
864 end % END UTP_21
865
866 %% UTP_22
867
868 % <TestDescription>
869 %
870 % Tests the possibility to set the number of averages rather than setting the Nfft:
871 % 1) white noise produced from uniform pdf, with:
872 % a given mean value and sigma (distribution's 1st and 2nd order)
873 % 2) tfe of the time series, without detrending, random window, random navs
874 % 3) get the number of averages
875 % 4) get the nfft used
876 % 5) run tfe again, with the nfft used
877 % 6) compare the calculated objects
878 %
879
880 % </TestDescription>
881 function result = utp_22
882
883 % <SyntaxDescription>
884 %
885 % 1) white noise produced from uniform pdf, with:
886 % a given mean value and sigma (distribution's 1st and 2nd order)
887 % 2) tfe of the time series, without detrending, random window, random navs
888 % 3) get the number of averages
889 % 4) get the nfft used
890 % 5) run tfe again, with the nfft used
891 %
892 % </SyntaxDescription>
893
894 % <SyntaxCode>
895 try
896 % Array of parameters to pick from
897 fs_list = [0.1;1;2;5;10];
898 nsecs_list = [20 100 1000:1000:10000]';
899 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
900 trend_0_list = [1e-6 2e-3 0.25 1:0.1:10]';
901
902 % Build time-series test data
903
904 % Picks the values at random from the list
905 fs = utils.math.randelement(fs_list, 1);
906 nsecs = utils.math.randelement(nsecs_list, 1);
907 sigma_distr = utils.math.randelement(sigma_distr_list, 1);
908 trend_0 = utils.math.randelement(trend_0_list, 1);
909
910 % White noise
911 type = 'Uniform';
912 a_n1 = ao(plist('waveform', 'noise', ...
913 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
914 a_n2 = ao(plist('waveform', 'noise', ...
915 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
916
917 % Constant signal
918 a_c = ao(trend_0);
919
920 % Total signals
921 a1 = a_n1 + a_c;
922 a2 = a_n2 + a_c;
923
924 % Evaluate the tfe of the white noise time-series data
925 win_list = specwin.getTypes;
926 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1);
927 win_type = win_type{1};
928 switch win_type
929 case 'Kaiser'
930 win = specwin(win_type, 1, find(ao.getInfo('psd').plists, 'psll'));
931 otherwise
932 win = specwin(win_type, 1);
933 end
934
935 olap = win.rov;
936 detrend = 0;
937 navs = fix(utils.math.randelement(logspace(0,log10(max(0,a1.len/10)),50),1));
938
939 % Calculates the tfe asking for the number of averages
940 T1 = tfe(a1, a2, plist('Win', win.type, 'olap', olap, ...
941 'Nfft', -1, 'order', detrend, 'navs', navs));
942
943 % Calculates the tfe asking for the number of points just evaluated
944 T2 = tfe(a1, a2, plist('Win', win.type, 'olap', olap, ...
945 'Nfft', find(T1.hist.plistUsed, 'Nfft'), 'order', detrend));
946 stest = true;
947
948 catch err
949 disp(err.message)
950 stest = false;
951 end
952 % </SyntaxCode>
953
954 % <AlgoDescription>
955 %
956 % 1) Check that calculated objects T1 and T2 are identical
957 %
958 % </AlgoDescription>
959
960 % <AlgoCode>
961 atest = true;
962
963 if stest
964 % Compare the output objects
965 if ne(T1,T2,ple3)
966 atest = false;
967 end
968 else
969 atest = false;
970 end
971 % </AlgoCode>
972
973 % Return a result structure
974 result = utp_prepare_result(atest, stest, dbstack, mfilename);
975 end % END UTP_22
976
977 %% UTP_23
978
979 % <TestDescription>
980 %
981 % Tests the possibility to set the number of averages rather than setting the Nfft:
982 % 1) white noise produced from normal pdf, with:
983 % a given mean value and sigma (distribution's 1st and 2nd order)
984 % 2) tfe of the time series, without detrending, random window, random navs
985 % 3) get the number of averages
986 % 4) get the nfft used
987 % 5) run tfe again, with the nfft used
988 % 6) compare navs, nfft, tfes
989 %
990
991 % </TestDescription>
992 function result = utp_23
993
994 % <SyntaxDescription>
995 %
996 % 1) white noise produced from normal pdf, with:
997 % a given mean value and sigma (distribution's 1st and 2nd order)
998 % 2) tfe of the time series, without detrending, random window, random navs
999 % 3) get the number of averages
1000 % 4) get the nfft used
1001 % 5) run tfe again, with the nfft used
1002 % 6) run tfe again, with conflicting parameters, and verify it uses
1003 % nfft rather than navs
1004 %
1005 % </SyntaxDescription>
1006
1007 % <SyntaxCode>
1008 try
1009 % Array of parameters to pick from
1010 fs_list = [0.1;1;2;5;10];
1011 nsecs_list = [1000:1000:10000]';
1012 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
1013 trend_0_list = [1e-6 2e-3 0.25 1:0.1:10]';
1014
1015 % Build time-series test data
1016
1017 % Picks the values at random from the list
1018 fs = utils.math.randelement(fs_list, 1);
1019 nsecs = utils.math.randelement(nsecs_list, 1);
1020 sigma_distr = utils.math.randelement(sigma_distr_list, 1);
1021 trend_0 = utils.math.randelement(trend_0_list, 1);
1022
1023 % White noise
1024 type = 'Normal';
1025 a_n1 = ao(plist('waveform', 'noise', ...
1026 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
1027 a_n2 = ao(plist('waveform', 'noise', ...
1028 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
1029
1030 % Constant signal
1031 a_c = ao(trend_0);
1032
1033 % Total signals
1034 a1 = a_n1 + a_c;
1035 a2 = a_n2 + a_c;
1036
1037 % Evaluate the tfe of the white noise time-series data
1038 win_list = specwin.getTypes;
1039 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1);
1040 win_type = win_type{1};
1041 switch win_type
1042 case 'Kaiser'
1043 win = specwin(win_type, 1, find(ao.getInfo('psd').plists, 'psll'));
1044 otherwise
1045 win = specwin(win_type, 1);
1046 end
1047
1048 olap = win.rov;
1049 detrend = 0;
1050 navs = fix(utils.math.randelement(logspace(0,log10(max(a1.len/10,0)),50),1));
1051
1052 % Calculates the tfe from a1 to a2 asking for the number of averages
1053 T1 = tfe(a1, a2, plist('Win', win.type, 'olap', olap, ...
1054 'Nfft', -1, 'order', detrend, 'navs', navs));
1055
1056 npts_2 = find(T1.hist.plistUsed, 'Nfft');
1057 % Calculates the tfe from a1 to a2 asking for the number of points
1058 T2 = tfe(a1, a2, plist('Win', win.type, 'olap', olap, ...
1059 'Nfft', npts_2, 'order', detrend));
1060
1061 npts_3 = fix(npts_2/2);
1062 % Calculates the tfe from a1 to a2 asking for the number of points AND the window length
1063 T3 = tfe(a1, a2, plist('Win', win.type, 'olap', olap, ...
1064 'Nfft', npts_3, ...
1065 'order', detrend, 'navs', navs));
1066
1067 stest = true;
1068
1069 catch err
1070 disp(err.message)
1071 stest = false;
1072 end
1073 % </SyntaxCode>
1074
1075 % <AlgoDescription>
1076 %
1077 % 1) Check that calculated objects T1 and T2 are identical
1078 % 2) Check that T3 used different values
1079 %
1080 % </AlgoDescription>
1081
1082 % <AlgoCode>
1083 atest = true;
1084
1085 if stest
1086 % Compare the navs written in the output object with the requested one
1087 if ne(T1,T2,ple3) || ...
1088 ne(find(T3.hist.plistUsed, 'Nfft'), npts_3) || eq(T3.data.navs, navs)
1089 atest = false;
1090 end
1091 else
1092 atest = false;
1093 end
1094 % </AlgoCode>
1095
1096 % Return a result structure
1097 result = utp_prepare_result(atest, stest, dbstack, mfilename);
1098 end % END UTP_23
1099
1100 %% UTP_25
1101
1102 % <TestDescription>
1103 %
1104 % Tests handling of units:
1105 % 1) white noise produced from normal pdf, with a given mean value and
1106 % sigma (distribution's 1st and 2nd orders)
1107 % 2) white noise produced from normal pdf, with a given mean value and
1108 % sigma (distribution's 1st and 2nd orders)
1109 % 3) tfe of the white noise series
1110 % 4) compares the units of the input and output
1111 %
1112
1113 % </TestDescription>
1114 function result = utp_25
1115
1116 % <SyntaxDescription>
1117 %
1118 % 1) Prepare the test tsdata:
1119 % white noise from normal distribution + offset
1120 % 2) Assign a random unit
1121 % 3) Prepare the test tsdata:
1122 % white noise from normal distribution + offset
1123 % 4) Assign a random unit
1124 % 5) tfe of the white noise
1125 %
1126 % </SyntaxDescription>
1127
1128 % <SyntaxCode>
1129 try
1130
1131 % Build time-series test data
1132 fs = 1;
1133 nsecs = 86400;
1134 sigma_distr_1 = 4.69e-12;
1135 mu_distr_1 = -5.11e-14;
1136 sigma_distr_2 = 6.04e-9;
1137 mu_distr_2 = 1.5e-10;
1138
1139 % White noise
1140 type = 'Normal';
1141
1142 a_n = ao(plist('waveform', 'noise', ...
1143 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_1));
1144 a_const = ao(mu_distr_1);
1145 a_1 = a_n + a_const;
1146
1147 a_n = ao(plist('waveform', 'noise', ...
1148 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_2));
1149 a_const = ao(mu_distr_2);
1150 a_2 = a_n + a_const;
1151
1152 % Set units and prefix from those supported
1153 unit_list = unit.supportedUnits;
1154 % remove the first empty unit '' from the list, because then is it
1155 % possible that we add a prefix to an empty unit
1156 unit_list = unit_list(2:end);
1157 prefix_list = unit.supportedPrefixes;
1158 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
1159 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
1160
1161 % Evaluate the tfe of the time-series data
1162 win = 'Kaiser';
1163 detrend = 0;
1164 n_pts = nsecs*fs/10;
1165
1166 T = tfe(a_1,a_2,plist('Win', win,'Nfft', n_pts, 'order', detrend));
1167
1168 stest = true;
1169
1170 catch err
1171 disp(err.message)
1172 stest = false;
1173 end
1174 % </SyntaxCode>
1175
1176 % <AlgoDescription>
1177 %
1178 % 1) Check that (calculated tfe yunits) equals [1/Hz]
1179
1180 % </AlgoDescription>
1181
1182 % <AlgoCode>
1183 atest = true;
1184
1185 if stest
1186 if ne(T.yunits, a_2.yunits ./ a_1.yunits) || ne(T.xunits, unit('Hz'))
1187 atest = false;
1188 end
1189 else
1190 atest = false;
1191 end
1192 % </AlgoCode>
1193
1194 % Return a result structure
1195 result = utp_prepare_result(atest, stest, dbstack, mfilename);
1196 end % END UTP_25
1197
1198 %% UTP_30
1199
1200 % <TestDescription>
1201 %
1202 % Tests handling of special cases:
1203 % 1) white noise produced from normal pdf, with a given mean value and
1204 % sigma (distribution's 1st and 2nd orders)
1205 % 2) the same noise series
1206 % 3) tfe of the white noise series
1207 % 4) compares the output to unity
1208 %
1209
1210 % </TestDescription>
1211 function result = utp_30
1212
1213 % <SyntaxDescription>
1214 %
1215 % 1) Prepare the test tsdata:
1216 % white noise from normal distribution + offset
1217 % 2) Assign a random unit
1218 % 3) Prepare the test tsdata:
1219 % the same data as 1) and 2)
1220 % 4) tfe of the series
1221 %
1222 % </SyntaxDescription>
1223
1224 % <SyntaxCode>
1225 try
1226
1227 % Build time-series test data
1228 fs = 1;
1229 nsecs = 86400;
1230 sigma_distr_1 = 4.69e-12;
1231 mu_distr_1 = -5.11e-14;
1232
1233 % White noise
1234 type = 'Normal';
1235
1236 a_n = ao(plist('waveform', 'noise', ...
1237 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_1));
1238 a_const = ao(mu_distr_1);
1239 a_1 = a_n + a_const;
1240
1241 % Set units and prefix from those supported
1242 unit_list = unit.supportedUnits;
1243 % remove the first empty unit '' from the list, because then is it
1244 % possible that we add a prefix to an empty unit
1245 unit_list = unit_list(2:end);
1246 prefix_list = unit.supportedPrefixes;
1247 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
1248
1249 % Build the second object as a copy of the first
1250 a_2 = a_1;
1251
1252 % Evaluate the tfe of the time-series data
1253 win = specwin('BH92');
1254 olap = win.rov;
1255 detrend = 0;
1256 n_pts = nsecs*fs/10;
1257
1258 T = tfe(a_1,a_2,plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend));
1259
1260 stest = true;
1261
1262 catch err
1263 disp(err.message)
1264 stest = false;
1265 end
1266 % </SyntaxCode>
1267
1268 % <AlgoDescription>
1269 %
1270 % 1) Check that calculated tfe equals 1
1271
1272 % </AlgoDescription>
1273
1274 % <AlgoCode>
1275 atest = true;
1276
1277 if stest
1278 if sum(ne(T.y, 1))
1279 atest = false;
1280 end
1281 else
1282 atest = false;
1283 end
1284 % </AlgoCode>
1285
1286 % Return a result structure
1287 result = utp_prepare_result(atest, stest, dbstack, mfilename);
1288 end % END UTP_30
1289
1290 end