summaryrefslogtreecommitdiff
path: root/macros/upsample.sci
blob: 98a9e6d4421235fac9ce8b142bdbe2d25fbc0dc2 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// 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

//Calling sequence:
//  y = upsample (x, n)
//  y = upsample (x, n, offset)
// Upsample the signal, inserting n-1 zeros between every element.
//
// If x is a matrix, upsample every column.
//
// If offset is specified, control the position of the inserted sample in
// the block of n zeros.
//

//Testcases:
//1.upsample([1,3,5],2)
//EXPECTED OUTPUT:[1,0,3,0,5,0]


//2.upsample([1;3;5],2)
//EXPECTED OUTPUT:[1;0;3;0;5;0]


//3.upsample([1,2;5,6;9,10],2)
//EXPECTED OUTPUT:[1,2;0,0;5,6;0,0;9,10;0,0]
//
//



function y = upsample (x,n,phase )
  [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

  [nr,nc] = size(x);
  if (nc==1 | nr==1) then

  if ( nc==1)
    y = zeros(n*nr*nc,1);
   y(phase+1:n:$) = x;
   end
    if (nr==1)
         y = zeros(n*nr*nc,1);
        y(phase+1:n:$) = x';
        y = y.';
        end
  else
    y = zeros(n*nr,nc);
    y(phase + 1:n:$,:) = x;
  end

endfunction