Mercurial > hg > ltpda
comparison testing/utp_1.1/utps/ao/utp_ao_heterodyne.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_HETERODYNE a set of UTPs for the ao/heterodyne method | |
2 % | |
3 % M Nofrarias 19-12-08 | |
4 % | |
5 % $Id: utp_ao_heterodyne.m,v 1.8 2010/07/08 08:49:37 mauro Exp $ | |
6 % | |
7 | |
8 % <MethodDescription> | |
9 % | |
10 % The hetrodyne method mixes the input ao at the specified frequency | |
11 % | |
12 % </MethodDescription> | |
13 | |
14 function results = utp_ao_heterodyne(varargin) | |
15 | |
16 % Check the inputs | |
17 if nargin == 0 | |
18 | |
19 % Some keywords | |
20 class = 'ao'; | |
21 mthd = 'heterodyne'; | |
22 | |
23 results = []; | |
24 disp('******************************************************'); | |
25 disp(['**** Running UTPs for ' class '/' mthd]); | |
26 disp('******************************************************'); | |
27 | |
28 % Test AOs | |
29 [at1,at2,at3,at4,at5,at6,atvec,atmat] = eval(['get_test_objects_' class]); | |
30 | |
31 % Exception list for the UTPs: | |
32 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples(); | |
33 | |
34 % Run the tests | |
35 results = [results utp_01]; % getInfo call | |
36 results = [results utp_02]; % Vector input | |
37 results = [results utp_03]; % Matrix input | |
38 results = [results utp_04]; % List input | |
39 results = [results utp_05]; % Test with mixed input | |
40 results = [results utp_06]; % Test history is working | |
41 results = [results utp_07]; % Test functionality, no downsample | |
42 results = [results utp_08]; % Test functionality, downsampling | |
43 | |
44 results = [results utp_11(mthd, at1, ple1, plist('f0', 1))]; % Test plotinfo doesn't disappear | |
45 | |
46 disp('Done.'); | |
47 disp('******************************************************'); | |
48 | |
49 elseif nargin == 1 % Check for UTP functions | |
50 if strcmp(varargin{1}, 'isutp') | |
51 results = 1; | |
52 else | |
53 results = 0; | |
54 end | |
55 else | |
56 error('### Incorrect inputs') | |
57 end | |
58 | |
59 %% UTP_01 | |
60 | |
61 % <TestDescription> | |
62 % | |
63 % Tests that the getInfo call works for this method. | |
64 % | |
65 % </TestDescription> | |
66 function result = utp_01 | |
67 | |
68 % <SyntaxDescription> | |
69 % | |
70 % Test that the getInfo call works for no sets, all sets, and each set | |
71 % individually. | |
72 % | |
73 % </SyntaxDescription> | |
74 | |
75 % <SyntaxCode> | |
76 try | |
77 % Call for no sets | |
78 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']); | |
79 % Call for all sets | |
80 io(2) = eval([class '.getInfo(''' mthd ''')']); | |
81 % Call for each set | |
82 for kk=1:numel(io(2).sets) | |
83 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']); | |
84 end | |
85 stest = true; | |
86 catch err | |
87 disp(err.message) | |
88 stest = false; | |
89 end | |
90 % </SyntaxCode> | |
91 | |
92 % <AlgoDescription> | |
93 % | |
94 % 1) Check that getInfo call returned an minfo object in all cases. | |
95 % 2) Check that all plists have the correct parameters. | |
96 % | |
97 % </AlgoDescription> | |
98 | |
99 % <AlgoCode> | |
100 atest = true; | |
101 if stest | |
102 % check we have minfo objects | |
103 if isa(io, 'minfo') | |
104 %%% SET 'None' | |
105 if ~isempty(io(1).sets), atest = false; end | |
106 if ~isempty(io(1).plists), atest = false; end | |
107 %%% Check all Sets | |
108 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end | |
109 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end | |
110 %%%%%%%%%% SET 'Default' | |
111 if io(3).plists.nparams ~= 7, atest = false; end | |
112 % Check key | |
113 if ~io(3).plists.isparam('f0'), atest = false; end | |
114 if ~io(3).plists.isparam('t0'), atest = false; end | |
115 if ~io(3).plists.isparam('quad'), atest = false; end | |
116 if ~io(3).plists.isparam('bw'), atest = false; end | |
117 if ~io(3).plists.isparam('lp'), atest = false; end | |
118 if ~io(3).plists.isparam('filter'), atest = false; end | |
119 if ~io(3).plists.isparam('ds'), atest = false; end | |
120 % Check default value | |
121 if ~isEmptyDouble(io(3).plists.find('f0')), atest = false; end | |
122 if ~isequal(io(3).plists.find('t0'), 0), atest = false; end | |
123 if ~strcmp(io(3).plists.find('quad'), 'cos'), atest = false; end | |
124 if ~isEmptyDouble(io(3).plists.find('bw')), atest = false; end | |
125 if ~isequal(io(3).plists.find('lp'), 'yes'), atest = false; end | |
126 if ~isEmptyDouble(io(3).plists.find('filter')), atest = false; end | |
127 if ~isequal(io(3).plists.find('ds'), 'yes'), atest = false; end | |
128 % Check options | |
129 if ~isequal(io(3).plists.getOptionsForParam('f0'), {[]}), atest = false; end | |
130 if ~isequal(io(3).plists.getOptionsForParam('t0'), {0}), atest = false; end | |
131 if ~isequal(io(3).plists.getOptionsForParam('quad'), {'sin', 'cos'}), atest = false; end | |
132 if ~isequal(io(3).plists.getOptionsForParam('bw'), {[]}), atest = false; end | |
133 if ~isequal(io(3).plists.getOptionsForParam('lp'), {'yes', 'no'}), atest = false; end | |
134 if ~isequal(io(3).plists.getOptionsForParam('filter'), {[]}), atest = false; end | |
135 if ~isequal(io(3).plists.getOptionsForParam('ds'), {'yes', 'no'}), atest = false; end | |
136 end | |
137 else | |
138 atest = false; | |
139 end | |
140 % </AlgoCode> | |
141 | |
142 % Return a result structure | |
143 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
144 end % END UTP_01 | |
145 | |
146 %% UTP_02 | |
147 | |
148 % <TestDescription> | |
149 % | |
150 % Tests that the heterodyne method works with a vector of AOs as input. | |
151 % | |
152 % </TestDescription> | |
153 function result = utp_02 | |
154 | |
155 % <SyntaxDescription> | |
156 % | |
157 % Test that the heterodyne method works for a vector of AOs as input. | |
158 % | |
159 % </SyntaxDescription> | |
160 | |
161 % <SyntaxCode> | |
162 try | |
163 avec = [at1 at5 at6]; | |
164 pl = plist('f0',1); | |
165 out = heterodyne(avec,pl); | |
166 stest = true; | |
167 catch err | |
168 disp(err.message) | |
169 stest = false; | |
170 end | |
171 % </SyntaxCode> | |
172 | |
173 % <AlgoDescription> | |
174 % | |
175 % 1) Check that the number of elements in 'out' is the square of the | |
176 % number in the input. | |
177 % 2) Check that each output AO contains the correct data. | |
178 % | |
179 % </AlgoDescription> | |
180 | |
181 % <AlgoCode> | |
182 atest = true; | |
183 if stest | |
184 % Check we have the correct number of outputs | |
185 if numel(out) ~= numel(avec), atest = false; end | |
186 else | |
187 atest = false; | |
188 end | |
189 % </AlgoCode> | |
190 | |
191 % Return a result structure | |
192 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
193 end % END UTP_02 | |
194 | |
195 %% UTP_03 | |
196 | |
197 % <TestDescription> | |
198 % | |
199 % Tests that the heterodyne method works with a matrix of AOs as input. | |
200 % | |
201 % </TestDescription> | |
202 function result = utp_03 | |
203 | |
204 % <SyntaxDescription> | |
205 % | |
206 % Test that the heterodyne method works for a matrix of AOs as input. | |
207 % | |
208 % </SyntaxDescription> | |
209 | |
210 % <SyntaxCode> | |
211 try | |
212 amat = [at1 at5 at6; at5 at6 at1]; | |
213 pl = plist('f0',1); | |
214 out = heterodyne(amat,pl); | |
215 stest = true; | |
216 catch err | |
217 disp(err.message) | |
218 stest = false; | |
219 end | |
220 % </SyntaxCode> | |
221 | |
222 % <AlgoDescription> | |
223 % | |
224 % 1) Check that the number of elements in 'out' is the square of the | |
225 % number in the input. | |
226 % 2) Check that each output AO contains the correct data. | |
227 % | |
228 % </AlgoDescription> | |
229 | |
230 % <AlgoCode> | |
231 atest = true; | |
232 if stest | |
233 % Check we have the correct number of outputs | |
234 if numel(out) ~= numel(amat), atest = false; end | |
235 else | |
236 atest = false; | |
237 end | |
238 % </AlgoCode> | |
239 | |
240 % Return a result structure | |
241 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
242 end % END UTP_03 | |
243 | |
244 %% UTP_04 | |
245 | |
246 % <TestDescription> | |
247 % | |
248 % Tests that the heterodyne method works with a list of AOs as input. | |
249 % | |
250 % </TestDescription> | |
251 function result = utp_04 | |
252 | |
253 % <SyntaxDescription> | |
254 % | |
255 % Test that the heterodyne method works for a list of AOs as input. | |
256 % | |
257 % </SyntaxDescription> | |
258 | |
259 % <SyntaxCode> | |
260 try | |
261 pl = plist('f0',1); | |
262 out = heterodyne(at1,at5,at6,pl); | |
263 stest = true; | |
264 catch err | |
265 disp(err.message) | |
266 stest = false; | |
267 end | |
268 % </SyntaxCode> | |
269 | |
270 % <AlgoDescription> | |
271 % | |
272 % 1) Check that the number of elements in 'out' is the square of the | |
273 % number in the input. | |
274 % 2) Check that each output AO contains the correct data. | |
275 % | |
276 % </AlgoDescription> | |
277 | |
278 % <AlgoCode> | |
279 atest = true; | |
280 if stest | |
281 % Check we have the correct number of outputs | |
282 if numel(out) ~= 3, atest = false; end | |
283 else | |
284 atest = false; | |
285 end | |
286 % </AlgoCode> | |
287 | |
288 % Return a result structure | |
289 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
290 end % END UTP_04 | |
291 | |
292 %% UTP_05 | |
293 | |
294 % <TestDescription> | |
295 % | |
296 % Tests that the heterodyne method works with a mix of different shaped AOs as | |
297 % input. | |
298 % | |
299 % </TestDescription> | |
300 function result = utp_05 | |
301 | |
302 % <SyntaxDescription> | |
303 % | |
304 % Test that the heterodyne method works with an input of matrices and vectors | |
305 % and single AOs. | |
306 % | |
307 % </SyntaxDescription> | |
308 | |
309 % <SyntaxCode> | |
310 try | |
311 pl = plist('f0',1); | |
312 out = heterodyne(at1,[at5 at6],at5,[at5 at1; at6 at1],at6,pl); | |
313 stest = true; | |
314 catch err | |
315 disp(err.message) | |
316 stest = false; | |
317 end | |
318 % </SyntaxCode> | |
319 | |
320 % <AlgoDescription> | |
321 % | |
322 % 1) Check that the number of elements in 'out' is the same as in | |
323 % input. | |
324 % 2) Check that each output AO contains the correct data. | |
325 % | |
326 % </AlgoDescription> | |
327 | |
328 % <AlgoCode> | |
329 atest = true; | |
330 if stest | |
331 % Check we have the correct number of outputs | |
332 if numel(out) ~= 9, atest = false; end | |
333 else | |
334 atest = false; | |
335 end | |
336 % </AlgoCode> | |
337 | |
338 % Return a result structure | |
339 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
340 end % END UTP_05 | |
341 | |
342 %% UTP_06 | |
343 % <TestDescription> | |
344 % | |
345 % Tests that the heterodyne method properly applies history. | |
346 % | |
347 % </TestDescription> | |
348 function result = utp_06 | |
349 | |
350 % <SyntaxDescription> | |
351 % | |
352 % Test that the result of applying the heterodyne method can be processed back | |
353 % to an m-file. | |
354 % | |
355 % </SyntaxDescription> | |
356 | |
357 % <SyntaxCode> | |
358 try | |
359 pl = plist('f0',1); | |
360 out = heterodyne(at5,pl); | |
361 mout = rebuild(out); | |
362 stest = true; | |
363 catch err | |
364 disp(err.message) | |
365 stest = false; | |
366 end | |
367 % </SyntaxCode> | |
368 | |
369 % <AlgoDescription> | |
370 % | |
371 % 1) Check that the last entry in the history of 'out' corresponds to | |
372 % 'heterodyne'. | |
373 % 2) Check that the re-built object is the same object as 'out'. | |
374 % | |
375 % </AlgoDescription> | |
376 | |
377 % <AlgoCode> | |
378 atest = true; | |
379 if stest | |
380 % Check the last step in the history of 'out' | |
381 if ~strcmp(out.hist.methodInfo.mname, 'heterodyne'), atest = false; end | |
382 % Check the re-built object | |
383 if ~eq(mout, out, ple2), atest = false; end | |
384 else | |
385 atest = false; | |
386 end | |
387 % </AlgoCode> | |
388 | |
389 % Return a result structure | |
390 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
391 end % END UTP_06 | |
392 | |
393 %% UTP_07 | |
394 | |
395 % <TestDescription> | |
396 % | |
397 % Tests the heterodyne method functionality. | |
398 % | |
399 % </TestDescription> | |
400 function result = utp_07 | |
401 | |
402 % <SyntaxDescription> | |
403 % | |
404 % Build reference signal, mixed signal and heterodyne the 2nd to obtain the first | |
405 % Downsample is set to 'no' | |
406 % | |
407 % </SyntaxDescription> | |
408 | |
409 % <SyntaxCode> | |
410 try | |
411 % generate reference ao | |
412 fs = 50; | |
413 fhet = 5; | |
414 nsecs = 1000; | |
415 pl = plist(... | |
416 'tsfcn', '(1 + sin(2*pi*0.01*t))', ... | |
417 'fs', fs, ... | |
418 'nsecs', nsecs); | |
419 a1 = ao(pl); | |
420 % generate reference ao at f_heterodyne | |
421 pl = plist('tsfcn', '(1 + sin(2*pi*0.01*t))','fs', fhet, 'nsecs', nsecs); | |
422 a1h = ao(pl); | |
423 % generate same ao mixed and noisy | |
424 pl = plist('tsfcn', ... | |
425 '(1 + sin(2*pi*0.01*t)) .* cos(2*pi*5*t)',... | |
426 'fs', fs, 'nsecs', nsecs); | |
427 a2 = ao(pl); | |
428 % compute heterodyne | |
429 a2h = heterodyne(a2,plist('f0', fhet, 'bw', fhet,'ds','no')); | |
430 stest = true; | |
431 catch err | |
432 disp(err.message) | |
433 stest = false; | |
434 end | |
435 % </SyntaxCode> | |
436 | |
437 % <AlgoDescription> | |
438 % | |
439 % Test that we can recover the initial signal after heterodyne up to | |
440 % a numerical error given by tol | |
441 % | |
442 % </AlgoDescription> | |
443 atest = false; | |
444 % <AlgoCode> | |
445 if stest | |
446 tol = 1e-5; % numerical tolerance | |
447 trans = 150; % samples out of test at the beginning and end due to transient | |
448 if all(abs(a2h.y(1+trans:end-trans) - a1.y(1+trans:end-trans) ) < tol) | |
449 atest = true; | |
450 else | |
451 atest = false; | |
452 end | |
453 end | |
454 % </AlgoCode> | |
455 | |
456 % Return a result structure | |
457 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
458 end % END UTP_07 | |
459 | |
460 %% UTP_08 | |
461 | |
462 % <TestDescription> | |
463 % | |
464 % Tests the heterodyne method functionality. | |
465 % | |
466 % </TestDescription> | |
467 function result = utp_08 | |
468 | |
469 % <SyntaxDescription> | |
470 % | |
471 % Build reference signal, mixed signal and heterodyne the 2nd to obtain the first | |
472 % Downsample is set to 'yes' | |
473 % | |
474 % </SyntaxDescription> | |
475 | |
476 % <SyntaxCode> | |
477 try | |
478 % generate reference ao | |
479 fs = 50; | |
480 fhet = 5; | |
481 nsecs = 1000; | |
482 pl = plist(... | |
483 'tsfcn', '(1 + sin(2*pi*0.01*t))', ... | |
484 'fs', fs, ... | |
485 'nsecs', nsecs); | |
486 a1 = ao(pl); | |
487 % generate reference ao at f_heterodyne | |
488 pl = plist('tsfcn', ... | |
489 '(1 + sin(2*pi*0.01*t))','fs', fhet, 'nsecs', nsecs); | |
490 a1h = ao(pl); | |
491 % generate same ao mixed and noisy | |
492 pl = plist('tsfcn', ... | |
493 '(1 + sin(2*pi*0.01*t)) .* cos(2*pi*5*t)',... | |
494 'fs', fs, 'nsecs', nsecs); | |
495 a2 = ao(pl); | |
496 % compute heterodyne | |
497 a2h = heterodyne(a2,plist('f0', fhet, 'bw', fhet,'ds','yes')); | |
498 stest = true; | |
499 catch err | |
500 disp(err.message) | |
501 stest = false; | |
502 end | |
503 % </SyntaxCode> | |
504 | |
505 % <AlgoDescription> | |
506 % | |
507 % Test that we can recover the initial signal after heterodyne up to | |
508 % a numerical error given by tol | |
509 % | |
510 % </AlgoDescription> | |
511 atest = false; | |
512 % <AlgoCode> | |
513 if stest | |
514 tol = 1e-5; % numerical tolerance | |
515 trans = 15; % samples out of test at the beginning and end due to transient | |
516 if all(abs(a2h.y(1+trans:end-trans)-a1h.y(1+trans:end-trans)) < tol) | |
517 atest = true; | |
518 else | |
519 atest = false; | |
520 end | |
521 end | |
522 % </AlgoCode> | |
523 | |
524 % Return a result structure | |
525 result = utp_prepare_result(atest, stest, dbstack, mfilename); | |
526 end % END UTP_08 | |
527 | |
528 end | |
529 |