


FSDATA frequency-series object class constructor.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
DESCRIPTION: FSDATA frequency-series object class constructor.
Create a frequency-series data object.
Properties:
name - name of frequency-series object
x - frequency samples vector
y - y samples vector
enbw - equivalent noise bandwidth
navs - number of averages
fs - sample rate of data
xunits - units to interpret the frequency samples (e.g., seconds)
yunits - units to interpret the data samples (e.g., Volts)
version - version of the constructor code
created - creation time of this fsdata object.
Possible constructors:
fsd = fsdata() - creates a blank frequency-series object
fsd = fsdata(y) - creates a frequency-series object with the given
y-data. Sample rate of the data is assumed to
be 1Hz.
fsd = fsdata(f,y) - creates a frequency-series object with the given
(x,y)-data. The sample rate is then set as
2*x(end).
fsd = fsdata(y,fs) - creates a frequency-series object with the given
y-data and sample rate. The frequency
vector is grown assuming the first y
sample corresponds to 0Hz and the last
sample corresponds to the Nyquist
frequency.
fsd = fsdata(x,y,fs) - creates a frequency-series object with the given
x,y-data and sample rate.
HISTORY: 30-01-2007 Hewitson
Creation
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


0001 function fsd = fsdata(varargin) 0002 % FSDATA frequency-series object class constructor. 0003 % 0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0005 % 0006 % DESCRIPTION: FSDATA frequency-series object class constructor. 0007 % Create a frequency-series data object. 0008 % 0009 % Properties: 0010 % name - name of frequency-series object 0011 % x - frequency samples vector 0012 % y - y samples vector 0013 % enbw - equivalent noise bandwidth 0014 % navs - number of averages 0015 % fs - sample rate of data 0016 % xunits - units to interpret the frequency samples (e.g., seconds) 0017 % yunits - units to interpret the data samples (e.g., Volts) 0018 % version - version of the constructor code 0019 % created - creation time of this fsdata object. 0020 % 0021 % Possible constructors: 0022 % fsd = fsdata() - creates a blank frequency-series object 0023 % fsd = fsdata(y) - creates a frequency-series object with the given 0024 % y-data. Sample rate of the data is assumed to 0025 % be 1Hz. 0026 % fsd = fsdata(f,y) - creates a frequency-series object with the given 0027 % (x,y)-data. The sample rate is then set as 0028 % 2*x(end). 0029 % fsd = fsdata(y,fs) - creates a frequency-series object with the given 0030 % y-data and sample rate. The frequency 0031 % vector is grown assuming the first y 0032 % sample corresponds to 0Hz and the last 0033 % sample corresponds to the Nyquist 0034 % frequency. 0035 % fsd = fsdata(x,y,fs) - creates a frequency-series object with the given 0036 % x,y-data and sample rate. 0037 % 0038 % HISTORY: 30-01-2007 Hewitson 0039 % Creation 0040 % 0041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0042 0043 VERSION = '$Id: fsdata.m,v 1.18 2007/11/30 19:36:04 ingo Exp $'; 0044 0045 %%%%% Is this a 'Params' call? %%%%% 0046 if nargin == 2 && isa(varargin{1}, 'fsdata') && ischar(varargin{2}) 0047 if strcmp(varargin{2}, 'Params') 0048 fsd = plist(); 0049 return 0050 elseif strcmp(varargin{2}, 'Version') 0051 fsd = VERSION; 0052 return 0053 end 0054 end 0055 0056 %%%%%%%%%%%%%%%%%%%%%%%% define fsdata properties %%%%%%%%%%%%%%%%%%%%%%%%% 0057 0058 function fs = init() 0059 fs.name = 'None'; 0060 fs.x = []; 0061 fs.y = []; 0062 fs.enbw = []; 0063 fs.navs = []; 0064 fs.fs = 0; 0065 fs.xunits = 'Hz'; 0066 fs.yunits = ''; 0067 fs.version = VERSION; 0068 fs.created = time; 0069 fs = class(fs, 'fsdata'); 0070 end 0071 0072 %%%%%%%%%%%%%%%%%%%%%%%%%% Create fsdata object %%%%%%%%%%%%%%%%%%%%%%%%%%% 0073 0074 %%%%%%%%%% fsd = fsdata() %%%%%%%%%% 0075 % create default fsdata object 0076 if nargin == 0 0077 0078 fsd = init(); 0079 0080 elseif nargin == 1 0081 %%%%%%%%%% Create from XML fragment %%%%%%%%%%% 0082 if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') 0083 fsd = fromxml(varargin{1}); 0084 %%%%%%%%%%% From File %%%%%%%%%%%%%%%% 0085 elseif ischar(varargin{1}) 0086 0087 filename = varargin{1}; 0088 [path, name, ext, vers] = fileparts(filename); 0089 switch ext 0090 case '.mat' 0091 fsd = load(filename); 0092 fsd = fsd.a; 0093 case '.xml' 0094 fsd = xmlparse(fsdata, filename); 0095 otherwise 0096 error('### Unknown file type.'); 0097 end 0098 %%%%%%%%%% fsd = fsdata(fsdata) %%%%%%%%%% 0099 elseif isa(varargin{1}, 'fsdata') 0100 0101 fsd = varargin{1}; 0102 0103 %%%%%%%%%% fsd = fsdata(struct) %%%%%%%%%% 0104 elseif isstruct(varargin{1}) 0105 0106 fsd = init(); 0107 0108 fields = fieldnames(varargin{1}); 0109 for ii = 1:length(fields) 0110 field = fields{ii}; 0111 0112 %%% created -> time-object 0113 if strcmp(field, 'created') 0114 created = varargin{1}.created; 0115 if isstruct(created) 0116 created = time(created); 0117 end 0118 fsd.created = created; 0119 %%% All other 0120 else 0121 try 0122 fsd.(field) = varargin{1}.(field); 0123 catch 0124 error('### The field ''%s'' in the struct is not a fsdata property.', field) 0125 end 0126 end 0127 end 0128 0129 %%%%%%%%%% fsd = fsdata(y_vector) %%%%%%%%%% 0130 else 0131 fsd = init(); 0132 fsd.fs = 1; 0133 fsd.y = varargin{1}; 0134 0135 fsd = setFreq(fsd); 0136 end 0137 0138 % Unify the y-axis and y-axis 0139 if size(fsd.y,2) > size(fsd.y,1) 0140 fsd.y = [fsd.y].'; 0141 end 0142 if size(fsd.x, 1) ~= size(fsd.y,1) 0143 fsd.x = [fsd.x].'; 0144 end 0145 0146 %%%%%%%%%% fsd = fsdata(x_vector, y_vector) %%%%%%%%%% 0147 elseif nargin == 2 0148 %%%%%%%%%%% From DATABASE 0149 if isa(varargin{1}, 'database') 0150 fsd = retrieve(varargin{1}, varargin{2:end}); 0151 elseif length(varargin{1}) == length(varargin{2}) 0152 0153 fsd = init(); 0154 fsd.x = varargin{1}; 0155 fsd.y = varargin{2}; 0156 fsd.fs = fsd.x(end)*2; 0157 0158 if size(fsd.y,2) > size(fsd.y,1) 0159 fsd.y = [fsd.y].'; 0160 end 0161 fsd = reshapeF(fsd); 0162 0163 %%%%%%%%%% fsd = fsdata(y_vector, fs) %%%%%%%%%% 0164 else 0165 % check we have fs properly here 0166 if length(varargin{2}) > 1 0167 error(['### unknown constructor call. Either x and y should be the' ... 0168 'same length, or fs should be a single value.']); 0169 end 0170 0171 fsd = init(); 0172 fsd.y = varargin{1}; 0173 fsd.fs = varargin{2}; 0174 0175 if size(fsd.y,2) > size(fsd.y,1) 0176 fsd.y = [fsd.y].'; 0177 end 0178 fsd = setFreq(fsd); 0179 end 0180 0181 0182 %%%%%%%%%% fsd = fsdata(x_vector, y_vector, fs) %%%%%%%%%% 0183 elseif nargin == 3 0184 0185 fsd = init(); 0186 fsd.x = varargin{1}; 0187 fsd.y = varargin{2}; 0188 fsd.fs = varargin{3}; 0189 0190 if size(fsd.y,2) > size(fsd.y,1) 0191 fsd.y = [fsd.y].'; 0192 end 0193 fsd = reshapeF(fsd); 0194 else 0195 error('### Unknown number of constructor arguments.'); 0196 end 0197 0198 end