Vous êtes sur la page 1sur 4

Efficient Bit and Digital Reversal Algorithm Using Vector Calculation

Soo-Chang Pei and Kuo-Wei Chang Department of Electrical Engineering National Taiwan University Taipei, Taiwan, 10617, R.O.C. Email: pei.cc.ee.ntu.edu.tw, Fax: 886-2-23671909 AbstractThis paper describes an efficient bit and digital
reversal algorithm using vector calculation. It is much more efficient and simple than calculating the bit and digital reversal sequentially one by one using for-loop. An auxiliary small size seed table can also be used for building up larger table in our algorithm to speed up the computation time. It will be very useful for data shuffling in radix-2 and radix-4 fast Fourier transforms

using not more than 4 line MATLAB procedures. Meanwhile table look-up methods are generally much faster than calculating directly, but need a lot of memory storage. An auxiliary small size seed table [3]~[5] can be used to build a large table look-up for efficient bit-reversal. This approach can speed up the computation time with a small size table for paying the price. The similar idea can also be used in our method for table look-up using a small sized seed table. The above new method for bit-reversal can be easily generalized to non-binary digit reversal. For example, in radix-4 FFT, it will need 4-nary digital reversal process for data shuffling to speed up the transform. II. BASIC STRUCTURE AND IDEAS:

I.

INTRODUCTION

The well-known radix2 Fast Fourier Transform (FFT) algorithm [1] can be classified into two major classes, one is Decimation-in-Time (DIT) FFT, the other is Decimation-in-Frequency (DIF) FFT. The bit reversal data shuffling is in the first stage of DIT-FFT or the last stage of DIF-FFT to speed up the transform. A number of bit-reversal algorithm have been investigated and published in the open literature[1]~[11]. We can classify into two classes, the first class needs an auxiliary small size table [3]~[5], the second class performs efficient bit-reversal algorithm without tables. The conventional algorithms calculate the bit reversal one by one using for-loop. The new idea is to calculate the bit-reversal index in vector form. vector calculation is much more efficient and simple than calculating the bit reversal sequentially one by one using for-loop, especially taking the advantage of MATLABs vector characteristics. It can be implemented very effectively

The problem of Bit Reversal comes from FFT, so it can be certainly solved with some FFT-like ways. Observe that bit Re verse {0, 1, 2, 3} {0, 2, 1, 3} (1) bit Re verse {0,1,2,3,4,5,6,7} {0,4,2,6,1,5,3,7} (2) One can find (2) is in fact made up by two (1) s: Use (1), Bit Reversal of 2bits, separately to operate on {0, 1, 2, 3 } and {4, 5, 6, 7 }, so we get {0, 2, 1, 3 } and {4, 6, 5, 7}. Divide these into odd-even parts, and then make intersection which gets higher order (order 3) of Bit Reversal. This method, like FFT, is also the algorithm of divide and conquer. So the time complexity should be O(Nlog2N).

The second trivial method of Bit Reversal, as its name suggests, is converting every number in binary presentation, puts left-hand-side right these digits, and then converts back to the number. For example: 0=000 000 =0 bitRverse 1=001 100 =4 bitRverse 2=010 010 =2 bitRverse 3=011 110 =6 bitRverse 4=100 001 =1 bitRverse 5=101 101 =5 bitRverse 6=110 110 =3 bitRverse 7=111 111 =7 So the complexity of making operation like this is obviously O(Nlog2N).
bitRverse

Our final simple method, which is also one of the most famous method, is Karim Drouiches idea (see [11]). Although O(Nlog2N) has been already not bad, but use the idea of dynamic programming (DP) can reach O(N). The concept is to find the corresponding relation at some number first, and then use the relation to find out the corresponding relation of other numbers, so in fact every number is only calculated once. That raises a question: which numbers should we calculate first? It is trivial that we should first calculate n = 2m, because they are the easiest parts (1 2m1, 2 2m2, ..) and other numbers are straight forward. Suppose that we want to calculate the bit reversal of number K 2m, Br(K), we should write K as: K =2m + R where 0 < R < 2m. R, m N Because R <2m, Br(R) must have been calculated before. Then we use the relation: Br(K) =Br(2m)+Br(R) We can find what we want. Lets take 3 bits as example. The real situation is as follows: Step1: 0 0 , 1 4 ,2 2 ,4 1 Step2: use 1 4 ,2 2 we can find 3 2+1corresponding to2+4 6, so 3 6 . Step3: 5 = 4+1, 6 = 4+2, 7 = 4+3 So 5 corresponding to 1+4, 6 to 1+2, and 7 to 1+6. Then the bit reversal is completed. III. NEW OBSERVATION.

