0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % function show_gap_problem
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 close all
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 mc
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 %% common params
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 ns = 1e4;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 fs = 100;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 ts = 1/fs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 tf = ns-ts;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 Ns = ns*fs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 nfft = Ns;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 %% no gaps
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % p1 = pzmodel(1e-8,[pz(1e-5) pz(1e-5) pz(1e-5) pz(2e-5) pz(2e-5) pz(1) pz(1) pz(1)],...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 % [ pz(2e-4) pz(2e-4) pz(1e-4) pz(1e-4) pz(1e-4) pz(1e-3) pz(1e-2)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 % p1 = pzmodel(1e-8,[pz(1e-5) pz(2e-5) pz(3e-5) pz(4e-5) pz(5e-5) pz(0.9) pz(1) pz(1.1) pz(1.2) pz(1.3)],...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 % [ pz(2e-4) pz(3e-4) pz(4e-4) pz(5e-4) pz(1e-4) pz(1e-3) pz(1e-2)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 p1 = pzmodel(0.1,[pz(1e-5) pz(1e-5) pz(1e-5) pz(2e-5) pz(3e-5) pz(4e-5) pz(5e-5) pz(0.9) pz(1) pz(1.1) pz(1.2) pz(1.3)],...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 [ pz(2e-4) pz(3e-4) pz(4e-4) pz(5e-4) pz(1e-4) pz(1e-3) pz(1e-2)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 % iplot(resp(p1))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 p2 = pzmodel(1e-9,[ pz(1e-5) pz(2e-5) pz(3e-5) pz(4e-5) pz(5e-5) pz(0.9) pz(1) pz(1.1) pz(1.2) pz(1.3)],...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 [ pz(2e-4) pz(3e-4) pz(4e-4) pz(5e-4) pz(1e-4) pz(1e-3) pz(1e-2)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 %% data generation
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 s1 = ssm(p1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 s1.modiftimestep(ts);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 s1.isstable
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 a00hf = s1.simulate(plist('Nsamples', Ns,'noise variable names',{'U>1 '} ,'covariance' , 1, 'return outputs', {'Y>1 '} ));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 a02hf = ao(p1,ns,fs );
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 %% plotting data generation results
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 p_hf = plist('Scale', 'ASD', 'Order',1,'Nfft', nfft);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 ps_hf = plist('Scale', 'ASD', 'Order',1,'Nfft', floor(nfft/3));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 % iplot([psd(a00hf,p_hf) resp(p1) psd(a02hf, p_hf)])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 %% downsampling
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 dns = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 k = 500;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 if dns
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 opt = plist('fsout', fs/k);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 a00 = a00hf.dsmean(opt);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 a02 = a02hf.dsmean(opt);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 ns = k*floor(ns/k);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 fs = fs/k;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 ts = ts*k;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 tf = ns-ts;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 Ns = floor(Ns/k);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 nfft = Ns;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 %% acceleration and spectrum
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 a00hf = a00hf.diff;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 a00hf = a00hf.diff;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 a02hf = a02hf.diff;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 a02hf = a02hf.diff;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 a00 = a00.diff;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 a00 = a00.diff;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 a02 = a02.diff;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 a02 = a02.diff;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 p = plist('Scale', 'ASD', 'Order',1,'Nfft', nfft);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 ps = plist('Scale', 'ASD', 'Order',1,'Nfft', floor(nfft/3));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 iplot([resp(p2) psd(a00hf,ps_hf) psd(a02hf, ps_hf) psd(a00,ps) psd(a02, ps)])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 %% baseline : periodic gaps 1s / 249s / 400 cycles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 kick1 = double(~(mod(0:ts:tf, 250)>min(245,250-ts-1) )).';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 a1k = ao(tsdata(kick1,fs ));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 a10 = a00.*a1k;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 %% pb2 : not so periodic gaps : <dn> = 5s, <Tauk+ taud> = 1/500*sqrt(10/fs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 time2 = cumsum(ts*ones(1,Ns) + ts*0.1*randn(1,Ns));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 kick2 = double(~(mod(time2, 250)>min(245,250-ts-1) )).';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 a2k = ao(tsdata(kick2,fs ));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 a20 = a00.*a2k;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 %% pb3 : time series too short : 100 cycles
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 a30 = ao(tsdata(a10.data.y(1:floor(Ns/4)), fs));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 p3 = plist('Scale', 'ASD', 'Order',1,'Nfft', floor(nfft/4));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 ps3 = plist('Scale', 'ASD', 'Order',1,'Nfft', floor(nfft/20));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 %% pb4 : longer gaps : 10s / 230s
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 kick1 = double(~(mod(0:ts:tf, 250)> min(200,250-ts-1) )).';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 a4k = ao(tsdata(kick1,fs ));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 a40 = a00.*a4k;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 % iplot([psd(a00,p) psd(a10,p) psd(a20,p) psd(a30,p3) psd(a40,p)])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 iplot([psd(a00,ps) psd(a10,ps) psd(a20,ps) psd(a30,ps3) psd(a40,ps)])
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 %% gap-fill all 4 examples
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 tic
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 a10g = a10.gapfillingoptim(p2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 t(1)=toc;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 tic
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 a20g = a20.gapfillingoptim(p2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 t(2)=toc;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 tic
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 a30g = a30.gapfillingoptim(p2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 t(3)=toc;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 tic
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 a40g = a40.gapfillingoptim(p2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 t(4)=toc;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 a40gworked = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 catch
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 a40gworked = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 %% plotting again
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 display('time')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 display(t)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 if a40gworked
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 pplot1= plist('LineColors',{'r' 'r' 'r' 'b' 'k' 'g ' 'r' 'b' 'k' 'g' } ,'LineStyles', {'-' '-' '-' '-' '-' '-' ':' ':' ':' ':'},'LineWidths', {2 2 1 1 1 1 1 1 1 1});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 iplot([abs(resp(p2)) psd(a00,ps) psd(a10,ps) psd(a20,ps) psd(a30,ps3) psd(a40,ps) psd(a10g,ps) psd(a20g,ps) psd(a30g,ps3) psd(a40g,ps)], pplot1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 pplot1= plist('LineColors',{'r' 'r' 'r' 'b' 'k' 'g' 'r' 'b' 'k' } ,'LineStyles', {'-' '-' '-' '-' '-' '-' ':' ':' ':'},'LineWidths', {2 2 1 1 1 1 1 1 1});
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 iplot([abs(resp(p2)) psd(a00,ps) psd(a10,ps) psd(a20,ps) psd(a30,ps3) psd(a40,ps) psd(a10g,ps) psd(a20g,ps) psd(a30g,ps3) ], pplot1)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118
|