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
       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

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

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 %       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.16 2007/10/12 15:30:16 ingo 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 
0100       %%% created -> time-object
0101       if strcmp(field, 'created')
0102         created       = varargin{1}.created;
0103         if isstruct(created)
0104           created = time(created);
0105         end
0106         fsd.created     = created;
0107       %%% All other
0108       else
0109         try
0110           fsd.(field) = varargin{1}.(field);
0111         catch
0112           error('### The field ''%s'' in the struct is not a fsdata property.', field)
0113         end
0114       end
0115     end
0116 
0117   %%%%%%%%%%  fsd = fsdata(y_vector)   %%%%%%%%%%
0118   else
0119     fsd = init();
0120     fsd.xx      = varargin{1};
0121   end
0122   if size(fsd.xx,2) > size(fsd.xx,1)
0123     fsd.xx = [fsd.xx].';
0124   end
0125 
0126 %%%%%%%%%%  fsd = fsdata(x_vector, y_vector)   %%%%%%%%%%
0127 elseif nargin == 2
0128   %%%%%%%%%%% From DATABASE
0129   if isa(varargin{1}, 'database')
0130     fsd = retrieve(varargin{1}, varargin{2:end});
0131   elseif length(varargin{1}) == length(varargin{2})
0132 
0133     fsd    = init();
0134     fsd.f  = varargin{1};
0135     fsd.xx = varargin{2};
0136     fsd.fs = fsd.f(end)*2;
0137 
0138     if size(fsd.xx,2) > size(fsd.xx,1)
0139       fsd.xx = [fsd.xx].';
0140     end
0141     fsd = reshapeF(fsd);
0142 
0143   %%%%%%%%%%  fsd = fsdata(y_vector, fs)   %%%%%%%%%%
0144   else
0145     % check we have fs properly here
0146     if length(varargin{2}) > 1
0147       error(['### unknown constructor call. Either f and xx should be the' ...
0148         'same length, or fs should be a single value.']);
0149     end
0150 
0151     fsd = init();
0152     fsd.xx      = varargin{1};
0153     fsd.fs      = varargin{2};
0154 
0155     if size(fsd.xx,2) > size(fsd.xx,1)
0156       fsd.xx = [fsd.xx].';
0157     end
0158     fsd = setFreq(fsd);
0159   end
0160 
0161 
0162 %%%%%%%%%%  fsd = fsdata(x_vector, y_vector, fs)   %%%%%%%%%%
0163 elseif nargin == 3
0164 
0165   fsd = init();
0166   fsd.f       = varargin{1};
0167   fsd.xx      = varargin{2};
0168   fsd.fs      = varargin{3};
0169 
0170   if size(fsd.xx,2) > size(fsd.xx,1)
0171     fsd.xx = [fsd.xx].';
0172   end
0173   fsd = reshapeF(fsd);
0174 else
0175   error('### Unknown number of constructor arguments.');
0176 end
0177 
0178 end

Generated on Thu 01-Nov-2007 09:42:34 by m2html © 2003