The method in [11] can be quite easily implemented in for-loop. But we know that in some languages, such as MATLAB, calculation in vectors is faster than using for-loop. The method discussed above is calculating the bit reversal one by one, and cant take the advantage of MATLABs characteristics. So a new observation is made. Rewrite (1) and (2): bit Re verse {0,1,2,3} {0,2,1,3} (3) bitReverse {0,1,2,3,4,5,6,7} {0,4,2,6,1,5,3,7} (4) The first four numbers in (4) are exactly what we just find in (3) multiply 2. And the last four numbers, they are the first four numbers multiply 2 plus one respectively! Moreover, bitRe {0,1,2,3,4,5,6,7} {0,4,2,6,1,5,3,7} verse (5) {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} bit Re verse {0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15} (6) It is very like the first one, so we can conclude a MATLAB procedure as follows: Step1: x(1)=0 Step2: for 1: log2N x = [2*x 2*x+1]; end Step3: Now x is the vector of bit reversal of [0 : N-1], but in MATLAB, index begins from 1, so if a is the input, we should write a = a ( x + 1) to complete bit reversal. We now prove the method is correct. Let N 2m, first we know that the bit reversal of 0 is still 0. Assume k the bit reversal of uk = [0, 1,, 2 -1] is vk, k = 1 ~ m-1. Because we know that um = [0*2m-1 + um1, 1*2m-1 + um1], the bit reversal of um is [Br(um1) with left shift one bit and the added bit is 0, Br(um1) with left shift one bit and the added bit is 1 ] = [2*vm1, 2* vm1+1]. Where + is the + in vector, i.e. [1, 2, 3] +1= [2, 3, 4]. So from the mathematic induction, the method is correct for all m N. IV. TABLE LOOK-UP METHOD

Generally speaking, table lookup methods are much faster than calculating directly, but waste a lot of space. So a lot of compromise method has been build, such as [5], [12]. They use smaller size table, cooperate with the characteristic of some symmetry or the algebra and re-

ceive faster speed. In [5] and [12], the table size is N Similarly, we can use the same size of table and build a new table lookup method suit for MATLAB. Observing that: bitReverse {0, 1, 2, 3} {0, 2, 1, 3}-----table of N = 4 {0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15} bit Re verse {0,8,4,12,2,10,6,14, 1,9,5,13,3,11,7,15} --------------- table of N = 16 One can easily tell that {0, 8, 4, 12} is {0, 2, 1, 3} 4 + 0 , {2, 10, 6, 14} is {0, 2, 1, 3} 4 + 2 , {1, 9, 5, 13} is {0, 2, 1, 3} 4 + 1 , and {3, 11, 7, 15} is {0, 2, 1, 3} 4 + 3 , where + is the + in MATLAB, i.e. {1, 2, 3} +1= {2, 3, 4}. Note that the add term, {0, 2, 1, 3}, is added separately. And {0, 2, 1, 3} is also the bit reversal of N = 4 case. So a MATLAB procedure can be written with this method. The details are: Step1: get a lookup table of size N , called x. Step2: y = N *xT*ones (1, N ) + ones ( N , 1)*x; Step3: y = y(:)T; % rearrange y, then y is the bit reversal of [0: N-1]. Similar to 2, we should use a = a ( x + 1) to complete bit reversal. The Step2 looks hard, so we explain this in figure: Use our previous example, assume we have table of N = 4, i.e. x = [0 2 1 3]. And we want to calculate N = 16.
1 0 1 2 y = 4 * [1 1 1 1] + [0 2 1 3] 1 1 3 1

To begin with, rewrite u m 2 = [0, 1, , 2 m 1 ] = [um + 0*2m, um + 1*2m, .., um + (2m 1)*2m]. Then we know that v m 2 =[vm shift m bits and add vm0, vm shift m bits and add vm1,, vm shift m bits and add vm(2m-1)]= [vm*2m + vm0, vm *2m + vm1,, vm*2m + vm(2m-1)]. Thus the proof is complete. IV. GENERALIZTION TO DIGIT REVERSAL

In modern FFT, we want to calculate non-binary reversal, or digit reversal. Unfortunately, method in [12] uses operation like XOR, which is hard to do in non-binary case. However, the new views of bit reversal discussed above can easily generalize to non-binary case, like radix-4. Take N = 42 as an example. digit Re verse {0, 1, 2, 3} {0, 1, 2, 3} (Radix-4 case) (7) {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15} digit Re verse {0, 4, 8, 12, 1, 5, 9, 13, 2, 6, 10, 14, 3, 7, 11, 15} (8) One can easily observe that the first four numbers of (8) are 4*(7). We can say that: (8) = {4*(7) +0, 4*(7) +1, 4*(7) +2, 4*(7) +3}, or in general: If N = km, vm is the k-nary digit reversal of [0 : N-1], then vm = [k * vm1 +0, k * vm1 +1, k * vm1 +2, , k * vm1 + k 1] (9) Not surprisingly, the new table lookup method can also be generalized. If N = km, vm is the k-nary digit reversal of [0: N-1], and vm = [v0, v1, ..., vN1]. Then v m 2 = [N* vm + v0, N* vm + v1, .., N* vm + vN1] (10) (It can be easily checked that the discussions above are special case of k = 2.) Notice that (7) and (8) are also powerful when using vector calculation, so implementation in MATLAB is straight forward. V. COMPARISON

0 0 0 0 0 8 8 8 8 0 + = 4 4 4 4 0 12 12 12 12 0

