Home > classes > @ao > fixfs.m

fixfs

PURPOSE ^

FIXFS resamples the input time-series to have a fixed sample rate.

SYNOPSIS ^

function varargout = fixfs(varargin)

DESCRIPTION ^

 FIXFS resamples the input time-series to have a fixed sample rate.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

 FIXFS resamples the input time-series to have a fixed sample rate.

 The new sampling grid is computed from the specified sample rate. If no
 sample rate is specified, the target is taken from a fit to the input tsdata
 object. The new sampling grid starts at the time returned from the fit
 (unless specified) and contains the same number of points or spans the
 same time as specified.

   >> bs = fixfs(as)

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

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

   Parameter list:
           'fs'   - specify the target sample rate. Either a single value
                    for all input time-series, or a vector of values, one
                    for each input. To take a fitted value from the data,
                    specify a sample rate of -1.
                    e.g.: fs = [1 2 -1 4] to work on 4 input time-series
                    [default: take from data]
 
           'Method' - Choose the behaviour
                      'Time'    - new data span the sam time [default]
                      'Samples' - new data preserves number of samples
 
           't0'   - specify start time of the sample grid. Set a single
                    value or one per input time-series. Use a value of -1
                    to take a fitted value from the data.

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

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

 M Hewitson 26-05-08

 $Id: fixfs.m,v 1.11 2008/09/05 11:05:29 ingo Exp $

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

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 % FIXFS resamples the input time-series to have a fixed sample rate.
0002 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0003 %
0004 % FIXFS resamples the input time-series to have a fixed sample rate.
0005 %
0006 % The new sampling grid is computed from the specified sample rate. If no
0007 % sample rate is specified, the target is taken from a fit to the input tsdata
0008 % object. The new sampling grid starts at the time returned from the fit
0009 % (unless specified) and contains the same number of points or spans the
0010 % same time as specified.
0011 %
0012 %   >> bs = fixfs(as)
0013 %
0014 %   Inputs:
0015 %     as  - array of analysis objects
0016 %     pl  - parameter list (see below)
0017 %
0018 %   Outputs:
0019 %     bs  - array of analysis objects, one for each input
0020 %
0021 %   Parameter list:
0022 %           'fs'   - specify the target sample rate. Either a single value
0023 %                    for all input time-series, or a vector of values, one
0024 %                    for each input. To take a fitted value from the data,
0025 %                    specify a sample rate of -1.
0026 %                    e.g.: fs = [1 2 -1 4] to work on 4 input time-series
0027 %                    [default: take from data]
0028 %
0029 %           'Method' - Choose the behaviour
0030 %                      'Time'    - new data span the sam time [default]
0031 %                      'Samples' - new data preserves number of samples
0032 %
0033 %           't0'   - specify start time of the sample grid. Set a single
0034 %                    value or one per input time-series. Use a value of -1
0035 %                    to take a fitted value from the data.
0036 %
0037 % M-FILE INFO: Get information about this methods by calling
0038 %              >> ao.getInfo('fixfs')
0039 %
0040 %              Get information about a specified set-plist by calling:
0041 %              >> ao.getInfo('fixfs', 'None')
0042 %
0043 % M Hewitson 26-05-08
0044 %
0045 % $Id: fixfs.m,v 1.11 2008/09/05 11:05:29 ingo Exp $
0046 %
0047 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
0048 
0049 function varargout = fixfs(varargin)
0050 
0051   % Check if this is a call for parameters
0052   if utils.helper.isinfocall(varargin{:})
0053     varargout{1} = getInfo(varargin{3});
0054     return
0055   end
0056 
0057   import utils.const.*
0058   utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0059   
0060   % Collect input variable names
0061   in_names = cell(size(varargin));
0062   for ii = 1:nargin,in_names{ii} = inputname(ii);end
0063 
0064   % Collect all AOs and plists
0065   [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0066   [pl, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names);
0067 
0068   % Decide on a deep copy or a modify
0069   bs = copy(as, nargout);
0070 
0071   % combine plists
0072   pl = combine(pl, getDefaultPlist());
0073 
0074   % Get fs and t0
0075   t0s    = find(pl, 't0');
0076   fss    = find(pl, 'fs');
0077   method = find(pl, 'method');
0078   
0079   if numel(fss) ~= 1 && numel(fss) < na
0080     error('### Please specify either a no sample rate, a single sample rate, or one for each input time-series.');
0081   end
0082 
0083   % Get only tsdata AOs
0084   for j=1:numel(bs)
0085     if isa(bs(j).data, 'tsdata')
0086       % record input hist
0087       hin = bs(j).hist;
0088       utils.helper.msg(msg.PROC1, 'fixing AO: %s', bs(j).name);
0089       %------------- Fit sample rate and t0
0090       [ffs, ft0] = tsdata.fitfs(bs(j).data.getX);
0091       %---------------- Get target sample rate
0092       if numel(fss) > 1
0093         fs = fss(j);
0094       else
0095         fs = fss;
0096       end
0097       if fs < 0
0098         utils.helper.msg(msg.PROC1, 'using sample rate from fit: %f', ffs);
0099         fs = ffs;
0100       end
0101       %---------------- Get target start time
0102       if numel(t0s) > 1
0103         t0 = t0s(j);
0104       else
0105         t0 = t0s;
0106       end
0107       if t0 < 0
0108         utils.helper.msg(msg.PROC1, 'using start time from fit: %f', ft0);
0109         t0 = ft0;
0110       end
0111       t0 = t0 + bs(j).data.getX(1);
0112       %-------------- Compute new grid
0113       switch method
0114         case 'Samples'
0115           N = length(bs(j).data.y);
0116           t = linspace(t0, (N-1)/fs, N);
0117         case 'Time'
0118           Nsecs = bs(j).data.nsecs;
0119           t = t0 + [0:1/fs:Nsecs-1/fs].';
0120         otherwise
0121           error('### Unknown interpolation method. Do you want to preserve data duration or number of samples?');
0122       end
0123       %-------------- Interpolate
0124       interp(bs(j), plist('vertices', t));
0125       % Add history
0126       bs(j).addHistory(getInfo, pl, ao_invars(j), hin);
0127       % Set name
0128       bs(j).setName(sprintf('%s(%s)', mfilename, ao_invars{j}), 'internal');
0129     else
0130       warning('!!! Skipping AO %s - it''s not a time-series AO.', ao_invars{j});
0131       bs(j) = [];
0132     end
0133   end
0134 
0135   % Set output
0136   if nargout > 0
0137     varargout{1} = bs;
0138   end
0139 end
0140 
0141 %--------------------------------------------------------------------------
0142 % Get Info Object
0143 %--------------------------------------------------------------------------
0144 function ii = getInfo(varargin)
0145   if nargin == 1 && strcmpi(varargin{1}, 'None')
0146     sets = {};
0147     pl   = [];
0148   else
0149     sets = {'Default'};
0150     pl   = getDefaultPlist;
0151   end
0152   % Build info object
0153   ii = minfo(mfilename, 'ao', '', utils.const.categories.sigproc, '$Id: fixfs.m,v 1.11 2008/09/05 11:05:29 ingo Exp $', sets, pl);
0154 end
0155 
0156 %--------------------------------------------------------------------------
0157 % Get Default Plist
0158 %--------------------------------------------------------------------------
0159 function pl_default = getDefaultPlist()
0160   pl_default = plist('fs', -1, 't0', -1, 'Method', 'Time');
0161 end
0162 
0163

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