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.20 2008/02/13 10:13:53 ingo Exp $'; 0044 CATEGORY = 'Constructor'; 0045 0046 %%%%% Is this a 'Params' call? %%%%% 0047 if nargin == 2 && isa(varargin{1}, 'fsdata') && ischar(varargin{2}) 0048 if strcmp(varargin{2}, 'Params') 0049 fsd = plist(); 0050 return 0051 elseif strcmp(varargin{2}, 'Version') 0052 fsd = VERSION; 0053 return 0054 elseif strcmp(varargin{2}, 'Category') 0055 fsd = CATEGORY; 0056 return 0057 end 0058 end 0059 0060 %%%%%%%%%%%%%%%%%%%%%%%% define fsdata properties %%%%%%%%%%%%%%%%%%%%%%%%% 0061 0062 function fs = init() 0063 fs.name = 'None'; 0064 fs.x = []; 0065 fs.y = []; 0066 fs.enbw = []; 0067 fs.navs = []; 0068 fs.fs = 0; 0069 fs.xunits = 'Hz'; 0070 fs.yunits = ''; 0071 fs.version = VERSION; 0072 fs.created = time; 0073 fs = class(fs, 'fsdata'); 0074 end 0075 0076 %%%%%%%%%%%%%%%%%%%%%%%%%% Create fsdata object %%%%%%%%%%%%%%%%%%%%%%%%%%% 0077 0078 %%%%%%%%%% fsd = fsdata() %%%%%%%%%% 0079 % create default fsdata object 0080 if nargin == 0 0081 0082 fsd = init(); 0083 0084 elseif nargin == 1 0085 %%%%%%%%%%% From File %%%%%%%%%%%%%%%% 0086 if ischar(varargin{1}) 0087 0088 filename = varargin{1}; 0089 [path, name, ext, vers] = fileparts(filename); 0090 switch ext 0091 case '.mat' 0092 fsd = load(filename); 0093 fsd = fsd.a; 0094 case '.xml' 0095 root_node = xmlread(filename); 0096 fsd = ltpda_xmlread(root_node, 'fsdata'); 0097 otherwise 0098 error('### Unknown file type.'); 0099 end 0100 %%%%%%%%%% fsd = fsdata(fsdata) %%%%%%%%%% 0101 elseif isa(varargin{1}, 'fsdata') 0102 0103 fsd = varargin{1}; 0104 0105 %%%%%%%%%% fsd = fsdata(struct) %%%%%%%%%% 0106 elseif isstruct(varargin{1}) 0107 0108 fsd = init(); 0109 0110 fields = fieldnames(varargin{1}); 0111 for ii = 1:length(fields) 0112 field = fields{ii}; 0113 0114 %%% created -> time-object 0115 if strcmp(field, 'created') 0116 created = varargin{1}.created; 0117 if isstruct(created) 0118 created = time(created); 0119 end 0120 fsd.created = created; 0121 %%% All other 0122 else 0123 try 0124 fsd.(field) = varargin{1}.(field); 0125 catch 0126 error('### The field ''%s'' in the struct is not a fsdata property.', field) 0127 end 0128 end 0129 end 0130 0131 %%%%%%%%%% fsd = fsdata(y_vector) %%%%%%%%%% 0132 else 0133 fsd = init(); 0134 fsd.fs = 1; 0135 fsd.y = varargin{1}; 0136 0137 fsd = setFreq(fsd); 0138 end 0139 0140 % Unify the y-axis and y-axis 0141 if size(fsd.y,2) > size(fsd.y,1) 0142 fsd.y = [fsd.y].'; 0143 end 0144 if size(fsd.x, 1) ~= size(fsd.y,1) 0145 fsd.x = [fsd.x].'; 0146 end 0147 0148 %%%%%%%%%% fsd = fsdata(x_vector, y_vector) %%%%%%%%%% 0149 elseif nargin == 2 0150 %%%%%%%%%%% From DATABASE 0151 if isa(varargin{1}, 'database') 0152 fsd = retrieve(varargin{1}, varargin{2:end}); 0153 elseif length(varargin{1}) == length(varargin{2}) 0154 0155 fsd = init(); 0156 fsd.x = varargin{1}; 0157 fsd.y = varargin{2}; 0158 fsd.fs = fsd.x(end)*2; 0159 0160 if size(fsd.y,2) > size(fsd.y,1) 0161 fsd.y = [fsd.y].'; 0162 end 0163 fsd = reshapeF(fsd); 0164 0165 %%%%%%%%%% fsd = fsdata(y_vector, fs) %%%%%%%%%% 0166 else 0167 % check we have fs properly here 0168 if length(varargin{2}) > 1 0169 error(['### unknown constructor call. Either x and y should be the' ... 0170 'same length, or fs should be a single value.']); 0171 end 0172 0173 fsd = init(); 0174 fsd.y = varargin{1}; 0175 fsd.fs = varargin{2}; 0176 0177 if size(fsd.y,2) > size(fsd.y,1) 0178 fsd.y = [fsd.y].'; 0179 end 0180 fsd = setFreq(fsd); 0181 end 0182 0183 0184 %%%%%%%%%% fsd = fsdata(x_vector, y_vector, fs) %%%%%%%%%% 0185 elseif nargin == 3 0186 0187 fsd = init(); 0188 fsd.x = varargin{1}; 0189 fsd.y = varargin{2}; 0190 fsd.fs = varargin{3}; 0191 0192 if size(fsd.y,2) > size(fsd.y,1) 0193 fsd.y = [fsd.y].'; 0194 end 0195 fsd = reshapeF(fsd); 0196 else 0197 error('### Unknown number of constructor arguments.'); 0198 end 0199 0200 end