2 1 3 0 2 1 3 2 1 3 8 10 9 11 = 2 1 3 4 6 5 7 2 1 3 12 14 13 15

The Step3 is convert the matrix above to [0, 8, 4, 12, 2, 10, 6, 14, 1, 9, 5, 13, 3, 11, 7, 15], which is exactly the bit reversal of N = 16. The proof of this method is very similar to the method discussed in the section 2. But this time we do not need mathematic induction. Let vm = [vm0, vm1, .., vm(2m-1)] be the bit reversal of um =[0, 1,, 2m-1]. We want to prove that v m 2 = [vm *2m+ vm0, vm *2m+ vm1,, vm *2m+ vm(2m-1)].

The method in section 2 is actually from the definition of bit reversal, and it needs

log N

2i = 2N 1

i=0

As we know, C doesnt have vector calculation. So the new method is almost the same as the others. VI. CONCLUSION

shifts, N additions, and an index adjusting. The method in section 3 needs N shifts, N additions, and an index adjusting. Both of them use O(N) memories. The major difference of these two methods is that the table lookup method can be applied for parallel computing. For example, for N=16 and table size = 4, if we just want to calculate the output y[12] ~ y[15], we need not wait until the calculation of y[0] ~ y[11] is completed. We can directly compute {0, 2, 1, 3} 4 + 3 = {3, 11, 7, 15} and output these four values x[3], x[11], x[7],and x[15]. Table 1 shows the comparison of the running time of different algorithms using MATLAB. Each of the time is averaged on 1000 runs.
TABLE 1 COMPARISON FOR RUNNING TIME OF BIT-RIVERSAL BY DIFFERENT ALGORITHMS (BY MATLAB)

In this paper, we showed that bit reversal can be presented in vector way, which is suit for some languages like MATLAB. We also provide the method of table lookup and mix method, with similar math structure and proof. Besides, the new points of view make it possible to generalize bit reversal, which can be used in modern FFT. VII. REFERENCE
[1] A. Karp, Bit reversal on uniprocessors, SIAM Rev., vol. 38, no. 1, pp. 1-26, Mar. 1996. [2] A. Elster, Fast bit-reversal algorithms, in Proc, ICASSP89, 1989, pp.1099-1102. [3] D. Evans, An improved digital-reversal permutation algorithm for the fast fourier transforms, IEEE Trans. Acoust., Speech, Signal Processing, vol. ASSP-35, pp. 1120-1125, Aug.1987. [4] D. Evans, A second improved digital-reversal permutation algo-

Walkers[5] Table size = 24 Table size = 25 Table size = 26 Table size = 27 1.625 ms 5.782 ms 22.25 ms 88.83 ms

Prados[12] 1.797 ms 7.602 ms 28.91 ms 117.1 ms

Proposed 0.079 ms 0.141 ms 0.515 ms 2.109 ms

rithm for the fast fourier transforms, IEEE Trans. Acoust., Speech, Signal Processing, vol. 37, pp. 1288-1291, Aug. 1989. [5] J. Walker, A new bit-reversal algorithm," IEEE Trans. Signal Processing, vol. 38, pp. 1472-1473, Aug. 1989. [6] P. Duhamel and J. Prado, A connection between bit-reverse and matrix transpose, hardware and software consequences, in Proc, ICASSP88, 1988, pp. 1403-1406. [7] B. Gold and B. Rader, Digital Processing of Signal. New York:McGraw-Hill, 1969. [8] A. Yong, A better FFT bit-revesal algorithm without tables, IEEE Trans. Signal Processing, vol. 39. pp. 2365-2367, Oct. 1991. [9] M. Orchard, Fast bit-reversal algorithms based on index representa-

One can notice that the new method is significantly faster than the others, because of MATLAB s characteristics. Table 2 is, however, the same as Table 1 except using C. Because C usually runs faster than MATLAB, the time is averaged on 10000. Table 2 COMPARISON FOR RUNNING TIME OF BIT-RIVERSAL
BY DIFFERENT ALGORITHMS (BY C-PROGRAM)

tions in gf(2b), IEEE Trans. Signal Processing, vol. 40, pp. 1004-1008, Apr. 1992. [10] J. Rius and R. D. Porrata-Dorin, New FFT bit-reversal algorithm, IEEE Trans. Signal Processing, vol. 49, pp. 251-254, Jan. 2001. [11] K. Drouiche, A new efficient computational algorithm for bit

Walkers[5] Table size = 24 Table size = 25 Table size = 26 Table size = 27 0.0156 ms 0.0453 ms 0.1766 ms 1.0938 ms

Prados[12] 0.0172 ms 0.0453 ms 0.1703 ms 0.9719 ms

Proposed 0.0141 ms 0.0469 ms 0.1844 ms 1.0187 ms

reversal mapping," IEEE Trans. Signal Processing, vol. 49, pp. 251-254, Jan. 2001. [12] J. Prado, A new fast bit-reversal permutation algorithm based on a symmetry" IEEE Signal Processing Letters, vol. 11, pp. 933-936, Dec. 2004.