comparison testing/utp_1.1/utps/ao/utp_ao_fixfs.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_FIXFS a set of UTPs for the ao/fixfs method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_fixfs.m,v 1.19 2011/08/22 05:04:49 hewitson Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The fixfs method of the ao class resamples time-series AOs to have a
11 % fixed sample rate.
12 %
13 % </MethodDescription>
14
15 function results = utp_ao_fixfs(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 class = 'ao';
22 mthd = 'fixfs';
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,atvec,atmat] = eval(['get_test_objects_' class]);
31
32 % Exception list for the UTPs:
33 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
34
35 % Run the tests
36 results = [results utp_01]; % getInfo call
37 results = [results utp_02]; % Vector input
38 results = [results utp_03]; % Matrix input
39 results = [results utp_04]; % List input
40 results = [results utp_05]; % Test with mixed input
41 results = [results utp_06]; % Test history is working
42 results = [results utp_07]; % Test the modify call works
43 results = [results utp_08]; % Test the data shape
44 results = [results utp_09]; % Test output of the data
45 results = [results utp_10]; % Test multiple 'fs' for multiple input AOs
46
47 results = [results utp_11(mthd, at1, ple1)]; % Test plotinfo doesn't disappear
48
49 results = [results utp_12]; % Test with plist: method == 'samples'
50 results = [results utp_13]; % Test with antialising filter
51 results = [results utp_14]; % Test AO with non evenly sampled data
52
53 disp('Done.');
54 disp('******************************************************');
55
56 elseif nargin == 1 % Check for UTP functions
57 if strcmp(varargin{1}, 'isutp')
58 results = 1;
59 else
60 results = 0;
61 end
62 else
63 error('### Incorrect inputs')
64 end
65
66 %% UTP_01
67
68 % <TestDescription>
69 %
70 % Tests that the getInfo call works for this method.
71 %
72 % </TestDescription>
73 function result = utp_01
74
75
76 % <SyntaxDescription>
77 %
78 % Test that the getInfo call works for no sets, all sets, and each set
79 % individually.
80 %
81 % </SyntaxDescription>
82
83 try
84 % <SyntaxCode>
85 % Call for no sets
86 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
87 % Call for all sets
88 io(2) = eval([class '.getInfo(''' mthd ''')']);
89 % Call for each set
90 for kk=1:numel(io(2).sets)
91 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
92 end
93 % </SyntaxCode>
94 stest = true;
95 catch err
96 disp(err.message)
97 stest = false;
98 end
99
100 % <AlgoDescription>
101 %
102 % 1) Check that getInfo call returned an minfo object in all cases.
103 % 2) Check that all plists have the correct parameters.
104 %
105 % </AlgoDescription>
106
107 atest = true;
108 if stest
109 % <AlgoCode>
110 % check we have minfo objects
111 if isa(io, 'minfo')
112 %%% SET 'None'
113 if ~isempty(io(1).sets), atest = false; end
114 if ~isempty(io(1).plists), atest = false; end
115 %%% Check all Sets
116 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
117 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
118 %%%%%%%%%% SET 'Default'
119 if io(3).plists.nparams ~= 4, atest = false; end
120 % Check key
121 if ~io(3).plists.isparam('fs'), atest = false; end
122 if ~io(3).plists.isparam('method'), atest = false; end
123 if ~io(3).plists.isparam('filter'), atest = false; end
124 if ~io(3).plists.isparam('interpolation'), atest = false; end
125 % Check default value
126 if ~isequal(io(3).plists.find('fs'), -1), atest = false; end
127 if ~strcmpi(io(3).plists.find('method'), 'time'), atest = false; end
128 if ~isequal(io(3).plists.find('filter'), 'off'), atest = false; end
129 if ~isequal(io(3).plists.find('interpolation'), 'spline'), atest = false; end
130 % Check options
131 if ~isequal(io(3).plists.getOptionsForParam('fs'), {-1}), atest = false; end
132 if ~isequal(io(3).plists.getOptionsForParam('method'), {'time', 'samples'}), atest = false; end
133 if ~isequal(io(3).plists.getOptionsForParam('interpolation'), {'nearest', 'linear', 'spline', 'cubic'}), atest = false; end
134 end
135 % </AlgoCode>
136 else
137 atest = false;
138 end
139
140 % Return a result structure
141 result = utp_prepare_result(atest, stest, dbstack, mfilename);
142 end % END UTP_01
143
144 %% UTP_02
145
146 % <TestDescription>
147 %
148 % Tests that the fixfs method works with a vector of AOs as input.
149 %
150 % </TestDescription>
151 function result = utp_02
152
153 % <SyntaxDescription>
154 %
155 % Test that the fixfs method works for a vector of AOs as input.
156 %
157 % </SyntaxDescription>
158
159 try
160 % <SyntaxCode>
161 avec = [at1 at5 at6];
162 out = fixfs(avec);
163 % </SyntaxCode>
164 stest = true;
165 catch err
166 disp(err.message)
167 stest = false;
168 end
169
170 % <AlgoDescription>
171 %
172 % 1) Check that the number of elements in 'out' is the same as
173 % the number in the input.
174 % 2) Check that each output AO contains the correct data.
175 %
176 % </AlgoDescription>
177
178 atest = true;
179 if stest
180 % <AlgoCode>
181 % Check we have the correct number of outputs
182 if numel(out) ~= numel(avec), atest = false; end
183 % Check the output data
184 for kk = 1:numel(avec)
185 fs = avec(kk).fs;
186 t0 = 0;
187 Nsecs = avec(kk).data.nsecs;
188 t = t0 + [0:1/fs:Nsecs-1/fs].';
189 y = interp1(avec(kk).x,avec(kk).y, t, 'spline', 'extrap');
190 if ~isequal(y, out(kk).y), atest = false; end
191 if ~isequal(t, out(kk).x), atest = false; end
192 end
193 % </AlgoCode>
194 else
195 atest = false;
196 end
197
198 % Return a result structure
199 result = utp_prepare_result(atest, stest, dbstack, mfilename);
200 end % END UTP_02
201
202 %% UTP_03
203
204 % <TestDescription>
205 %
206 % Tests that the fixfs method works with a matrix of AOs as input.
207 %
208 % </TestDescription>
209 function result = utp_03
210
211 % <SyntaxDescription>
212 %
213 % Test that the fixfs method works for a matrix of AOs as input.
214 %
215 % </SyntaxDescription>
216
217 try
218 % <SyntaxCode>
219 amat = [at1 at5 at6; at5 at6 at1];
220 out = fixfs(amat);
221 % </SyntaxCode>
222 stest = true;
223 catch err
224 disp(err.message)
225 stest = false;
226 end
227
228 % <AlgoDescription>
229 %
230 % 1) Check that the number of elements in 'out' is the same as
231 % the number in the input.
232 % 2) Check that each output AO contains the correct data.
233 %
234 % </AlgoDescription>
235
236 atest = true;
237 if stest
238 % <AlgoCode>
239 % Check we have the correct number of outputs
240 if numel(out) ~= numel(amat), atest = false; end
241 % Check the output data
242 for kk = 1:numel(amat)
243 fs = amat(kk).fs;
244 t0 = 0;
245 Nsecs = amat(kk).data.nsecs;
246 t = t0 + [0:1/fs:Nsecs-1/fs].';
247 y = interp1(amat(kk).x,amat(kk).y, t, 'spline', 'extrap');
248 if ~isequal(y, out(kk).y), atest = false; end
249 if ~isequal(t, out(kk).x), atest = false; end
250 end
251 % </AlgoCode>
252 else
253 atest = false;
254 end
255
256 % Return a result structure
257 result = utp_prepare_result(atest, stest, dbstack, mfilename);
258 end % END UTP_03
259
260 %% UTP_04
261
262 % <TestDescription>
263 %
264 % Tests that the fixfs method works with a list of AOs as input.
265 %
266 % </TestDescription>
267 function result = utp_04
268
269 % <SyntaxDescription>
270 %
271 % Test that the fixfs method works for a list of AOs as input.
272 %
273 % </SyntaxDescription>
274
275 try
276 % <SyntaxCode>
277 out = fixfs(at1,at5,at6);
278 % </SyntaxCode>
279 stest = true;
280 catch err
281 disp(err.message)
282 stest = false;
283 end
284
285 % <AlgoDescription>
286 %
287 % 1) Check that the number of elements in 'out' is the same as
288 % the number in the input.
289 % 2) Check that each output AO contains the correct data.
290 %
291 % </AlgoDescription>
292
293 atest = true;
294 aoin = [at1, at5, at6];
295 if stest
296 % <AlgoCode>
297 % Check we have the correct number of outputs
298 if numel(out) ~= 3, atest = false; end
299 % Check the output data
300 for kk = 1:numel(aoin)
301 fs = aoin(kk).fs;
302 t0 = 0;
303 Nsecs = aoin(kk).data.nsecs;
304 t = t0 + [0:1/fs:Nsecs-1/fs].';
305 y = interp1(aoin(kk).x,aoin(kk).y, t, 'spline', 'extrap');
306 if ~isequal(y, out(kk).y), atest = false; end
307 if ~isequal(t, out(kk).x), atest = false; end
308 end
309 % </AlgoCode>
310 else
311 atest = false;
312 end
313
314 % Return a result structure
315 result = utp_prepare_result(atest, stest, dbstack, mfilename);
316 end % END UTP_04
317
318 %% UTP_05
319
320 % <TestDescription>
321 %
322 % Tests that the fixfs method works with a mix of different shaped AOs as
323 % input.
324 %
325 % </TestDescription>
326 function result = utp_05
327
328 % <SyntaxDescription>
329 %
330 % Test that the fixfs method works with an input of matrices and vectors
331 % and single AOs. Additionally define a 'fs' in a plist.
332 %
333 % </SyntaxDescription>
334
335 try
336 % <SyntaxCode>
337 fs = 7;
338 pl = plist('fs', fs);
339 out = fixfs(at1,[at5 at6],at5,[at5 at1; at6 at1],at6, pl);
340 % </SyntaxCode>
341 stest = true;
342 catch err
343 disp(err.message)
344 stest = false;
345 end
346
347 % <AlgoDescription>
348 %
349 % 1) Check that the number of elements in 'out' is the same as in
350 % input.
351 % 2) Check that each output AO contains the correct data.
352 % 3) Check that 't0' and 'fs' are correct.
353 %
354 % </AlgoDescription>
355
356 TOL = 1e-14;
357 atest = true;
358 aoin = [at1, reshape([at5 at6], 1, []), at5, reshape([at5 at1; at6 at1], 1, []), at6];
359 if stest
360 % <AlgoCode>
361 % Check we have the correct number of outputs
362 if numel(out) ~= 9, atest = false; end
363 % Check the output data
364 for kk = 1:numel(aoin)
365 Nsecs = aoin(kk).data.nsecs;
366 % We have to think about what we want to do with t0
367 t0 = aoin(kk).data.t0.double;
368 % This is numerically more accurate
369 t = [0:1/fs:Nsecs-1/fs].';
370 y = interp1(aoin(kk).x, aoin(kk).y, t, 'spline', 'extrap');
371 if ~isequal(y, out(kk).y), atest = false; end
372 if any(abs(t-out(kk).x)>TOL), atest = false; end
373 % Check 't0' and 'fs'
374 if ~isequal(out(kk).fs, fs), atest = false; end
375 if ~isequal(out(kk).t0.utc_epoch_milli, t0*1000), atest = false; end
376 end
377 % </AlgoCode>
378 else
379 atest = false;
380 end
381
382 % Return a result structure
383 result = utp_prepare_result(atest, stest, dbstack, mfilename);
384 end % END UTP_05
385
386 %% UTP_06
387
388 % <TestDescription>
389 %
390 % Tests that the fixfs method properly applies history.
391 %
392 % </TestDescription>
393 function result = utp_06
394
395 % <SyntaxDescription>
396 %
397 % Test that the result of applying the fixfs method can be processed back
398 % to an m-file. Additionally define a 'fs' in a plist.
399 %
400 % </SyntaxDescription>
401
402 try
403 % <SyntaxCode>
404 fs = 7;
405 pl = plist('fs', fs);
406 out = fixfs(at5, pl);
407 mout = rebuild(out);
408 % </SyntaxCode>
409 stest = true;
410 catch err
411 disp(err.message)
412 stest = false;
413 end
414
415 % <AlgoDescription>
416 %
417 % 1) Check that the last entry in the history of 'out' corresponds to
418 % 'fixfs'.
419 % 2) % Check that the re-built object is the same object as 'out'.
420 %
421 % </AlgoDescription>
422
423 TOL = 1e-14;
424 atest = true;
425 if stest
426 % <AlgoCode>
427 % Check the last step in the history of 'out'
428 if ~strcmp(out.hist.methodInfo.mname, 'fixfs'), atest = false; end
429 % Check the output data
430 Nsecs = at5.data.nsecs;
431 % We have to think about what we want to do with t0
432 t0 = at5.data.t0.double;
433 % This is numerically more accurate
434 t = [0:1/fs:Nsecs-1/fs].';
435 y = interp1(at5.x, at5.y, t, 'spline', 'extrap');
436 if ~isequal(y, out.y), atest = false; end
437 if any(abs(t-out.x)>TOL), atest = false; end
438 % Check 't0' and 'fs'
439 if ~isequal(out.fs, fs), atest = false; end
440 if ~isequal(out.t0.utc_epoch_milli, t0*1000), atest = false; end
441 % % Check the re-built object
442 if ~eq(mout, out, ple2), atest = false; end
443 % </AlgoCode>
444 else
445 atest = false;
446 end
447
448 % Return a result structure
449 result = utp_prepare_result(atest, stest, dbstack, mfilename);
450 end % END UTP_06
451
452 %% UTP_07
453
454 % <TestDescription>
455 %
456 % Tests that the fixfs method can modify the input AO.
457 %
458 % </TestDescription>
459 function result = utp_07
460
461 % <SyntaxDescription>
462 %
463 % Test that the fixfs method can modify the input AO by calling
464 % with no output.
465 %
466 % </SyntaxDescription>
467
468 try
469 % <SyntaxCode>
470 fs = 27;
471 pl = plist('fs', fs);
472 % copy at1 to work with
473 ain = ao(at1);
474 % modify ain
475 aout = ain.fixfs(pl);
476 ain.fixfs(pl);
477 % </SyntaxCode>
478 stest = true;
479 catch err
480 disp(err.message)
481 stest = false;
482 end
483
484 % <AlgoDescription>
485 %
486 % 1) Check that 'at1' and 'ain' are now different.
487 % 2) Check that 'ain' is fixfs(at1).
488 %
489 % </AlgoDescription>
490
491 TOL = 1e-14;
492 atest = true;
493 if stest
494 % <AlgoCode>
495 % Check that fixfs modified the input by comparing to the copy
496 if eq(ao(at1), ain, ple1), atest = false; end
497 % Check that fixfs doesn't modified the input for the function notation
498 if ~eq(aout, ain, ple1), atest = false; end
499 % Check the output data
500 Nsecs = at1.data.nsecs;
501 % We have to think about what we want to do with t0
502 t0 = at1.data.t0.double;
503 % This is numerically more accurate
504 t = [0:1/fs:Nsecs-1/fs].';
505 y = interp1(at1.x, at1.y, t, 'spline', 'extrap');
506 if ~isequal(y, ain.y), atest = false; end
507 if any(abs(t-ain.x)>TOL), atest = false; end
508 % Check 't0' and 'fs'
509 if ~isequal(ain.fs, fs), atest = false; end
510 if ~isequal(ain.t0.utc_epoch_milli, t0*1000), atest = false; end
511 % </AlgoCode>
512 else
513 atest = false;
514 end
515
516 % Return a result structure
517 result = utp_prepare_result(atest, stest, dbstack, mfilename);
518 end % END UTP_07
519
520 %% UTP_08
521
522 % <TestDescription>
523 %
524 % Tests that the fixfs method keeps the data shape of the input object.
525 %
526 % </TestDescription>
527 function result = utp_08
528
529 % <SyntaxDescription>
530 %
531 % Test that the fixfs method keeps the data shape of the input object. The
532 % input AO must be an AO with row data and an AO with column data.
533 %
534 % </SyntaxDescription>
535
536 try
537 % <SyntaxCode>
538 fs = 27;
539 pl = plist('fs', fs);
540 out1 = fixfs(at5, pl);
541 out2 = fixfs(at6, pl);
542 % </SyntaxCode>
543 stest = true;
544 catch err
545 disp(err.message)
546 stest = false;
547 end
548
549 % <AlgoDescription>
550 %
551 % 1) Check that the shpe of the data doesn't change.
552 %
553 % </AlgoDescription>
554
555 atest = true;
556 if stest
557 % <AlgoCode>
558 % Check the shape of the output data
559 if size(out1.data.y,2) ~= 1, atest = false; end
560 if size(out2.data.y,1) ~= 1, atest = false; end
561 % </AlgoCode>
562 else
563 atest = false;
564 end
565
566 % Return a result structure
567 result = utp_prepare_result(atest, stest, dbstack, mfilename);
568 end % END UTP_08
569
570 %% UTP_09
571
572 % <TestDescription>
573 %
574 % Check that the fixfs method pass back the output objects to a list of
575 % output variables or to a single variable.
576 %
577 % </TestDescription>
578 function result = utp_09
579
580 % <SyntaxDescription>
581 %
582 % Call the method with a list of output variables and with a single output
583 % variable. Additionaly check that the rebuild method works on the output.
584 %
585 % </SyntaxDescription>
586
587 try
588 % <SyntaxCode>
589 fs = 27;
590 pl = plist('fs', fs);
591 [o1, o2] = fixfs(at5, at6, pl);
592 o3 = fixfs(at5, at6, pl);
593 mout1 = rebuild(o1);
594 mout2 = rebuild(o2);
595 mout3 = rebuild(o3);
596 % </SyntaxCode>
597 stest = true;
598 catch err
599 disp(err.message)
600 stest = false;
601 end
602
603 % <AlgoDescription>
604 %
605 % 1) Check that the output contains the right number of objects
606 % 2) Check that the 'rebuild' method produces the same object as 'out'.
607 %
608 % </AlgoDescription>
609
610 atest = true;
611 if stest
612 % <AlgoCode>
613 % Check the number of outputs
614 if numel(o1) ~=1, atest = false; end
615 if numel(o2) ~=1, atest = false; end
616 if numel(o3) ~=2, atest = false; end
617 % Check the rebuilding of the object
618 if ~eq(o1, mout1, ple2), atest = false; end
619 if ~eq(o2, mout2, ple2), atest = false; end
620 if ~eq(o3, mout3, ple2), atest = false; end
621 % </AlgoCode>
622 else
623 atest = false;
624 end
625
626 % Return a result structure
627 result = utp_prepare_result(atest, stest, dbstack, mfilename);
628 end % END UTP_09
629
630 %% UTP_10
631
632 % <TestDescription>
633 %
634 % Tests that the fixfs method works with a list of AOs as input and different
635 % 't0' and 'fs' for the inputs.
636 %
637 % </TestDescription>
638 function result = utp_10
639
640 % <SyntaxDescription>
641 %
642 % Test that the fixfs method works for a list of AOs as input and different
643 % 't0' and 'fs'
644 %
645 % </SyntaxDescription>
646
647 try
648 % <SyntaxCode>
649 fs_in = [ 3 7 9 ];
650 pl = plist('fs', fs_in);
651 out = fixfs(at1,at5,at6, pl);
652 % </SyntaxCode>
653 stest = true;
654 catch err
655 disp(err.message)
656 stest = false;
657 end
658
659 % <AlgoDescription>
660 %
661 % 1) Check that the number of elements in 'out' is the same as
662 % the number in the input.
663 % 2) Check that each output AO contains the correct data.
664 % 3) Check that each output contains the correct frequency and start time.
665 %
666 % </AlgoDescription>
667
668 TOL = 1e-14;
669 atest = true;
670 aoin = [at1, at5, at6];
671 if stest
672 % <AlgoCode>
673 % Check we have the correct number of outputs
674 if numel(out) ~= 3, atest = false; end
675 % Check the output data
676 for kk = 1:numel(aoin)
677 fs = fs_in(kk);
678 t0 = aoin(kk).data.t0.double;
679 Nsecs = aoin(kk).data.nsecs;
680 t = [0:1/fs:Nsecs-1/fs].';
681 y = interp1(aoin(kk).x,aoin(kk).y, t, 'spline', 'extrap');
682 if ~isequal(y, out(kk).y), atest = false; end
683 if any(abs(t-out(kk).x)>TOL), atest = false; end
684 % Check 't0' and 'fs'
685 if abs(out(kk).fs - fs)>TOL, atest = false; end
686 if ~isequal(out(kk).t0.utc_epoch_milli, t0*1000), atest = false; end
687 end
688 % </AlgoCode>
689 else
690 atest = false;
691 end
692
693 % Return a result structure
694 result = utp_prepare_result(atest, stest, dbstack, mfilename);
695 end % END UTP_10
696
697
698 %% UTP_12
699
700 % <TestDescription>
701 %
702 % Tests that the fixfs method works with the method 'samples'.
703 %
704 % </TestDescription>
705 function result = utp_12
706
707 % <SyntaxDescription>
708 %
709 % Test that the fixfs method works for the method 'samples'.
710 %
711 % </SyntaxDescription>
712
713 try
714 % <SyntaxCode>
715 pl = plist('method', 'Samples');
716 out = fixfs(at1, pl);
717 % </SyntaxCode>
718 stest = true;
719 catch err
720 disp(err.message)
721 stest = false;
722 end
723
724 % <AlgoDescription>
725 %
726 % 1) Check that each output AO contains the correct data.
727 % 2) Check that each output contains the correct frequency and start time.
728 %
729 % </AlgoDescription>
730
731 TOL = 1e-14;
732 atest = true;
733 if stest
734 % <AlgoCode>
735 % Check the output data
736 N = length(at1.y);
737 t = linspace(0, (N-1)/at1.fs, N).';
738 y = interp1(at1.x,at1.y, t, 'spline', 'extrap');
739 if ~isequal(y, out.y), atest = false; end
740 if any(abs(t-out.x)>TOL), atest = false; end
741 % Check 'fs'
742 if ~isequal(out.fs, 1/(t(2)-t(1))), atest = false; end
743 % </AlgoCode>
744 else
745 atest = false;
746 end
747
748 % Return a result structure
749 result = utp_prepare_result(atest, stest, dbstack, mfilename);
750 end % END UTP_12
751
752 %% UTP_13
753
754 % <TestDescription>
755 %
756 % Tests that the fixfs method works with antialising filter.
757 %
758 % </TestDescription>
759 function result = utp_13
760
761 % <SyntaxDescription>
762 %
763 % Test that the fixfs method works for the antialising filters iir and fir.
764 %
765 % </SyntaxDescription>
766
767 try
768 % <SyntaxCode>
769 pl_iir = plist('filter', 'iir');
770 pl_fir = plist('filter', 'fir');
771 out_iir = fixfs(at1, pl_iir);
772 out_fir = fixfs(at1, pl_fir);
773 % </SyntaxCode>
774 stest = true;
775 catch err
776 disp(err.message)
777 stest = false;
778 end
779
780 % <AlgoDescription>
781 %
782 % 1) Check that each output AO contains the correct data.
783 % 2) Check that each output contains the correct frequency and start time.
784 %
785 % </AlgoDescription>
786
787 TOL = 1e-14;
788 atest = true;
789 if stest
790 % <AlgoCode>
791 % Check the output data
792 Nsecs = at1.data.nsecs;
793 t = [0:1/at1.fs:Nsecs-1/at1.fs].';
794 % Compute antialiasing filter (iir filter)
795 pl = plist('type', 'lowpass', 'order', 8, 'fs', at1.fs,'fc', 0.9*(at1.fs/2));
796 f = miir(pl);
797 at1_iir = filtfilt(at1, f);
798 y_iir = interp1(at1_iir.x, at1_iir.y, t, 'spline', 'extrap');
799 % Compute antialiasing filter (fir filter)
800 pl = plist('type', 'lowpass', 'order', 64, 'fs', at1.fs, 'fc', 0.9*(at1.fs/2));
801 f = mfir(pl);
802 at1_fir = filter(at1, f);
803 y_fir = interp1(at1_fir.x, at1_fir.y, t, 'spline', 'extrap');
804
805 % Check with iir filter
806 if ~isequal(y_iir, out_iir.y), atest = false; end
807 if any(abs(t-out_iir.x)>TOL), atest = false; end
808 if ~isequal(out_iir.fs, 1/(t(2)-t(1))), atest = false; end
809 % Check with fir filter
810 if ~isequal(y_fir, out_fir.y), atest = false; end
811 if any(abs(t-out_fir.x)>TOL), atest = false; end
812 if ~isequal(out_fir.fs, 1/(t(2)-t(1))), atest = false; end
813 % </AlgoCode>
814 else
815 atest = false;
816 end
817
818 % Return a result structure
819 result = utp_prepare_result(atest, stest, dbstack, mfilename);
820 end % END UTP_13
821
822 %% UTP_14
823
824 % <TestDescription>
825 %
826 % Tests that the fixfs method works with an AO with non evenly sampled data.
827 %
828 % </TestDescription>
829 function result = utp_14
830
831 % <SyntaxDescription>
832 %
833 % Test that the fixfs method works for an AO with non evenly samples data.
834 %
835 % </SyntaxDescription>
836 msg = '';
837 try
838 % <SyntaxCode>
839 xvals = sort(randn(30,1));
840 yvals = randn(30,1);
841 pl_ao = plist('xvals', xvals, 'yvals', yvals, 'type', 'tsdata');
842 aa = ao(pl_ao);
843
844 fs = 13;
845 t0 = 7;
846 pl = plist('t0', t0, 'fs', fs);
847 out = fixfs(aa, pl);
848 % </SyntaxCode>
849 stest = true;
850 catch err
851 disp(err.message)
852 msg = err.message;
853 stest = false;
854 end
855
856 % <AlgoDescription>
857 %
858 % 1) Check that each output AO contains the correct data.
859 % 2) Check that each output contains the correct frequency and start time.
860 %
861 % </AlgoDescription>
862
863 TOL = 1e-14;
864 atest = true;
865 if stest
866 % <AlgoCode>
867 % Check the output data
868 Nsecs = aa.data.nsecs;
869 t0 = aa.data.getX(1);
870 t = t0 + [0:1/fs:Nsecs-1/fs].';
871 y = interp1(aa.x,aa.y, t, 'spline', 'extrap');
872 if ~isequal(y, out.y), msg = 'y values are not equal'; atest = false; end
873 if any(abs(t-out.x)>TOL), msg = 'x values are not evenly spaced'; atest = false; end
874 % Check 't0' and 'fs'
875 if abs(out.fs - fs)>TOL, msg = 'the sample rates are not correct'; atest = false; end
876 if ~eq(out.t0, aa.t0), msg = 'the t0 is not correct'; atest = false; end
877 % </AlgoCode>
878 else
879 atest = false;
880 end
881
882 % Return a result structure
883 result = utp_prepare_result(atest, stest, dbstack, mfilename, msg);
884 end % END UTP_14
885
886
887 end