Home > classes > @fsdata > fsdata.m

fsdata

PURPOSE ^

FSDATA frequency-series object class constructor.

SYNOPSIS ^

function fsd = fsdata(varargin)

DESCRIPTION ^

 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

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

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.22 2008/03/17 09:16:36 mauro 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(version)
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(VERSION);
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(VERSION);
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   elseif isnumeric(varargin{1}) && length(varargin{1}) > 1
0133     fsd    = init(VERSION);
0134     fsd.fs = 1;
0135     fsd.y  = varargin{1};
0136 
0137     fsd    = setFreq(fsd);
0138 
0139   %%%%%%%%%%  fsd = fsdata(plist)   %%%%%%%%%%
0140   elseif isa(varargin{1}, 'plist')
0141     %% is the plist is empty then return an empty fsdata object
0142     if nparams(varargin{1}) == 0
0143       fsd = init(VERSION);
0144     else
0145       error('### Unknown fsdata constructor method.');
0146     end
0147 
0148   else
0149     error('### Unknown fsdata constructor method.');
0150   end
0151 
0152   % Unify the y-axis and y-axis
0153   if size(fsd.y,2) > size(fsd.y,1)
0154     fsd.y = [fsd.y].';
0155   end
0156   if size(fsd.x, 1) ~= size(fsd.y,1)
0157     fsd.x = [fsd.x].';
0158   end
0159 
0160 %%%%%%%%%%  fsd = fsdata(x_vector, y_vector)   %%%%%%%%%%
0161 elseif nargin == 2
0162   %%%%%%%%%%% From DATABASE
0163   if isa(varargin{1}, 'database')
0164     fsd = retrieve(varargin{1}, varargin{2:end});
0165   elseif length(varargin{1}) == length(varargin{2})
0166 
0167     fsd    = init(VERSION);
0168     fsd.x  = varargin{1};
0169     fsd.y = varargin{2};
0170     fsd.fs = fsd.x(end)*2;
0171 
0172     if size(fsd.y,2) > size(fsd.y,1)
0173       fsd.y = [fsd.y].';
0174     end
0175     fsd = reshapeF(fsd);
0176 
0177   %%%%%%%%%%  fsd = fsdata(y_vector, fs)   %%%%%%%%%%
0178   else
0179     % check we have fs properly here
0180     if length(varargin{2}) > 1
0181       error(['### unknown constructor call. Either x and y should be the' ...
0182         'same length, or fs should be a single value.']);
0183     end
0184 
0185     fsd = init(VERSION);
0186     fsd.y      = varargin{1};
0187     fsd.fs      = varargin{2};
0188 
0189     if size(fsd.y,2) > size(fsd.y,1)
0190       fsd.y = [fsd.y].';
0191     end
0192     fsd = setFreq(fsd);
0193   end
0194 
0195 
0196 %%%%%%%%%%  fsd = fsdata(x_vector, y_vector, fs)   %%%%%%%%%%
0197 elseif nargin == 3
0198 
0199   fsd = init(VERSION);
0200   fsd.x       = varargin{1};
0201   fsd.y      = varargin{2};
0202   fsd.fs      = varargin{3};
0203 
0204   if size(fsd.y,2) > size(fsd.y,1)
0205     fsd.y = [fsd.y].';
0206   end
0207   fsd = reshapeF(fsd);
0208 else
0209   error('### Unknown number of constructor arguments.');
0210 end
0211 
0212 end

Generated on Mon 31-Mar-2008 13:54:54 by m2html © 2003