summaryrefslogtreecommitdiff
path: root/macros/bitrevorder.sci
diff options
context:
space:
mode:
Diffstat (limited to 'macros/bitrevorder.sci')
-rw-r--r--macros/bitrevorder.sci70
1 files changed, 52 insertions, 18 deletions
diff --git a/macros/bitrevorder.sci b/macros/bitrevorder.sci
index a4b6da8..cf27cd8 100644
--- a/macros/bitrevorder.sci
+++ b/macros/bitrevorder.sci
@@ -1,25 +1,59 @@
-function [y,i]=bitrevorder(x)
+// Returns input data in bit-reversed order
-// Returns input data in bit-reversed order
// Calling Sequence
-// [y,i]=bitrevorder(x)
+//[y,i] = bitrevorder(x)
+//y = bitrevorder(x)
+
// Parameters
-// x: Vector of real or complex values
+//x: Vector of real or complex values
+//y: input vector in bit reverse order
+//i: indices
+
// Description
-// This is an Octave function.
-// This function returns the input data after reversing the bits of the indices and reordering the elements of the input array.
+//This function returns the input data after reversing the bits of the indices and reordering the elements of the input array.
+
// Examples
-// 1. [y]=bitrevorder ([i,1,3,6i])
-// y = [0 + 1i 3 + 0i 1 + 0i 0 + 6i]
-// 2. [y,i]=bitrevorder (['a','b','c','d'])
-// y = acbd
-// i = [1 3 2 4]
-
-funcprot(0);
-[lhs,rhs]=argn(0);
-if (rhs<1) then
- error ("Wrong number of input arguments.")
-end
-[y,i]=callOctave("bitrevorder",x)
+//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