0
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
1 % FROMPOLYVAL Construct an ao from polynomial coefficients
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
3 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
4 % FUNCTION: fromPolyval
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
5 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
6 % DESCRIPTION: Construct an ao from polynomial coefficients
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
7 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
8 % CALL: a = fromPolyval(a, vals)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
9 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
10 % PARAMETER: pl: plist containing 'polyval', 'Nsecs', 'fs', or 't'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
11 %
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
13
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
14 function a = fromPolyval(a, pli)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
15
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
16 VERSION = '$Id: fromPolyval.m,v 1.27 2011/08/15 05:57:20 hewitson Exp $';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
17
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
18 import utils.const.*
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
19
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
20 % get AO info
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
21 ii = ao.getInfo('ao', 'From Polynomial');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
22
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
23 % Set the method version string in the minfo object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
24 ii.setMversion([VERSION '-->' ii.mversion]);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
25
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
26 % Add default values
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
27 pl = applyDefaults(ii.plists, pli);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
28
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
29 coeffs = find(pl, 'polyval');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
30 Nsecs = find(pl, 'Nsecs');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
31 fs = find(pl, 'fs');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
32 t = find(pl, 't');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
33 x = find(pl, 'x');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
34 f = find(pl, 'f');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
35 dtype = find(pl, 'type');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
36
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
37 % Collect the coefficients
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
38 coeff_class = class(coeffs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
39
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
40 switch coeff_class
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
41 case 'ao'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
42 if numel(coeffs) == 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
43 % Single AO with an array of coefficients
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
44 coeffs = coeffs.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
45 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
46 % Vector of AOs with single coefficients
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
47 error(['### Incorrect container for coefficients. \n' ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
48 'Supporting only aos, aos inside Nx1 or 1xN matrix object, single pest objects, double arrays']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
49 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
50 case 'matrix'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
51 % A matrix of AOs with single coefficients
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
52 coeff_array = [ao];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
53 ncol = ncols(coeffs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
54 nrow = nrows(coeffs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
55 if ncol > 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
56 if nrow == 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
57 nc = ncol;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
58 for jj = 1:nc
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
59 coeff_array(jj) = coeffs.getObjectAtIndex(1, jj);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
60 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
61 coeffs = coeff_array.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
62 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
63 error(['### Incorrect container for coefficients. \n' ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
64 'Supporting only aos, aos inside Nx1 or 1xN matrix object, single pest objects, double arrays']);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
65 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
66 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
67 nc = nrow;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
68 for jj = 1:nc
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
69 coeff_array(jj) = coeffs.getObjectAtIndex(jj, 1);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
70 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
71 coeffs = coeff_array.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
72 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
73 case 'pest'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
74 nc = numel(coeffs.y);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
75 if numel(coeffs) == 1
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
76 % Single pest with an array of coefficients
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
77 if ~isempty(coeffs.models)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
78 yunits = coeffs.models.yunits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
79 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
80 yunits = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
81 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
82 coeff_yunits = coeffs.yunits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
83 coeffs = coeffs.y;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
84 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
85 % Vector of pests with single coefficients
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
86 error(sprintf(['### Incorrect container for coefficients. \n' ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
87 'Supporting only aos, aos inside Nx1 or 1xN matrix object, single pest objects, double arrays']));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
88 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
89 case 'double'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
90 % Do nothing in this case
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
91 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
92 error(sprintf(['### Incorrect container for coefficients. \n' ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
93 'Supporting only aos, aos inside Nx1 or 1xN matrix object, single pest objects, double arrays']));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
94 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
95
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
96 % Try to decide what to do if the user doesn't specify data type
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
97 if isempty(dtype)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
98 if ~isempty(Nsecs) || ~isempty(t) || ~isempty(fs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
99 dtype = 'tsdata';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
100 elseif ~isempty(x)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
101 dtype = 'xydata';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
102 elseif ~isempty(f)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
103 dtype = 'fsdata';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
104 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
105 error('### Please specify data type and parameters');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
106 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
107 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
108
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
109 switch dtype
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
110 case 'tsdata'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
111 if isa(t, 'ao')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
112 t_xunits = t.xunits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
113 % Override the xunits by using those from the t vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
114 utils.helper.msg(msg.OFF, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
115 'warning: overriding the user-input xunits %s with the t ao %s', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
116 char(find(pl, 'xunits')), char(t_xunits));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
117 t = t.x;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
118 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
119 t_xunits = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
120 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
121
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
122 % Check t vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
123 if isempty(t)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
124 if isempty(Nsecs) || isempty(fs)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
125 error('Please provide either ''Nsecs'' and ''fs'', or ''t'' for polyval constructor with data type ''tsdata''.');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
126 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
127 t = 0 : 1/fs : Nsecs-1/fs; %t = linspace(0, Nsecs - 1/fs, Nsecs*fs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
128 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
129
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
130 y = polyval(coeffs,t);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
131
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
132 % Make a tsdata object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
133 p = tsdata(t, y);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
134
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
135 % Make sure the actual sampling frequency fs is captured in the plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
136 pl.pset('fs', p.fs);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
137
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
138 % set T0
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
139 p.setT0(pl.find('t0'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
140
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
141 % set Toffset
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
142 if ~isempty(pl.find('toffset'))
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
143 toffset = p.toffset + 1000*pl.find('toffset');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
144 p.setToffset(toffset);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
145 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
146
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
147 % Checks the units
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
148 % xunits
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
149 if isempty(t_xunits)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
150 new_xunits = find(pl, 'xunits');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
151 if isempty(new_xunits)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
152 new_xunits = 's';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
153 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
154 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
155 new_xunits = t_xunits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
156 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
157 pl.pset('xunits', new_xunits);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
158
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
159 case 'xydata'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
160 if isa(x, 'ao')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
161 x_xunits = x.xunits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
162 % Override the xunits by using those from the x vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
163 utils.helper.msg(msg.OFF, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
164 'warning: overriding the user-input xunits %s with the x ao %s', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
165 char(find(pl, 'xunits')), char(x_xunits));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
166 pl.pset('xunits', x_xunits);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
167 x = x.x;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
168 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
169 x_xunits = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
170 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
171
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
172 % Check x vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
173 if isempty(x)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
174 error('### Please provide the x values');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
175 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
176
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
177 y = polyval(coeffs,x);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
178
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
179 % Make a xydata object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
180 p = xydata(x, y);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
181
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
182 % Checks the units
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
183 % xunits
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
184 if isempty(x_xunits)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
185 new_xunits = find(pl, 'xunits');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
186 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
187 new_xunits = x_xunits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
188 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
189 pl.pset('xunits', new_xunits);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
190
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
191 case 'fsdata'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
192 if isa(f, 'ao')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
193 f_xunits = f.xunits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
194 % Override the xunits by using those from the x vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
195 utils.helper.msg(msg.OFF, ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
196 'warning: overriding the user-input xunits %s with the x ao %s', ...
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
197 char(find(pl, 'xunits')), char(f_xunits));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
198 pl.pset('xunits', f_xunits);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
199 f = f.x;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
200 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
201 f_xunits = [];
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
202 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
203
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
204 % Check f vector
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
205 if isempty(f)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
206 error('### Please provide the frequency values');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
207 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
208
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
209 y = polyval(coeffs,f);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
210
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
211 % Make a fsdata object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
212 p = fsdata(f, y);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
213
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
214 % Checks the units
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
215 % xunits
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
216 if isempty(f_xunits)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
217 new_xunits = find(pl, 'xunits');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
218 if isempty(new_xunits)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
219 new_xunits = 'Hz';
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
220 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
221 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
222 new_xunits = f_xunits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
223 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
224 pl.pset('xunits', new_xunits);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
225
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
226 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
227 error('### Unsupported data type %s', dtype);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
228 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
229
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
230 % yunits
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
231 switch lower(coeff_class)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
232 case 'matrix'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
233 % Matrix of AOs with coefficients was provided. So the units must be
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
234 % consistent (with requested, if any, and between each other)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
235 new_yunits = find(pl, 'yunits');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
236 if isempty(new_yunits)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
237 new_yunits = simplify(coeff_array(1).yunits .* (new_xunits.^(nc-1)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
238 else
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
239 new_yunits = unit(new_yunits);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
240 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
241 for jj = 1:nc
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
242 if coeff_array(jj).yunits * (new_xunits.^(nc-jj)) ~= new_yunits
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
243 error('### Inconsistent units either between coefficients or with requested')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
244 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
245 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
246 pl.pset('yunits', new_yunits);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
247 case 'pest'
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
248 % A pest object with coefficients was provided
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
249 % Did the user provide yunits? Let's use them
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
250 new_yunits = find(pl, 'yunits');
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
251 % Otherwise, let's use the yunits of the smodel inside the pest
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
252 if isempty(new_yunits)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
253 new_yunits = yunits;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
254 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
255 % Otherwise, let's calculate them
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
256 if isempty(new_yunits)
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
257 new_yunits = simplify(coeff_yunits(1) .* (new_xunits.^(nc-1)));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
258 for jj = 1:nc
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
259 if simplify(coeff_yunits(jj) * (new_xunits.^(nc-jj))) ~= new_yunits
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
260 error('### Inconsistent units either between coefficients')
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
261 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
262 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
263 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
264 pl.pset('yunits', new_yunits);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
265 otherwise
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
266 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
267
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
268 % Make an analysis object
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
269 a.data = p;
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
270 % Set xunits
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
271 a.setXunits(pl.find('xunits'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
272 % Set yunits
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
273 a.setYunits(pl.find('yunits'));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
274 % Simplify units
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
275 a.simplifyYunits(plist('Prefixes', false));
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
276 % Add history
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
277 a.addHistory(ii, pl, [], []);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
278 % Set object properties from the plist
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
279 a.setObjectProperties(pl);
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
280
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
281
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
282
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
283 end
|
Daniele Nicolodi <nicolodi@science.unitn.it>
parents:
diff
changeset
|
284
|