Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/timeshift.m @ 0:f0afece42f48
Import.
author | Daniele Nicolodi <nicolodi@science.unitn.it> |
---|---|
date | Wed, 23 Nov 2011 19:22:13 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:f0afece42f48 |
---|---|
1 % TIMESHIFT for AO/tsdata objects, shifts data in time by the specified value in seconds. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: TIMESHIFT for AO/tsdata objects, shifts data in time by the | |
5 % specified value. | |
6 % | |
7 % This method does no fancy interpolation it just shifts the start time of | |
8 % the first sample by the given amount relative to t0. | |
9 % | |
10 % CALL: b = timeshift(a, offset) | |
11 % bs = timeshift(a1,a2,a3, offset) | |
12 % bs = timeshift(a1,a2,a3,...,pl) | |
13 % bs = timeshift(as,pl) | |
14 % bs = as.timeshift(pl) | |
15 % | |
16 % INPUTS: aN - input analysis objects | |
17 % as - input analysis objects array | |
18 % pl - input parameter list | |
19 % | |
20 % OUTPUTS: bs - array of analysis objects, one for each input | |
21 % | |
22 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'timeshift')">Parameters Description</a> | |
23 % | |
24 % VERSION: $Id: timeshift.m,v 1.33 2011/09/16 04:58:35 hewitson Exp $ | |
25 % | |
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
27 | |
28 function varargout = timeshift(varargin) | |
29 | |
30 % Check if this is a call for parameters | |
31 if utils.helper.isinfocall(varargin{:}) | |
32 varargout{1} = getInfo(varargin{3}); | |
33 return | |
34 end | |
35 | |
36 import utils.const.* | |
37 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
38 | |
39 % Collect input variable names | |
40 in_names = cell(size(varargin)); | |
41 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
42 | |
43 % Collect all AOs and plists | |
44 [as, ao_invars, rest] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
45 [pl, ~, rest] = utils.helper.collect_objects(rest(:), 'plist', in_names); | |
46 [offsetIn, ~, ~] = utils.helper.collect_objects(rest(:), 'double', in_names); | |
47 | |
48 % Decide on a deep copy or a modify | |
49 bs = copy(as, nargout); | |
50 | |
51 % Combine input and default PLIST | |
52 usepl = combine(pl, getDefaultPlist); | |
53 | |
54 % Get the offset | |
55 if ~isempty(offsetIn) | |
56 offset = offsetIn; | |
57 usepl.pset('offset', offset); | |
58 else | |
59 offset = usepl.find('offset'); | |
60 end | |
61 | |
62 % Check input analysis object | |
63 for jj = 1:numel(bs) | |
64 % Which data type do we have | |
65 switch class(bs(jj).data) | |
66 case 'tsdata' | |
67 | |
68 % Add the new offset | |
69 if ~isempty(offset) | |
70 bs(jj).data.setToffset(bs(jj).data.toffset + offset*1000); | |
71 end | |
72 | |
73 % Add history | |
74 bs(jj).addHistory(getInfo('None'), usepl, ao_invars(jj), bs(jj).hist); | |
75 | |
76 case {'fsdata', 'cdata', 'xydata'} | |
77 error('### I don''t work for frequency-series, xy and constant data.'); | |
78 | |
79 otherwise | |
80 error('### unknown data type. They can not be addded.') | |
81 end | |
82 end | |
83 | |
84 % Set output | |
85 varargout = utils.helper.setoutputs(nargout, bs); | |
86 | |
87 end | |
88 | |
89 %-------------------------------------------------------------------------- | |
90 % Get Info Object | |
91 %-------------------------------------------------------------------------- | |
92 function ii = getInfo(varargin) | |
93 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
94 sets = {}; | |
95 pl = []; | |
96 else | |
97 sets = {'Default'}; | |
98 pl = getDefaultPlist; | |
99 end | |
100 % Build info object | |
101 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.helper, '$Id: timeshift.m,v 1.33 2011/09/16 04:58:35 hewitson Exp $', sets, pl); | |
102 end | |
103 | |
104 %-------------------------------------------------------------------------- | |
105 % Get Default Plist | |
106 %-------------------------------------------------------------------------- | |
107 function plout = getDefaultPlist() | |
108 persistent pl; | |
109 if ~exist('pl', 'var') || isempty(pl) | |
110 pl = buildplist(); | |
111 end | |
112 plout = pl; | |
113 end | |
114 | |
115 function pl = buildplist() | |
116 pl = plist(); | |
117 | |
118 % offset | |
119 p = param({'offset', 'Offset in seconds to shift the data in time.'}, paramValue.DOUBLE_VALUE(0)); | |
120 pl.append(p); | |
121 | |
122 end | |
123 | |
124 |