comparison testing/utp_1.1/utps/ao/utp_ao_whiten1D.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_WHITEN1D a set of UTPs for the ao/whiten1D method
2 %
3 % M Hewitson 06-08-08
4 %
5 % $Id: utp_ao_whiten1D.m,v 1.24 2011/04/18 16:57:44 ingo Exp $
6 %
7
8 % <MethodDescription>
9 %
10 % The whiten1D method of the ao class computes the whiten1Dolute value of the y
11 % and/or x data.
12 %
13 % </MethodDescription>
14
15 function results = utp_ao_whiten1D(varargin)
16
17 % Check the inputs
18 if nargin == 0
19
20 % Some keywords
21 class = 'ao';
22 mthd = 'whiten1D';
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] = get_test_objects_ao;
31
32 % Exception list for the UTPs:
33 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
34
35 % add useful params to standard exceptions
36 ple3 = plist('Exceptions', {'history', 'created', 'UUID', 'param/desc', 'name', 'procinfo'});
37
38 % Run the tests
39 results = [results utp_01]; % getInfo call
40 results = [results utp_02]; % Vector input
41 results = [results utp_03]; % Matrix input
42 results = [results utp_04]; % List input
43 results = [results utp_05]; % Test with mixed input
44 results = [results utp_06]; % Test history is working
45 results = [results utp_07]; % Test the modify call works
46 results = [results utp_08]; % Test input data shape == output data shape
47 results = [results utp_09]; % Test output of the data
48 results = [results utp_10]; % Test flatness capability - no model input
49 results = [results utp_11]; % Test flatness capability - model input
50
51 disp('Done.');
52 disp('******************************************************');
53
54 elseif nargin == 1 % Check for UTP functions
55 if strcmp(varargin{1}, 'isutp')
56 results = 1;
57 else
58 results = 0;
59 end
60 else
61 error('### Incorrect inputs')
62 end
63
64 %% UTP_01
65
66 % <TestDescription>
67 %
68 % Tests that the getInfo call works for this method.
69 %
70 % </TestDescription>
71 function result = utp_01
72
73
74 % <SyntaxDescription>
75 %
76 % Test that the getInfo call works for no sets, all sets, and each set
77 % individually.
78 %
79 % </SyntaxDescription>
80
81 try
82 % <SyntaxCode>
83 % Call for no sets
84 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
85 % Call for all sets
86 io(2) = eval([class '.getInfo(''' mthd ''')']);
87 % Call for each set
88 for kk=1:numel(io(2).sets)
89 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
90 end
91 % </SyntaxCode>
92 stest = true;
93 catch err
94 disp(err.message)
95 stest = false;
96 end
97
98 % <AlgoDescription>
99 %
100 % 1) Check that getInfo call returned an minfo object in all cases.
101 % 2) Check that all plists have the correct parameters.
102 %
103 % </AlgoDescription>
104
105 atest = true;
106 if stest
107 % <AlgoCode>
108 % check we have minfo objects
109 if isa(io, 'minfo')
110 prefs = getappdata(0, 'LTPDApreferences');
111 defaultWinType = char(prefs.getMiscPrefs.getDefaultWindow);
112
113 %%% SET 'None'
114 if ~isempty(io(1).sets), atest = false; end
115 if ~isempty(io(1).plists), atest = false; end
116 %%% Check all Sets
117 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
118 if ~any(strcmpi(io(2).sets, 'psd')), atest = false; end
119 if ~any(strcmpi(io(2).sets, 'lpsd')), atest = false; end
120 %%%%%%%%%% SET 'Default'
121 pn = 3;
122 if io(pn).plists.nparams ~= 15, atest = false; end
123 % Check key
124 if ~io(pn).plists.isparam('model'), atest = false; end
125 if ~io(pn).plists.isparam('range'), atest = false; end
126 if ~io(pn).plists.isparam('fs'), atest = false; end
127 if ~io(pn).plists.isparam('complete_hf'), atest = false; end
128 if ~io(pn).plists.isparam('maxiter'), atest = false; end
129 if ~io(pn).plists.isparam('poletype'), atest = false; end
130 if ~io(pn).plists.isparam('minorder'), atest = false; end
131 if ~io(pn).plists.isparam('maxorder'), atest = false; end
132 if ~io(pn).plists.isparam('weights'), atest = false; end
133 if ~io(pn).plists.isparam('plot'), atest = false; end
134 if ~io(pn).plists.isparam('disp'), atest = false; end
135 if ~io(pn).plists.isparam('msevartol'), atest = false; end
136 if ~io(pn).plists.isparam('fittol'), atest = false; end
137 if ~io(pn).plists.isparam('flim'), atest = false; end
138 if ~io(pn).plists.isparam('scaleout'), atest = false; end
139
140 % Check default value
141 if ~isEmptyDouble(io(pn).plists.find('model')), atest = false; end
142 if ~isequal(io(pn).plists.find('range'), []), atest = false; end
143 if ~isequal(io(pn).plists.find('fs'), []), atest = false; end
144 if ~isequal(io(pn).plists.find('complete_hf'), 'flat'), atest = false; end
145 if ~isequal(io(pn).plists.find('maxiter'), 30), atest = false; end
146 if ~isequal(io(pn).plists.find('poletype'), 1), atest = false; end
147 if ~isequal(io(pn).plists.find('minorder'), 2), atest = false; end
148 if ~isequal(io(pn).plists.find('maxorder'), 25), atest = false; end
149 if ~isequal(io(pn).plists.find('weights'), '1/abs'), atest = false; end
150 if ~isequal(io(pn).plists.find('plot'), false), atest = false; end
151 if ~isequal(io(pn).plists.find('disp'), false), atest = false; end
152 if ~isequal(io(pn).plists.find('msevartol'), .1), atest = false; end
153 if ~isequal(io(pn).plists.find('fittol'), .01), atest = false; end
154 if ~isequal(io(pn).plists.find('flim'), [1e-3 30e-3]), atest = false; end
155 if ~isequal(io(pn).plists.find('scaleout'), false), atest = false; end
156
157 % Check options
158 if ~isequal(io(pn).plists.getOptionsForParam('model'), {[]}), atest = false; end
159 if ~isequal(io(pn).plists.getOptionsForParam('range'), {[]}), atest = false; end
160 if ~isequal(io(pn).plists.getOptionsForParam('fs'), {[]}), atest = false; end
161 if ~isequal(io(pn).plists.getOptionsForParam('complete_hf'), {'flat', 'lowpass'}), atest = false; end
162 if ~isequal(io(pn).plists.getOptionsForParam('maxiter'), {30}), atest = false; end
163 if ~isequal(io(pn).plists.getOptionsForParam('minorder'), {2}), atest = false; end
164 if ~isequal(io(pn).plists.getOptionsForParam('maxorder'), {25}), atest = false; end
165 if ~isequal(io(pn).plists.getOptionsForParam('weights'), {'equal', '1/abs', '1/abs^2'}), atest = false; end
166 if ~isequal(io(pn).plists.getOptionsForParam('plot'), {false, true}), atest = false; end
167 if ~isequal(io(pn).plists.getOptionsForParam('disp'), {false, true}), atest = false; end
168 if ~isequal(io(pn).plists.getOptionsForParam('msevartol'), {.1}), atest = false; end
169 if ~isequal(io(pn).plists.getOptionsForParam('fittol'), {.01}), atest = false; end
170 if ~isequal(io(pn).plists.getOptionsForParam('poletype'), {1 2 3}), atest = false; end
171 if ~isequal(io(pn).plists.getOptionsForParam('flim'), {[1e-3 30e-3]}), atest = false; end
172 if ~isequal(io(pn).plists.getOptionsForParam('scaleout'), {false, true}), atest = false; end
173
174 %%%%%%%%%% SET 'psd'
175 pn = 4;
176 if io(pn).plists.nparams ~= 29, atest = false; end
177 % Check key
178 if ~io(pn).plists.isparam('model'), atest = false; end
179 if ~io(pn).plists.isparam('range'), atest = false; end
180 if ~io(pn).plists.isparam('fs'), atest = false; end
181 if ~io(pn).plists.isparam('complete_hf'), atest = false; end
182 if ~io(pn).plists.isparam('maxiter'), atest = false; end
183 if ~io(pn).plists.isparam('poletype'), atest = false; end
184 if ~io(pn).plists.isparam('minorder'), atest = false; end
185 if ~io(pn).plists.isparam('maxorder'), atest = false; end
186 if ~io(pn).plists.isparam('weights'), atest = false; end
187 if ~io(pn).plists.isparam('plot'), atest = false; end
188 if ~io(pn).plists.isparam('disp'), atest = false; end
189 if ~io(pn).plists.isparam('msevartol'), atest = false; end
190 if ~io(pn).plists.isparam('fittol'), atest = false; end
191 if ~io(pn).plists.isparam('nfft'), atest = false; end
192 if ~io(pn).plists.isparam('win'), atest = false; end
193 if ~io(pn).plists.isparam('psll'), atest = false; end
194 if ~io(pn).plists.isparam('olap'), atest = false; end
195 if ~io(pn).plists.isparam('order'), atest = false; end
196 if ~io(pn).plists.isparam('navs'), atest = false; end
197 if ~io(pn).plists.isparam('times'), atest = false; end
198 if ~io(pn).plists.isparam('split'), atest = false; end
199 if ~io(pn).plists.isparam('scale'), atest = false; end
200 if ~io(pn).plists.isparam('method'), atest = false; end
201 if ~io(pn).plists.isparam('xscale'), atest = false; end
202 if ~io(pn).plists.isparam('resolution'), atest = false; end
203 if ~io(pn).plists.isparam('xvals'), atest = false; end
204 if ~io(pn).plists.isparam('inherit_dy'), atest = false; end
205 if ~io(pn).plists.isparam('flim'), atest = false; end
206 if ~io(pn).plists.isparam('scaleout'), atest = false; end
207
208 % Check default value
209 if ~isequal(io(pn).plists.find('model'), 'PSD'), atest = false; end
210 if ~isequal(io(pn).plists.find('range'), []), atest = false; end
211 if ~isequal(io(pn).plists.find('fs'), []), atest = false; end
212 if ~isequal(io(pn).plists.find('complete_hf'), 'flat'), atest = false; end
213 if ~isequal(io(pn).plists.find('maxiter'), 30), atest = false; end
214 if ~isequal(io(pn).plists.find('poletype'), 1), atest = false; end
215 if ~isequal(io(pn).plists.find('minorder'), 2), atest = false; end
216 if ~isequal(io(pn).plists.find('maxorder'), 25), atest = false; end
217 if ~isequal(io(pn).plists.find('weights'), '1/abs'), atest = false; end
218 if ~isequal(io(pn).plists.find('plot'), false), atest = false; end
219 if ~isequal(io(pn).plists.find('disp'), false), atest = false; end
220 if ~isequal(io(pn).plists.find('msevartol'), .1), atest = false; end
221 if ~isequal(io(pn).plists.find('fittol'), .01), atest = false; end
222 if ~isequal(io(pn).plists.find('nfft'), -1), atest = false; end
223 if ~strcmpi(io(pn).plists.find('win'), defaultWinType), atest = false; end
224 if ~isequal(io(pn).plists.find('psll'), 200), atest = false; end
225 if ~isequal(io(pn).plists.find('olap'), 50), atest = false; end
226 if ~isequal(io(pn).plists.find('order'), 1), atest = false; end
227 if ~isequal(io(pn).plists.find('navs'), 16), atest = false; end
228 if ~isequal(io(pn).plists.find('times'), []), atest = false; end
229 if ~isequal(io(pn).plists.find('split'), []), atest = false; end
230 if ~isequal(io(pn).plists.find('scale'), 'PSD'), atest = false; end
231 if ~isequal(io(pn).plists.find('method'), 'MEAN'), atest = false; end
232 if ~isequal(io(pn).plists.find('xscale'), 'LOG'), atest = false; end
233 if ~isequal(io(pn).plists.find('resolution'), 50), atest = false; end
234 if ~isequal(io(pn).plists.find('xvals'), []), atest = false; end
235 if ~isequal(io(pn).plists.find('inherit_dy'), 'yes'), atest = false; end
236 if ~isequal(io(pn).plists.find('flim'), [1e-3 30e-3]), atest = false; end
237 if ~isequal(io(pn).plists.find('scaleout'), false), atest = false; end
238
239 % Check options
240 if ~isequal(io(pn).plists.getOptionsForParam('model'), {'PSD'}), atest = false; end
241 if ~isequal(io(pn).plists.getOptionsForParam('range'), {[]}), atest = false; end
242 if ~isequal(io(pn).plists.getOptionsForParam('fs'), {[]}), atest = false; end
243 if ~isequal(io(pn).plists.getOptionsForParam('complete_hf'), {'flat', 'lowpass'}), atest = false; end
244 if ~isequal(io(pn).plists.getOptionsForParam('maxiter'), {30}), atest = false; end
245 if ~isequal(io(pn).plists.getOptionsForParam('poletype'), {1 2 3}), atest = false; end
246 if ~isequal(io(pn).plists.getOptionsForParam('minorder'), {2}), atest = false; end
247 if ~isequal(io(pn).plists.getOptionsForParam('maxorder'), {25}), atest = false; end
248 if ~isequal(io(pn).plists.getOptionsForParam('weights'), {'equal', '1/abs', '1/abs^2'}), atest = false; end
249 if ~isequal(io(pn).plists.getOptionsForParam('plot'), {false, true}), atest = false; end
250 if ~isequal(io(pn).plists.getOptionsForParam('disp'), {false, true}), atest = false; end
251 if ~isequal(io(pn).plists.getOptionsForParam('msevartol'), {.1}), atest = false; end
252 if ~isequal(io(pn).plists.getOptionsForParam('fittol'), {.01}), atest = false; end
253 if ~isequal(io(pn).plists.getOptionsForParam('nfft'), {-1}), atest = false; end
254 if ~isequal(io(pn).plists.getOptionsForParam('win'), specwin.getTypes), atest = false; end
255 if ~isequal(io(pn).plists.getOptionsForParam('psll'), {200}), atest = false; end
256 if ~isequal(io(pn).plists.getOptionsForParam('olap'), {50}), atest = false; end
257 if ~isequal(io(pn).plists.getOptionsForParam('order'), {1}), atest = false; end
258 if ~isequal(io(pn).plists.getOptionsForParam('navs'), {16}), atest = false; end
259 if ~isequal(io(pn).plists.getOptionsForParam('times'), {[]}), atest = false; end
260 if ~isequal(io(pn).plists.getOptionsForParam('split'), {[]}), atest = false; end
261 if ~isequal(io(pn).plists.getOptionsForParam('scale'), {'PSD', 'ASD', 'PS', 'AS'}), atest = false; end
262 if ~isequal(io(pn).plists.getOptionsForParam('method'), {'MEAN'}), atest = false; end
263 if ~isequal(io(pn).plists.getOptionsForParam('xscale'), {'LOG','LIN'}), atest = false; end
264 if ~isequal(io(pn).plists.getOptionsForParam('resolution'), {50}), atest = false; end
265 if ~isequal(io(pn).plists.getOptionsForParam('xvals'), {[]}), atest = false; end
266 if ~isequal(io(pn).plists.getOptionsForParam('inherit_dy'), {'yes','no'}), atest = false; end
267 if ~isequal(io(pn).plists.getOptionsForParam('flim'), {[1e-3 30e-3]}), atest = false; end
268 if ~isequal(io(pn).plists.getOptionsForParam('scaleout'), {false, true}), atest = false; end
269
270 %%%%%%%%%% SET 'lpsd'
271 pn = 5;
272 if io(pn).plists.nparams ~= 25, atest = false; end
273 % Check key
274 if ~io(pn).plists.isparam('model'), atest = false; end
275 if ~io(pn).plists.isparam('range'), atest = false; end
276 if ~io(pn).plists.isparam('fs'), atest = false; end
277 if ~io(pn).plists.isparam('complete_hf'), atest = false; end
278 if ~io(pn).plists.isparam('maxiter'), atest = false; end
279 if ~io(pn).plists.isparam('poletype'), atest = false; end
280 if ~io(pn).plists.isparam('minorder'), atest = false; end
281 if ~io(pn).plists.isparam('maxorder'), atest = false; end
282 if ~io(pn).plists.isparam('weights'), atest = false; end
283 if ~io(pn).plists.isparam('plot'), atest = false; end
284 if ~io(pn).plists.isparam('disp'), atest = false; end
285 if ~io(pn).plists.isparam('msevartol'), atest = false; end
286 if ~io(pn).plists.isparam('fittol'), atest = false; end
287 if ~io(pn).plists.isparam('kdes'), atest = false; end
288 if ~io(pn).plists.isparam('jdes'), atest = false; end
289 if ~io(pn).plists.isparam('lmin'), atest = false; end
290 if ~io(pn).plists.isparam('win'), atest = false; end
291 if ~io(pn).plists.isparam('psll'), atest = false; end
292 if ~io(pn).plists.isparam('olap'), atest = false; end
293 if ~io(pn).plists.isparam('order'), atest = false; end
294 if ~io(pn).plists.isparam('times'), atest = false; end
295 if ~io(pn).plists.isparam('split'), atest = false; end
296 if ~io(pn).plists.isparam('scale'), atest = false; end
297 if ~io(pn).plists.isparam('flim'), atest = false; end
298 if ~io(pn).plists.isparam('scaleout'), atest = false; end
299
300 % Check default value
301 if ~isequal(io(pn).plists.find('model'), 'LPSD'), atest = false; end
302 if ~isequal(io(pn).plists.find('range'), []), atest = false; end
303 if ~isequal(io(pn).plists.find('fs'), []), atest = false; end
304 if ~isequal(io(pn).plists.find('complete_hf'), 'flat'), atest = false; end
305 if ~isequal(io(pn).plists.find('maxiter'), 30), atest = false; end
306 if ~isequal(io(pn).plists.find('poletype'), 1), atest = false; end
307 if ~isequal(io(pn).plists.find('minorder'), 2), atest = false; end
308 if ~isequal(io(pn).plists.find('maxorder'), 25), atest = false; end
309 if ~isequal(io(pn).plists.find('weights'), '1/abs'), atest = false; end
310 if ~isequal(io(pn).plists.find('plot'), false), atest = false; end
311 if ~isequal(io(pn).plists.find('disp'), false), atest = false; end
312 if ~isequal(io(pn).plists.find('msevartol'), .1), atest = false; end
313 if ~isequal(io(pn).plists.find('fittol'), .01), atest = false; end
314 if ~isequal(io(pn).plists.find('kdes'), 100), atest = false; end
315 if ~isequal(io(pn).plists.find('jdes'), 1000), atest = false; end
316 if ~isequal(io(pn).plists.find('lmin'), 0), atest = false; end
317 if ~strcmpi(io(pn).plists.find('win'), defaultWinType), atest = false; end
318 if ~isequal(io(pn).plists.find('psll'), 200), atest = false; end
319 if ~isequal(io(pn).plists.find('olap'), -1), atest = false; end
320 if ~isequal(io(pn).plists.find('order'), 0), atest = false; end
321 if ~isEmptyDouble(io(pn).plists.find('times')), atest = false; end
322 if ~isEmptyDouble(io(pn).plists.find('split')), atest = false; end
323 if ~isequal(io(pn).plists.find('scale'), 'PSD'), atest = false; end
324 if ~isequal(io(pn).plists.find('flim'), [1e-3 30e-3]), atest = false; end
325 if ~isequal(io(pn).plists.find('scaleout'), false), atest = false; end
326
327 % Check options
328 if ~isequal(io(pn).plists.getOptionsForParam('model'), {'LPSD'}), atest = false; end
329 if ~isequal(io(pn).plists.getOptionsForParam('range'), {[]}), atest = false; end
330 if ~isequal(io(pn).plists.getOptionsForParam('fs'), {[]}), atest = false; end
331 if ~isequal(io(pn).plists.getOptionsForParam('complete_hf'), {'flat', 'lowpass'}), atest = false; end
332 if ~isequal(io(pn).plists.getOptionsForParam('maxiter'), {30}), atest = false; end
333 if ~isequal(io(pn).plists.getOptionsForParam('poletype'), {1 2 3}), atest = false; end
334 if ~isequal(io(pn).plists.getOptionsForParam('minorder'), {2}), atest = false; end
335 if ~isequal(io(pn).plists.getOptionsForParam('maxorder'), {25}), atest = false; end
336 if ~isequal(io(pn).plists.getOptionsForParam('weights'), {'equal', '1/abs', '1/abs^2'}), atest = false; end
337 if ~isequal(io(pn).plists.getOptionsForParam('plot'), {false, true}), atest = false; end
338 if ~isequal(io(pn).plists.getOptionsForParam('disp'), {false, true}), atest = false; end
339 if ~isequal(io(pn).plists.getOptionsForParam('msevartol'), {.1}), atest = false; end
340 if ~isequal(io(pn).plists.getOptionsForParam('fittol'), {.01}), atest = false; end
341 if ~isequal(io(pn).plists.getOptionsForParam('kdes'), {100}), atest = false; end
342 if ~isequal(io(pn).plists.getOptionsForParam('jdes'), {1000}), atest = false; end
343 if ~isequal(io(pn).plists.getOptionsForParam('lmin'), {0}), atest = false; end
344 if ~isequal(io(pn).plists.getOptionsForParam('win'), specwin.getTypes), atest = false; end
345 if ~isequal(io(pn).plists.getOptionsForParam('psll'), {200}), atest = false; end
346 if ~isequal(io(pn).plists.getOptionsForParam('olap'), {-1}), atest = false; end
347 if ~isequal(io(pn).plists.getOptionsForParam('order'), {-1 0 1 2 3 4 5 6 7 8 9}), atest = false; end
348 if ~isequal(io(pn).plists.getOptionsForParam('times'), {[]}), atest = false; end
349 if ~isequal(io(pn).plists.getOptionsForParam('split'), {[]}), atest = false; end
350 if ~isequal(io(pn).plists.getOptionsForParam('scale'), {'PSD', 'ASD', 'PS', 'AS'}), atest = false; end
351 if ~isequal(io(pn).plists.getOptionsForParam('flim'), {[1e-3 30e-3]}), atest = false; end
352 if ~isequal(io(pn).plists.getOptionsForParam('scaleout'), {false, true}), atest = false; end
353
354 end
355 % </AlgoCode>
356 else
357 atest = false;
358 end
359
360 % Return a result structure
361 result = utp_prepare_result(atest, stest, dbstack, mfilename);
362 end % END UTP_01
363
364 %% UTP_02
365
366 % <TestDescription>
367 %
368 % Tests that the whiten1D method works with a vector of AOs as input.
369 %
370 % </TestDescription>
371 function result = utp_02
372
373 % <SyntaxDescription>
374 %
375 % Test that the whiten1D method works for a vector of AOs as input.
376 %
377 % </SyntaxDescription>
378
379 try
380 % <SyntaxCode>
381 u = get_random_unit();
382 atvec.setYunits(u);
383 out = whiten1D(atvec);
384 % </SyntaxCode>
385 stest = true;
386 catch err
387 disp(err.message)
388 stest = false;
389 end
390
391 % <AlgoDescription>
392 %
393 % 1) Check that the number of elements in 'out' is the same as in 'atvec'
394 % 2) Check that each output AO contains the correct data.
395 % 3) Check that each output AO contains empty yunits
396 %
397 % </AlgoDescription>
398
399 atest = true;
400 if stest
401 % <AlgoCode>
402 % Check we have the correct number of outputs
403 if ~isequal(size(out), size(atvec)), atest = false; end
404 % Check each output against the absolute value of the input
405 for kk=1:numel(out)
406 % Check the whiten ao(tsdata) objects
407 if isa(out(kk).data, 'tsdata')
408 used_filt = out(kk).procinfo.find('Filter');
409 obj = atvec(kk).filter(used_filt);
410 if ~eq(out(kk), obj, ple3), atest = false; end
411 if ~eq(out(kk).yunits, unit('')), atest = false; end
412 else
413 % Check the other objects (they must be the same)
414 if ~eq(out(kk), atvec(kk), ple1), atest = false; end
415 end
416 end
417 % </AlgoCode>
418 else
419 atest = false;
420 end
421
422 % Return a result structure
423 result = utp_prepare_result(atest, stest, dbstack, mfilename);
424 end % END UTP_02
425
426 %% UTP_03
427
428 % <TestDescription>
429 %
430 % Tests that the whiten1D method works with a matrix of AOs as input.
431 %
432 % </TestDescription>
433 function result = utp_03
434
435 % <SyntaxDescription>
436 %
437 % Test that the whiten1D method works for a matrix of AOs as input.
438 %
439 % </SyntaxDescription>
440
441 try
442 % <SyntaxCode>
443 u = get_random_unit();
444 atmat.setYunits(u);
445 out = whiten1D(atmat);
446 % </SyntaxCode>
447 stest = true;
448 catch err
449 disp(err.message)
450 stest = false;
451 end
452
453 % <AlgoDescription>
454 %
455 % 1) Check that the number of elements in 'out' is the same as in 'atmat'
456 % 2) Check that each output AO contains the correct data.
457 % 3) Check that each output AO contains empty yunits
458 %
459 % </AlgoDescription>
460
461 atest = true;
462 if stest
463 % <AlgoCode>
464 % Check we have the correct number of outputs
465 if ~isequal(size(out), size(atmat)), atest = false; end
466 % Check each output against the absolute value of the input
467 for kk=1:numel(out)
468 % Check the whiten ao(tsdata) objects
469 if isa(out(kk).data, 'tsdata')
470 used_filt = out(kk).procinfo.find('Filter');
471 obj = atmat(kk).filter(used_filt);
472 if ~eq(out(kk), obj, ple3), atest = false; end
473 if ~eq(out(kk).yunits, unit('')), atest = false; end
474 else
475 % Check the other objects (they must be the same)
476 if ~eq(out(kk), atmat(kk), ple1), atest = false; end
477 end
478 end
479 % </AlgoCode>
480 else
481 atest = false;
482 end
483
484 % Return a result structure
485 result = utp_prepare_result(atest, stest, dbstack, mfilename);
486 end % END UTP_03
487
488 %% UTP_04
489
490 % <TestDescription>
491 %
492 % Tests that the whiten1D method works with a list of AOs as input.
493 %
494 % </TestDescription>
495 function result = utp_04
496
497 % <SyntaxDescription>
498 %
499 % Test that the whiten1D method works for a list of AOs as input.
500 %
501 % </SyntaxDescription>
502
503 try
504 % <SyntaxCode>
505 at1.setYunits(get_random_unit());
506 at2.setYunits(get_random_unit());
507 at3.setYunits(get_random_unit());
508 out = whiten1D(at1,at2,at3);
509 % </SyntaxCode>
510 stest = true;
511 catch err
512 disp(err.message)
513 stest = false;
514 end
515
516 % <AlgoDescription>
517 %
518 % 1) Check that the number of elements in 'out' is the same as in
519 % input.
520 % 2) Check that each output AO contains the correct data.
521 % 3) Check that each output AO contains empty yunits
522 %
523 % </AlgoDescription>
524
525 atest = true;
526 aoin = [at1,at2,at3];
527 if stest
528 % <AlgoCode>
529 % Check we have the correct number of outputs
530 if ~isequal(size(out), size(aoin)), atest = false; end
531 % Check each output against the absolute value of the input
532 for kk=1:numel(out)
533 % Check the whiten ao(tsdata) objects
534 if isa(out(kk).data, 'tsdata')
535 used_filt = out(kk).procinfo.find('Filter');
536 obj = aoin(kk).filter(used_filt);
537 if ~eq(out(kk), obj, ple3), atest = false; end
538 if ~eq(out(kk).yunits, unit('')), atest = false; end
539 else
540 % Check the other objects (they must be the same)
541 if ~eq(out(kk), aoin(kk), ple1), atest = false; end
542 end
543 end
544 % </AlgoCode>
545 else
546 atest = false;
547 end
548
549 % Return a result structure
550 result = utp_prepare_result(atest, stest, dbstack, mfilename);
551 end % END UTP_04
552
553 %% UTP_05
554
555 % <TestDescription>
556 %
557 % Tests that the whiten1D method works with a mix of different shaped AOs as
558 % input.
559 %
560 % </TestDescription>
561 function result = utp_05
562
563 % <SyntaxDescription>
564 %
565 % Test that the whiten1D method works with an input of matrices and vectors
566 % and single AOs.
567 %
568 % </SyntaxDescription>
569
570 try
571 % <SyntaxCode>
572 out = whiten1D(at1,[at2 at3],[at4 at5; at6 at1]);
573 % </SyntaxCode>
574 stest = true;
575 catch err
576 disp(err.message)
577 stest = false;
578 end
579
580 % <AlgoDescription>
581 %
582 % 1) Check that the number of elements in 'out' is the same as in
583 % input.
584 % 2) Check that each output AO contains the correct data.
585 % 3) Check that each output AO contains empty yunits
586 %
587 % </AlgoDescription>
588
589 atest = true;
590 aoin = [at1,reshape([at2 at3],1,[]),reshape([at4 at5; at6 at1],1,[])];
591 if stest
592 % <AlgoCode>
593 % Check we have the correct number of outputs
594 if ~isequal(size(out), size(aoin)), atest = false; end
595 % Check each output against the absolute value of the input
596 for kk=1:numel(out)
597 % Check the whiten ao(tsdata) objects
598 if isa(out(kk).data, 'tsdata')
599 used_filt = out(kk).procinfo.find('Filter');
600 obj = aoin(kk).filter(used_filt);
601 if ~eq(out(kk), obj, ple3), atest = false; end
602 if ~eq(out(kk).yunits, unit('')), atest = false; end
603 else
604 % Check the other objects (they must be the same)
605 if ~eq(out(kk), aoin(kk), ple1), atest = false; end
606 end
607 end
608 % </AlgoCode>
609 else
610 atest = false;
611 end
612
613 % Return a result structure
614 result = utp_prepare_result(atest, stest, dbstack, mfilename);
615 end % END UTP_05
616
617 %% UTP_06
618
619 % <TestDescription>
620 %
621 % Tests that the whiten1D method properly applies history.
622 %
623 % </TestDescription>
624 function result = utp_06
625
626 % <SyntaxDescription>
627 %
628 % Test that the result of applying the whiten1D method can be processed back.
629 %
630 % </SyntaxDescription>
631
632 try
633 % <SyntaxCode>
634 out = whiten1D(at1);
635 mout = rebuild(out);
636 % </SyntaxCode>
637 stest = true;
638 catch err
639 disp(err.message)
640 stest = false;
641 end
642
643 % <AlgoDescription>
644 %
645 % 1) Check that the last entry in the history of 'out' corresponds to
646 % 'whiten1D'.
647 % 2) Check that the re-built object is the same object as the input.
648 %
649 % </AlgoDescription>
650
651 atest = true;
652 if stest
653 % <AlgoCode>
654 % Check the last step in the history of 'out'
655 if ~strcmp(out.hist.methodInfo.mname, 'whiten1D'), atest = false; end
656 % Check the re-built object
657 if ~eq(mout, out, ple2), atest = false; end
658 % </AlgoCode>
659 else
660 atest = false;
661 end
662
663 % Return a result structure
664 result = utp_prepare_result(atest, stest, dbstack, mfilename);
665 end % END UTP_06
666
667 %% UTP_07
668
669 % <TestDescription>
670 %
671 % Tests that the whiten1D method can modify the input AO.
672 %
673 % </TestDescription>
674 function result = utp_07
675
676 % <SyntaxDescription>
677 %
678 % Test that the whiten1D method can modify the input AO by calling with no
679 % output and that the method doesn't change the input of the function
680 % notation (with a equal sign).
681 %
682 % </SyntaxDescription>
683
684 try
685 % <SyntaxCode>
686 % copy at1 to work with
687 ain = ao(at1);
688 % modify ain
689 aout = ain.whiten1D();
690
691 % It is necessary that ain uses the same random state
692 ain.whiten1D(plist('rand_stream', aout.hist.plistUsed.find('rand_stream')));
693 % </SyntaxCode>
694 stest = true;
695 catch err
696 disp(err.message)
697 stest = false;
698 end
699
700 % <AlgoDescription>
701 %
702 % 1) Check that 'at1' and 'ain' are now different.
703 % 2) Check that 'ain' is whiten1D(at1).
704 %
705 % </AlgoDescription>
706
707 atest = true;
708 if stest
709 % <AlgoCode>
710 % Check that whiten1D modified the input by comparing to the copy
711 if eq(ao(at1), ain, ple1), atest = false; end
712 % Check that whiten1D doesn't modified the input for the function
713 % notation
714 if ~eq(aout, ain, ple3), atest = false; end
715 % </AlgoCode>
716 else
717 atest = false;
718 end
719
720 % Return a result structure
721 result = utp_prepare_result(atest, stest, dbstack, mfilename);
722 end % END UTP_07
723
724 %% UTP_08
725
726 % <TestDescription>
727 %
728 % Test the shape of the output.
729 %
730 % </TestDescription>
731 function result = utp_08
732
733 % <SyntaxDescription>
734 %
735 % Test that the whiten1D method keeps the data shape of the input object. The
736 % input AO must be an AO with row data and an AO with column data.
737 %
738 % </SyntaxDescription>
739
740 try
741 % <SyntaxCode>
742 at5.setYunits(get_random_unit());
743 at6.setYunits(get_random_unit());
744 out1 = whiten1D(at5);
745 out2 = whiten1D(at6);
746 % </SyntaxCode>
747 stest = true;
748 catch err
749 disp(err.message)
750 stest = false;
751 end
752
753 % <AlgoDescription>
754 %
755 % 1) Check that the shape of the data doesn't change.
756 % 2) Check that the output AOs have empty yunits
757 %
758 % </AlgoDescription>
759
760 atest = true;
761 if stest
762 % <AlgoCode>
763 % Check the shape of the output data
764 if size(out1.data.x) ~= size(at5.data.x), atest = false; end
765 if size(out1.data.y) ~= size(at5.data.y), atest = false; end
766 if size(out2.data.x) ~= size(at6.data.x), atest = false; end
767 if size(out2.data.y) ~= size(at6.data.y), atest = false; end
768 if ~eq(out1.yunits, unit('')), atest = false; end
769 if ~eq(out2.yunits, unit('')), atest = false; end
770 % </AlgoCode>
771 else
772 atest = false;
773 end
774
775 % Return a result structure
776 result = utp_prepare_result(atest, stest, dbstack, mfilename);
777 end % END UTP_08
778
779 %% UTP_09
780
781 % <TestDescription>
782 %
783 % Check that the whiten1D method pass back the output objects to a list of
784 % output variables or to a single variable.
785 %
786 % </TestDescription>
787 function result = utp_09
788
789 % <SyntaxDescription>
790 %
791 % Call the method with a list of output variables and with a single output
792 % variable. Additionaly check that the rebuild method works on the output.
793 %
794 % </SyntaxDescription>
795
796 try
797 % <SyntaxCode>
798 [o1, o2] = whiten1D(at5, at6);
799 o3 = whiten1D(at5, at6);
800 mout1 = rebuild(o1);
801 mout2 = rebuild(o2);
802 mout3 = rebuild(o3);
803 % </SyntaxCode>
804 stest = true;
805 catch err
806 disp(err.message)
807 stest = false;
808 end
809
810 % <AlgoDescription>
811 %
812 % 1) Check that the output contains the right number of objects
813 % 2) Check that the 'rebuild' method produces the same object as 'out'.
814 %
815 % </AlgoDescription>
816
817 atest = true;
818 if stest
819 % <AlgoCode>
820 % Check the number of outputs
821 if numel(o1) ~=1, atest = false; end
822 if numel(o2) ~=1, atest = false; end
823 if numel(o3) ~=2, atest = false; end
824 % Check the rebuilding of the object
825 if ~eq(o1, mout1, ple2), atest = false; end
826 if ~eq(o2, mout2, ple2), atest = false; end
827 if ~eq(o3, mout3, ple2), atest = false; end
828 % </AlgoCode>
829 else
830 atest = false;
831 end
832
833 % Return a result structure
834 result = utp_prepare_result(atest, stest, dbstack, mfilename);
835 end % END UTP_09
836
837 %% UTP_10
838
839 % <TestDescription>
840 %
841 % Check that the whiten1D method is capable to increase spectral flatness
842 % in case of no model input
843 %
844 % </TestDescription>
845 function result = utp_10
846
847 % <SyntaxDescription>
848 %
849 % Generate a fixed series of noise data, apply a filter to colour data
850 % and run the method with a certain number of parameters.
851 %
852 % </SyntaxDescription>
853
854 try
855 % <SyntaxCode>
856 % Making test data
857
858 a = ao(plist('tsfcn', 'randn(size(t))', 'fs', 10, 'nsecs', 10000, ...
859 'yunits', get_random_unit())); % random noise
860 pzm10 = pzmodel(1, {0.01}, {0.1});
861 ft = miir(pzm10);
862 af = filter(a, ft); % Colored noise
863
864 % Running whiten1D with no model input
865 pl10 = plist(...
866 'model', [], ...
867 'MaxIter', 30, ...
868 'PoleType', 1, ...
869 'MinOrder', 2, ...
870 'MaxOrder', 9, ...
871 'Weights', 2, ...
872 'Plot', false,...
873 'Disp', false,...
874 'RMSEVar', 3,...
875 'FitTolerance', 0.6); % tolerance on fit residuals spectral flatness
876
877 aw = whiten1D(af,pl10);
878 % </SyntaxCode>
879 stest = true;
880 catch err
881 disp(err.message)
882 stest = false;
883 end
884
885 % <AlgoDescription>
886 %
887 % 1) Check that the output spectrum is flatter than input colored
888 % spectrum
889 % 2) Check that the output AOs have empty yunits
890 %
891 % </AlgoDescription>
892
893 atest = true;
894 if stest
895 % <AlgoCode>
896 % Make spectra
897 afxx = af.psd;
898 awxx = aw.psd;
899
900 % Claculating flatness
901 sf = utils.math.spflat([afxx.data.y awxx.data.y]);
902
903 % Checking flatness
904 if sf(1)>sf(2), atest = false; end
905 if ~eq(aw.yunits, unit('')), atest = false; end
906 % </AlgoCode>
907 else
908 atest = false;
909 end
910
911 % Return a result structure
912 result = utp_prepare_result(atest, stest, dbstack, mfilename);
913 end % END UTP_10
914
915 %% UTP_11
916
917 % <TestDescription>
918 %
919 % Check that the whiten1D method is capable to increase spectral flatness
920 % when a model is input
921 %
922 % </TestDescription>
923 function result = utp_11
924
925 % <SyntaxDescription>
926 %
927 % Generate a fixed series of noise data, apply a filter to colour data
928 % and run the method with a certain number of parameters.
929 %
930 % </SyntaxDescription>
931
932 try
933 % <SyntaxCode>
934 % Making test data
935 a = ao(plist('tsfcn', 'randn(size(t))', 'fs', 10, 'nsecs', 10000, ...
936 'yunits', get_random_unit())); % random noise
937 pzm11 = pzmodel(1, {0.01}, {0.1});
938 ft = miir(pzm11);
939 af = filter(a, ft); % Colored noise
940
941 % Running whiten1D with model input
942 pl11 = plist(...
943 'model', abs(pzm11.resp).^2, ...
944 'fs', 10, ...
945 'MaxIter', 30, ...
946 'PoleType', 1, ...
947 'MinOrder', 2, ...
948 'MaxOrder', 9, ...
949 'Weights', 2, ...
950 'Plot', false,...
951 'Disp', false,...
952 'RMSEVar', 8,...
953 'FitTolerance', 2); % tolerance on fit residuals log difference with model data
954
955 aw = whiten1D(af,pl11);
956 % </SyntaxCode>
957 stest = true;
958 catch err
959 disp(err.message)
960 stest = false;
961 end
962
963 % <AlgoDescription>
964 %
965 % 1) Check that the output spectrum is flatter than input colored
966 % spectrum
967 %
968 % </AlgoDescription>
969
970 atest = true;
971 if stest
972 % <AlgoCode>
973 % Make spectra
974 afxx = af.psd;
975 awxx = aw.psd;
976
977 % Claculating flatness
978 sf = utils.math.spflat([afxx.data.y awxx.data.y]);
979
980 % Checking flatness
981 if sf(1)>sf(2), atest = false; end
982 if ~eq(aw.yunits, unit('')), atest = false; end
983 % </AlgoCode>
984 else
985 atest = false;
986 end
987
988 % Return a result structure
989 result = utp_prepare_result(atest, stest, dbstack, mfilename);
990 end % END UTP_11
991
992 end