Misplaced Pages

Fast Walsh–Hadamard transform

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
(Redirected from Fast Hadamard transform)
The fast Walsh–Hadamard transform applied to a vector of length 8
Divide-and-conquer algorithm to compute a Hadamard transform
Example for the input vector (1, 0, 1, 0, 0, 1, 1, 0)

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 n = 2 m {\displaystyle n=2^{m}} would have a computational complexity of O( n 2 {\displaystyle n^{2}} ). The FWHTh requires only n log n {\displaystyle n\log n} additions or subtractions.

The FWHTh is a divide-and-conquer algorithm that recursively breaks down a WHT of size n {\displaystyle n} into two smaller WHTs of size n / 2 {\displaystyle n/2} . This implementation follows the recursive definition of the 2 m × 2 m {\displaystyle 2^{m}\times 2^{m}} Hadamard matrix H m {\displaystyle H_{m}} :

H m = 1 2 ( H m 1 H m 1 H m 1 H m 1 ) . {\displaystyle H_{m}={\frac {1}{\sqrt {2}}}{\begin{pmatrix}H_{m-1}&H_{m-1}\\H_{m-1}&-H_{m-1}\end{pmatrix}}.}

The 1 / 2 {\displaystyle 1/{\sqrt {2}}} 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 H m = A m {\displaystyle H_{m}=A^{m}} , where A is m-th root of H m {\displaystyle H_{m}} .

Python example code

import math
def fwht(a) -> None:
    """In-place Fast Walsh–Hadamard Transform of array a."""
    assert math.log2(len(a)).is_integer(), "length of a is a power of 2"
    h = 1
    while h < len(a):
        # perform FWHT
        for i in range(0, len(a), h * 2):
            for j in range(i, i + h):
                x = a
                y = a
                a = x + y
                a = x - y
        # normalize and increment
        a /= math.sqrt(2)
        h *= 2

See also

References

  1. 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. S2CID 13252360.
  2. Yarlagadda and Hershey, "Hadamard Matrix Analysis and Synthesis", 1997 (Springer)

External links


Stub icon

This signal processing-related article is a stub. You can help Misplaced Pages by expanding it.

Stub icon

This algorithms or data structures-related article is a stub. You can help Misplaced Pages by expanding it.

Categories: