summaryrefslogtreecommitdiff
path: root/macros/bitrevorder.sci
blob: cf27cd8b8a705fa9e7fdb6ceb1a784c1ba3bfc2e (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
// Returns input data in bit-reversed order

// Calling Sequence
//[y,i] = bitrevorder(x)
//y = bitrevorder(x)

// Parameters
//x: Vector of real or complex values
//y: input vector in bit reverse order
//i: indices

// Description
//This function returns the input data after reversing the bits of the indices and reordering the elements of the input array.

// Examples
//x = [%i,1,3,6*%i] ;
//[y i]=bitrevorder(x)
//Output :
// i  =
//
//    1.    3.    2.    4.
// y  =
//
//    i      3.    1.    6.i


//*************************************************************************************
//-------------------version1 (using callOctave / errored)-----------------------------
//*************************************************************************************

//function [y,i]=bitrevorder(x)
//funcprot(0);
//[lhs,rhs]=argn(0);
//if (rhs<1) then
//	error ("Wrong number of input arguments.")
//end
//[y,i]=callOctave("bitrevorder",x)
//
//endfunction

//*************************************************************************************
//-----------------------------version2 (pure scilab code)-----------------------------
//*************************************************************************************
function [y, i] = bitrevorder (x)

    funcprot(0);
    [nargout, nargin] = argn() ;

  if (nargin ~= 1)
    print_usage ();
  elseif (~ isvector (x))
    error ("bitrevorder: X must be a vector");
  elseif (fix (log2 (length (x))) ~= log2 (length (x)))
    error ("bitrevorder: X must have length equal to an integer power of 2");
  end

  [y, i] = digitrevorder (x, 2);

endfunction