Mercurial > octave
comparison scripts/signal/movfun.m @ 26261:eb1903f8bf98
movfun.m: Tweak documentation and remove spaces at EOL.
* movfun.m: Tweak documentation and remove spaces at EOL.
author | Rik <rik@octave.org> |
---|---|
date | Tue, 18 Dec 2018 14:33:35 -0800 |
parents | 9d3c22f7fff1 |
children | 00f796120a6d |
comparison
equal
deleted
inserted
replaced
26260:9d3c22f7fff1 | 26261:eb1903f8bf98 |
---|---|
20 ## Created: 2018-08-09 | 20 ## Created: 2018-08-09 |
21 | 21 |
22 ## -*- texinfo -*- | 22 ## -*- texinfo -*- |
23 ## @deftypefn {} {@var{y} =} movfun (@var{fcn}, @var{x}, @var{wlen}) | 23 ## @deftypefn {} {@var{y} =} movfun (@var{fcn}, @var{x}, @var{wlen}) |
24 ## @deftypefnx {} {@var{y} =} movfun (@var{fcn}, @var{x}, @var{[@var{nb}, @var{na}}]) | 24 ## @deftypefnx {} {@var{y} =} movfun (@var{fcn}, @var{x}, @var{[@var{nb}, @var{na}}]) |
25 ## @deftypefnx {} {@var{y} =} movfun (@dots{}, @var{property}, @var{value}) | 25 ## @deftypefnx {} {@var{y} =} movfun (@dots{}, "@var{property}", @var{value}) |
26 ## | |
26 ## Apply function @var{fcn} to a moving window of length @var{wlen} on data | 27 ## Apply function @var{fcn} to a moving window of length @var{wlen} on data |
27 ## @var{x}. | 28 ## @var{x}. |
28 ## | 29 ## |
29 ## If @var{wlen} is a scalar, the function @var{fcn} is applied to a moving | 30 ## If @var{wlen} is a scalar, the function @var{fcn} is applied to a moving |
30 ## window of length @var{wlen}. When @var{wlen} is an odd number the window is | 31 ## window of length @var{wlen}. When @var{wlen} is an odd number the window is |
31 ## symmetric and includes @w{@code{(@var{wlen} - 1) / 2}} elements on either | 32 ## symmetric and includes @w{@code{(@var{wlen} - 1) / 2}} elements on either |
32 ## side of the central element. For example, when calculating the output at | 33 ## side of the central element. For example, when calculating the output at |
33 ## index 5 with a window length of 3, @code{movfun} uses data elements | 34 ## index 5 with a window length of 3, @code{movfun} uses data elements |
34 ## @w{@code{[4, 5, 6]}}. If @var{wlen} is an even number, the window is | 35 ## @w{@code{[4, 5, 6]}}. If @var{wlen} is an even number, the window is |
35 ## asymmetric and has @w{@code{@var{wlen}/2}} elements to the left of the | 36 ## asymmetric and has @w{@code{@var{wlen}/2}} elements to the left of the |
36 ## central element | 37 ## central element and @w{@code{@var{wlen}/2 - 1}} elements to the right of the |
37 ## and @w{@code{@var{wlen}/2 - 1}} elements to the right of the central element. | 38 ## central element. For example, when calculating the output at index 5 with a |
38 ## For example, when calculating the output at index 5 with a window length of | 39 ## window length of 4, @code{movfun} uses data elements |
39 ## 4, @code{movfun} uses data elements @w{@code{[3, 4, 5, 6]}}. | 40 ## @w{@code{[3, 4, 5, 6]}}. |
40 ## | 41 ## |
41 ## If @var{wlen} is an array with two elements @w{@code{[@var{nb}, @var{na}]}}, | 42 ## If @var{wlen} is an array with two elements @w{@code{[@var{nb}, @var{na}]}}, |
42 ## the function is applied to a moving window @code{-@var{nb}:@var{na}}. This | 43 ## the function is applied to a moving window @code{-@var{nb}:@var{na}}. This |
43 ## window includes @var{nb} number of elements @strong{before} the current | 44 ## window includes @var{nb} number of elements @emph{before} the current |
44 ## element and @var{na} number of elements @strong{after} the current element. | 45 ## element and @var{na} number of elements @emph{after} the current element. |
45 ## The current element is always included. For example, given | 46 ## The current element is always included. For example, given |
46 ## @w{@code{@var{wlen} = [3, 0]}}, the data used to calculate index 5 is | 47 ## @w{@code{@var{wlen} = [3, 0]}}, the data used to calculate index 5 is |
47 ## @w{@code{[2, 3, 4, 5]}}. | 48 ## @w{@code{[2, 3, 4, 5]}}. |
48 ## | 49 ## |
49 ## During calculations the data input @var{x} is reshaped into a 2-dimensional | 50 ## During calculations the data input @var{x} is reshaped into a 2-dimensional |
129 ## Note that for some of these choices, the window size at the boundaries is | 130 ## Note that for some of these choices, the window size at the boundaries is |
130 ## not the same as for the central part, and @var{fcn} must work in these | 131 ## not the same as for the central part, and @var{fcn} must work in these |
131 ## cases. | 132 ## cases. |
132 ## | 133 ## |
133 ## @item @qcode{"nancond"} | 134 ## @item @qcode{"nancond"} |
134 ## Controls whether @code{NaN} or @code{NA} values should be included (value: | 135 ## Controls whether @code{NaN} and @code{NA} values should be included (value: |
135 ## @qcode{"includenan"}), or excluded (value: @qcode{"omitnan"}), from the data | 136 ## @qcode{"includenan"}), or excluded (value: @qcode{"omitnan"}), from the data |
136 ## passed to @var{fcn}. The default is @qcode{"includenan"}. Caution: | 137 ## passed to @var{fcn}. The default is @qcode{"includenan"}. Caution: |
137 ## The @qcode{"omitnan"} option is not yet implemented. | 138 ## The @qcode{"omitnan"} option is not yet implemented. |
138 ## | 139 ## |
139 ## @item @qcode{"outdim"} | 140 ## @item @qcode{"outdim"} |
196 szx = size (x); | 197 szx = size (x); |
197 if (isempty (dim)) | 198 if (isempty (dim)) |
198 (dim = find (szx > 1, 1)) || (dim = 1); | 199 (dim = find (szx > 1, 1)) || (dim = 1); |
199 endif | 200 endif |
200 | 201 |
201 N = szx(dim); | 202 N = szx(dim); |
202 | 203 |
203 ## Calculate slicing indices. This call also validates WLEN input. | 204 ## Calculate slicing indices. This call also validates WLEN input. |
204 [slc, C, Cpre, Cpos, win] = movslice (N, wlen); | 205 [slc, C, Cpre, Cpos, win] = movslice (N, wlen); |
205 | 206 |
206 ## Use [nb, na] format which makes replaceval_bc() simpler. | 207 ## Use [nb, na] format which makes replaceval_bc() simpler. |
312 | 313 |
313 n = length (idxp); | 314 n = length (idxp); |
314 y = zeros (n, odim); | 315 y = zeros (n, odim); |
315 ## FIXME: This nested for loop accounts for 70% of running time. | 316 ## FIXME: This nested for loop accounts for 70% of running time. |
316 ## Given that "shrink" is the default Endpoint value this | 317 ## Given that "shrink" is the default Endpoint value this |
317 ## code needs to be reworked | 318 ## code needs to be reworked. |
318 for i = 1:n | 319 for i = 1:n |
319 k = idx(tf(:,i),i); | 320 k = idx(tf(:,i),i); |
320 y(i,:) = fcn (x(k)); | 321 y(i,:) = fcn (x(k)); |
321 endfor | 322 endfor |
322 endfunction | 323 endfunction |