


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.
>> 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]
'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.8 2008/08/08 12:29:16 hewitson Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


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