Mercurial > hg > ltpda
comparison m-toolbox/classes/@fsdata/fsdata.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % FSDATA frequency-series object class constructor. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: FSDATA frequency-series object class constructor. | |
5 % Create a frequency-series data object. | |
6 % | |
7 % SUPER CLASSES: data2D < ltpda_data < ltpda_nuo < ltpda_obj | |
8 % | |
9 % CONSTRUCTORS: | |
10 % | |
11 % fsd = fsdata() - creates a blank frequency-series object | |
12 % fsd = fsdata(y) - creates a frequency-series object with the given | |
13 % y-data. Sample rate of the data is assumed to | |
14 % be 1Hz. | |
15 % fsd = fsdata(f,y) - creates a frequency-series object with the given | |
16 % (x,y)-data. The sample rate is then set as | |
17 % 2*x(end). | |
18 % fsd = fsdata(y,fs) - creates a frequency-series object with the given | |
19 % y-data and sample rate. The frequency | |
20 % vector is grown assuming the first y | |
21 % sample corresponds to 0Hz and the last | |
22 % sample corresponds to the Nyquist | |
23 % frequency. | |
24 % fsd = fsdata(x,y,fs) - creates a frequency-series object with the given | |
25 % x,y-data and sample rate. | |
26 % | |
27 % VERSION: $Id: fsdata.m,v 1.62 2011/03/30 13:17:33 mauro Exp $ | |
28 % | |
29 % SEE ALSO: tsdata, fsdata, xydata, cdata, data2D, data3D, xyzdata | |
30 % | |
31 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
32 | |
33 classdef (Hidden = true) fsdata < data2D | |
34 | |
35 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
36 % Property definition % | |
37 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
38 | |
39 %---------- Public (read/write) Properties ---------- | |
40 properties | |
41 end | |
42 | |
43 %---------- Protected read-only Properties ---------- | |
44 properties (GetAccess = public, SetAccess = protected) | |
45 t0 = time(0); % time-stamp of the first data sample | |
46 navs = NaN; % number of averages | |
47 fs = NaN; % sample rate of data | |
48 enbw = NaN; % equivalent noise bandwidth | |
49 end | |
50 | |
51 %---------- Private Properties ---------- | |
52 properties (GetAccess = protected, SetAccess = protected) | |
53 end | |
54 | |
55 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
56 % Check property setting % | |
57 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
58 | |
59 methods | |
60 function set.t0(obj, val) | |
61 if (~isa(val, 'time') && ~ischar(val) && ~isnumeric(val))|| isempty(val) | |
62 error('### The value for the property ''t0'' must be a string, a number or a time object'); | |
63 end | |
64 if ischar(val) || isnumeric(val) | |
65 obj.t0 = time(val); | |
66 else | |
67 obj.t0 = val; | |
68 end | |
69 end | |
70 function set.navs(obj, val) | |
71 if ~isnumeric(val) || isempty(val) || length(val) < 0 || (~isnan(val) && rem(val,1)~=0) | |
72 error('### The value for the property ''navs'' must be a positive integer'); | |
73 end | |
74 obj.navs = val; | |
75 end | |
76 function set.fs(obj, val) | |
77 if ~isempty(val) | |
78 if ~isnumeric(val) || ~isreal(val) || val < 0 | |
79 error('### The value for the property ''fs'' must be a real positive number'); | |
80 end | |
81 end | |
82 obj.fs = val; | |
83 end | |
84 function set.enbw(obj, val) | |
85 if ~isnumeric(val) || ~isreal(val) || any(val < 0) | |
86 error('### The value for the property ''enbw'' must be a real positive number or a vector'); | |
87 end | |
88 if ~isempty(val) && ~isempty(obj.y) | |
89 if length(val) ~=1 && (length(val) ~= length(obj.y)) | |
90 error('### The ENBW can only be a single number, of a vector the same length as the y data.'); | |
91 end | |
92 end | |
93 if size(val, 1) == 1 | |
94 obj.enbw = val.'; | |
95 else | |
96 obj.enbw = val; | |
97 end | |
98 end | |
99 end | |
100 | |
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
102 % Constructor % | |
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
104 | |
105 methods | |
106 function obj = fsdata(varargin) | |
107 | |
108 switch nargin | |
109 case 0 | |
110 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
111 %%%%%%%%%%%%%%%%%%%%%%%%%%% no inputs %%%%%%%%%%%%%%%%%%%%%%%%%%% | |
112 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
113 | |
114 case 1 | |
115 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
116 %%%%%%%%%%%%%%%%%%%%%%%%%%% one input %%%%%%%%%%%%%%%%%%%%%%%%%%% | |
117 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
118 | |
119 if isa(varargin{1}, 'fsdata') | |
120 %%%%%%%%%% data = fsdata(fsdata-object) %%%%%%%%%% | |
121 %----------- Copy fsdata Object | |
122 obj = copy(varargin{1}, 1); | |
123 | |
124 elseif isstruct(varargin{1}) | |
125 %%%%%%%%%% data = fsdata(struct) %%%%%%%%%% | |
126 obj = fromStruct(obj, varargin{1}); | |
127 | |
128 elseif isnumeric(varargin{1}) | |
129 %%%%%%%%%% data = fsdata(y-vector) %%%%%%%%%% | |
130 %----------- y vector | |
131 obj.setY(varargin{1}); | |
132 obj.setFs(1); | |
133 obj.setX(fsdata.getFfromYFs(length(obj.y), obj.fs)); | |
134 | |
135 else | |
136 error('### Unknown single argument constructor.'); | |
137 end | |
138 case 2 | |
139 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
140 %%%%%%%%%%%%%%%%%%%%%%%%%%% two input %%%%%%%%%%%%%%%%%%%%%%%%%%% | |
141 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
142 | |
143 if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') && ... | |
144 isa(varargin{2}, 'history') | |
145 %%%%%%%%%% obj = fsdata(DOM node, history-objects) %%%%%%%%%% | |
146 obj = fromDom(obj, varargin{1}, varargin{2}); | |
147 | |
148 elseif numel(varargin{1}) > numel(varargin{2}) && numel(varargin{2}) == 1 | |
149 %%%%%%%%%% data = fsdata(y-vector, fs) %%%%%%%%%% | |
150 % fsdata(y,fs) | |
151 obj.setY(varargin{1}); | |
152 obj.setFs(varargin{2}); | |
153 obj.setX(fsdata.getFfromYFs(length(obj.y), obj.fs)); | |
154 | |
155 elseif numel(varargin{1}) == numel(varargin{2}) | |
156 %%%%%%%%%% data = fsdata(x-vector, y-vector) %%%%%%%%%% | |
157 % fsdata(x,y) | |
158 obj.setXY(varargin{1}, varargin{2}); | |
159 | |
160 else | |
161 error('### Unknown two argument constructor.'); | |
162 end | |
163 case 3 | |
164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
165 %%%%%%%%%%%%%%%%%%%%%%%%%% three input %%%%%%%%%%%%%%%%%%%%%%%%%% | |
166 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
167 | |
168 if numel(varargin{1}) == numel(varargin{2}) && numel(varargin{3}) == 1 | |
169 %%%%%%%%%% data = fsdata(x-vector, y-vector, fs) %%%%%%%%%% | |
170 % fsdata(x,y,fs) | |
171 obj.setXY(varargin{1}, varargin{2}); | |
172 obj.setFs(varargin{3}); | |
173 | |
174 else | |
175 error('### Unknown three argument constructor.'); | |
176 end | |
177 otherwise | |
178 error('### Unknown number of constructor arguments.'); | |
179 end | |
180 end % End constructor | |
181 end % End public methods | |
182 | |
183 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
184 % Methods (Public, hidden) % | |
185 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
186 | |
187 methods (Hidden = true) | |
188 varargout = attachToDom(varargin) | |
189 end | |
190 | |
191 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
192 % Methods (protected) % | |
193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
194 | |
195 methods (Access = protected) | |
196 varargout = fromStruct(varargin) | |
197 varargout = fromDom(varargin) | |
198 end | |
199 | |
200 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
201 % Methods (private) % | |
202 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
203 | |
204 methods (Access = private) | |
205 end | |
206 | |
207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
208 % Methods (static) % | |
209 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
210 methods (Static) | |
211 | |
212 function out = VEROUT() | |
213 out = '$Id: fsdata.m,v 1.62 2011/03/30 13:17:33 mauro Exp $'; | |
214 end | |
215 | |
216 function ii = getInfo(varargin) | |
217 ii = utils.helper.generic_getInfo(varargin{:}, 'fsdata'); | |
218 end | |
219 | |
220 function out = SETS() | |
221 out = {'Default'}; | |
222 end | |
223 | |
224 function out = getDefaultPlist(set) | |
225 switch lower(set) | |
226 case 'default' | |
227 out = plist(); | |
228 otherwise | |
229 error('### Unknown set [%s]', set'); | |
230 end | |
231 end | |
232 | |
233 function obj = initObjectWithSize(n,m) | |
234 obj = fsdata.newarray([n m]); | |
235 end | |
236 | |
237 end % End static methods | |
238 | |
239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
240 % Methods (static, private) % | |
241 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
242 | |
243 methods (Static, Access = private) | |
244 f = getFfromYFs(N,fs) | |
245 end % End static, private methods | |
246 | |
247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
248 % Methods (static, hidden) % | |
249 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
250 | |
251 methods (Static = true, Hidden = true) | |
252 varargout = loadobj(varargin) | |
253 varargout = update_struct(varargin); | |
254 end | |
255 | |
256 end % End classdef |