comparison m-toolbox/test/test_iplot.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % TEST_IPLOT test some aspects of iplot.
2 %
3 % M Hewitson
4 %
5 % $Id: test_iplot.m,v 1.11 2009/08/02 10:42:50 hewitson Exp $
6 %
7 function test_iplot
8
9 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
10 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
11 % TSDATA OBJECTS
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
14 %% Make test AOS
15
16 p = plist('waveform', 'noise', 'fs', 10, 'nsecs', 10);
17 tsao1 = ao(p);
18 p = plist('waveform', 'sine wave', 'fs', 10, 'nsecs', 10, 'f', 1, 'phi', 0);
19 tsao2 = ao(p);
20
21 tsvec = [tsao1 tsao2];
22 tsmat = [tsao1 tsao2; tsao1 tsao2];
23
24 %% Default plot
25 iplot(tsao1, tsao2)
26 iplot(tsvec)
27 iplot(tsmat)
28
29 %% Change X units
30
31 p = plist('waveform', 'noise', 'fs', 1, 'nsecs', 100000);
32 a1 = ao(p);
33
34 pl = plist('Xunits', 'h');
35 iplot(a1, pl)
36
37 pl = plist('Xunits', 'D');
38 iplot(a1, pl)
39
40 %% Try with datetick
41
42 p = plist('waveform', 'noise', 'fs', 0.01, 'nsecs', 6*3600);
43 a1 = ao(p);
44 a1.data.setT0('1980-01-01 12:00:00')
45
46 pl = plist('Xunits', 'dd HH:MM:SS');
47 iplot(a1, pl)
48
49
50 %% Change colors and line styles
51
52 pl = plist('Linecolors', {'g', 'k'}, 'LineStyles', {'', '--'}, 'LineWidths', {1, 4});
53 iplot(tsao1, tsao2, pl);
54
55 %% Change arrangement to single plots
56
57 pl = plist('Arrangement', 'single');
58 iplot(tsao1, tsao2, pl);
59
60 %% Change arrangement to subplots
61
62 % Also override the second legend text and the first line style
63 pl = plist('Arrangement', 'subplots', 'LineStyles', {'--'}, 'Legends', {'', 'My Sine Wave'});
64 iplot(tsao1, tsao2, pl);
65
66 %% Changel ylabel
67
68 % Overide the Y-labels
69 pl = plist('Arrangement', 'subplots', 'YLabels', {'signal 1', 'signal 2'}, 'Legends', {'', 'My Sine Wave'});
70 iplot(tsao1, tsao2, pl);
71
72 %% Changel xlabel
73
74 % Overide the X-labels
75 pl = plist('Arrangement', 'subplots', 'XLabels', {'', 'Time-stamps'}, 'Legends', {'', 'My Sine Wave'});
76 iplot(tsao1, tsao2, pl);
77
78 %% No legends
79
80 pl = plist('Arrangement', 'subplots', 'Legends', 'off');
81 iplot(tsao1, tsao2, pl);
82
83 %% Change legends
84
85 pl = plist('Arrangement', 'subplots', 'Legends', {'ts1', 'ts2'});
86 iplot(tsao1, tsao2, pl);
87
88 %% Check math functions
89
90 pl = plist('Arrangement', 'subplots', 'YMaths', 'y.^2', 'XMaths', {'', 'log(x)'});
91 iplot(tsao1, tsao2, pl);
92
93 %% Change Y limits
94 pl = plist('Arrangement', 'subplots', 'YRanges', {[-5 10], [-2 2]});
95 iplot(tsao1, tsao2, pl);
96
97 %% Change X limits
98 pl = plist('Arrangement', 'subplots', 'XRanges', {[1 3], [2 5]});
99 iplot(tsao1, tsao2, pl);
100
101 %% Change Y Scales
102 pl = plist('Arrangement', 'subplots', 'YScales', {'log', 'log'}, 'YMaths', {'all', 'abs(y)'});
103 iplot(tsao1, tsao2, pl);
104
105 %% Use markers
106
107 pl = plist('Markers', {'s', 'x'});
108 iplot(tsao1, tsao2, pl);
109
110 close all
111 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
113 % FSDATA OBJECTS
114 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
116
117 %% Make test AOs
118
119 fsd1 = resp(miir(plist('type','lowpass','fs', 100)), plist('f', logspace(-4, log10(50), 1000)));
120 fsd1 = fsd1.setYunits('m V^-1');
121 fsd2 = psd(tsao1+tsao2);
122 fsd3 = fsd2*10;
123 fsd4 = resp(miir(plist('type', 'highpass')));
124 fsd4 = fsd4.setYunits('m V^-1');
125
126 %% Default plot
127
128 iplot(fsd1, fsd2, fsd3, fsd4)
129
130 %% Subplots
131
132 pl = plist('Arrangement', 'subplots');
133 iplot(fsd1, fsd2, fsd3, fsd4, pl)
134
135 %% Single plots
136
137 pl = plist('Arrangement', 'single');
138 iplot(fsd1, fsd2, fsd3, fsd4, pl)
139
140 %% Use math function on y-data
141
142 pl = plist('Ymaths', {'abs(y)'});
143 iplot(fsd1, pl);
144
145 pl = plist('Ymaths', 'abs(y)');
146 iplot(fsd1, fsd2, pl);
147
148
149 %% Change colors and line styles
150
151 pl = plist('Colors', {'g', 'k', 'm'}, 'LineStyles', {'--'}, 'LineWidths', {1, 4});
152 iplot(fsd1, fsd2, pl);
153
154 %% Use markers
155 pl = plist('Colors', {'g', 'k', 'm'}, 'Markers', {'', 's'});
156 iplot(fsd1, fsd2, pl);
157
158 %% Change arrangement to subplots
159
160 % Also override the second legend text and the first line style
161 pl = plist('Arrangement', 'subplots', 'LineStyles', {'--'}, 'Legends', {'', 'My Sine Wave'});
162 iplot(fsd1, fsd2, pl);
163
164 %% Changel ylabel
165
166 % Overide the Y-labels
167 pl = plist('Arrangement', 'subplots', 'YLabels', {'signal 1 mag', '', 'signal 2'}, 'Legends', {'', 'My Sine Wave'});
168 iplot(fsd1, fsd2, pl);
169
170 %% Changel xlabel
171
172 % Overide the X-labels
173 pl = plist('Arrangement', 'subplots', 'XLabels', {'', 'Freq'}, 'Legends', {'', 'My Sine Wave'});
174 iplot(fsd1, fsd2, pl);
175
176 %% Change legends
177
178 pl = plist('Arrangement', 'subplots', 'Legends', {'fsd1', 'fsd2'});
179 iplot(fsd1, fsd2, pl);
180
181 %% No legends
182
183 pl = plist('Arrangement', 'subplots', 'Legends', 'off');
184 iplot(fsd1, fsd2, pl);
185
186 %% Set Y scales
187
188 pl = plist('Arrangement', 'subplots', 'YScales', {'', 'log', 'lin'});
189 iplot(fsd1, fsd2, pl);
190
191 %% Set X scales
192
193 pl = plist('Arrangement', 'subplots', 'XScales', {'', 'lin', 'lin'});
194 iplot(fsd1, fsd2, pl);
195
196 %% Set Y ranges
197
198 pl = plist('Arrangement', 'subplots', 'YRanges', {[0.1 10], [], [1e-3 100]});
199 iplot(fsd1, fsd2, pl);
200
201
202 %% Set X ranges
203 pl = plist('Arrangement', 'subplots', 'YRanges', [0.001, 10], 'XRanges', {[0.1 10], [0 10], [0.1 10]});
204 iplot(fsd1, fsd2, pl);
205
206
207 close all
208 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
210 % XYDATA OBJECTS
211 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
212 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
213
214 %% Make test AOs
215
216 xy1 = ao(xydata(1:100, cos([1:100]/10)));
217 xy1 = xy1.setXunits('arb');
218 xy1 = xy1.setYunits('arb');
219 xy2 = ao(xydata(1:100, sin([1:100]/3)));
220 xy2 = xy2.setXunits('arb');
221 xy2 = xy2.setYunits('arb');
222
223
224 %% Default plot
225 iplot(xy1, xy2)
226
227 %% Use Math function on y-data
228
229 pl = plist('Ymaths', {'abs(y)', 'y.^2'}, 'Xmaths', 'log(x)');
230 iplot(xy1, xy2, pl);
231
232
233 %% Change colors and line styles
234
235 pl = plist('Colors', {'g', 'k', 'm'}, 'LineStyles', {'--'}, 'LineWidths', {1, 4});
236 iplot(xy1, xy2, pl);
237
238 %% Change arrangement to single plots
239
240 pl = plist('Arrangement', 'single');
241 iplot(xy1, xy2, pl);
242
243 %% Change arrangement to subplots
244
245 % Also override the second legend text and the first line style
246 pl = plist('Arrangement', 'subplots', 'LineStyles', {'--'}, 'Legends', {'', 'My Sine Wave'});
247 iplot(xy1, xy2, pl);
248
249 %% Changel ylabel
250
251 % Overide the Y-labels
252 pl = plist('Arrangement', 'subplots', 'YLabels', {'signal 1', 'signal 2'}, 'Legends', {'', 'My Sine Wave'});
253 iplot(xy1, xy2, pl);
254
255 %% Changel xlabel
256
257 % Overide the X-labels
258 pl = plist('Arrangement', 'subplots', 'XLabels', {'', 'Time-stamps'}, 'Legends', {'', 'My Sine Wave'});
259 iplot(xy1, xy2, pl);
260
261 %% No legends
262
263 pl = plist('Arrangement', 'subplots', 'Legends', 'off');
264 iplot(xy1, xy2, pl);
265
266
267 close all
268
269 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271 % CDATA OBJECTS
272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
273 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274
275
276 %% Make test AOS
277
278 c1 = ao(randn(1,10));
279 c2 = ao(1:10);
280
281
282 %% Default plot
283 iplot(c1, c2)
284
285 %% Change colors and line styles
286
287 pl = plist('Colors', {'g', 'k', 'm'}, 'LineStyles', {'--'}, 'LineWidths', {1, 4});
288 iplot(c1, c2, pl);
289
290 %% Change arrangement to single plots
291
292 pl = plist('Arrangement', 'single');
293 iplot(c1, c2, pl);
294
295 %% Change arrangement to subplots
296
297 % Also override the second legend text and the first line style
298 pl = plist('Arrangement', 'subplots', 'LineStyles', {'--'}, 'Legends', {'', 'My Sine Wave'}, 'Markers', {'x', 's'});
299 iplot(c1, c2, pl);
300
301 %% Changel ylabel
302
303 % Overide the Y-labels
304 pl = plist('Arrangement', 'subplots', 'YLabels', {'signal 1', 'signal 2'}, 'Legends', {'', 'My Sine Wave'});
305 iplot(c1, c2, pl);
306
307 %% Changel xlabel
308
309 % Overide the X-labels
310 pl = plist('Arrangement', 'subplots', 'XLabels', {'', 'Time-stamps'}, 'Legends', {'', 'My Sine Wave'});
311 iplot(c1, c2, pl);
312
313 %% No legends
314
315 pl = plist('Arrangement', 'subplots', 'Legends', 'off');
316 iplot(c1, c2, pl);
317
318 %% Change legends
319
320 pl = plist('Arrangement', 'subplots', 'Legends', {'c1', 'c2'});
321 iplot(c1, c2, pl);
322
323 %% Y math
324
325 pl = plist('Arrangement', 'subplots', 'YMaths', {'y.^2', 'abs(y)'});
326 iplot(c1, c2, pl);
327
328 %% X math
329
330 pl = plist('Arrangement', 'subplots', 'XMaths', {'x+2', 'x/2'});
331 iplot(c1, c2, pl);
332
333 %% X Scale
334 pl = plist('Arrangement', 'subplots', 'XScales', {'log', 'log'});
335 iplot(c1, c2, pl);
336
337 %% Y Scale
338 pl = plist('Arrangement', 'subplots', 'YMaths', {'all', 'abs(y)'}, 'YScales', {'log', 'log'});
339 iplot(c1, c2, pl);
340
341 %% Y range
342 pl = plist('Arrangement', 'subplots', 'YRanges', {[-5 5], [-1 12]});
343 iplot(c1, c2, pl);
344
345 %% X range
346 pl = plist('Arrangement', 'subplots', 'XRanges', {[2 4], [1 6]});
347 iplot(c1, c2, pl);
348
349 close all
350 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
351 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
352 % XYZ DATA OBJECTS
353 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
354 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
355
356 %% Test data
357 nsecs = 100;
358 fs = 100;
359 p = plist('waveform', 'noise', 'fs', fs, 'nsecs', nsecs);
360 n = ao(p);
361 p = plist('waveform', 'chirp', 'fs', fs, 'nsecs', nsecs, 'f0', 0, 'f1', 50, 't1', nsecs);
362 s = ao(p);
363
364 a = s+n;
365
366 % Make spectrogram
367
368 sxx = spectrogram(a, plist('Nfft', 4*fs));
369 rxx = spectrogram(s, plist('Nfft', 4*fs));
370
371 %% Plot
372
373 pl = plist('Arrangement', 'subplots', 'YMaths', {'log10(y)', 'log10(y)'}, ...
374 'Zmaths', {'20*log10(z)', '20*log10(z)'}, ...
375 'Xmaths', {'log10(x)'});
376
377 iplot(sxx, rxx, pl)
378
379
380 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
381 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
382 % MIXED OBJECTS
383 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
384 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
385
386 %% XY and TSDATA
387 iplot(xy1, tsao1, xy2, tsao2, c1)
388 close all
389
390 end