Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/interp.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 % INTERP interpolate the values in the input AO(s) at new values. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: INTERP interpolate the values in the input AO(s) at new values | |
5 % specified by the input parameter list. | |
6 % | |
7 % CALL: b = interp(a, pl) | |
8 % | |
9 % INPUTS: a - input array of AOs | |
10 % pl - parameter list with the keys 'vertices' and 'method' | |
11 % | |
12 % OUTPUTS: b - output array of AOs | |
13 % | |
14 % REMARKs: 1) Matrix cdata objects are not supported. | |
15 % 2) If a time-series object is interpolated, the sample rate | |
16 % is adjusted to the best fit of the new data. | |
17 % | |
18 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'interp')">Parameters Description</a> | |
19 % | |
20 % VERSION: $Id: interp.m,v 1.43 2011/08/23 13:49:41 hewitson Exp $ | |
21 % | |
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
23 | |
24 function varargout = interp(varargin) | |
25 | |
26 % Check if this is a call for parameters | |
27 if utils.helper.isinfocall(varargin{:}) | |
28 varargout{1} = getInfo(varargin{3}); | |
29 return | |
30 end | |
31 | |
32 import utils.const.* | |
33 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
34 | |
35 % Collect input variable names | |
36 in_names = cell(size(varargin)); | |
37 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
38 | |
39 % Collect all AOs and plists | |
40 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
41 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names); | |
42 | |
43 % Decide on a deep copy or a modify | |
44 bs = copy(as, nargout); | |
45 | |
46 % Combine plists | |
47 pl = parse(pl, getDefaultPlist); | |
48 | |
49 % Get parameters | |
50 vertices = find(pl, 'vertices'); | |
51 method = find(pl, 'method'); | |
52 | |
53 utils.helper.msg(msg.PROC1, 'using %s interpolation', method); | |
54 | |
55 %----------------------- | |
56 % Loop over input AOs | |
57 for jj = 1:numel(bs) | |
58 %---------------------------- | |
59 % Interpolate this vector | |
60 if ~isa(bs(jj).data, 'cdata') | |
61 x = bs(jj).x; | |
62 y = bs(jj).y; | |
63 dy = bs(jj).dy; | |
64 % for tsdata, fsdata and xydata objects | |
65 bs(jj).data.setXY(vertices, interp1(x,y,vertices, method, 'extrap')); | |
66 if isa(bs(jj).data, 'tsdata') | |
67 % here we have to set the toffset to 0 because that information is | |
68 % stored in the x-values until it is collapsed below. Otherwise we | |
69 % end up with double the toffset. | |
70 bs(jj).data.setToffset(0); | |
71 end | |
72 if ~isempty(dy) && numel(dy) > 1 | |
73 bs(jj).data.setDy(interp1(x, dy, vertices, method, 'extrap')); | |
74 end | |
75 if isprop(bs(jj).data, 'enbw') | |
76 if ~isempty(bs(jj).data.enbw) && numel(bs(jj).data.enbw) > 1 | |
77 bs(jj).data.setEnbw(interp1(x, bs(jj).data.enbw, vertices, method, 'extrap')); | |
78 end | |
79 end | |
80 else | |
81 % for cdata object | |
82 bs(jj).data.setY(interp1(bs(jj).data.y,vertices, method, 'extrap')); | |
83 if ~isempty(bs(jj).dy) && numel(bs(jj).dy) > 1 | |
84 bs(jj).data.setDy(interp1(bs(jj).dy, vertices, method, 'extrap')); | |
85 end | |
86 end | |
87 | |
88 % Adjust sample rate for tsdata | |
89 if isa(bs(jj).data, 'tsdata') | |
90 utils.helper.msg(msg.PROC1, 'adjusting sample rate of new data to best fit'); | |
91 [fs, t0, fitted] = tsdata.fitfs(bs(jj).data.getX); | |
92 utils.helper.msg(msg.PROC2, 'got new sample rate of %g Hz', fs); | |
93 utils.helper.msg(msg.PROC2, 'got new t0 %g', t0); | |
94 bs(jj).data.setFs(fs); | |
95 if ~fitted | |
96 bs(jj).data.collapseX; | |
97 end | |
98 end | |
99 % set name | |
100 bs(jj).name = sprintf('%s(%s)', method, ao_invars{jj}); | |
101 % Add history | |
102 bs(jj).addHistory(getInfo('None'), pl, ao_invars, bs(jj).hist); | |
103 end | |
104 | |
105 % Set output | |
106 if nargout == numel(bs) | |
107 % List of outputs | |
108 for ii = 1:numel(bs) | |
109 varargout{ii} = bs(ii); | |
110 end | |
111 else | |
112 % Single output | |
113 varargout{1} = bs; | |
114 end | |
115 end | |
116 | |
117 %-------------------------------------------------------------------------- | |
118 % Get Info Object | |
119 %-------------------------------------------------------------------------- | |
120 function ii = getInfo(varargin) | |
121 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
122 sets = {}; | |
123 pl = []; | |
124 else | |
125 sets = {'Default'}; | |
126 pl = getDefaultPlist; | |
127 end | |
128 % Build info object | |
129 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: interp.m,v 1.43 2011/08/23 13:49:41 hewitson Exp $', sets, pl); | |
130 end | |
131 | |
132 %-------------------------------------------------------------------------- | |
133 % Get Default Plist | |
134 %-------------------------------------------------------------------------- | |
135 function plout = getDefaultPlist() | |
136 persistent pl; | |
137 if exist('pl', 'var')==0 || isempty(pl) | |
138 pl = buildplist(); | |
139 end | |
140 plout = pl; | |
141 end | |
142 | |
143 function pl = buildplist() | |
144 | |
145 pl = plist(); | |
146 | |
147 % Vertices | |
148 p = param({'vertices', 'A new set of vertices to interpolate on.'}, paramValue.EMPTY_DOUBLE); | |
149 pl.append(p); | |
150 | |
151 % Method | |
152 p = param({'method', 'Specify the interpolation method.'},{3, {'nearest', 'linear', 'spline', 'cubic'}, paramValue.SINGLE}); | |
153 pl.append(p); | |
154 | |
155 end |