static public void ReorderArray(double[] data) { Debug.Assert(data != null); int length = data.Length / 2; Debug.Assert(FourierUtils.IsPowerOf2(length) == true); Debug.Assert(length >= cMinLength); Debug.Assert(length <= cMaxLength); int[] reversedBits = FourierUtils.GetReversedBits(FourierUtils.Log2(length)); for (int i = 0; i < length; i++) { int swap = reversedBits[i]; if (swap > i) { FourierUtils.Swap(ref data[i << 1], ref data[swap << 1]); FourierUtils.Swap(ref data[i << 1 + 1], ref data[swap << 1 + 1]); } } }
static public void ReorderArray(ComplexF[] data) { Debug.Assert(data != null); int length = data.Length; Debug.Assert(FourierUtils.IsPowerOf2(length) == true); Debug.Assert(length >= cMinLength); Debug.Assert(length <= cMaxLength); int[] reversedBits = FourierUtils.GetReversedBits(FourierUtils.Log2(length)); for (int i = 0; i < length; i++) { int swap = reversedBits[i]; if (swap > i) { ComplexF temp = data[i]; data[i] = data[swap]; data[swap] = temp; } } }
static public int[] GetReversedBits(int numberOfBits) { Debug.Assert(numberOfBits >= cMinBits); Debug.Assert(numberOfBits <= cMaxBits); if (_reversedBits[numberOfBits - 1] == null) { int maxBits = FourierUtils.Pow2(numberOfBits); int[] reversedBits = new int[maxBits]; for (int i = 0; i < maxBits; i++) { int oldBits = i; int newBits = 0; for (int j = 0; j < numberOfBits; j++) { newBits = (newBits << 1) | (oldBits & 1); oldBits = (oldBits >> 1); } reversedBits[i] = newBits; } _reversedBits[numberOfBits - 1] = reversedBits; } return(_reversedBits[numberOfBits - 1]); }