Home > classes > @tsdata > tsdata.m

tsdata

PURPOSE ^

TSDATA time-series object class constructor.

SYNOPSIS ^

function ts = tsdata(varargin)

DESCRIPTION ^

 TSDATA time-series object class constructor.

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

 DESCRIPTION: TSDATA time-series object class constructor.
              Create a time-series data object.

     Properties:
       name    - name of time-series object
       fs      - sample rate of data
       t       - time samples vector
       x       - x samples vector
       nsecs   - the length of this time-series in seconds
       xunits  - units to interpret the time samples (e.g., seconds)
       yunits  - units to interpret the data samples (e.g., Volts)
       t0      - time-stamp of the first data sample in UTC format €˜yyyy-mm-dd HH:MM:SS€™
       created - creation time of this fsdata object in UTC format ˜yyyy-mm-dd HH:MM:SS
       version - version of the constructor code

     Possible constructors:
       ts = tsdata()      - creates a blank time-series object
       ts = tsdata(x)     - creates a time-series object with the given
                            x-data.
       ts = tsdata(t,x)   - creates a time-series object with the given
                            (t,x)-data. The sample rate is then set as
                            1/(t(2)-t(1)).
       ts = tsdata(x,fs)  - creates a time-series object with the given
                            x-data. The time vector t[] is grown from the
                            sample rate. The first sample is assigned time 0.

 HISTORY: 30-01-2007 Hewitson
             Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function ts = tsdata(varargin)
0002 % TSDATA time-series object class constructor.
0003 %
0004 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0005 %
0006 % DESCRIPTION: TSDATA time-series object class constructor.
0007 %              Create a time-series data object.
0008 %
0009 %     Properties:
0010 %       name    - name of time-series object
0011 %       fs      - sample rate of data
0012 %       t       - time samples vector
0013 %       x       - x samples vector
0014 %       nsecs   - the length of this time-series in seconds
0015 %       xunits  - units to interpret the time samples (e.g., seconds)
0016 %       yunits  - units to interpret the data samples (e.g., Volts)
0017 %       t0      - time-stamp of the first data sample in UTC format €˜yyyy-mm-dd HH:MM:SS€™
0018 %       created - creation time of this fsdata object in UTC format ˜yyyy-mm-dd HH:MM:SS
0019 %       version - version of the constructor code
0020 %
0021 %     Possible constructors:
0022 %       ts = tsdata()      - creates a blank time-series object
0023 %       ts = tsdata(x)     - creates a time-series object with the given
0024 %                            x-data.
0025 %       ts = tsdata(t,x)   - creates a time-series object with the given
0026 %                            (t,x)-data. The sample rate is then set as
0027 %                            1/(t(2)-t(1)).
0028 %       ts = tsdata(x,fs)  - creates a time-series object with the given
0029 %                            x-data. The time vector t[] is grown from the
0030 %                            sample rate. The first sample is assigned time 0.
0031 %
0032 % HISTORY: 30-01-2007 Hewitson
0033 %             Creation
0034 %
0035 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0036 
0037 ALGONAME = mfilename;
0038 VERSION  = '$Id: tsdata.html,v 1.1 2007/06/08 14:15:09 hewitson Exp $';
0039 
0040 if nargin == 0                  % create default tsdata object
0041   ts.name    = 'None';
0042   ts.t       = [];
0043   ts.x       = [];
0044   ts.fs      = 0;
0045   ts.xunits  = '';
0046   ts.yunits  = '';
0047   ts.nsecs   = 0;
0048   ts.t0      = '0000-00-00 00:00:00';
0049   ts.version = VERSION;
0050   ts.created   = sprintf('%s', datestr(now));
0051   ts = class(ts, 'tsdata');
0052 elseif nargin == 1              % create tsdata with x data
0053   if isa(varargin{1}, 'tsdata')
0054     ts = varargin{1};
0055   elseif isstruct(varargin{1})
0056     ts = class(varargin{1}, 'tsdata');
0057   else
0058     ts.name    = 'None';
0059     ts.t       = [];
0060     ts.x       = varargin{1};
0061     ts.fs      = 1;
0062     ts.xunits  = '';
0063     ts.yunits  = '';
0064     ts.nsecs   = length(ts.x)/ts.fs;
0065     ts.t0      = '0000-00-00 00:00:00';
0066     ts.version = VERSION;
0067     ts.created   = sprintf('%s', datestr(now));
0068     ts = class(ts, 'tsdata');
0069     ts = setTime(ts);
0070     if size(ts.x,2) > size(ts.x,1)
0071       ts.x = [ts.x].';
0072     end
0073   end
0074 elseif nargin == 2              % t,x data or x,fs data
0075   if length(varargin{1}) == length(varargin{2}) && length(varargin{1})>1
0076     ts.name    = 'None';
0077     ts.t       = varargin{1};
0078     ts.x       = varargin{2};
0079     ts.fs      = 1.0/(ts.t(min(2,length(ts.t)))-ts.t(1));
0080     ts.xunits  = '';
0081     ts.yunits  = '';
0082     ts.nsecs   = ts.t(end) - ts.t(1) + 1/ts.fs;
0083     ts.t0      = '0000-00-00 00:00:00';
0084     ts.version = VERSION;
0085     ts.created   = sprintf('%s', datestr(now));
0086     ts = class(ts, 'tsdata');
0087     if size(ts.x,2) > size(ts.x,1)
0088       ts.x = [ts.x].';
0089     end
0090     ts = reshapeT(ts);
0091   else
0092     % check we have fs properly here
0093     if length(varargin{2}) > 1
0094       error(['### unknown constructor call. Either t and x should be the' ...
0095              'same length, or fs should be a single value.']);
0096     end
0097     ts.name    = 'None';
0098     ts.t       = [];
0099     ts.x       = varargin{1};
0100     ts.fs      = varargin{2};
0101     ts.xunits  = '';
0102     ts.yunits  = '';
0103     ts.nsecs   = length(ts.x)/ts.fs;
0104     ts.t0      = '0000-00-00 00:00:00';
0105     ts.version = VERSION;
0106     ts.created   = sprintf('%s', datestr(now));
0107     ts = class(ts, 'tsdata');
0108     if size(ts.x,2) > size(ts.x,1)
0109       ts.x = [ts.x].';
0110     end
0111     ts = setTime(ts);
0112     
0113   end
0114 else
0115   error('### Unknown number of constructor arguments.');
0116 end
0117

Generated on Fri 08-Jun-2007 16:09:11 by m2html © 2003