Fast Walsh–Hadamard transform

From Wikipedia, the free encyclopedia
(Redirected from Fast Hadamard transform)
Jump to navigation Jump to search
File:Fast walsh hadamard transform 8.svg
The fast Walsh–Hadamard transform applied to a vector of length 8
File:1010 0110 Walsh spectrum (fast WHT).svg
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=2m would have a computational complexity of O(n2). The FWHTh requires only nlogn additions or subtractions.

The FWHTh is a divide-and-conquer algorithm that recursively breaks down a WHT of size n into two smaller WHTs of size n/2. [1] This implementation follows the recursive definition of the 2m×2m Hadamard matrix Hm:

Hm=12(Hm1Hm1Hm1Hm1).

The 1/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 Hm=Am, where A is m-th root of Hm. [2]

Python example code

[edit | edit source]
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[j]
                y = a[j + h]
                a[j] = x + y
                a[j + h] = x - y
        # normalize and increment
        a /= math.sqrt(2)
        h *= 2

See also

[edit | edit source]

References

[edit | edit source]
  1. ^ Lua error in Module:Citation/CS1/Configuration at line 2172: attempt to index field '?' (a nil value).
  2. ^ Yarlagadda and Hershey, "Hadamard Matrix Analysis and Synthesis", 1997 (Springer)
[edit | edit source]