Main Content

fwht

Fast Walsh-Hadamard transform

Description

example

y = fwht(x) returns the coefficients of the discrete Walsh-Hadamard transform of the input x.

y = fwht(x,n) returns the n-point discrete Walsh-Hadamard transform.

y = fwht(x,n,ordering) specifies the ordering to use for the returned Walsh-Hadamard transform coefficients.

Examples

collapse all

This example shows a simple input signal and its Walsh-Hadamard transform.

x = [19 -1 11 -9 -7 13 -15 5];
y = fwht(x)
y = 1×8

     2     3     0     4     0     0    10     0

y contains nonzero values at locations 0, 1, 3, and 6. Form the Walsh functions with the sequency values 0, 1, 3, and 6 to recreate x.

w0 = [1 1 1 1 1 1 1 1];
w1 = [1 1 1 1 -1 -1 -1 -1];
w3 = [1 1 -1 -1 1 1 -1 -1];
w6 = [1 -1 1 -1 -1 1 -1 1];
w = y(0+1)*w0 + y(1+1)*w1 + y(3+1)*w3 + y(6+1)*w6
w = 1×8

    19    -1    11    -9    -7    13   -15     5

Obtain the same result by extracting the nonzero values and Walsh functions programmatically.

ww = fwht(eye(length(y)))*length(y)
ww = 8×8

     1     1     1     1     1     1     1     1
     1     1     1     1    -1    -1    -1    -1
     1     1    -1    -1    -1    -1     1     1
     1     1    -1    -1     1     1    -1    -1
     1    -1    -1     1     1    -1    -1     1
     1    -1    -1     1    -1     1     1    -1
     1    -1     1    -1    -1     1    -1     1
     1    -1     1    -1     1    -1     1    -1

nz = find(y);
w = sum(y(nz)'.*ww(nz,:))
w = 1×8

    19    -1    11    -9    -7    13   -15     5

Input Arguments

collapse all

Input signal, specified as a matrix or a vector. If x is a matrix, the Fast Walsh-Hadamard transform is calculated on each column of x. fwht operates only on signals with length equal to a power of 2. If the length of x is less than a power of 2, its length is padded with zeros to the next greater power of two before processing.

Points in discrete Walsh Hadamard transform, specified as a positive even integer scalar.x and n must be the same length. If x is longer than n, x is truncated. If x is shorter than n, x is padded with zeros.

Order of Walsh Hadamard transform coefficients, specified as 'sequency', 'hadamard' or 'dyadic'. To specify the ordering, you must enter a value for the length n or, to use the default behavior, specify an empty vector ([]) for n. Valid values for the ordering are the following:

OrderingDescription
'sequency'Coefficients in order of increasing sequency value, where each row has an additional zero crossing. This is the default ordering.
'hadamard'Coefficients in normal Hadamard order.
'dyadic'Coefficients in Gray code order, where a single bit change occurs from one coefficient to the next.

For more information on the Walsh functions and ordering, see Walsh-Hadamard Transform.

Output Arguments

collapse all

Discrete Walsh-Hadamard transform, returned as a matrix or a vector.

Algorithms

The fast Walsh-Hadamard transform algorithm is similar to the Cooley-Tukey algorithm used for the FFT. Both use a butterfly structure to determine the transform coefficients. See the references for details.

References

[1] Beauchamp, Kenneth G. Applications of Walsh and Related Functions: With an Introduction to Sequency Theory. London: Academic Press, 1984.

[2] Beer, Tom. “Walsh Transforms.” American Journal of Physics. Vol. 49, 1981, pp. 466–472.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using MATLAB® Coder™.

See Also

| | | |

Introduced in R2008b