Home > classes > @ao > interpmissing.m

interpmissing

PURPOSE ^

INTERPMISSING interpolate missing samples in a time-series.

SYNOPSIS ^

function varargout = interpmissing(varargin)

DESCRIPTION ^

 INTERPMISSING interpolate missing samples in a time-series.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 INTERPMISSING interpolate missing samples in a time-series. Missing samples
               are identified as being those where the time-span between one
               sample and the next is larger than d/fs where d is a
               tolerance value. Missing data is then placed in the gap in
               steps of 1/fs. Obviously this is only really correct for
               evenly sampled time-series.

 CALL:        bs = interpmissing(as)

 INPUTS:      as  - array of analysis objects
              pl  - parameter list (see below)

 OUTPUTS:     bs  - array of analysis objects, one for each input

 PARAMETER LIST:
              'd'   - specify tolerance for finding missing samples.
                      [default: 1.5]

 M-FILE INFO: Get information about this methods by calling
              >> ao.getInfo('interpmissing')

              Get information about a specified set-plist by calling:
              >> ao.getInfo('interpmissing', 'None')

 VERSION:     $Id: interpmissing.m,v 1.12 2008/09/08 08:31:18 hewitson Exp $

 HISTORY:     22-05-08 M Hewitson
                 Creation

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % INTERPMISSING interpolate missing samples in a time-series.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % INTERPMISSING interpolate missing samples in a time-series. Missing samples
0005 %               are identified as being those where the time-span between one
0006 %               sample and the next is larger than d/fs where d is a
0007 %               tolerance value. Missing data is then placed in the gap in
0008 %               steps of 1/fs. Obviously this is only really correct for
0009 %               evenly sampled time-series.
0010 %
0011 % CALL:        bs = interpmissing(as)
0012 %
0013 % INPUTS:      as  - array of analysis objects
0014 %              pl  - parameter list (see below)
0015 %
0016 % OUTPUTS:     bs  - array of analysis objects, one for each input
0017 %
0018 % PARAMETER LIST:
0019 %              'd'   - specify tolerance for finding missing samples.
0020 %                      [default: 1.5]
0021 %
0022 % M-FILE INFO: Get information about this methods by calling
0023 %              >> ao.getInfo('interpmissing')
0024 %
0025 %              Get information about a specified set-plist by calling:
0026 %              >> ao.getInfo('interpmissing', 'None')
0027 %
0028 % VERSION:     $Id: interpmissing.m,v 1.12 2008/09/08 08:31:18 hewitson Exp $
0029 %
0030 % HISTORY:     22-05-08 M Hewitson
0031 %                 Creation
0032 %
0033 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0034 
0035 function varargout = interpmissing(varargin)
0036 
0037   % Check if this is a call for parameters
0038   if utils.helper.isinfocall(varargin{:})
0039     varargout{1} = getInfo(varargin{3});
0040     return
0041   end
0042 
0043   import utils.const.*
0044   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0045   
0046   % Collect input variable names
0047   in_names = cell(size(varargin));
0048   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0049 
0050   % Collect all AOs and plists
0051   [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0052   [pl, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names);
0053 
0054   % Decide on a deep copy or a modify
0055   bs = copy(as, nargout);
0056 
0057   % Combine plists
0058   pl = combine(pl, getDefaultPlist);
0059 
0060   % Get tolerance
0061   dtol = find(pl, 'd');
0062 
0063   % Get only tsdata AOs
0064   for j=1:numel(bs)
0065     if isa(bs(j).data, 'tsdata')
0066 
0067       % capture input history
0068       ih = bs(j).hist;
0069 
0070       % find missing samples
0071       t    = [];
0072       d    = diff(bs(j).data.getX);
0073       idxs = find(d>dtol/bs(j).data.fs);
0074       utils.helper.msg(msg.PROC1, 'found %d data gaps', numel(idxs));
0075 
0076       % create new time grid
0077       count = 0;
0078       for k=1:numel(idxs)
0079         idx = idxs(k);
0080         if isempty(t)
0081           t   = bs(j).data.getX(1+idx-idxs(1):idx);
0082         end
0083         % now add samples at 1/fs until we are within 1/fs of the next sample
0084         while bs(j).data.getX(idx+1)-t(end) > 1/bs(j).data.fs
0085           t(end+1) = t(end)+1/bs(j).data.fs;
0086           count = count + 1;
0087         end
0088         if k==numel(idxs)
0089           t = [t; bs(j).data.getX(idx+1:end)];
0090         else
0091           t = [t; bs(j).data.getX(idx+1:idxs(k+1))];
0092         end
0093       end
0094       utils.helper.msg(msg.PROC1, 'filled with %d samples', count);
0095 
0096       % now interpolate onto this new time-grid
0097       if ~isempty(t)
0098         interp(bs(j), plist('vertices', t));
0099         bs(j).setName(sprintf('interpmissing(%s)', ao_invars{j}), 'internal');
0100         % Add history
0101         bs(j).addHistory(getInfo, pl, ao_invars(j), ih);
0102       else
0103         utils.helper.msg(msg.PROC1, 'no missing samples found in %s - no action performed.', ao_invars{j});
0104       end
0105     else
0106       utils.helper.msg(msg.PROC1, 'skipping AO %s - it''s not a time-series AO.', ao_invars{j});
0107     end
0108   end
0109 
0110   % Set output
0111   if nargout > 0
0112     varargout{1} = bs;
0113   end
0114 end
0115 
0116 %--------------------------------------------------------------------------
0117 % Get Info Object
0118 %--------------------------------------------------------------------------
0119 function ii = getInfo(varargin)
0120   if nargin == 1 && strcmpi(varargin{1}, 'None')
0121     sets = {};
0122     pl   = [];
0123   else
0124     sets = {'Default'};
0125     pl   = getDefaultPlist;
0126   end
0127   % Build info object
0128   ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: interpmissing.m,v 1.12 2008/09/08 08:31:18 hewitson Exp $', sets, pl);
0129 end
0130 
0131 %--------------------------------------------------------------------------
0132 % Get Default Plist
0133 %--------------------------------------------------------------------------
0134 function pl_default = getDefaultPlist()
0135   pl_default = plist('d', 1.5);
0136 end
0137 
0138

Generated on Mon 08-Sep-2008 13:18:47 by m2html © 2003