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