Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/resample.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 % RESAMPLE overloads resample function for AOs. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: RESAMPLE overloads resample function for AOs. | |
5 % | |
6 % CALL: bs = resample(a1,a2,a3,...,pl) | |
7 % bs = resample(as,pl) | |
8 % bs = as.resample(pl) | |
9 % | |
10 % INPUTS: aN - input analysis objects | |
11 % as - input analysis objects array | |
12 % pl - input parameter list | |
13 % | |
14 % OUTPUTS: bs - array of analysis objects, one for each input | |
15 % | |
16 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'resample')">Parameters Description</a> | |
17 % | |
18 % VERSION: $Id: resample.m,v 1.50 2011/07/14 05:33:18 mauro Exp $ | |
19 % | |
20 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
21 | |
22 function varargout = resample(varargin) | |
23 | |
24 % Check if this is a call for parameters | |
25 if utils.helper.isinfocall(varargin{:}) | |
26 varargout{1} = getInfo(varargin{3}); | |
27 return | |
28 end | |
29 | |
30 import utils.const.* | |
31 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
32 | |
33 % Collect input variable names | |
34 in_names = cell(size(varargin)); | |
35 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
36 | |
37 % Collect all AOs and plists | |
38 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
39 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names); | |
40 | |
41 % Decide on a deep copy or a modify | |
42 bs = copy(as, nargout); | |
43 | |
44 % Combine plists | |
45 pl = parse(pl, getDefaultPlist); | |
46 | |
47 if isempty(pl) | |
48 error('### Please give a plist with a parameter ''fsout''.'); | |
49 end | |
50 | |
51 % Get output sample rate | |
52 fsout = find(pl, 'fsout'); | |
53 if isempty(fsout) | |
54 error('### Please give a plist with a parameter ''fsout''.'); | |
55 end | |
56 | |
57 % Get a filter if specified | |
58 filt = find(pl, 'filter'); | |
59 if ~isempty(filt) && ~isa(filt, 'mfir') | |
60 error('The filter specified must be an mfir filter object (FIR filter).'); | |
61 end | |
62 | |
63 % Loop over AOs | |
64 for jj = 1:numel(bs) | |
65 if ~isa(bs(jj).data, 'tsdata') | |
66 warning('!!! Skipping non-tsdata AO: %s', ao_invars{jj}); | |
67 else | |
68 % Compute the resampling factors | |
69 [P,Q] = utils.math.intfact(fsout,bs(jj).data.fs); | |
70 utils.helper.msg(msg.PROC1, 'resampling by %g/%g', P, Q); | |
71 | |
72 % Check we have an evenly sampled data series | |
73 if ~bs(jj).data.evenly() | |
74 error('### The AO %s is unevenly sampled. It can not be resampled this way.', ao_invars{jj}); | |
75 end | |
76 % resample y | |
77 if isempty(filt) | |
78 bs(jj).data.setY(resample(bs(jj).data.getY, P, Q)); | |
79 else | |
80 [p,q] = rat( fsout/bs(jj).fs, 1e-12 ); | |
81 b = p*filt.a; | |
82 bs(jj).data.setY(resample(bs(jj).data.getY, P, Q, b)); | |
83 end | |
84 % Set new sample rate | |
85 bs(jj).data.setFs(fsout); | |
86 % Set output AO name | |
87 bs(jj).name = sprintf('resample(%s)', ao_invars{jj}); | |
88 % Add history | |
89 bs(jj).addHistory(getInfo('None'), pl, ao_invars(jj), bs(jj).hist); | |
90 % clear errors | |
91 bs(jj).clearErrors; | |
92 end | |
93 end | |
94 | |
95 % Set output | |
96 varargout = utils.helper.setoutputs(nargout, bs); | |
97 end | |
98 | |
99 %-------------------------------------------------------------------------- | |
100 % Get Info Object | |
101 %-------------------------------------------------------------------------- | |
102 function ii = getInfo(varargin) | |
103 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
104 sets = {}; | |
105 pl = []; | |
106 else | |
107 sets = {'Default'}; | |
108 pl = getDefaultPlist; | |
109 end | |
110 % Build info object | |
111 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: resample.m,v 1.50 2011/07/14 05:33:18 mauro Exp $', sets, pl); | |
112 end | |
113 | |
114 %-------------------------------------------------------------------------- | |
115 % Get Default Plist | |
116 %-------------------------------------------------------------------------- | |
117 function plout = getDefaultPlist() | |
118 persistent pl; | |
119 if ~exist('pl', 'var') || isempty(pl) | |
120 pl = buildplist(); | |
121 end | |
122 plout = pl; | |
123 end | |
124 | |
125 function pl = buildplist() | |
126 | |
127 pl = plist(); | |
128 | |
129 % Type | |
130 p = param({'fsout',['The desired output frequency<br>'... | |
131 '(must be positive and integer).']}, paramValue.EMPTY_DOUBLE); | |
132 pl.append(p); | |
133 | |
134 p = param({'filter', 'The filter to apply in the resampling process.'}, paramValue.EMPTY_STRING); | |
135 pl.append(p); | |
136 | |
137 end | |
138 % END | |
139 |