IEEE TRANSACTIONS ON COMPUTERS, NOVEMBER 1975 On Computation of the Hadamard Transform and the R Transform in Ordered Form MURAT KUNT Abstract-This correspondence describes an improved computa- tional algorithm for the Hadamard transform and the R transform. By performing the computation "in place", the number of storage locations is minimized and the speed is increased. The transformed coefficients are in the order of increasing sequency. Index Terms-Gray code, Hadamard transform, R transform, sequency ordering. Input Binary Gray Bit-reversed code code ordering X0 000 000 __ ,c x 001 001 IC, X2 010 011 0 _ X3 011 010 / j\ p X4 loo 'lo d / X5 101 1" C-11 x6 110 101 O -- X7 1 11 loo 0 ( Various types of computational algorithm for the Hadamard transform have been reported recently [1]-[3]. The algorithm de- scribed in [1] provides the transformed coefficients in "ordered" form which corresponds to the order of increasing sequency [4]. However, it requires N/2 auxiliary storage locations where N = 2m is the number of input samples, and it cannot be used for the com- putation of the R transform [3]. The method proposed by Shanks [2] performs the computation "in place" which means that intermediate results are stored in the locations of the input samples without any need for auxiliary storage. However, the transformed coefficients are in the "natural" form (not in the order of increasing sequency). The computational algorithm for both the Hadamard and the R transforms in ordered form is given by Ulman [3]. This method re- quires N auxiliary storage locations for intermediate results. The algorithm proposed here can be performed in place, it gives the transformed coefficients in ordered form and it is faster than Ulman's algorithm. Let us first consider the Cooley-Tukey fast Fourier transform (FFT) algorithm. Generally in this algorithm a dummy parameter having the value +1 or -1 is placed on the exponent in order to perform the direct (+1) or the inverse (-1) transform. If this parameter is set to 0, all multiplicative factors are reduced to 41 and the FFT algorithm computes the Hadamard transform in the "bit-reversed order". It is therefore an easy task to exploit the structure of the FFT in order to establish an algorithm for the fast Hadamard transform (FHT) in the bit-reversed order without using complex numbers. Walsh functions represented by the rows of a symmetric Hada- mard matrix are characters of the dyadic group. Their reordering in the order of increasing sequency can be carried out with Gray code. The corresponding points in the dyadic space are then ordered into a path of minimum length [5]. The R transform introduced by Reitboeck and Brody [6] has the interesting property of invariance under cyclical permutation of the input data. This transform may be considered in terms of a Hadamard transform matrix in which absolute value is taken after each subtraction. Fig. 1 is an eight-point flow graph showing the computational steps (numbered from 0 to 5) for Hadamard and R transforms. Each column corresponds to a particular step, starting with the input samples at left and ending with-the transformed coefficients at right. Binary and Gray codes equivalent of the subscripts of the input samples are indicated for reordering purposes. A bit-reversed reordering based on binary code is first carried out, changing for example xi at address 001 with x4 at address 100 (step 0). Then, a fast transformation is performed which is quite similar to the Manuscript received June 26, 1973; revised April 17, 1975. The author is with the Research Laboratory of Electronics, Massa- chusetts Institute of Technology, Cambridge, Mass. 02139, on leave from Ecole Polytechnique Federale de Lausanne, Lausanne, Switzerland. Steps_- 0 1 2 Addition -----: Subtraction 3 4 5 :-----:Permutation Fig. 1. Eight-point flow graph for efficient Hadamard and R trans- forms computation. SUBROUTINE FHT(X.N.NU) C THIS SUBROUTINE COMPUTES THE HADAMARD TRANSFORM OR C THE R-TRANSFORM OF A SAMPLED SIGNAL. THE TRANSFORMED C COEFFICIENTS ARE IN THE ORDER OF INCREASING SEQUENCY. C X - REAL ARRAY CONTAINING THE SIGNAL S SAMPLES BEFORE C THE CALL AND THE COEFFICIENTS AFTER THE CALL. C N - 2**NU - NUMBER OF SAMPLES. C RESERVE STORAGE FOR X(N) IN THE CALLING PROGRAM. DIMENSION X(N) Ni-N-1 $N2-N/2 $NUI-NU-i $N4-N/4 $I-1 DO 1 J=1,N1 IF(I.LE.J) GO TO 2 Z-X(I) $X(I)-x(J) $X(J)-Z 2 K-N2 3 IF(I.LE.K) GO TO I I-I-K $K-K/2 $GO TO 3 1 I-I+K DO 4 I-i.NU IA=2**I $IB-IA/2 DO 4 J-1,IB DO 4 K-J.N,IA IC-K+IB $Z-X(IC) $X(IC)-X(K)-Z C FOR THE R-TRANSFORM USE X(IC)-ABS(X(K)-Z) 4 X(K)-X(K)+Z FAC-SQHT(2. )**NU DO 5 I-1,N 5 X(I)-X(I)/FAC DO 6 I-1.NUI IGA.2**( I-1) DO 7 L-1.IGA DO 7 J-1.N4 IY-N2+J+(L-1)*N/IGA $IX-IY+N4 Z-x(Ix) $x(Ix)-X(IY) 7 X(IY)-Z N2-N2/2 6 N4-N4/2 RETURN END Fig. 2. Fortran subroutine for efficient Hadamard and R transforms computation. Cooley-Tukey algorithm (Steps 1, 2, and 3). In this transformation the value at a node of the step j is found by computing the sum or difference of two values in the preceding step j - 1 from rows dif- fering by 2i-1. This structure allows to store intermediate results in the storage locations of the input data. In this flow graph solid lines represent addition and the dashed lines represent substraction. If the R-transform is being performed, absolute value must be taken at each node reached by a dashed line. Finally, at Steps 4 and 5 Gray code reordering is carried out by placing the value of a node with a given binary coded address to the node which has the same code word in Gray code. The listing of a Fortran subroutine performing these computations is shown on Fig. 2. Note that the results are normalized in the loop "DO 5." Two successive calls of this subroutine lead to the initial input data. From a computation time point of view, we can compare tile per- formances of this subroutine and Ulman's program. It is well Fast transformation Gray code Output ordering XO, X, X2 X3, X. X, X. X, 1120