Divide-and-conquer algorithm to compute a Hadamard transform
In computational mathematics, the Hadamard ordered fast Walsh–Hadamard transform (FWHTh) is an efficient algorithm to compute the Walsh–Hadamard transform (WHT). A naive implementation of the WHT of order would have a computational complexity of O(). The FWHTh requires only additions or subtractions.
The normalization factors for each stage may be grouped together or even omitted.
The sequency-ordered, also known as Walsh-ordered, fast Walsh–Hadamard transform, FWHTw, is obtained by computing the FWHTh as above, and then rearranging the outputs.
A simple fast nonrecursive implementation of the Walsh–Hadamard transform follows from decomposition of the Hadamard transform matrix as , where A is m-th root of . [2]
Python example code
importmathdeffwht(a)->None:"""In-place Fast Walsh–Hadamard Transform of array a."""assertmath.log2(len(a)).is_integer(),"length of a is a power of 2"h=1whileh<len(a):# perform FWHTforiinrange(0,len(a),h*2):forjinrange(i,i+h):x=a[j]y=a[j+h]a[j]=x+ya[j+h]=x-y# normalize and incrementa/=math.sqrt(2)h*=2
^Fino, B. J.; Algazi, V. R. (1976). "Unified Matrix Treatment of the Fast Walsh–Hadamard Transform". IEEE Transactions on Computers. 25 (11): 1142–1146. doi:10.1109/TC.1976.1674569. S2CID13252360.
^Yarlagadda and Hershey, "Hadamard Matrix Analysis and Synthesis", 1997 (Springer)