44
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % UTP_AO_COHERE a set of UTPs for the ao/cohere method
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 % M Hewitson 06-08-08
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 % $Id: utp_ao_cohere.m,v 1.44 2011/07/22 12:29:58 mauro Exp $
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % <MethodDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % The cohere method of the ao class computes the coherence between two
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 % time-series AOs.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13 % </MethodDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15 function results = utp_ao_cohere(varargin)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17 % Check the inputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 if nargin == 0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 % Some keywords
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 class = 'ao';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22 mthd = 'cohere';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 results = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25 disp('******************************************************');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 disp(['**** Running UTPs for ' class '/' mthd]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 disp('******************************************************');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 % Test AOs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 [at1,at2,at3,at4,at5,at6] = eval(['get_test_objects_' class]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 % Exception list for the UTPs:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 [ple1,ple2,ple3,ple4,ple5,ple6] = get_test_ples();
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 % Get default window from the preferences
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36 prefs = getappdata(0, 'LTPDApreferences');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 defaultWinType = char(prefs.getMiscPrefs.getDefaultWindow);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39 % Run the tests
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 results = [results utp_01]; % getInfo call
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 results = [results utp_02]; % Vector input (only with two objects)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 results = [results utp_03]; % Matrix input (not possible)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 results = [results utp_04]; % List input (only with two objects)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 results = [results utp_05]; % Test with mixed input (not possible)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 results = [results utp_06]; % Test history is working
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 results = [results utp_07]; % Test the modify call works
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 results = [results utp_08]; % Test input data shape == output data shape
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 results = [results utp_09]; % Test output of the data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 results = [results utp_10]; % Test the basic usage against MATLAB mscohere
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 results = [results utp_11(mthd, [at1 at1], ple1)]; % Test plotinfo doesn't disappear
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 results = [results utp_12]; % Test basic symmetry properties of cohere (C)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 results = [results utp_13]; % Test basic symmetry properties of cohere (MS)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 results = [results utp_14]; % Test basic symmetry properties of cohere (C)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 results = [results utp_15]; % Test basic symmetry properties of cohere (MS)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 results = [results utp_16]; % Test basic relationship (MS) <-> (C)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 results = [results utp_17]; % Test units handling: complex cohere
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 results = [results utp_18]; % Test units handling: magnitude-squared cohere
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 results = [results utp_19]; % Test data lengths
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 results = [results utp_20]; % Test with single window
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 results = [results utp_21]; % Test number of averages: requested/obtained
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 results = [results utp_22]; % Test number of averages: correct number
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 results = [results utp_23]; % Test number of averages: syntax
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 results = [results utp_24]; % Test the basic usage against MATLAB mscohere
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 results = [results utp_25]; % Test Kaiser win and olap: (C)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 results = [results utp_26]; % Test Kaiser win and olap: (MS)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 results = [results utp_30]; % Special cases: same input
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 disp('Done.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 disp('******************************************************');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 elseif nargin == 1 % Check for UTP functions
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 if strcmp(varargin{1}, 'isutp')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 results = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 results = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 error('### Incorrect inputs')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 %% UTP_01
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 % Tests that the getInfo call works for this method.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 function result = utp_01
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95 % Test that the getInfo call works for no sets, all sets, and each set
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 % individually.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 % Call for no sets
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 io(1) = eval([class '.getInfo(''' mthd ''', ''None'')']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 % Call for all sets
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 io(2) = eval([class '.getInfo(''' mthd ''')']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 % Call for each set
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 for kk=1:numel(io(2).sets)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108 io(kk+2) = eval([class '.getInfo(''' mthd ''', ''' io(2).sets{kk} ''')']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 stest = false;
|
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 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 % 1) Check that getInfo call returned an minfo object in all cases.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 % 2) Check that all plists have the correct parameters.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 % check we have minfo objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 if isa(io, 'minfo')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 % SET 'None'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131 if ~isempty(io(1).sets), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 if ~isempty(io(1).plists), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 % Check all Sets
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134 if ~any(strcmpi(io(2).sets, 'Default')), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 if numel(io(2).plists) ~= numel(io(2).sets), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 % SET 'Default'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137 if io(3).plists.nparams ~= 9, atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 % Check key
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 if ~io(3).plists.isparam('nfft'), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140 if ~io(3).plists.isparam('win'), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 if ~io(3).plists.isparam('olap'), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 if ~io(3).plists.isparam('type'), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 if ~io(3).plists.isparam('order'), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 if ~io(3).plists.isparam('navs'), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 if ~io(3).plists.isparam('times'), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146 if ~io(3).plists.isparam('split'), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 if ~io(3).plists.isparam('psll'), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 % Check default value
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 if ~isequal(io(3).plists.find('nfft'), -1), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 if ~strcmpi(io(3).plists.find('win'), defaultWinType), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 if ~isequal(io(3).plists.find('olap'), -1), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 if ~isequal(io(3).plists.find('type'), 'C'), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 if ~isequal(io(3).plists.find('order'), 0), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 if ~isequal(io(3).plists.find('navs'), -1), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 if ~isEmptyDouble(io(3).plists.find('times')), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 if ~isEmptyDouble(io(3).plists.find('split')), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157 if ~isequal(io(3).plists.find('psll'), 200), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158 % Check options
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 if ~isequal(io(3).plists.getOptionsForParam('nfft'), {-1}), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 if ~isequal(io(3).plists.getOptionsForParam('win'), specwin.getTypes), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 if ~isequal(io(3).plists.getOptionsForParam('olap'), {-1}), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 if ~isequal(io(3).plists.getOptionsForParam('type'), {'C', 'MS'}), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 if ~isequal(io(3).plists.getOptionsForParam('order'), {-1 0 1 2 3 4 5 6 7 8 9}), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 if ~isequal(io(3).plists.getOptionsForParam('navs'), {-1}), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 if ~isequal(io(3).plists.getOptionsForParam('times'), {[]}), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 if ~isequal(io(3).plists.getOptionsForParam('split'), {[]}), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 if ~isequal(io(3).plists.getOptionsForParam('psll'), {200}), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176 end % END UTP_01
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178 %% UTP_02
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 % Tests that the cohere method works with a vector of AOs as input. (only
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 % with two objects in the vector)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 function result = utp_02
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190 % Test that the cohere method works for a vector of AOs as input.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196 avec = [at1 at5];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197 out = cohere(avec);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207 % 1) Check that the number of elements in 'out' is equal to 1.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208 % 2) Check that each output AO contains the correct data.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
214 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
215 % Check we have the correct number of outputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
216 if numel(out) ~= 1, atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
217
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
218 TOL = 1e-13;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
219
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
220 % Get shortest vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
221 lmin = min([length(at1.y), length(at5.y), length(at6.y)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
222 % Set Nfft
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
223 Nfft = lmin;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
224 % Get default window
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
225 if strcmpi(defaultWinType, 'kaiser')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
226 win = specwin(defaultWinType, Nfft, find(ao.getInfo('cohere').plists, 'psll'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
227 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
228 win = specwin(defaultWinType, Nfft);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
229 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
230 % Compute magnitude squared coherence estimate with MATLAB
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
231 % out: at1->at5
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
232 [cxy, f] = mscohere(at1.y(1:lmin), at5.y(1:lmin), win.win, Nfft/2, Nfft, at1.fs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
233 if any(abs(out.y-cxy > TOL)), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
234 if any(abs(out.x-f > TOL)), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
235 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
236 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
237 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
238 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
239
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
240 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
241 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
242 end % END UTP_02
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
243
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
244 %% UTP_03
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
245
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
246 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
247 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
248 % Test that the cohere method doesn't work for a matrix of AOs as input.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
249 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
250 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
251 function result = utp_03
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
252
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
253 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
254 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
255 % Test that the cohere method doesn't work for a matrix of AOs as input.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
256 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
257 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
258
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
259 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
260 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
261 amat = [at1 at2;at5 at6];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
262 out = cohere(amat);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
263 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
264 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
265 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
266 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
267 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
268
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
269 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
270 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
271 % 1) Nothing to check.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
272 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
273 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
274
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
275 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
276 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
277 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
278 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
279 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
280 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
281 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
282
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
283 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
284 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
285 end % END UTP_03
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
286
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
287 %% UTP_04
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
288
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
289 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
290 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
291 % Tests that the cohere method works with a list of AOs as input.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
292 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
293 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
294 function result = utp_04
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
295
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
296 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
297 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
298 % Test that the cohere method works for a list of AOs as input.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
299 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
300 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
301
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
302 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
303 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
304 out = cohere(at1,at5);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
305 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
306 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
307 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
308 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
309 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
310 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
311
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
312 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
313 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
314 % 1) Check that the number of elements in 'out' is equal to 1.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
315 % 2) Check that each output AO contains the correct data.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
316 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
317 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
318
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
319 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
320 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
321 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
322 % Check we have the correct number of outputs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
323 if numel(out) ~= 1, atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
324
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
325 TOL = 1e-13;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
326
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
327 % Get shortest vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
328 lmin = min([length(at1.y), length(at5.y)]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
329 % Set Nfft
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
330 Nfft = lmin;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
331 % Get default window
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
332 if strcmpi(defaultWinType, 'kaiser')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
333 win = specwin(defaultWinType, Nfft, find(ao.getInfo('cohere').plists, 'psll'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
334 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
335 win = specwin(defaultWinType, Nfft);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
336 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
337 % Compute magnitude squared coherence estimate with MATLAB
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
338 % out: at1->at5
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
339 [cxy, f] = mscohere(at1.y(1:lmin), at5.y(1:lmin), win.win, Nfft/2, Nfft, at1.fs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
340 if any(abs(out.y-cxy > TOL)), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
341 if any(abs(out.x-f > TOL)), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
342 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
343 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
344 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
345 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
346
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
347 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
348 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
349 end % END UTP_04
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
350
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
351 %% UTP_05
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
352
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
353 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
354 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
355 % Test that the cohere method doesn't work with an input of matrices
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
356 % and vectors and single AOs.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
357 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
358 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
359 function result = utp_05
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
360
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
361 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
362 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
363 % Test that the cohere method doesn't work with an input of matrices
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
364 % and vectors and single AOs.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
365 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
366 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
367
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
368 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
369 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
370 out = cohere([at5 at6], [at5 at1; at6 at1], at6);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
371 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
372 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
373 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
374 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
375 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
376
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
377 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
378 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
379 % 1) Nothing to check
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
380 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
381 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
382
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
383 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
384 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
385 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
386 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
387 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
388 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
389 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
390
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
391 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
392 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
393 end % END UTP_05
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
394
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
395 %% UTP_06
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
396
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
397 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
398 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
399 % Tests that the cohere method properly applies history.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
400 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
401 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
402 function result = utp_06
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
403
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
404 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
405 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
406 % Test that the result of applying the cohere method can be processed back
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
407 % to an m-file.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
408 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
409 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
410
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
411 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
412 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
413 out = cohere(at5,at6);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
414 mout = rebuild(out);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
415 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
416 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
417 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
418 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
419 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
420 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
421
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
422 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
423 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
424 % 1) Check that the last entry in the history of 'out' corresponds to
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
425 % 'cohere'.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
426 % 2) Check that the re-built object is the same as 'out'.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
427 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
428 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
429
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
430 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
431 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
432 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
433 % Check the last step in the history of 'out'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
434 if ~strcmp(out.hist.methodInfo.mname, 'cohere'), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
435 % Check the re-built object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
436 if ~eq(mout, out, ple2), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
437 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
438 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
439 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
440 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
441
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
442 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
443 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
444 end % END UTP_06
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
445
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
446 %% UTP_07
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
447
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
448 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
449 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
450 % Tests that the cohere method can not modify the input AO.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
451 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
452 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
453 function result = utp_07
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
454
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
455 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
456 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
457 % Test that the cohere method can not modify the input AO.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
458 % The method must throw an error for the modifier call.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
459 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
460 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
461
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
462 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
463 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
464 % copy at1 to work with
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
465 ain = ao(at1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
466 % modify ain
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
467 ain.cohere(at5);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
468 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
469 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
470 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
471 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
472 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
473
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
474 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
475 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
476 % 1) Nothing to check.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
477 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
478 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
479
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
480 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
481 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
482 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
483 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
484 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
485 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
486 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
487
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
488 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
489 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
490 end % END UTP_07
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
491
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
492 %% UTP_08
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
493
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
494 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
495 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
496 % Test the shape of the output.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
497 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
498 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
499 function result = utp_08
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
500
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
501 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
502 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
503 % Test that the cohere method keeps the data shape of the input object. The
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
504 % input AO must be an AO with row data and an AO with column data.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
505 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
506 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
507
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
508 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
509 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
510 out1 = cohere(at5, at6);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
511 out2 = cohere(at6, at5);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
512 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
513 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
514 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
515 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
516 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
517 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
518
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
519 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
520 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
521 % 1) Check that the shpe of the output data doesn't change.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
522 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
523 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
524
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
525 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
526 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
527 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
528 % Check the shape of the output data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
529 if size(out1.data.y, 2) ~= 1, atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
530 if size(out2.data.y, 1) ~= 1, atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
531 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
532 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
533 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
534 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
535
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
536 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
537 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
538 end % END UTP_08
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
539
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
540 %% UTP_09
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
541
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
542 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
543 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
544 % Check that the cohere method pass back the output objects to a list of
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
545 % output variables or to a single variable.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
546 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
547 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
548 function result = utp_09
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
549
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
550 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
551 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
552 % This test is not longer necessary because the cohere method pass back
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
553 % always only one object.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
554 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
555 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
556
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
557 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
558 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
559 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
560 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
561 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
562 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
563 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
564 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
565
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
566 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
567 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
568 % 1) Nothing to check.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
569 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
570 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
571
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
572 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
573 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
574 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
575 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
576 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
577 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
578 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
579
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
580 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
581 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
582 end % END UTP_09
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
583
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
584 %% UTP_10
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
585
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
586 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
587 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
588 % Tests that the cohere method agrees with MATLAB's mscohere when
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
589 % configured to use the same parameters.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
590 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
591 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
592 function result = utp_10
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
593
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
594 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
595 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
596 % Test that applying cohere works on two AOs.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
597 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
598 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
599
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
600 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
601 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
602 % Construct two test AOs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
603 nsecs = 10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
604 fs = 1000;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
605 pl = plist('nsecs', nsecs, 'fs', fs, 'tsfcn', 'randn(size(t))');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
606 a1 = ao(pl); a2 = ao(pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
607 % Filter one time-series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
608 f2 = miir(plist('type', 'bandpass', 'fs', fs, 'order', 3, 'fc', [50 250]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
609 a1f = filter(a1, plist('filter', f2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
610 % make some cross-power
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
611 a4 = a1f+a2; a4.setName;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
612 % Compute coherence
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
613 Nfft = 2*fs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
614 win = specwin('Hanning', Nfft);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
615 pl = plist('Nfft', Nfft, 'Win', win.type, 'order', -1, 'type', 'MS');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
616 out = cohere(a4,a1,pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
617 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
618 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
619 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
620 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
621 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
622 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
623
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
624 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
625 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
626 % 1) Check that output agrees with the output of MATLAB's mscohere.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
627 % 2) Check that the shape of the output data is equal to the input data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
628 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
629 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
630
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
631 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
632 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
633 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
634 % Compute coherence using MATLAB's cohere
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
635 [cxy, f] = mscohere(a4.y, a1.y, win.win, Nfft/2, Nfft, a1.fs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
636 if ne(cxy(:), out.y), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
637 if ne(f, out.x), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
638 if ne(out, out, ple2), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
639 % Check the data shape
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
640 if size(a4.y,1) == 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
641 if size(out.y,1) ~= 1, atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
642 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
643 if size(out.y,2) ~= 1, atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
644 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
645 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
646 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
647 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
648 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
649
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
650 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
651 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
652 end % END UTP_10
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
653
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
654
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
655 %% UTP_12
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
656
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
657 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
658 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
659 % Tests symmetry properties of complex-coherence:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
660 % 1) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
661 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
662 % 2) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
663 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
664 % 3) complex coherence of the white noise series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
665 % 4) compare C(x,y) with conj(C(y,x))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
666 % 5) compare C(x,x) and C(y,y) with 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
667 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
668
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
669 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
670 function result = utp_12
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
671
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
672 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
673 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
674 % 1) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
675 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
676 % 2) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
677 % 3) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
678 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
679 % 4) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
680 % 5) complex coherence of the white noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
681 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
682 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
683
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
684 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
685 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
686
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
687 % Array of parameters to pick from
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
688 fs_list = [0.1;1;10];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
689 nsecs_list = [100:100:10000]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
690 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
691 mu_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
692
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
693 % Build time-series test data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
694
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
695 % Picks the values at random from the list
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
696 fs = utils.math.randelement(fs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
697 nsecs = utils.math.randelement(nsecs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
698 sigma_distr = utils.math.randelement(sigma_distr_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
699 mu_distr = utils.math.randelement(mu_distr_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
700 f = [1:5] / 100 * fs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
701 A = sigma_distr + sigma_distr*rand(1,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
702 phi = 0 + 2*pi*rand(1,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
703
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
704 % White noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
705 type = 'Normal';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
706 a_n1 = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
707 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
708 a_n2 = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
709 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
710 a_const = ao(mu_distr);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
711 a_wave = ao(plist('waveform', 'sine-wave', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
712 'fs', fs, 'nsecs', nsecs, 'f', f, 'A', A, 'phi', phi));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
713 a_1 = a_n1 + a_const + a_wave;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
714 a_2 = a_n2 + a_wave;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
715
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
716 % Set units and prefix from those supported
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
717 unit_list = unit.supportedUnits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
718 % remove the first empty unit '' from the list, because then is it
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
719 % possible that we add a prefix to an empty unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
720 unit_list = unit_list(2:end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
721 prefix_list = unit.supportedPrefixes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
722 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
723 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
724
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
725 % Evaluate the complex coherence of the time-series data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
726 win_list = specwin.getTypes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
727 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
728 win_type = win_type{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
729 if strcmp(win_type, 'Kaiser')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
730 win = specwin(win_type, 1, find(ao.getInfo('psd').plists, 'psll'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
731 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
732 win = specwin(win_type, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
733 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
734 olap = win.rov;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
735 detrend = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
736 scale_type = 'C';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
737 n_pts = nsecs*fs/10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
738
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
739 C12 = cohere(a_1, a_2, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
740 plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
741 C21 = cohere(a_2, a_1, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
742 plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
743 C21_cc = conj(C21);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
744 C11 = cohere(a_1, a_1, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
745 plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
746 C22 = cohere(a_2, a_2, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
747 plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
748 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
749
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
750 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
751 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
752 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
753 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
754 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
755
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
756 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
757 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
758 % 1) Check that C(x,y) equals conj(C(y,x))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
759 % 2) Check that C(x,x) equals 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
760 % 2) Check that C(y,y) equals 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
761
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
762 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
763
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
764 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
765 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
766
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
767 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
768 if ~eq(C12.data, C21_cc.data, 'dy') || ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
769 ~isequal(C11.y, ones(size(C11.y))) || ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
770 ~isequal(C22.y, ones(size(C22.y)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
771 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
772 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
773 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
774 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
775 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
776 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
777
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
778 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
779 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
780 end % END UTP_12
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
781
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
782 %% UTP_13
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
783
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
784 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
785 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
786 % Tests symmetry properties of complex-coherence:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
787 % 1) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
788 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
789 % 2) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
790 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
791 % 3) magnitude-squared coherence of the white noise series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
792 % 4) compare C(x,y) with C(y,x)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
793 % 5) compare C(x,x) and C(y,y) with 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
794 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
795
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
796 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
797 function result = utp_13
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
798
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
799 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
800 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
801 % 1) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
802 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
803 % 2) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
804 % 3) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
805 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
806 % 4) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
807 % 5) magnitude-squared coherence of the white noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
808 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
809 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
810
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
811 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
812 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
813
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
814 % Array of parameters to pick from
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
815 fs_list = [0.1;1;10];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
816 nsecs_list = [100:100:10000]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
817 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
818 mu_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
819
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
820 % Build time-series test data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
821
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
822 % Picks the values at random from the list
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
823 fs = utils.math.randelement(fs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
824 nsecs = utils.math.randelement(nsecs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
825 sigma_distr = utils.math.randelement(sigma_distr_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
826 mu_distr = utils.math.randelement(mu_distr_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
827 f = [1:5] / 100 * fs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
828 A = sigma_distr + sigma_distr*rand(1,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
829 phi = 0 + 2*pi*rand(1,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
830
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
831 % White noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
832 type = 'Normal';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
833 a_n1 = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
834 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
835 a_n2 = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
836 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
837 a_const = ao(mu_distr);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
838 a_wave = ao(plist('waveform', 'sine-wave', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
839 'fs', fs, 'nsecs', nsecs, 'f', f, 'A', A, 'phi', phi));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
840 a_1 = a_n1 + a_const + a_wave;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
841 a_2 = a_n2 + a_wave;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
842
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
843 % Set units and prefix from those supported
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
844 unit_list = unit.supportedUnits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
845 % remove the first empty unit '' from the list, because then is it
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
846 % possible that we add a prefix to an empty unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
847 unit_list = unit_list(2:end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
848 prefix_list = unit.supportedPrefixes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
849 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
850 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
851
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
852 % Evaluate the magnitude-squared coherence of the time-series data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
853 win_list = specwin.getTypes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
854 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
855 win_type = win_type{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
856 if strcmp(win_type, 'Kaiser')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
857 win = specwin(win_type, 1, find(ao.getInfo('psd').plists, 'psll'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
858 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
859 win = specwin(win_type, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
860 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
861 olap = win.rov;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
862 detrend = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
863 scale_type = 'MS';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
864 n_pts = nsecs*fs/10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
865
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
866 C12 = cohere(a_1, a_2, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
867 plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
868 C21 = cohere(a_2, a_1, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
869 plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
870 C11 = cohere(a_1, a_1, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
871 plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
872 C22 = cohere(a_2, a_2, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
873 plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
874 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
875
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
876 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
877 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
878 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
879 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
880 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
881
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
882 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
883 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
884 % 1) Check that C(x,y) equals C(y,x)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
885 % 1) Check that C(x,x) equals 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
886 % 1) Check that C(y,y) equals 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
887
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
888 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
889
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
890 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
891 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
892
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
893 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
894 if ~isequal(C12.data, C21.data) || ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
895 ~isequal(C11.y, ones(size(C11.y))) ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
896 || ~isequal(C22.y, ones(size(C22.y)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
897 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
898 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
899 if atest == false
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
900 fs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
901 nsecs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
902 sigma_distr
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
903 mu_distr
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
904 f
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
905 A
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
906 phi
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
907 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
908 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
909 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
910 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
911 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
912
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
913 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
914 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
915 end % END UTP_13
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
916
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
917 %% UTP_14
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
918
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
919 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
920 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
921 % Tests symmetry properties of complex-coherence:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
922 % 1) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
923 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
924 % 2) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
925 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
926 % 3) complex coherence of the combination of white noise series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
927 % 4) compare C(x,y) with 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
928 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
929
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
930 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
931 function result = utp_14
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
932
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
933 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
934 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
935 % 1) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
936 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
937 % 2) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
938 % 3) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
939 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
940 % 4) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
941 % 5) complex coherence of the combination of noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
942 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
943 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
944
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
945 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
946 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
947
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
948 % Array of parameters to pick from
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
949 fs_list = [0.1;1;10];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
950 nsecs_list = [100:100:10000]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
951 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
952 mu_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
953
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
954 % Build time-series test data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
955
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
956 % Picks the values at random from the list
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
957 fs = utils.math.randelement(fs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
958 nsecs = utils.math.randelement(nsecs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
959 sigma_distr = utils.math.randelement(sigma_distr_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
960 mu_distr = utils.math.randelement(mu_distr_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
961 f = [1:5] / 100 * fs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
962 A = sigma_distr + sigma_distr*rand(1,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
963 phi = 0 + 2*pi*rand(1,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
964
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
965 % White noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
966 type = 'Normal';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
967 a_n = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
968 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
969 a_const = ao(mu_distr);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
970 % Sinusoidal signal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
971 a_wave = ao(plist('waveform', 'sine-wave', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
972 'fs', fs, 'nsecs', nsecs, 'f', f, 'A', A, 'phi', phi));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
973 a_1 = a_n + a_wave;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
974 % Linear combination (totally correlated time series)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
975 a_2 = a_1 + a_const;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
976
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
977 % Set units and prefix from those supported
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
978 unit_list = unit.supportedUnits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
979 % remove the first empty unit '' from the list, because then is it
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
980 % possible that we add a prefix to an empty unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
981 unit_list = unit_list(2:end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
982 prefix_list = unit.supportedPrefixes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
983 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
984 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
985
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
986 % Evaluate the complex coherence of the time-series data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
987 win_list = specwin.getTypes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
988 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
989 win_type = win_type{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
990 if strcmp(win_type, 'Kaiser')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
991 win = specwin(win_type, 1, find(ao.getInfo('psd').plists, 'psll'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
992 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
993 win = specwin(win_type, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
994 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
995 olap = win.rov;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
996 detrend = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
997 scale_type = 'C';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
998 n_pts = nsecs*fs/10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
999
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1000 C = cohere(a_1, a_2, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1001 plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1002 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1003
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1004 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1005 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1006 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1007 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1008 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1009
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1010 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1011 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1012 % 1) Check that the complex coherence equals 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1013
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1014 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1015
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1016 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1017 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1018 TOL = 1e-12;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1019
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1020 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1021 if any(abs((C.y - 1)) > TOL)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1022 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1023 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1024 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1025 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1026 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1027 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1028
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1029 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1030 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1031 end % END UTP_14
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1032
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1033 %% UTP_15
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1034
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1035 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1036 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1037 % Tests symmetry properties of complex-coherence:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1038 % 1) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1039 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1040 % 2) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1041 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1042 % 3) magnitude-squared coherence of the combination of white noise series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1043 % 4) compare C(x,y) with 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1044 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1045
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1046 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1047 function result = utp_15
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1048
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1049 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1050 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1051 % 1) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1052 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1053 % 2) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1054 % 3) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1055 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1056 % 4) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1057 % 5) magnitude-squared coherence of the combination of noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1058 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1059 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1060
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1061 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1062 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1063
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1064 % Array of parameters to pick from
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1065 fs_list = [0.1;1;10];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1066 nsecs_list = [100:100:10000]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1067 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1068 mu_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1069
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1070 % Build time-series test data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1071
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1072 % Picks the values at random from the list
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1073 fs = utils.math.randelement(fs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1074 nsecs = utils.math.randelement(nsecs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1075 sigma_distr = utils.math.randelement(sigma_distr_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1076 mu_distr = utils.math.randelement(mu_distr_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1077 f = [1:5] / 100 * fs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1078 A = sigma_distr + sigma_distr*rand(1,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1079 phi = 0 + 2*pi*rand(1,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1080
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1081 % White noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1082 type = 'Normal';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1083 a_n = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1084 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1085 a_const = ao(mu_distr);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1086 % Sinusoidal signal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1087 a_wave = ao(plist('waveform', 'sine-wave', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1088 'fs', fs, 'nsecs', nsecs, 'f', f, 'A', A, 'phi', phi));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1089 a_1 = a_n + a_wave;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1090 % Linear combination (totally correlated time series)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1091 a_2 = a_1 + a_const;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1092
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1093 % Set units and prefix from those supported
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1094 unit_list = unit.supportedUnits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1095 % remove the first empty unit '' from the list, because then is it
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1096 % possible that we add a prefix to an empty unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1097 unit_list = unit_list(2:end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1098 prefix_list = unit.supportedPrefixes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1099 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1100 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1101
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1102 % Evaluate the complex coherence of the time-series data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1103 win_list = specwin.getTypes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1104 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1105 win_type = win_type{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1106 if strcmp(win_type, 'Kaiser')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1107 win = specwin(win_type, 1, find(ao.getInfo('psd').plists, 'psll'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1108 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1109 win = specwin(win_type, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1110 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1111 olap = win.rov;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1112 detrend = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1113 scale_type = 'MS';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1114 n_pts = nsecs*fs/10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1115
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1116 C = cohere(a_1, a_2, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1117 plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1118 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1119
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1120 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1121 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1122 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1123 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1124 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1125
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1126 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1127 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1128 % 1) Check that the magnitude-squared coherence equals 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1129
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1130 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1131
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1132 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1133 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1134
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1135 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1136 if ~eq(C.y, ones(size(C.y)))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1137 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1138 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1139 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1140 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1141 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1142 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1143
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1144 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1145 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1146 end % END UTP_15
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1147
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1148 %% UTP_16
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1149
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1150 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1151 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1152 % Tests symmetry properties of complex-coherence:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1153 % 1) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1154 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1155 % 2) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1156 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1157 % 3) magnitude-squared coherence M of the combination of white noise series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1158 % 4) complex coherence C of the combination of white noise series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1159 % 5) compare abs(C)^2 with M
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1160 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1161
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1162 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1163 function result = utp_16
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1164
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1165 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1166 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1167 % 1) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1168 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1169 % 2) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1170 % 3) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1171 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1172 % 4) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1173 % 5) magnitude-squared coherence of the combination of noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1174 % 6) complex coherence of the combination of noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1175 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1176 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1177
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1178 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1179 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1180
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1181 % Array of parameters to pick from
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1182 fs_list = [0.1;1;10];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1183 nsecs_list = [100:100:10000]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1184 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1185 mu_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1186
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1187 % Build time-series test data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1188
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1189 % Picks the values at random from the list
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1190 fs = utils.math.randelement(fs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1191 nsecs = utils.math.randelement(nsecs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1192 sigma_distr = utils.math.randelement(sigma_distr_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1193 mu_distr = utils.math.randelement(mu_distr_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1194 f = [1:5] / 100 * fs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1195 A = sigma_distr + sigma_distr*rand(1,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1196 phi = 0 + 2*pi*rand(1,1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1197
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1198 % White noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1199 type = 'Normal';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1200 a_n = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1201 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1202 a_const = ao(mu_distr);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1203 % Sinusoidal signal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1204 a_wave = ao(plist('waveform', 'sine-wave', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1205 'fs', fs, 'nsecs', nsecs, 'f', f, 'A', A, 'phi', phi));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1206 a_1 = a_n + a_wave;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1207 % Linear combination (totally correlated time series)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1208 a_2 = a_1 + a_const;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1209
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1210 % Set units and prefix from those supported
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1211 unit_list = unit.supportedUnits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1212 % remove the first empty unit '' from the list, because then is it
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1213 % possible that we add a prefix to an empty unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1214 unit_list = unit_list(2:end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1215 prefix_list = unit.supportedPrefixes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1216 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1217 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1218
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1219 % Evaluate the complex coherence of the time-series data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1220 win_list = specwin.getTypes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1221 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1222 win_type = win_type{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1223 if strcmp(win_type, 'Kaiser')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1224 win = specwin(win_type, 1, find(ao.getInfo('psd').plists, 'psll'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1225 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1226 win = specwin(win_type, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1227 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1228 olap = win.rov;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1229 detrend = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1230 n_pts = nsecs*fs/10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1231
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1232 M = cohere(a_1, a_2, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1233 plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend, 'type', 'MS'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1234 C = cohere(a_1, a_2, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1235 plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend, 'type', 'C'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1236 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1237
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1238 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1239 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1240 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1241 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1242 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1243
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1244 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1245 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1246 % 1) Check that the magnitude-squared coherence equals the square
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1247 % modulus of the complex coherence
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1248
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1249 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1250
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1251 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1252 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1253 TOL = 1e-15;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1254
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1255 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1256 if any(abs(M.y - abs(C.y).^2) > TOL)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1257 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1258 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1259 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1260 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1261 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1262 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1263
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1264 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1265 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1266 end % END UTP_16
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1267
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1268 %% UTP_17
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1269
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1270 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1271 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1272 % Tests handling of units:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1273 % 1) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1274 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1275 % 2) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1276 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1277 % 3) complex coherence of the white noise series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1278 % 4) compares the units of the input and output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1279 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1280
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1281 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1282 function result = utp_17
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1283
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1284 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1285 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1286 % 1) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1287 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1288 % 2) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1289 % 3) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1290 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1291 % 4) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1292 % 5) complex cohere of the white noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1293 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1294 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1295
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1296 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1297 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1298
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1299 % Build time-series test data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1300 fs = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1301 nsecs = 86400;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1302 sigma_distr_1 = 4.69e-12;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1303 mu_distr_1 = -5.11e-14;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1304 sigma_distr_2 = 6.04e-9;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1305 mu_distr_2 = 1.5e-10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1306
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1307 % White noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1308 type = 'Normal';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1309
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1310 a_n = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1311 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1312 a_const = ao(mu_distr_1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1313 a_1 = a_n + a_const;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1314
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1315 a_n = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1316 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1317 a_const = ao(mu_distr_2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1318 a_2 = a_n + a_const;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1319
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1320 % Set units and prefix from those supported
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1321 unit_list = unit.supportedUnits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1322 % remove the first empty unit '' from the list, because then is it
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1323 % possible that we add a prefix to an empty unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1324 unit_list = unit_list(2:end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1325 prefix_list = unit.supportedPrefixes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1326 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1327 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1328
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1329 % Evaluate the coherence of the time-series data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1330 win = specwin('BH92');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1331 olap = win.rov;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1332 detrend = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1333 scale_type = 'C';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1334 n_pts = nsecs*fs/10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1335
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1336 C = cohere(a_1, a_2, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1337 plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1338
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1339 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1340
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1341 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1342 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1343 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1344 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1345 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1346
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1347 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1348 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1349 % 1) Check that (complex coherence yunits) equals [1]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1350 % 2) Check that (complex coherence xunits) equals [Hz]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1351
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1352 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1353
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1354 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1355 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1356
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1357 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1358 if ~eq(C.yunits, unit('')) || ~eq(C.xunits, unit('Hz'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1359 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1360 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1361 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1362 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1363 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1364 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1365
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1366 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1367 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1368 end % END UTP_17
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1369
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1370 %% UTP_18
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1371
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1372 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1373 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1374 % Tests handling of units:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1375 % 1) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1376 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1377 % 2) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1378 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1379 % 3) magnitude-squared coherence of the white noise series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1380 % 4) compares the units of the input and output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1381 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1382
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1383 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1384 function result = utp_18
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1385
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1386 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1387 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1388 % 1) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1389 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1390 % 2) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1391 % 3) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1392 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1393 % 4) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1394 % 5) magnitude-squared cohere of the white noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1395 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1396 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1397
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1398 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1399 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1400
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1401 % Build time-series test data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1402 fs = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1403 nsecs = 86400;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1404 sigma_distr_1 = 4.69e-12;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1405 mu_distr_1 = -5.11e-14;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1406 sigma_distr_2 = 6.04e-9;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1407 mu_distr_2 = 1.5e-10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1408
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1409 % White noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1410 type = 'Normal';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1411
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1412 a_n = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1413 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1414 a_const = ao(mu_distr_1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1415 a_1 = a_n + a_const;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1416
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1417 a_n = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1418 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1419 a_const = ao(mu_distr_2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1420 a_2 = a_n + a_const;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1421
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1422 % Set units and prefix from those supported
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1423 unit_list = unit.supportedUnits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1424 % remove the first empty unit '' from the list, because then is it
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1425 % possible that we add a prefix to an empty unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1426 unit_list = unit_list(2:end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1427 prefix_list = unit.supportedPrefixes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1428 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1429 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1430
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1431 % Evaluate the coherence of the time-series data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1432 win = specwin('BH92');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1433 olap = win.rov;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1434 detrend = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1435 scale_type = 'MS';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1436 n_pts = nsecs*fs/10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1437
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1438 C = cohere(a_1, a_2, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1439 plist('Win', win.type, 'olap', olap, 'Nfft', n_pts, 'order', detrend,'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1440
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1441 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1442
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1443 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1444 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1445 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1446 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1447 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1448
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1449 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1450 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1451 % 1) Check that (magnitude-squared coherence yunits) equals [1]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1452 % 2) Check that (magnitude-squared coherence xunits) equals [Hz]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1453
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1454 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1455
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1456 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1457 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1458
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1459 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1460 if ~eq(C.yunits, unit('')) || ~eq(C.xunits, unit('Hz'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1461 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1462 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1463 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1464 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1465 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1466 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1467
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1468 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1469 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1470 end % END UTP_18
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1471
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1472 %% UTP_19
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1473
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1474 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1475 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1476 % Tests that differently sized data sets are treated properly
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1477 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1478 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1479 function result = utp_19
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1480
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1481 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1482 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1483 % Test that applying cohere works on two AOs.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1484 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1485 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1486
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1487 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1488 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1489 % Construct two test AOs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1490 nsecs = [10000:1:20000];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1491 fs = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1492 pl = plist('fs', fs, 'tsfcn', 'randn(size(t))');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1493 a1 = ao(pl.pset('nsecs', utils.math.randelement(nsecs, 1)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1494 a2 = ao(pl.pset('nsecs', utils.math.randelement(nsecs, 1)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1495 len_1 = a1.len;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1496 len_2 = a2.len;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1497 % Filter one time-series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1498 f2 = miir(plist('type', 'bandpass', 'fs', fs, 'order', 3, 'fc', [.050 .25]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1499 a1f = filter(a1, plist('filter', f2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1500 % Compute cohere
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1501 Nfft = -1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1502 win = 'Hanning';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1503 pl = plist('Nfft', Nfft, 'Win', win, 'order', -1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1504 out = cohere(a2,a1f,pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1505 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1506 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1507 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1508 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1509 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1510 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1511
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1512 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1513 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1514 % 1) Check that cohere used the length of the shortest ao.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1515 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1516 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1517
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1518 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1519 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1520 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1521 % Compare the nfft with the length of the input data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1522
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1523 if out.x(2) ~= 1/min(len_1,len_2)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1524 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1525 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1526 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1527 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1528 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1529 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1530
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1531 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1532 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1533 end % END UTP_19
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1534
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1535 %% UTP_20
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1536
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1537 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1538 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1539 % Tests that applying a single window the coherence is 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1540 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1541 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1542 function result = utp_20
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1543
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1544 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1545 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1546 % Test that applying cohere works on two AOs.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1547 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1548 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1549
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1550 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1551 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1552 % Construct two test AOs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1553 nsecs = [10000:100:20000];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1554 fs = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1555 pl = plist('fs', fs, 'tsfcn', 'randn(size(t))');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1556 a1 = ao(pl.pset('nsecs', utils.math.randelement(nsecs, 1)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1557 a2 = ao(pl.pset('nsecs', utils.math.randelement(nsecs, 1)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1558 % Filter one time-series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1559 f2 = miir(plist('type', 'bandpass', 'fs', fs, 'order', 3, 'fc', [.050 .25]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1560 a1f = filter(a1, plist('filter', f2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1561 % Compute cohere
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1562 Nfft = -1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1563 win = 'Hanning';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1564 pl = plist('Nfft', Nfft, 'Win', win, 'order', -1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1565 out_c = cohere(a2, a1f, pl.pset('type', 'C'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1566 out_ms = cohere(a2, a1f, pl.pset('type', 'MS'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1567 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1568 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1569 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1570 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1571 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1572 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1573
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1574 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1575 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1576 % 1) Check that the calculated cohere is 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1577 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1578 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1579
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1580 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1581 TOL = 1e-12;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1582 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1583 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1584 % Compare the calculated cohere with 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1585
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1586 if any(abs(abs(out_c.y) - 1) > TOL)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1587 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1588 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1589 if any(abs(abs(out_ms.y) - 1) > TOL)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1590 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1591 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1592 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1593 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1594 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1595 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1596
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1597 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1598 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1599 end % END UTP_20
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1600
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1601 %% UTP_21
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1602
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1603 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1604 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1605 % Tests the possibility to set the number of averages rather than setting the Nfft:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1606 % 1) white noise produced from normal pdf, with:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1607 % a given mean value and sigma (distribution's 1st and 2nd order)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1608 % 2) cohere of the noise, without detrending, random window, set number of
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1609 % averages
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1610 % 3) check the effective number of averages
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1611 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1612
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1613 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1614 function result = utp_21
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1615
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1616 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1617 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1618 % 1) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1619 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1620 % 2) cohere of the noise, without detrending, random window, set number of
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1621 % averages
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1622 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1623 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1624
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1625 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1626 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1627 % Array of parameters to pick from
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1628 fs_list = [0.1;1;2;5;10];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1629 nsecs_list = [2000:1000:10000]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1630 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1631 trend_0_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1632
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1633 % Build time-series test data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1634
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1635 % Picks the values at random from the list
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1636 fs = utils.math.randelement(fs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1637 nsecs = utils.math.randelement(nsecs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1638 sigma_distr = utils.math.randelement(sigma_distr_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1639 trend_0 = utils.math.randelement(trend_0_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1640
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1641 % White noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1642 type = 'Normal';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1643 a_n1 = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1644 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1645 a_n2 = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1646 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1647
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1648 % Constant signal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1649 a_c = ao(trend_0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1650
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1651 % Total signals
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1652 a1 = a_n1 + a_c;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1653 a2 = a_n2 + a_c;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1654
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1655 % Evaluate the complex coherence of the white noise time-series data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1656 win_list = specwin.getTypes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1657 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1658 win_type = win_type{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1659 switch win_type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1660 case 'Kaiser'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1661 win = specwin(win_type, 1, find(ao.getInfo('psd').plists, 'psll'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1662 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1663 win = specwin(win_type, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1664 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1665
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1666 olap = win.rov;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1667 detrend = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1668 n_pts = -1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1669 scale_type = 'C';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1670 navs = utils.math.randelement([1:100],1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1671
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1672 % Evaluates the coherence asking for the number of averages
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1673 C = cohere(a1, a2, plist('Win', win.type, 'olap', olap, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1674 'Nfft', n_pts, 'order', detrend, 'type', scale_type, 'navs', navs));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1675
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1676 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1677
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1678 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1679 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1680 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1681 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1682 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1683
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1684 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1685 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1686 % 1) Check that calculated navs are identical to those requested
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1687 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1688 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1689
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1690 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1691 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1692
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1693 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1694 % Compare the navs written in the output object with the requested one
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1695 if ne(navs, C.data.navs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1696 if ne(find(C.hist.plistUsed, 'navs'), C.data.navs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1697 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1698 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1699 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1700 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1701 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1702 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1703 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1704
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1705 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1706 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1707 end % END UTP_21
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1708
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1709 %% UTP_22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1710
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1711 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1712 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1713 % Tests the possibility to set the number of averages rather than setting the Nfft:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1714 % 1) white noise produced from uniform pdf, with:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1715 % a given mean value and sigma (distribution's 1st and 2nd order)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1716 % 2) cohere of the noise, without detrending, random window, random navs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1717 % 3) get the number of averages
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1718 % 4) get the nfft used
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1719 % 5) run cohere again, with the nfft used
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1720 % 6) compare the calculated objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1721 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1722
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1723 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1724 function result = utp_22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1725
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1726 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1727 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1728 % 1) white noise produced from uniform pdf, with:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1729 % a given mean value and sigma (distribution's 1st and 2nd order)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1730 % 2) cohere of the noise, without detrending, random window, random navs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1731 % 3) get the number of averages
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1732 % 4) get the nfft used
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1733 % 5) run cohere again, with the nfft used
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1734 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1735 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1736
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1737 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1738 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1739 % Array of parameters to pick from
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1740 fs_list = [0.1;1;2;5;10];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1741 nsecs_list = [20 100 1000:1000:10000]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1742 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1743 trend_0_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1744
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1745 % Build time-series test data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1746
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1747 % Picks the values at random from the list
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1748 fs = utils.math.randelement(fs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1749 nsecs = utils.math.randelement(nsecs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1750 sigma_distr = utils.math.randelement(sigma_distr_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1751 trend_0 = utils.math.randelement(trend_0_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1752
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1753 % White noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1754 type = 'Uniform';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1755 a_n1 = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1756 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1757 a_n2 = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1758 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1759
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1760 % Constant signal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1761 a_c = ao(trend_0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1762
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1763 % Total signals
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1764 a1 = a_n1 + a_c;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1765 a2 = a_n2 + a_c;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1766
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1767 % Evaluate the complex coherence of the white noise time-series data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1768 win_list = specwin.getTypes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1769 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1770 win_type = win_type{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1771 switch win_type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1772 case 'Kaiser'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1773 win = specwin(win_type, 1, find(ao.getInfo('psd').plists, 'psll'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1774 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1775 win = specwin(win_type, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1776 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1777
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1778 olap = win.rov;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1779 detrend = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1780 scale_type = 'MS';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1781 navs = fix(utils.math.randelement(logspace(0,log10(max(0,a1.len/10)),50),1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1782
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1783 % Calculates the coherence asking for the number of averages
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1784 C1 = cohere(a1, a2, plist('Win', win.type, 'olap', olap, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1785 'Nfft', -1, 'order', detrend, 'type', scale_type, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1786 'navs', navs));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1787
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1788 % Calculates the coherence asking for the number of points just evaluated
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1789 C2 = cohere(a1, a2, plist('Win', win.type, 'olap', olap, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1790 'Nfft', find(C1.hist.plistUsed, 'Nfft'), 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1791 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1792
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1793 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1794 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1795 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1796 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1797 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1798
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1799 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1800 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1801 % 1) Check that calculated objects C1 and C2 are identical
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1802 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1803 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1804
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1805 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1806 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1807
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1808 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1809 % Compare the output objects
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1810 if ne(C1,C2,ple3)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1811 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1812 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1813 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1814 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1815 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1816 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1817
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1818 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1819 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1820 end % END UTP_22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1821
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1822 %% UTP_23
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1823
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1824 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1825 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1826 % Tests the possibility to set the number of averages rather than setting the Nfft:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1827 % 1) white noise produced from normal pdf, with:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1828 % a given mean value and sigma (distribution's 1st and 2nd order)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1829 % 2) cohere of the noise, without detrending, random window, random navs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1830 % 3) get the number of averages
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1831 % 4) get the nfft used
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1832 % 5) run cohere again, with the nfft used
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1833 % 6) compare navs, nfft, coheres
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1834 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1835
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1836 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1837 function result = utp_23
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1838
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1839 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1840 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1841 % 1) white noise produced from normal pdf, with:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1842 % a given mean value and sigma (distribution's 1st and 2nd order)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1843 % 2) cohere of the noise, without detrending, random window, random navs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1844 % 3) get the number of averages
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1845 % 4) get the nfft used
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1846 % 5) run cohere again, with the nfft used
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1847 % 6) run cohere again, with conflicting parameters, and verify it uses
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1848 % nfft rather than navs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1849 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1850 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1851
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1852 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1853 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1854 % Array of parameters to pick from
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1855 fs_list = [0.1;1;2;5;10];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1856 nsecs_list = [1000:1000:10000]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1857 sigma_distr_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1858 trend_0_list = [1e-6 2e-3 0.25 1:0.1:10]';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1859
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1860 % Build time-series test data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1861
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1862 % Picks the values at random from the list
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1863 fs = utils.math.randelement(fs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1864 nsecs = utils.math.randelement(nsecs_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1865 sigma_distr = utils.math.randelement(sigma_distr_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1866 trend_0 = utils.math.randelement(trend_0_list, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1867
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1868 % White noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1869 type = 'Normal';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1870 a_n1 = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1871 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1872 a_n2 = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1873 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1874
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1875 % Constant signal
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1876 a_c = ao(trend_0);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1877
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1878 % Total signals
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1879 a1 = a_n1 + a_c;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1880 a2 = a_n2 + a_c;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1881
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1882 % Evaluate the complex coherence of the white noise time-series data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1883 win_list = specwin.getTypes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1884 win_type = utils.math.randelement(win_list(~strcmpi(win_list, 'levelledhanning')), 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1885 win_type = win_type{1};
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1886 switch win_type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1887 case 'Kaiser'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1888 win = specwin(win_type, 1, find(ao.getInfo('psd').plists, 'psll'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1889 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1890 win = specwin(win_type, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1891 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1892
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1893 olap = win.rov;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1894 detrend = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1895 scale_type = 'C';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1896 navs = fix(utils.math.randelement(logspace(0,log10(max(a1.len/10,0)),50),1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1897
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1898 % Calculates the coherence asking for the number of averages
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1899 C1 = cohere(a1, a2, plist('Win', win.type, 'olap', olap, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1900 'Nfft', -1, 'order', detrend, 'type', scale_type, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1901 'navs', navs));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1902
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1903 npts_2 = find(C1.hist.plistUsed, 'Nfft');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1904 % Calculates the coherence asking for the number of points
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1905 C2 = cohere(a1, a2, plist('Win', win.type, 'olap', olap, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1906 'Nfft', npts_2, 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1907
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1908 npts_3 = fix(npts_2/2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1909 % Calculates the coherence asking for the number of points AND the window length
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1910 C3 = cohere(a1, a2, plist('Win', win.type, 'olap', olap, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1911 'Nfft', npts_3, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1912 'order', detrend, 'type', scale_type, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1913 'navs', navs));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1914
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1915 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1916
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1917 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1918 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1919 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1920 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1921 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1922
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1923 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1924 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1925 % 1) Check that calculated objects C1 and C2 are identical
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1926 % 2) Check that C3 used different values
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1927 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1928 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1929
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1930 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1931 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1932
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1933 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1934 % Compare the navs written in the output object with the requested one
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1935 if ne(C1,C2,ple3) || ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1936 ne(find(C3.hist.plistUsed, 'Nfft'), npts_3) || eq(C3.data.navs, navs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1937 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1938 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1939 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1940 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1941 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1942 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1943
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1944 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1945 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1946 end % END UTP_23
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1947
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1948 %% UTP_24
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1949
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1950 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1951 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1952 % Tests that the cohere method agrees with MATLAB's mscohere when
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1953 % configured to use the same parameters.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1954 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1955 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1956 function result = utp_24
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1957
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1958 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1959 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1960 % Test that the applying cohere works on two AOs.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1961 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1962 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1963
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1964 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1965 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1966 % Construct two test AOs
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1967 nsecs = 10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1968 fs = 1000;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1969 pl = plist('nsecs', nsecs, 'fs', fs, 'tsfcn', 'randn(size(t))');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1970 a1 = ao(pl); a2 = ao(pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1971 % Filter one time-series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1972 f2 = miir(plist('type', 'bandpass', 'fs', fs, 'order', 3, 'fc', [50 250]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1973 a1f = filter(a1, plist('filter', f2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1974 % make some cross-power
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1975 a4 = a1f+a2; a4.setName;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1976 % Create the transpose of a4 to check the output data shape
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1977 a4 = a4.';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1978 % Compute coherence
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1979 Nfft = 2*fs;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1980 % Use different windows size as Nfft
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1981 win = specwin('Hanning', 1000);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1982 pl = plist('Nfft', Nfft, 'Win', win.type, 'order', 0, 'type', 'MS');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1983 out = cohere(a4,a1,pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1984 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1985 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1986 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1987 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1988 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1989 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1990
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1991 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1992 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1993 % 1) Check that output agrees with the output of MATLAB's mscohere.
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1994 % 2) Check that the shape of the output data is equal to the input data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1995 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1996 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1997
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1998 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1999 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2000 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2001 TOL = 1e-12;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2002
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2003 % Redesign the window
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2004 win = specwin('Hanning', Nfft);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2005 % Compute coherence using MATLAB's cohere
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2006 [cxy, f] = mscohere(a4.y, a1.y, win.win, Nfft/2, Nfft, a1.fs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2007 if any(abs(cxy(4:end)-out.y(4:end))>TOL), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2008 if ne(f, out.x), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2009 if ne(out, out, ple2), atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2010 % Check the data shape
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2011 if size(a4.y,1) == 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2012 if size(out.y,1) ~= 1, atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2013 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2014 if size(out.y,2) ~= 1, atest = false; end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2015 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2016 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2017 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2018 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2019 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2020
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2021 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2022 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2023 end % END UTP_24
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2024
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2025 %% UTP_25
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2026
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2027 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2028 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2029 % Tests handling of units:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2030 % 1) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2031 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2032 % 2) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2033 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2034 % 3) complex coherence of the white noise series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2035 % 4) compares the units of the input and output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2036 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2037
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2038 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2039 function result = utp_25
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2040
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2041 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2042 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2043 % 1) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2044 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2045 % 2) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2046 % 3) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2047 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2048 % 4) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2049 % 5) complex cohere of the white noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2050 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2051 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2052
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2053 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2054 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2055
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2056 % Build time-series test data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2057 fs = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2058 nsecs = 86400;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2059 sigma_distr_1 = 4.69e-12;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2060 mu_distr_1 = -5.11e-14;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2061 sigma_distr_2 = 6.04e-9;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2062 mu_distr_2 = 1.5e-10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2063
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2064 % White noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2065 type = 'Normal';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2066
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2067 a_n = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2068 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2069 a_const = ao(mu_distr_1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2070 a_1 = a_n + a_const;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2071
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2072 a_n = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2073 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2074 a_const = ao(mu_distr_2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2075 a_2 = a_n + a_const;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2076
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2077 % Set units and prefix from those supported
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2078 unit_list = unit.supportedUnits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2079 % remove the first empty unit '' from the list, because then is it
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2080 % possible that we add a prefix to an empty unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2081 unit_list = unit_list(2:end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2082 prefix_list = unit.supportedPrefixes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2083 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2084 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2085
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2086 % Evaluate the coherence of the time-series data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2087 win = 'Kaiser';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2088 psll = utils.math.randelement([10:10:200], 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2089 detrend = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2090 scale_type = 'C';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2091 n_pts = nsecs*fs/10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2092
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2093 C = cohere(a_1, a_2, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2094 plist('Win', win, 'psll', psll, 'Nfft', n_pts, 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2095
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2096 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2097
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2098 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2099 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2100 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2101 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2102 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2103
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2104 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2105 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2106 % 1) Check that (complex coherence yunits) equals [1]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2107 % 2) Check that (complex coherence xunits) equals [Hz]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2108
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2109 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2110
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2111 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2112 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2113
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2114 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2115 if ~eq(C.yunits, unit('')) || ~eq(C.xunits, unit('Hz'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2116 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2117 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2118 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2119 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2120 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2121 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2122
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2123 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2124 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2125 end % END UTP_25
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2126
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2127 %% UTP_26
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2128
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2129 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2130 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2131 % Tests handling of units:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2132 % 1) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2133 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2134 % 2) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2135 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2136 % 3) complex coherence of the white noise series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2137 % 4) compares the units of the input and output
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2138 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2139
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2140 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2141 function result = utp_26
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2142
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2143 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2144 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2145 % 1) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2146 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2147 % 2) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2148 % 3) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2149 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2150 % 4) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2151 % 5) complex cohere of the white noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2152 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2153 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2154
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2155 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2156 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2157
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2158 % Build time-series test data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2159 fs = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2160 nsecs = 86400;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2161 sigma_distr_1 = 4.69e-12;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2162 mu_distr_1 = -5.11e-14;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2163 sigma_distr_2 = 6.04e-9;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2164 mu_distr_2 = 1.5e-10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2165
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2166 % White noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2167 type = 'Normal';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2168
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2169 a_n = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2170 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2171 a_const = ao(mu_distr_1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2172 a_1 = a_n + a_const;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2173
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2174 a_n = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2175 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_2));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2176 a_const = ao(mu_distr_2);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2177 a_2 = a_n + a_const;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2178
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2179 % Set units and prefix from those supported
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2180 unit_list = unit.supportedUnits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2181 % remove the first empty unit '' from the list, because then is it
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2182 % possible that we add a prefix to an empty unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2183 unit_list = unit_list(2:end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2184 prefix_list = unit.supportedPrefixes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2185 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2186 a_2.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2187
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2188 % Evaluate the coherence of the time-series data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2189 win = 'Kaiser';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2190 psll = utils.math.randelement([10:10:200], 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2191 detrend = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2192 scale_type = 'C';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2193 n_pts = nsecs*fs/10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2194
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2195 C = cohere(a_1, a_2, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2196 plist('Win', win, 'psll', psll, 'Nfft', n_pts, 'order', detrend, 'type', scale_type));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2197
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2198 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2199
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2200 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2201 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2202 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2203 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2204 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2205
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2206 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2207 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2208 % 1) Check that (complex coherence yunits) equals [1]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2209 % 2) Check that (complex coherence xunits) equals [Hz]
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2210
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2211 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2212
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2213 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2214 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2215
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2216 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2217 if ~eq(C.yunits, unit('')) || ~eq(C.xunits, unit('Hz'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2218 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2219 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2220 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2221 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2222 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2223 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2224
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2225 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2226 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2227 end % END UTP_26
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2228
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2229 %% UTP_30
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2230
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2231 % <TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2232 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2233 % Tests handling of special cases:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2234 % 1) white noise produced from normal pdf, with a given mean value and
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2235 % sigma (distribution's 1st and 2nd orders)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2236 % 2) the same noise series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2237 % 3) cohere of the white noise series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2238 % 4) compares the output to unity
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2239 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2240
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2241 % </TestDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2242 function result = utp_30
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2243
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2244 % <SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2245 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2246 % 1) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2247 % white noise from normal distribution + offset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2248 % 2) Assign a random unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2249 % 3) Prepare the test tsdata:
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2250 % the same data as 1) and 2)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2251 % 4) cohere of the series
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2252 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2253 % </SyntaxDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2254
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2255 % <SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2256 try
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2257
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2258 % Build time-series test data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2259 fs = 1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2260 nsecs = 86400;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2261 sigma_distr_1 = 4.69e-12;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2262 mu_distr_1 = -5.11e-14;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2263
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2264 % White noise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2265 type = 'Normal';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2266
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2267 a_n = ao(plist('waveform', 'noise', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2268 'type', type, 'fs', fs, 'nsecs', nsecs, 'sigma', sigma_distr_1));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2269 a_const = ao(mu_distr_1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2270 a_1 = a_n + a_const;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2271
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2272 % Set units and prefix from those supported
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2273 unit_list = unit.supportedUnits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2274 % remove the first empty unit '' from the list, because then is it
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2275 % possible that we add a prefix to an empty unit
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2276 unit_list = unit_list(2:end);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2277 prefix_list = unit.supportedPrefixes;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2278 a_1.setYunits(unit([cell2mat(utils.math.randelement(prefix_list,1)) cell2mat(utils.math.randelement(unit_list,1))]));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2279
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2280 % Build the second object as a copy of the first
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2281 a_2 = a_1;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2282
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2283 % Evaluate the cohere of the time-series data
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2284 win = specwin('BH92');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2285 olap = win.rov;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2286 detrend = 0;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2287 n_pts = nsecs*fs/10;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2288 scale_type = 'C';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2289
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2290 C = cohere(a_1, a_2, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2291 plist('Win', win, 'Nfft', n_pts, 'order', detrend, 'type', scale_type, 'olap', olap));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2292
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2293 stest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2294
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2295 catch err
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2296 disp(err.message)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2297 stest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2298 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2299 % </SyntaxCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2300
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2301 % <AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2302 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2303 % 1) Check that calculated cohere equals 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2304
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2305 % </AlgoDescription>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2306
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2307 % <AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2308 atest = true;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2309
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2310 if stest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2311 if sum(ne(C.y, 1))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2312 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2313 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2314 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2315 atest = false;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2316 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2317 % </AlgoCode>
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2318
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2319 % Return a result structure
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2320 result = utp_prepare_result(atest, stest, dbstack, mfilename);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2321 end % END UTP_30
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2322
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2323 end
|