Mercurial > hg > ltpda
comparison m-toolbox/test/test_ao_timeaverage.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 function test_timeaverage() | |
2 | |
3 % create a tsdata ao | |
4 a = ao(plist('waveform', 'noise', 'fs', 10, 'nsecs', 1000)); | |
5 | |
6 % times vector | |
7 times = [ 0 100 200 300 400 500 ]; | |
8 | |
9 % average | |
10 b1 = timeaverage(a, plist('times', times)); | |
11 | |
12 % this should have produced a time series with 3 points | |
13 assert(len(b1) == 3); | |
14 % check expected X values | |
15 assert(almostEqual(b1.x, [50 250 450], 0.055)); | |
16 % check expected Y values | |
17 assert(almostEqual(b1.y, [0; 0; 0], 0.1)); | |
18 | |
19 % average | |
20 b2 = timeaverage(a, plist('start', 0, 'duration', 100, 'decay', 100, 'repetitions', 3)); | |
21 | |
22 % this should have produced the same values | |
23 assert(len(b2) == 3); | |
24 assert(almostEqual(b2.x, b1.x)); | |
25 assert(almostEqual(b2.y, b1.y)); | |
26 | |
27 % average | |
28 b3 = timeaverage(a, plist('times', times, 'function', @mean)); | |
29 | |
30 % this should have produced the same values | |
31 assert(len(b3) == 3); | |
32 assert(almostEqual(b3.x, b1.x)); | |
33 assert(almostEqual(b3.y, b1.y)); | |
34 | |
35 % average | |
36 b4 = timeaverage(a, plist('times', times, 'xfunction', @min, 'yfunction', @mean)); | |
37 | |
38 % this should have produced the same values | |
39 assert(len(b4) == 3); | |
40 assert(almostEqual(b4.x, [0 200 400])); | |
41 assert(almostEqual(b4.y, b1.y)); | |
42 | |
43 % average | |
44 b5 = timeaverage(a, plist('times', times, 'function', 'center')); | |
45 | |
46 % this should have produced similar values | |
47 assert(len(b5) == 3); | |
48 % check expected X values | |
49 assert(almostEqual(b1.x, [50 250 450], 0.055)); | |
50 % check expected Y values | |
51 assert(almostEqual(b1.y, [0; 0; 0], 0.1)); | |
52 | |
53 end | |
54 | |
55 function rv = almostEqual(x, y, delta) | |
56 % fix dimensions | |
57 x = x(:); | |
58 y = y(:); | |
59 | |
60 % default tollerance | |
61 if nargin < 3 | |
62 delta = 2*eps(x); | |
63 end | |
64 | |
65 rv = all(abs(x - y) < delta); | |
66 end |