comparison m-toolbox/classes/@ao/sumjoin.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 % SUMJOIN sums time-series signals togther
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: SUMJOIN sums time-series signals togther. The start time of
5 % each signal is taken in to account when summing. The signals
6 % are zero-padded at non-overlapping times.
7 %
8 % s1: |. . + + | 0 0 0 0 0
9 % s2: 0 0 | + + + + | 0 0
10 % s3: 0 0 0 | + + + + . |
11 %
12 % CALL: b = sumjoin(a1, a2, pl)
13 %
14 % EXAMPLES:
15 %
16 % a1 = ao(plist('tsfcn', 'randn(size(t))', 'fs', 10, 'nsecs', 10, ...
17 % 't0', 10000))
18 % a2 = ao(plist('tsfcn', 't', 'fs', 10, 'nsecs', 15, 't0', 15000))
19 % b = sumjoin(a1,a2);
20 % iplot(a1,a2,b);
21 %
22 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'sumjoin')">Parameters Description</a>
23 %
24 % VERSION: $Id: sumjoin.m,v 1.19 2011/04/08 08:56:12 hewitson Exp $
25 %
26 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
27
28 function varargout = sumjoin(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 % if nargout == 0
37 % error('### join cannot be used as a modifier. Please give an output variable.');
38 % end
39
40 import utils.const.*
41 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
42
43 % Collect input variable names
44 in_names = cell(size(varargin));
45 for ii = 1:nargin,in_names{ii} = inputname(ii);end
46
47 % Collect all AOs
48 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
49 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names);
50
51 % Copy inputs
52 bs = copy(as, nargout);
53
54 % Combine plists
55 pl = parse(pl, getDefaultPlist);
56
57 % loop over AOs to get maximum and minimum end time
58 tEnd = 0;
59 tStart = 1e20;
60 fs = bs(1).data.fs;
61 inhists = [];
62 for j=1:numel(bs)
63 % Only get the data type we want
64 if isa(bs(j).data, 'tsdata')
65 % check sample rate
66 if bs(j).data.fs ~= fs
67 error('### All input time-series must have the same sample rate.');
68 end
69 % check sampling
70 if ~bs(j).data.evenly()
71 error('### This method only works on regularly sampled time-series.');
72 end
73 % get start and stop time
74 x1 = bs(j).data.getX(1);
75 ts = x1 + bs(j).data.t0.utc_epoch_milli/1000;
76 te = bs(j).data.nsecs + ts;
77 if te > tEnd
78 tEnd = te;
79 end
80 if ts < tStart
81 tStart = ts;
82 end
83 % store input history
84 inhists = [inhists bs(j).hist];
85 else
86 error('### It is not a time-series', bs(j).name);
87 end
88 end
89
90 % clear errors
91 bs.clearErrors;
92
93 % Zero pad and sum each signal
94 name = 'sumjoin(';
95 yall = zeros((tEnd - tStart)*fs,1);
96 for kk=1:numel(bs)
97 if isa(bs(kk).data, 'tsdata')
98
99 name = sprintf('%s%s, ', name, ao_invars{kk});
100
101 x1 = bs(kk).x(1) + bs(kk).t0.utc_epoch_milli/1000;
102 xn = bs(kk).x(end) + 1/fs;
103 post = zeros((tEnd - xn - x1)*fs,1);
104 pre = zeros((x1 - tStart)*fs,1);
105 y = [pre; bs(kk).y; post];
106 yall = yall + y;
107 end
108 end
109 xall = linspace(0, (tEnd - tStart) -1/fs, (tEnd - tStart)*fs)';
110 name = [name(1:end-2) ')'];
111
112 % Fix up this AO
113 out = bs(1);
114 out.data.setXY(xall, yall);
115 out.data.fixNsecs;
116 out.data.collapseX;
117 out.name = name;
118 out.data.setT0(time(tStart));
119 out.hist = [];
120 out.addHistory(getInfo('None'), pl, ao_invars, inhists);
121
122 % Set output
123 varargout{1} = out;
124
125 end
126
127 %--------------------------------------------------------------------------
128 % Get Info Object
129 %--------------------------------------------------------------------------
130 function ii = getInfo(varargin)
131 if nargin == 1 && strcmpi(varargin{1}, 'None')
132 sets = {};
133 pl = [];
134 else
135 sets = {'Default'};
136 pl = getDefaultPlist;
137 end
138 % Build info object
139 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.op, '$Id: sumjoin.m,v 1.19 2011/04/08 08:56:12 hewitson Exp $', sets, pl);
140 end
141
142 %--------------------------------------------------------------------------
143 % Get Default Plist
144 %--------------------------------------------------------------------------
145 function plout = getDefaultPlist()
146 persistent pl;
147 if exist('pl', 'var')==0 || isempty(pl)
148 pl = buildplist();
149 end
150 plout = pl;
151 end
152
153 function pl = buildplist()
154 pl = plist.EMPTY_PLIST;
155 end
156