comparison testing/utp_1.1/utp_test_files/makeTestFiles.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 % MAKETESTFILES builds a set of test files for the current LTPDA version.
2 %
3 % M Hewitson 09-09-08
4 %
5 % $Id: makeTestFiles.m,v 1.8 2010/05/12 15:55:19 ingo Exp $
6 %
7 function makeTestFiles()
8
9 mkPlist();
10
11 mkAO();
12 mkRational();
13 mkParfrac();
14 mkPzmodel();
15 mkMiir();
16 mkMfir();
17 mkTimespan();
18 mkSSM();
19
20 mkCollection();
21 mkMatrix;
22 mkSmodel;
23 mkPest;
24 mkFilterbank;
25
26 end
27
28 %% PLIST
29 function mkPlist()
30
31
32 pl1 = plist();
33 pl2 = plist('a', 1, 'b', 2, 'c', 3);
34 pl3 = plist('char', 'string', ...
35 'number', 123, ...
36 'logical', true, ...
37 'cell', {'asd', [1 2 3; 4 5 6], [true false], 'asd'});
38
39 pl4 = plist('spec', specwin('kaiser', 5, 20), ...
40 'time', time(123456), ...
41 'ao', ao(1:10, randn(10,1)), ...
42 'miir', miir(plist('type', 'lowpass')));
43
44 plvec = [pl1, pl2, pl3];
45 plmat = [pl1, pl2, pl3; pl4, pl1, pl2];
46
47 writeFiles([pl1, pl2, pl3, pl4], plvec, plmat);
48
49 end
50
51 %% AO
52 function mkAO()
53
54 % tsdata ao
55 aots = ao(plist('fs', 10, 'nsecs', 10, ...
56 'tsfcn', 'sin(2*pi*1.4*t) + 0.1*randn(size(t))', ...
57 't0', time('1980-12-01 12:43:12')));
58
59 aots.setName();
60
61 % fsdata ao
62 aofs = aots.psd;
63 aofs.setName();
64
65 % xydata ao
66 aoxy = ao(xydata(1:10,1:10));
67 aoxy.setName();
68
69 % cdata ao
70 aoc = ao(magic(3));
71 aoc.setName();
72
73 plvec = [aots, aofs, aoxy];
74 plmat = [aots, aofs, aoxy; aots, aoc, ao()];
75
76 writeFiles([aots, aofs, aoxy, aoc], plvec, plmat);
77
78 end
79
80 %% Pzmodel
81 function mkPzmodel()
82
83 pzm1 = pzmodel(1, pz(1), []);
84 pzm1.setName();
85
86 pzm2 = pzmodel(1, [], pz(1));
87 pzm2.setName();
88
89 pzm3 = pzmodel(1, 1, 10);
90 pzm3.setName();
91
92 pzm4 = pzmodel();
93 pzm4.setName();
94
95 pzm5 = pzmodel(2, 10, {1, [1 1]});
96 pzm5.setName();
97
98 pzmvec = [pzm1, pzm2, pzm3];
99 pzmmat = [pzm1, pzm2, pzm3; pzm4, pzm5, pzm5];
100
101 writeFiles([pzm1, pzm2, pzm3, pzm4, pzm5], pzmvec, pzmmat);
102
103 end
104
105 %% MFIR
106 function mkMfir()
107
108 fir1 = mfir(plist('type', 'highpass'));
109 fir1.setName();
110
111 fir2 = mfir(plist('type', 'lowpass'));
112 fir2.setName();
113
114 fir3 = mfir(plist('type', 'lowpass', 'fc', .1, 'gain', 1, 'fs', 1, 'order', 64, 'WIN', specwin('Hanning', 65)));
115 fir3.setName();
116
117 pzm = pzmodel(1, [pz(1) pz(200)], pz(50));
118 pl = plist('pzmodel', pzm, 'fs', 1000);
119 fir4 = mfir(pl);
120 fir4.setName();
121
122 a1 = ao(plist('fsfcn', '1./(50+f)', 'f', linspace(0, 500, 1000)));
123 a1.setFs(1000);
124 pl = plist('ao', a1);
125 fir5 = mfir(pl);
126 fir5.setName();
127
128 firvec = [fir1, fir2, fir3];
129 firmat = [fir1, fir2, fir3; fir4, fir5, fir5];
130
131 writeFiles([fir1, fir2, fir3, fir4, fir5], firvec, firmat);
132
133 end
134 %% MIIR
135 function mkMiir()
136
137 iir1 = miir(plist('type', 'lowpass'));
138 iir1.setName();
139
140 iir2 = miir(plist('type', 'bandpass', 'fc', [0.01 0.1]));
141 iir2.setName();
142
143 iir3 = miir(plist('type', 'bandreject', 'fc', [0.01 0.1]));
144 iir3.setName();
145
146 pzm = pzmodel(1, [pz(1) pz(200)], pz(50));
147 pzm.setName();
148 pl = plist('pzmodel', pzm, 'fs', 1000);
149 iir4 = miir(pl);
150 iir4.setName();
151
152 a = [0.5 -0.01];
153 b = [1 0.1];
154 fs = 1;
155 iir5 = miir(a,b,fs);
156 iir5.setName();
157
158 iirvec = [iir1, iir2, iir3];
159 iirmat = [iir1, iir2, iir3; iir4, iir5, iir5];
160
161 writeFiles([iir1, iir2, iir3, iir4, iir5], iirvec, iirmat);
162
163 end
164
165 %% SSM
166 function mkSSM
167
168 try
169 s1 = ssm();
170 s2 = ssm(plist('built-in', 'SMD'));
171 s3 = ssm(plist('built-in', 'HARMONIC_OSC_1D'));
172
173 sVec = [s1, s2, s3];
174 sMat = [s1, s2, s3; s2, s1, s2];
175
176 writeFiles([s1 s2 s3], sVec, sMat);
177 catch
178 warning('!!! Don''t know how to build this SSM object.');
179 end
180
181 end
182
183 %% TIMESPAN
184 function mkTimespan()
185
186 ts1 = timespan();
187 ts1.setName();
188
189 ts2 = timespan('2008-08-08 12:00:00', '2008-08-08 13:00:00');
190 ts2.setName();
191
192 ts3 = timespan(time(10), time(100));
193 ts3.setName();
194
195 ts4 = timespan(time(0) ,'14:00:00'); % timespan
196 ts4.setName();
197
198 pl = plist('timezone', 'GMT+06','start', time(1234),'end', time(12345));
199 ts5 = timespan(pl);
200 ts5.setName();
201
202 tsvec = [ts4, ts2, ts5];
203
204 tsmat = [ts1, ts2, ts5; ts4, ts3, ts2];
205
206 writeFiles([ts1, ts2, ts3, ts4, ts5], tsvec, tsmat)
207
208 end
209
210 %% PARFRAC
211 function mkParfrac()
212
213 pf1 = parfrac();
214 pf1.setName();
215
216 pf2 = parfrac([1 2], {4, 6+2i}, []);
217 pf2.setName();
218
219 pf3 = parfrac([1 2+1i 2-1i], [6 1+3i 1-3i], [1 2]);
220 pf3.setName();
221
222 pf4 = parfrac([1 2+1i 2-1i], [6 1+3i 1-3i], [1 2 3 4], 'my par frac', unit('V'), unit('Hz'));
223 pf4.setName();
224
225 pzm = pzmodel(1, pz(1), [pz(1,2), pz(1+2i)]);
226 pl = plist('pzmodel', pzm, 'name', 'new name', 'iunits', 'm^3', 'ounits', 'Hz');
227 pf5 = parfrac(pl);
228 pf5.setName();
229
230 pfvec = [pf4, pf2, pf5];
231
232 pfmat = [pf1, pf2, pf5; pf4, pf3, pf2];
233
234 writeFiles([pf1, pf2, pf3, pf4, pf5], pfvec, pfmat)
235
236 end
237
238 %% RATIONAL
239 function mkRational()
240
241 ra1 = rational();
242 ra1.setName();
243
244 ra2 = rational([1 2], [4, 6], 'my rational');
245 ra2.setName();
246
247 ra3 = rational([1 2 -3], [6 -7 1 -5], 'my par rat', unit('V'), unit('Hz'));
248 ra3.setName();
249
250 pzm = pzmodel(1, pz(1), [pz(1,2), pz(1+2i)]);
251 pl = plist('pzmodel', pzm, 'name', 'new name', 'iunits', 'm^3', 'ounits', 'Hz');
252 ra4 = rational(pl);
253 ra4.setName();
254
255 ravec = [ra4, ra3, ra2];
256
257 ramat = [ra1, ra2, ra3; ra4, ra3, ra2];
258
259 writeFiles([ra1, ra2, ra3, ra4], ravec, ramat)
260
261 end
262
263 %% COLLECTION
264 function mkCollection()
265
266 coll1 = collection();
267 coll1.setName();
268
269 coll2 = collection(rational([1 2], [4, 6], 'my rational'), ao(magic(8)), mfir(plist('type', 'lowpass')));
270 coll2.setName();
271
272 coll3 = collection(ao(1:51, randn(1,51) + 1.1i, 12.3), pzmodel(1, pz(1), [pz(1,2), pz(1+2i)]));
273 coll3.setName();
274 coll3.setPlotinfo(plist('color', 'black'));
275
276
277 collVec = [coll1, coll2, coll3];
278
279 collMat = [coll3, coll1, coll2; coll2 coll3, coll1];
280
281 writeFiles([coll1, coll2, coll3], collVec, collMat)
282
283 end
284
285 %% MATRIX
286 function mkMatrix()
287
288 m1 = matrix();
289 m1.setName();
290
291 m2 = matrix([ao(1), ao(2) ao(3); ao(4), ao(5), ao(6)]);
292 m2.setName();
293
294 m3 = matrix(ao(1), ao(2), ao(3));
295 m3.setName();
296 m3.setPlotinfo(plist('color', 'black'));
297
298
299 mVec = [m1, m2, m3];
300
301 mMat = [m3, m1, m2; m2 m3, m1];
302
303 writeFiles([m1, m2, m3], mVec, mMat)
304
305 end
306
307 %% SMODEL
308 function mkSmodel()
309
310 model1 = smodel();
311 model1.setName();
312
313 model2 = smodel('C1*X1 + C2*X2 + C3*X3');
314 model2.setParams('C1', 1.00447715161685);
315 model2.setParams('C2', 2.06131342419899);
316 model2.setParams('C3', 3.03410245878967);
317 model2.setXvals(randn(1,100));
318 % model2.setXvar({'X1', 'X2', 'X3'});
319 model2.setXvar('X1');
320 model2.setXunits(unit('T', 'm', 'C'));
321 model2.setYunits('m');
322 model2.setPlotinfo(plist('color', 'black'));
323 model2.setName();
324
325 modelVec = [model1, model2];
326
327 modelMat = [model1, model1 model2; model1 model2, model1];
328
329 writeFiles([model1, model2], modelVec, modelMat)
330
331 end
332
333 %% PEST
334 function mkPest()
335
336 model = smodel('C1*X1 + C2*X2 + C3*X3');
337 model.setParams('C1', 1.00447715161685);
338 model.setParams('C2', 2.06131342419899);
339 model.setParams('C3', 3.03410245878967);
340 % model.setXvar({'X1', 'X2', 'X3'});
341 model.setXvar('X1');
342 model.setXunits(unit('T', 'm', 'C'));
343 model.setYunits('m');
344 model.setName();
345
346 pest1 = pest([1;2.06;3.03], {'C1', 'C2', 'C3'}, [0.0917;0.089;0.0957], [0.00841 -0.000604 0.000455;-0.000604 0.00791 -0.000246;0.000455 -0.000246 0.00916]);
347 pest1.setYunits(unit('[m T^(-1)]','[m m^(-1)]','[m C^(-1)]'));
348 pest1.setModels(model);
349 pest1.setName();
350
351 pest2 = pest();
352 pest2.setName();
353
354 pestVec = [pest1, pest2];
355
356 pestMat = [pest1, pest1 pest2; pest1 pest2, pest1];
357
358 writeFiles([pest1, pest2], pestVec, pestMat)
359
360 end
361
362 %% FILTERBANK
363 function mkFilterbank()
364
365 a1 = ao(plist('fsfcn', '1./(50+f)', 'f', linspace(0, 500, 1000)));
366 a1.setFs(1000);
367 pl = plist('ao', a1);
368
369 f1 = mfir(pl);
370 f2 = mfir(plist('Type', 'lowpass'));
371 f3 = mfir(plist('type', 'lowpass', 'fc', .1, 'gain', 1, 'fs', 1, 'order', 64, 'WIN', specwin('Hanning', 65)));
372
373 pzm = pzmodel(1, [pz(1) pz(200)], pz(50));
374 pzm.setName();
375 pl = plist('pzmodel', pzm, 'fs', 1000);
376
377 f4 = miir(pl);
378 f5 = miir();
379 f6 = miir(plist('type', 'bandreject', 'fc', [0.01 0.1]));
380
381 fb1 = filterbank();
382 fb1.setName();
383
384 fb2 = filterbank([f1, f2, f3], 'serial');
385 fb2.setPlotinfo(plist('color', 'black'));
386 fb2.setName();
387
388 fb3 = filterbank(f4, f5, f6);
389
390 fbVec = [fb1, fb2, fb3];
391
392 fbMat = [fb1, fb3 fb2; fb1 fb2, fb3];
393
394 writeFiles([fb1, fb2, fb3], fbVec, fbMat)
395
396 end
397
398 %% Write Function
399 function writeFiles(objs, obj_vec, obj_mat)
400
401 % class
402 cln = class(objs);
403
404 % Get the toolbox version
405 tbxver = getappdata(0, 'ltpda_version');
406
407 % get only the version string without the MATLAB version
408 tbxver = strtok(tbxver);
409
410 % remove the points between the subversions
411 tbxver = strrep(tbxver, '.', '');
412
413 %%%%%%%%%% Save single objects %%%%%%%%%%
414 for ii = 1:numel(objs)
415
416 % Create filename
417 filename = sprintf('%s_%s_%d', cln, tbxver, ii);
418
419 % Save XML
420 save(objs(ii), [filename '.xml']);
421 if ~strcmp(tbxver, '191')
422 % Save MAT
423 save(objs(ii), [filename '.mat']);
424 end
425 end
426
427 %%%%%%%%%% Save vector of object %%%%%%%%%%
428
429 % Create filename
430 filename = sprintf('%s_%s_vec', cln, tbxver);
431
432 % Save XML
433 save(obj_vec, [filename '.xml']);
434 if ~strcmp(tbxver, '191')
435 % Save MAT
436 save(obj_vec, [filename '.mat']);
437 end
438
439 %%%%%%%%%% Save matrix of object %%%%%%%%%%
440
441 % Create filename
442 filename = sprintf('%s_%s_mat', cln, tbxver);
443
444 % Save XML
445 save(obj_mat, [filename '.xml']);
446 if ~strcmp(tbxver, '191')
447 % Save MAT
448 save(obj_mat, [filename '.mat']);
449 end
450
451 end