1 ## Author: Paul Kienzle <pkienzle@users.sf.net> (2007)
2 ## This program is granted to the public domain.
5 ## @deftypefn {Function File} {@var{y} =} downsample (@var{x}, @var{n})
6 ## @deftypefnx {Function File} {@var{y} =} downsample (@var{x}, @var{n}, @var{offset})
7 ## Downsample the signal, selecting every nth element. If @var{x}
8 ## is a matrix, downsample every column.
10 ## For most signals you will want to use @code{decimate} instead since
11 ## it prefilters the high frequency components of the signal and
12 ## avoids aliasing effects.
14 ## If @var{offset} is defined, select every nth element starting at
15 ## sample @var{offset}.
16 ## @seealso{decimate, interp, resample, upfirdn, upsample}
19 function y = downsample (x, n, phase = 0)
21 if nargin<2 || nargin>3, print_usage; end
24 warning("This is incompatible with Matlab (phase = 0:n-1). See ...
25 octave-forge signal package release notes for details.")
29 y = x(phase + 1:n:end);
31 y = x(phase + 1:n:end,:);
35 %!assert(downsample([1,2,3,4,5],2),[1,3,5]);
36 %!assert(downsample([1;2;3;4;5],2),[1;3;5]);
37 %!assert(downsample([1,2;3,4;5,6;7,8;9,10],2),[1,2;5,6;9,10]);
38 %!assert(downsample([1,2,3,4,5],2,1),[2,4]);
39 %!assert(downsample([1,2;3,4;5,6;7,8;9,10],2,1),[3,4;7,8]);