0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 function test_ltpda_arma_time()
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 % A test script for the ltpda_arma_time function
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % miquel 20-02-08
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % $Id: test_ltpda_arma_time.m,v 1.1 2008/03/04 12:55:05 miquel Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 %% Make test AOs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 fs=1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 nsecs=10000;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 pl = plist();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 pl = append(pl, param('nsecs',nsecs));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 pl = append(pl, param('fs',fs));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 pl = append(pl,param('tsfcn','(heaviside(t-1000.5)).*(1-(exp(-(t-1000.5)/300))+(exp(-(t-1000.5)/500)-1))'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19 ain = ao(pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 % Filter input time-series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 pl = append(pl, param('type', 'highpass'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 pl = append(pl, param('ripple', 5e-1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 pl = append(pl, param('order', 1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 pl = append(pl, param('gain', 1e-1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 pl = append(pl, param('fc', 1e-3));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28 f = miir(pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 [aout, fout] = filter(ain,plist(param('filter',f)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 % Add independent noise to both channels
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 pn1 = plist('waveform', 'noise','type','Uniform','fs', fs, 'nsecs', nsecs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 an1 = ao(pn1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 ain = ain + 1e-3*an1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 pn2 = plist('waveform', 'noise','type','Uniform','fs', fs, 'nsecs', nsecs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 an2 = ao(pn2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 aout = aout + 1e-3*an2;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 %% Find ARMA parameters for the transfer function
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 % Parameter list for ltpda_arma_time
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 pl = append(pl, param('MaxIter',1e3));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 pl = append(pl, param('MaxFunEvals',1e3));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 pl = append(pl, param('TolX',1e-7));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 pl = append(pl, param('TolFun',1e-7));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 pl = append(pl, param('ARMANum',2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 pl = append(pl, param('ARMADen',1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 % Use ltpda_arma_time
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 ao_arma = ltpda_arma_time(ain, aout, pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 disp(sprintf('\r! Filter parameters:\r'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 disp(sprintf('%d\t', fout.a,fout.b(2:length(fout.b))))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 disp(sprintf('\r! Estimated parameters:\r'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 disp(sprintf('%d\t',ao_arma.data.y(1:length(ao_arma.data.y)-1)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 % Compute fitted output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 p = find(pl, 'ARMANum');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 q = find(pl, 'ARMADen');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 f = miir([ao_arma.data.y(1:p)],[1 ao_arma.data.y(p+1:p+q)],find(pl,'fs'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 [afit, ffit] = filter(ain,plist(param('filter',f)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 % Plot
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 iplot(ain,aout,afit,plist('Legends', {'Input','Output','Fit'}))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 % %% Plot history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 % figure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 % plot(ao_arma.hist)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 % %% Reproduce from history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 % % Write an m-file from AO
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 % ao2m(ao_arma, 'ltpda_test.m');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 % % now run it
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 % clear all;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 % a_out = ltpda_test;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 % % iplot(a_out)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 % figure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 % plot(a_out.hist)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 %% Delete test files
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 % delete('ltpda_test.m');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92
|