Mercurial > hg > ltpda
comparison m-toolbox/classes/@ao/delay.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 % DELAY delays a time-series using various methods. | |
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
3 % | |
4 % DESCRIPTION: DELAY delays a time-series using various methods. | |
5 % | |
6 % CALL: b = delay(a, pl) | |
7 % | |
8 % | |
9 % PARAMETERS: N - delay the time-series by N samples. [default: 0] | |
10 % Choose a 'method' for how the end of the time-series | |
11 % is handled: | |
12 % 'zero' - zero pad the time-series | |
13 % | |
14 % <a href="matlab:utils.helper.displayMethodInfo('ao', 'delay')">Parameters Description</a> | |
15 % | |
16 % EXAMPLES: 1) Shift by 10 samples and zero pad the end of the time-series | |
17 % >> b = delay(a, plist('N', 10, 'method', 'zero')); | |
18 % | |
19 % | |
20 % VERSION: $Id: delay.m,v 1.27 2011/04/08 08:56:11 hewitson Exp $ | |
21 % | |
22 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% | |
23 | |
24 % TODO | |
25 % 'extrap' - extrapolate the last N samples | |
26 | |
27 function varargout = delay(varargin) | |
28 | |
29 % Check if this is a call for parameters | |
30 if utils.helper.isinfocall(varargin{:}) | |
31 varargout{1} = getInfo(varargin{3}); | |
32 return | |
33 end | |
34 | |
35 import utils.const.* | |
36 utils.helper.msg(msg.PROC3, 'running %s/%s', mfilename('class'), mfilename); | |
37 | |
38 % Collect input variable names | |
39 in_names = cell(size(varargin)); | |
40 for ii = 1:nargin,in_names{ii} = inputname(ii);end | |
41 | |
42 % Collect all AOs | |
43 [as, ao_invars] = utils.helper.collect_objects(varargin(:), 'ao', in_names); | |
44 pl = utils.helper.collect_objects(varargin(:), 'plist', in_names); | |
45 | |
46 % Decide on a deep copy or a modify | |
47 bs = copy(as, nargout); | |
48 | |
49 % Combine plists | |
50 pl = parse(pl, getDefaultPlist); | |
51 | |
52 %----------- Get parameters | |
53 | |
54 % 1: Sample shift | |
55 N = find(pl, 'N'); | |
56 method = find(pl, 'method'); | |
57 | |
58 % Loop over AOs | |
59 for j=1:numel(bs) | |
60 if ~isa(bs(j).data, 'tsdata') | |
61 warning('!!! Skipping object %s - it contains no tsdata.', ao_invars{j}); | |
62 else | |
63 % Which method to use | |
64 switch lower(method) | |
65 case 'zero' | |
66 bs(j).data.setY([zeros(N,1); bs(j).data.getY(1:end-N)]); | |
67 otherwise | |
68 error('### Unknown method for dealing with end of time-series.'); | |
69 end | |
70 % make output analysis object | |
71 bs(j).name = sprintf('delay(%s)', ao_invars{j}); | |
72 % Add history | |
73 bs(j).addHistory(getInfo('None'), pl, ao_invars(j), bs(j).hist); | |
74 % Clear the errors since they don't make sense anymore | |
75 clearErrors(bs(j)); | |
76 end | |
77 end | |
78 | |
79 | |
80 % Set output | |
81 if nargout == numel(bs) | |
82 % List of outputs | |
83 for ii = 1:numel(bs) | |
84 varargout{ii} = bs(ii); | |
85 end | |
86 else | |
87 % Single output | |
88 varargout{1} = bs; | |
89 end | |
90 end | |
91 | |
92 %-------------------------------------------------------------------------- | |
93 % Get Info Object | |
94 %-------------------------------------------------------------------------- | |
95 function ii = getInfo(varargin) | |
96 if nargin == 1 && strcmpi(varargin{1}, 'None') | |
97 sets = {}; | |
98 pl = []; | |
99 else | |
100 sets = {'Default'}; | |
101 pl = getDefaultPlist; | |
102 end | |
103 % Build info object | |
104 ii = minfo(mfilename, 'ao', 'ltpda', utils.const.categories.sigproc, '$Id: delay.m,v 1.27 2011/04/08 08:56:11 hewitson Exp $', sets, pl); | |
105 end | |
106 | |
107 %-------------------------------------------------------------------------- | |
108 % Get Default Plist | |
109 %-------------------------------------------------------------------------- | |
110 | |
111 function plout = getDefaultPlist() | |
112 persistent pl; | |
113 if exist('pl', 'var')==0 || isempty(pl) | |
114 pl = buildplist(); | |
115 end | |
116 plout = pl; | |
117 end | |
118 | |
119 function pl = buildplist() | |
120 pl = plist(); | |
121 | |
122 % N | |
123 p = param({'N', 'The number of samples to delay by.'}, {1, {0}, paramValue.OPTIONAL}); | |
124 pl.append(p); | |
125 | |
126 % Method | |
127 p = param({'method', 'The method for handling the end of the time-series.'}, {1, {'zero'}, paramValue.SINGLE}); | |
128 pl.append(p); | |
129 end | |
130 | |
131 |