summaryrefslogtreecommitdiff
path: root/macros/downsample.sci
blob: 864f054ffc0e6a9d7b30af522e8f7cf330dc75bb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Copyright (C) 2018 - IIT Bombay - FOSSEE
//
// This file must be used under the terms of the CeCILL.
// This source file is licensed as described in the file COPYING, which
// you should have received as part of this distribution.  The terms
// are also available at
// http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
// Author:[insert name]
// Organization: FOSSEE, IIT Bombay
// Email: toolbox@scilab.in



function y = downsample (x, n, phase)
//Function File vary = downsample (x, n)
//Function File y = downsample (x, n, offset)
// Downsample the signal, selecting every nth element.  If x
// is a matrix, downsample every column.
//
// If offset is defined, select every nth element starting at
// sample offset.
//
//
//Test cases:
//1.downsample([1,2,3,4,5],2)
//EXPECTED OUTPUT:[1,3,5]
//2.downsample([1;2;3;4;5],2)
//EXPECTED OUTPUT:[1;3;5]
//3.downsample([1,2;3,4;5,6;7,8;9,10],2)
//EXPECTED OUTPUT:[1,2;5,6;9,10]
//4.downsample([1,2,3,4,5],2,1)
//EXPECTED OUTPUT:[2,4]
//5.downsample([1,2;3,4;5,6;7,8;9,10],2,1)
//EXPECTED OUTPUT:[3,4;7,8]

[nargout,nargin]=argn();
  if (nargin<2 | nargin>3)
       error ("wrong no. of input arguments");
       end

if nargin==2
    phase=0;
    else
  if phase > n-1
    warning("This is incompatible with Matlab (phase = 0:n-1). See octave-forge signal package release notes for details." )
  end
end

  if isvector(x)
    y = x(phase + 1:n:$);
  else
    y = x(phase + 1:n:$,:);
  end

endfunction