X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?p=CreaPhase.git;a=blobdiff_plain;f=octave_packages%2Fsignal-1.1.3%2Fdownsample.m;fp=octave_packages%2Fsignal-1.1.3%2Fdownsample.m;h=2a32eeb341154669077aca27ad65a312d7241cb0;hp=0000000000000000000000000000000000000000;hb=f5f7a74bd8a4900f0b797da6783be80e11a68d86;hpb=1705066eceaaea976f010f669ce8e972f3734b05 diff --git a/octave_packages/signal-1.1.3/downsample.m b/octave_packages/signal-1.1.3/downsample.m new file mode 100644 index 0000000..2a32eeb --- /dev/null +++ b/octave_packages/signal-1.1.3/downsample.m @@ -0,0 +1,39 @@ +## Author: Paul Kienzle (2007) +## This program is granted to the public domain. + +## -*- texinfo -*- +## @deftypefn {Function File} {@var{y} =} downsample (@var{x}, @var{n}) +## @deftypefnx {Function File} {@var{y} =} downsample (@var{x}, @var{n}, @var{offset}) +## Downsample the signal, selecting every nth element. If @var{x} +## is a matrix, downsample every column. +## +## For most signals you will want to use @code{decimate} instead since +## it prefilters the high frequency components of the signal and +## avoids aliasing effects. +## +## If @var{offset} is defined, select every nth element starting at +## sample @var{offset}. +## @seealso{decimate, interp, resample, upfirdn, upsample} +## @end deftypefn + +function y = downsample (x, n, phase = 0) + + if nargin<2 || nargin>3, print_usage; end + + if phase > n - 1 + warning("This is incompatible with Matlab (phase = 0:n-1). See ... + octave-forge signal package release notes for details.") + end + + if isvector(x) + y = x(phase + 1:n:end); + else + y = x(phase + 1:n:end,:); + end +endfunction + +%!assert(downsample([1,2,3,4,5],2),[1,3,5]); +%!assert(downsample([1;2;3;4;5],2),[1;3;5]); +%!assert(downsample([1,2;3,4;5,6;7,8;9,10],2),[1,2;5,6;9,10]); +%!assert(downsample([1,2,3,4,5],2,1),[2,4]); +%!assert(downsample([1,2;3,4;5,6;7,8;9,10],2,1),[3,4;7,8]);