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 f - frequency samples vector xx - xx 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(xx) - creates a frequency-series object with the given xx-data. Sample rate of the data is assumed to be 1Hz. fsd = fsdata(f,xx) - creates a frequency-series object with the given (f,xx)-data. The sample rate is then set as 2*f(end). fsd = fsdata(xx,fs) - creates a frequency-series object with the given xx-data and sample rate. The frequency vector is grown assuming the first xx sample corresponds to 0Hz and the last sample corresponds to the Nyquist frequency. fsd = fsdata(f,xx,fs) - creates a frequency-series object with the given f,xx-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 % f - frequency samples vector 0012 % xx - xx 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(xx) - creates a frequency-series object with the given 0024 % xx-data. Sample rate of the data is assumed to 0025 % be 1Hz. 0026 % fsd = fsdata(f,xx) - creates a frequency-series object with the given 0027 % (f,xx)-data. The sample rate is then set as 0028 % 2*f(end). 0029 % fsd = fsdata(xx,fs) - creates a frequency-series object with the given 0030 % xx-data and sample rate. The frequency 0031 % vector is grown assuming the first xx 0032 % sample corresponds to 0Hz and the last 0033 % sample corresponds to the Nyquist 0034 % frequency. 0035 % fsd = fsdata(f,xx,fs) - creates a frequency-series object with the given 0036 % f,xx-data and sample rate. 0037 % 0038 % HISTORY: 30-01-2007 Hewitson 0039 % Creation 0040 % 0041 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0042 0043 VERSION = '$Id: fsdata.m,v 1.15 2007/08/31 17:40:09 hewitson Exp $'; 0044 0045 %%%%%%%%%%%%%%%%%%%%%%%% define fsdata properties %%%%%%%%%%%%%%%%%%%%%%%%% 0046 0047 function fs = init() 0048 fs.name = 'None'; 0049 fs.f = []; 0050 fs.xx = []; 0051 fs.enbw = []; 0052 fs.navs = []; 0053 fs.fs = 0; 0054 fs.xunits = 'Hz'; 0055 fs.yunits = ''; 0056 fs.version = VERSION; 0057 fs.created = time; 0058 fs = class(fs, 'fsdata'); 0059 end 0060 0061 %%%%%%%%%%%%%%%%%%%%%%%%%% Create fsdata object %%%%%%%%%%%%%%%%%%%%%%%%%%% 0062 0063 %%%%%%%%%% fsd = fsdata() %%%%%%%%%% 0064 % create default fsdata object 0065 if nargin == 0 0066 0067 fsd = init(); 0068 0069 elseif nargin == 1 0070 %%%%%%%%%% Create from XML fragment %%%%%%%%%%% 0071 if isa(varargin{1}, 'org.apache.xerces.dom.DeferredElementImpl') 0072 fsd = fromxml(varargin{1}); 0073 %%%%%%%%%%% From File %%%%%%%%%%%%%%%% 0074 elseif ischar(varargin{1}) 0075 0076 filename = varargin{1}; 0077 [path, name, ext, vers] = fileparts(filename); 0078 switch ext 0079 case '.mat' 0080 fsd = load(filename); 0081 case '.xml' 0082 fsd = xmlparse(fsdata, filename); 0083 otherwise 0084 error('### Unknown file type.'); 0085 end 0086 %%%%%%%%%% fsd = fsdata(fsdata) %%%%%%%%%% 0087 elseif isa(varargin{1}, 'fsdata') 0088 0089 fsd = varargin{1}; 0090 0091 %%%%%%%%%% fsd = fsdata(struct) %%%%%%%%%% 0092 elseif isstruct(varargin{1}) 0093 0094 fsd = init(); 0095 0096 fields = fieldnames(varargin{1}); 0097 for ii = 1:length(fields) 0098 field = fields{ii}; 0099 try 0100 fsd.(field) = varargin{1}.(field); 0101 catch 0102 error('### The field ''%s'' in the struct is not a fsdata property.', field) 0103 end 0104 end 0105 0106 %%%%%%%%%% fsd = fsdata(y_vector) %%%%%%%%%% 0107 else 0108 fsd = init(); 0109 fsd.xx = varargin{1}; 0110 end 0111 if size(fsd.xx,2) > size(fsd.xx,1) 0112 fsd.xx = [fsd.xx].'; 0113 end 0114 0115 %%%%%%%%%% fsd = fsdata(x_vector, y_vector) %%%%%%%%%% 0116 elseif nargin == 2 0117 %%%%%%%%%%% From DATABASE 0118 if isa(varargin{1}, 'database') 0119 fsd = retrieve(varargin{1}, varargin{2:end}); 0120 elseif length(varargin{1}) == length(varargin{2}) 0121 0122 fsd = init(); 0123 fsd.f = varargin{1}; 0124 fsd.xx = varargin{2}; 0125 fsd.fs = fsd.f(end)*2; 0126 0127 if size(fsd.xx,2) > size(fsd.xx,1) 0128 fsd.xx = [fsd.xx].'; 0129 end 0130 fsd = reshapeF(fsd); 0131 0132 %%%%%%%%%% fsd = fsdata(y_vector, fs) %%%%%%%%%% 0133 else 0134 % check we have fs properly here 0135 if length(varargin{2}) > 1 0136 error(['### unknown constructor call. Either f and xx should be the' ... 0137 'same length, or fs should be a single value.']); 0138 end 0139 0140 fsd = init(); 0141 fsd.xx = varargin{1}; 0142 fsd.fs = varargin{2}; 0143 0144 if size(fsd.xx,2) > size(fsd.xx,1) 0145 fsd.xx = [fsd.xx].'; 0146 end 0147 fsd = setFreq(fsd); 0148 end 0149 0150 0151 %%%%%%%%%% fsd = fsdata(x_vector, y_vector, fs) %%%%%%%%%% 0152 elseif nargin == 3 0153 0154 fsd = init(); 0155 fsd.f = varargin{1}; 0156 fsd.xx = varargin{2}; 0157 fsd.fs = varargin{3}; 0158 0159 if size(fsd.xx,2) > size(fsd.xx,1) 0160 fsd.xx = [fsd.xx].'; 0161 end 0162 fsd = reshapeF(fsd); 0163 else 0164 error('### Unknown number of constructor arguments.'); 0165 end 0166 0167 end