comparison m-toolbox/test/test_ao_diff.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 clear all
2
3 %% Make test AO
4 fs = 10;
5 Nsecs = 10;
6 a = ao(plist('waveform', 'sine wave', 'A', 1, 'f', .3, 'phi', 0, 'fs', fs, 'nsecs', Nsecs, 'yunits', 'm'));
7 b = ao(plist('waveform', 'sine wave', 'A', 2*pi*0.3, 'f', .3, 'phi', 90, 'fs', fs, 'nsecs', Nsecs, 'yunits', 'm')); % Theoretical first derivative
8 b2 = -1*((2*pi*0.3)^2).*a; % Theoretical second derivative
9
10 %% Test first derivative
11 c = diff(a, plist('method', '2POINT'));
12 d = diff(a, plist('method', 'ORDER2'));
13 e = diff(a, plist('method', 'ORDER2SMOOTH'));
14 f = diff(a, plist('method', '3POINT'));
15 g = diff(a, plist('method', '5POINT'));
16 h = diff(a, plist('method', 'FPS', 'ORDER', 'FIRST', 'COEFF', -1/5));
17
18 pl = plist('Legends', {'Original','2POINT','ORDER2','ORDER2SMOOTH','3POINT','5POINT','FPS PAR','Theory'},...
19 'Markers', {'x', 's', '^', 'p', '+', '<', 'o',''});
20 iplot(a,c,d,e,f,g,h,b, pl)
21
22 %% Use noise and measure TFs for First Derivatives
23
24 Nsecs = 1000;
25
26 a = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', Nsecs));
27 b = diff(a, plist('method', '2POINT'));
28 c = diff(a, plist('method', 'ORDER2'));
29 d = diff(a, plist('method', 'ORDER2SMOOTH'));
30 e = diff(a, plist('method', '3POINT'));
31 f = diff(a, plist('method', '5POINT'));
32 g = diff(a, plist('method', 'FPS', 'ORDER', 'FIRST', 'COEFF', -1/5));
33 h = diff(a, plist('method', 'FPS', 'ORDER', 'FIRST', 'COEFF', 1/12));
34
35 pl = plist('Nfft', fs*100);
36 tf1 = tfe(a,b,pl);
37 tf2 = tfe(a,c,pl);
38 tf3 = tfe(a,d,pl);
39 tf4 = tfe(a,e,pl);
40 tf5 = tfe(a,f,pl);
41 tf6 = tfe(a,g,pl);
42 tf7 = tfe(a,h,pl);
43
44 freq = tf1(1,2).data.x;
45 tfthy = 2.*pi.*1i.*freq;
46 tfth = ao(fsdata(freq,tfthy));
47
48 pl = plist('Legends', {'2POINT','ORDER2','ORDER2SMOOTH','3POINT',...
49 '5POINT', 'FPS PAR', 'FPS SER','Theory',});
50 iplot(tf1(1,2), tf2(1,2), tf3(1,2), tf4(1,2), tf5(1,2), tf6(1,2), tf7(1,2), tfth, pl)
51
52 %% Make test AO for second derivative
53
54 fs = 10;
55 Nsecs = 10;
56 a = ao(plist('waveform', 'sine wave', 'A', 1, 'f', .3, 'phi', 0, 'fs', fs, 'nsecs', Nsecs, 'yunits', 'm'));
57 b = ao(plist('waveform', 'sine wave', 'A', 2*pi*0.3, 'f', .3, 'phi', 90, 'fs', fs, 'nsecs', Nsecs, 'yunits', 'm')); % Theoretical first derivative
58 b2 = -1*((2*pi*0.3)^2).*a; % Theoretical second derivative
59
60 %% Test second derivatives
61
62 c = diff(a, plist('method', 'FPS', 'ORDER', 'SECOND', 'COEFF', 2/7));
63 d = diff(a, plist('method', 'FPS', 'ORDER', 'SECOND', 'COEFF', -1/12));
64 e = diff(a, plist('method', 'FPS', 'ORDER', 'SECOND', 'COEFF', 1/4));
65
66 pl = plist('Legends', {'Original','FPS PAR','FPS SER','FPS PI','Theory'},...
67 'Markers', {'x', 'o', 's', '^', ''});
68 iplot(a,c,d,e,b2, pl)
69
70 %% Use noise and measure TFs for SECOND Derivatives
71
72 Nsecs = 1000;
73
74 a = ao(plist('tsfcn', 'randn(size(t))', 'fs', fs, 'nsecs', Nsecs));
75 c = diff(a, plist('method', 'FPS', 'ORDER', 'SECOND', 'COEFF', 2/7));
76 d = diff(a, plist('method', 'FPS', 'ORDER', 'SECOND', 'COEFF', -1/12));
77 e = diff(a, plist('method', 'FPS', 'ORDER', 'SECOND', 'COEFF', 1/4));
78
79 pl = plist('Nfft', fs*100);
80
81 tf1 = tfe(a,c,pl);
82 tf2 = tfe(a,d,pl);
83 tf3 = tfe(a,e,pl);
84
85 freq = tf1(1,2).data.x;
86 tfthy = abs((2.*pi.*1i.*freq).^2);
87 tfth = ao(fsdata(freq,tfthy));
88
89 pl = plist('Legends', {'Theory','FPS PAR', 'FPS PI', 'FPS SER',});
90 iplot(tfth, tf1(1,2), tf3(1,2), tf2(1,2), pl)