comparison m-toolbox/classes/@ao/upsample.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 % UPSAMPLE overloads upsample function for AOs.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: UPSAMPLE AOs containing time-series data. All other AOs with
5 % no time-series data are skipped but appear in the output.
6 %
7 % A signal at sample rate fs is upsampled by inserting N-1 zeros between the
8 % input samples.
9 %
10 % CALL: b = upsample(a, pl)
11 %
12 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'upsample')">Parameters Description</a>
13 %
14 % VERSION: $Id: upsample.m,v 1.29 2011/07/14 05:33:18 mauro Exp $
15 %
16 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
17
18 function varargout = upsample(varargin)
19
20 % Check if this is a call for parameters
21 if utils.helper.isinfocall(varargin{:})
22 varargout{1} = getInfo(varargin{3});
23 return
24 end
25
26 import utils.const.*
27 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
28
29 % Collect input variable names
30 in_names = cell(size(varargin));
31 for ii = 1:nargin,in_names{ii} = inputname(ii);end
32
33 % Collect all AOs and plists
34 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
35 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names);
36
37 % Decide on a deep copy or a modify
38 bs = copy(as, nargout);
39
40 % combine plists
41 pl = parse(pl, getDefaultPlist());
42
43
44 % Get output sample rate
45 Nup = find(pl, 'N');
46 if isempty(Nup)
47 error('### Please give a plist with a parameter ''N''.');
48 end
49 % Get initial phase
50 phase = find(pl, 'phase');
51 if isempty(phase)
52 phase = 0;
53 end
54
55 % Loop over AOs
56 for jj = 1:numel(bs)
57 if ~isa(bs(jj).data, 'tsdata')
58 warning('!!! Upsample only works on tsdata objects. Skipping AO %s', ao_invars{jj});
59 else
60 % upsample y
61 bs(jj).data.setY(upsample(bs(jj).data.y, floor(Nup), phase));
62 % Correct fs
63 bs(jj).data.setFs(floor(Nup)*bs(jj).data.fs);
64 % Set name
65 bs(jj).name = sprintf('upsample(%s)', ao_invars{jj});
66 % Add history
67 bs(jj).addHistory(getInfo('None'), pl, ao_invars(jj), bs(jj).hist);
68 % clear errors
69 bs(jj).clearErrors;
70 end
71 end
72
73 % Set output
74 varargout = utils.helper.setoutputs(nargout, bs);
75 end
76
77 %--------------------------------------------------------------------------
78 % Get Info Object
79 %--------------------------------------------------------------------------
80 function ii = getInfo(varargin)
81 if nargin == 1 && strcmpi(varargin{1}, 'None')
82 sets = {};
83 pl = [];
84 else
85 sets = {'Default'};
86 pl = getDefaultPlist;
87 end
88 % Build info object
89 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: upsample.m,v 1.29 2011/07/14 05:33:18 mauro Exp $', sets, pl);
90 end
91
92 %--------------------------------------------------------------------------
93 % Get Default Plist
94 %--------------------------------------------------------------------------
95 function plout = getDefaultPlist()
96 persistent pl;
97 if ~exist('pl', 'var') || isempty(pl)
98 pl = buildplist();
99 end
100 plout = pl;
101 end
102
103 function pl = buildplist()
104
105 pl = plist();
106
107 % N
108 p = param({'N', 'The upsample factor.'}, paramValue.DOUBLE_VALUE(1));
109 pl.append(p);
110
111 % phase
112 p = param({'phase', 'The initial phase [0, N-1].'}, paramValue.DOUBLE_VALUE(0));
113 pl.append(p);
114
115 end