comparison m-toolbox/classes/@ao/zeropad.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 % ZEROPAD zero pads the input data series.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: ZEROPAD zero pads the input data series.
5 %
6 % CALL: b = zeropad(a, pl)
7 %
8 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'zeropad')">Parameters Description</a>
9 %
10 % VERSION: $Id: zeropad.m,v 1.28 2011/04/08 08:56:15 hewitson Exp $
11 %
12 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
13
14 function varargout = zeropad(varargin)
15
16 % Check if this is a call for parameters
17 if utils.helper.isinfocall(varargin{:})
18 varargout{1} = getInfo(varargin{3});
19 return
20 end
21
22 import utils.const.*
23 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename);
24
25 % Collect input variable names
26 in_names = cell(size(varargin));
27 for ii = 1:nargin,in_names{ii} = inputname(ii);end
28
29 % Collect all AOs and plists
30 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names);
31 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names);
32
33 %%% Decide on a deep copy or a modify
34 bs = copy(as, nargout);
35
36 % combine plists
37 pl = parse(pl, getDefaultPlist());
38
39 % Extract necessary parameters
40 Factor = find(pl, 'Factor');
41 N = find(pl, 'N');
42 pos = find(pl, 'position');
43
44 if isempty(Factor) && isempty(N)
45 error('### Specify either a padding Factor, or a number of samples.');
46 end
47
48 % Loop over input AOs
49 for j=1:numel(bs)
50 if ~isa(bs(j).data, 'tsdata')
51 error('Zero padding only works on time-series. AO %s is not a time-series.', ao_invars{j});
52 else
53 % Check the time-series is evenly samples
54 if ~isempty(bs(j).data.x)
55 error('### Zero padding only makes sense on evenly sampled time-series. Resample first.');
56 end
57 if isempty(N)
58 if Factor < 2
59 error('### Padding factor must be >= 2')
60 end
61 if strcmpi(pos, 'pre')
62 bs(j).data.setY([repmat(zeros(size(bs(j).data.getY)), Factor-1, 1); bs(j).data.getY]);
63 elseif strcmpi(pos, 'post')
64 bs(j).data.setY([bs(j).data.getY; repmat(zeros(size(bs(j).data.getY)), Factor-1, 1)]);
65 else
66 error('Unknown ''position'' to pad. Choose either ''pre'' or ''post'' for the ''position'' value.');
67 end
68 else
69 if N > 0
70 if strcmpi(pos, 'pre')
71 bs(j).data.setY([zeros(N,1); bs(j).data.getY]);
72 elseif strcmpi(pos, 'post')
73 bs(j).data.setY([bs(j).data.getY; zeros(N,1)]);
74 else
75 error('Unknown ''position'' to pad. Choose either ''pre'' or ''post'' for the ''position'' value.');
76 end
77 else
78 error('### Number of samples to pad must be > 0');
79 end
80 end
81 % Set name
82 bs(j).name = sprintf('zeropad(%s)', ao_invars{j});
83 % Correct Nsecs
84 bs(j).data.fixNsecs;
85 % Add history
86 bs(j).addHistory(getInfo('None'), pl, ao_invars(j), bs(j).hist);
87 % clear errors
88 bs(j).clearErrors;
89 end
90 end
91
92 % Set output
93 if nargout == numel(bs)
94 % List of outputs
95 for ii = 1:numel(bs)
96 varargout{ii} = bs(ii);
97 end
98 else
99 % Single output
100 varargout{1} = bs;
101 end
102 end
103
104 %--------------------------------------------------------------------------
105 % Get Info Object
106 %--------------------------------------------------------------------------
107 function ii = getInfo(varargin)
108 if nargin == 1 && strcmpi(varargin{1}, 'None')
109 sets = {};
110 pl = [];
111 else
112 sets = {'Default'};
113 pl = getDefaultPlist;
114 end
115 % Build info object
116 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: zeropad.m,v 1.28 2011/04/08 08:56:15 hewitson Exp $', sets, pl);
117 end
118
119 %--------------------------------------------------------------------------
120 % Get Default Plist
121 %--------------------------------------------------------------------------
122 function plout = getDefaultPlist()
123 persistent pl;
124 if exist('pl', 'var')==0 || isempty(pl)
125 pl = buildplist();
126 end
127 plout = pl;
128 end
129
130 function pl = buildplist()
131 pl = plist();
132
133 % Factor
134 p = param({'Factor', 'Pad to <Factor> times the input data length.'}, paramValue.DOUBLE_VALUE(2));
135 pl.append(p);
136
137 % N
138 p = param({'N', 'Pad with N zero samples.'}, paramValue.EMPTY_DOUBLE);
139 pl.append(p);
140
141 % Position
142 p = param({'Position', 'Where to pad: before or after.'}, {2, {'pre', 'post'}, paramValue.SINGLE});
143 pl.append(p);
144
145
146 end
147 % END
148
149
150 % PARAMETERS: 'Factor' - Pad to <Factor> times the input data length
151 % [default: 2]
152 % or
153 % 'N' - Pad with N zero samples
154