0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037 function varargout = consolidate(varargin)
0038
0039
0040 if utils.helper.isinfocall(varargin{:})
0041 varargout{1} = getInfo(varargin{3});
0042 return
0043 end
0044
0045 import utils.const.*
0046 utils.helper.msg(msg.MNAME, 'running %s/%s', mfilename('class'), mfilename);
0047
0048
0049 in_names = cell(size(varargin));
0050 for ii = 1:nargin,in_names{ii} = inputname(ii);end
0051
0052
0053 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
0054 [pl, pl_invars] = utils.helper.collect_objects(varargin(:), 'plist', in_names);
0055
0056
0057 bs = copy(as, nargout);
0058 na = numel(bs);
0059
0060
0061 pl = combine(pl, getDefaultPlist);
0062
0063
0064 inhists = [];
0065 for j=1:na
0066 if ~isa(bs(j).data, 'tsdata')
0067 bs(j) = [];
0068 warning('!!! Skipping AO %s - it''s not a time-series AO.', bs(j).name);
0069 else
0070
0071 inhists = [inhists bs(j).hist];
0072 end
0073 end
0074
0075
0076 utils.helper.msg(msg.PROC1, 'drop duplicates');
0077 for j=1:na
0078 utils.helper.msg(msg.PROC2, 'processing %s', bs(j).name);
0079 dropduplicates(bs(j));
0080 end
0081
0082
0083 utils.helper.msg(msg.PROC1, 'interpolate missing samples');
0084 for j=1:na
0085 utils.helper.msg(msg.PROC2, 'processing %s', bs(j).name);
0086 interpmissing(bs(j));
0087 end
0088
0089
0090 utils.helper.msg(msg.PROC1, 'fixing uneven sample rates');
0091 for j=1:na
0092 utils.helper.msg(msg.PROC2, 'processing %s', bs(j).name);
0093 fixfs(bs(j));
0094 end
0095
0096 utils.helper.msg(msg.PROC1, 'resample to same fs');
0097
0098
0099 fs = find(pl, 'fs');
0100 if isempty(fs)
0101
0102 fs = 0;
0103 for j=1:na
0104 if bs(j).data.fs > fs
0105 fs = bs(j).data.fs;
0106 end
0107 end
0108 end
0109 utils.helper.msg(msg.PROC2, 'resampling all time-series to an fs of %f', fs);
0110
0111 for j=1:na
0112
0113 [P,Q] = utils.math.intfact(fs,bs(j).data.fs);
0114 if P > 100 || Q > 100
0115 utils.helper.msg(msg.PROC2, 'resampling factor too high [%g/%g]. Trying interpolation', P, Q);
0116 N = length(bs(j).data.getX);
0117 t0 = bs(j).data.getX(1);
0118 t = linspace(t0, t0+(P*N/Q-1)/fs, P*N/Q);
0119 interp(bs(j), plist('vertices', t));
0120 else
0121 resample(bs(j), plist('fsout', fs));
0122 end
0123 end
0124
0125
0126
0127 utils.helper.msg(msg.PROC1, 'resample to same grid');
0128
0129 for j=1:na
0130 N = length(bs(j).data.getX);
0131 t = linspace(0, (N-1)/fs, N);
0132 interp(bs(j), plist('vertices', t));
0133 end
0134
0135
0136
0137 start = 0;
0138 for j=1:na
0139 dstart = bs(j).data.t0.utc_epoch_milli/1000 + bs(j).data.getX(1);
0140 if dstart > start
0141 start = dstart;
0142 end
0143 end
0144
0145
0146 stop = 1e20;
0147 for j=1:na
0148 dstop = floor(bs(j).data.t0.utc_epoch_milli/1000 + bs(j).data.getX(end));
0149 if dstop < stop
0150 stop = dstop;
0151 end
0152 end
0153
0154
0155
0156 utils.helper.msg(msg.PROC1, 'truncate all vectors');
0157 utils.helper.msg(msg.PROC2, 'truncating vectors on interval [%g,%g]', start, stop);
0158
0159
0160 bs = split(bs, plist('split_type', 'times', 'times', [start stop]));
0161
0162 nsecs = [];
0163 for j=1:na
0164 if isempty(nsecs)
0165 nsecs = bs(j).data.nsecs;
0166 end
0167 if nsecs ~= bs(j).data.nsecs
0168 error('### Something went wrong with the truncation. Vectors don''t span the same time period.');
0169 end
0170 end
0171
0172
0173
0174 for j=1:na
0175 bs(j).addHistory(getInfo, pl, ao_invars(j), inhists(j));
0176 bs(j).setName(sprintf('%s(%s)', mfilename, ao_invars{j}), 'internal');
0177 end
0178
0179 if nargout > 0
0180 varargout{1} = bs;
0181 end
0182 end
0183
0184
0185
0186
0187 function ii = getInfo(varargin)
0188 if nargin == 1 && strcmpi(varargin{1}, 'None')
0189 sets = {};
0190 pl = [];
0191 else
0192 sets = {'Default'};
0193 pl = getDefaultPlist;
0194 end
0195
0196 ii = minfo(mfilename, 'ao', '', 'Signal Processing', '$Id: consolidate.m,v 1.12 2008/08/08 12:29:16 hewitson Exp $', sets, pl);
0197 end
0198
0199
0200
0201
0202 function pl_default = getDefaultPlist()
0203 pl_default = plist('fs', []);
0204 end
0205