summaryrefslogtreecommitdiff
path: root/macros/bitrevorder.sci
diff options
context:
space:
mode:
Diffstat (limited to 'macros/bitrevorder.sci')
-rw-r--r--macros/bitrevorder.sci103
1 files changed, 58 insertions, 45 deletions
diff --git a/macros/bitrevorder.sci b/macros/bitrevorder.sci
index cf27cd8..7ffe2ec 100644
--- a/macros/bitrevorder.sci
+++ b/macros/bitrevorder.sci
@@ -1,54 +1,48 @@
-// 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)-----------------------------
-//*************************************************************************************
+// 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
+// Original Source : https://octave.sourceforge.io/signal/
+// Modifieded by: Abinash Singh Under FOSSEE Internship
+// Date of Modification: 3 Feb 2024
+// Organization: FOSSEE, IIT Bombay
+// Email: toolbox@scilab.in
function [y, i] = bitrevorder (x)
+ // 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
+ // Dependencies
+ // digitrevorder
funcprot(0);
[nargout, nargin] = argn() ;
if (nargin ~= 1)
- print_usage ();
- elseif (~ isvector (x))
+ error("bitrevorder: Usage : [ y , i ] = bitrevorder(x) ");
+ elseif ( ~isvector(x) & ~isscalar(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");
@@ -57,3 +51,22 @@ function [y, i] = bitrevorder (x)
[y, i] = digitrevorder (x, 2);
endfunction
+/*
+tests
+assert_checkequal (bitrevorder (0), 0); //passed
+assert_checkequal (bitrevorder (0:1), 0:1); //passed
+assert_checkequal (bitrevorder ([0:1]'), [0:1]'); //passed
+assert_checkequal (bitrevorder (0:7), [0 4 2 6 1 5 3 7]); //passed
+assert_checkequal (bitrevorder ([0:7]'), [0 4 2 6 1 5 3 7]'); // passed
+assert_checkequal (bitrevorder ([0:7]*%i), [0 4 2 6 1 5 3 7]*%i); // passed
+assert_checkequal (bitrevorder ([0:7]'*%i), [0 4 2 6 1 5 3 7]'*%i); // passed
+assert_checkequal (bitrevorder (0:15), [0 8 4 12 2 10 6 14 1 9 5 13 3 11 7 15]); //passed
+
+ Test input validation
+ // error testing
+assert_checkerror (bitrevorder ());
+assert_checkerror bitrevorder (1, 2);
+assert_checkerror bitrevorder ([]);
+assert_checkerror bitrevorder (0:2);
+
+*/ \ No newline at end of file