hadamard
Hadamard matrix of +1 and -1 entries.
Category: Mathematics > Elementary Math
Syntax
H = hadamard(n)
Returns an n-by-n matrix H whose entries are 1 or -1 and whose rows are mutually orthogonal.
Description
The defining property is that distinct rows are orthogonal, so H*H' is n times the identity. Such matrices are the basis of the Walsh-Hadamard transform and of error-correcting codes and experimental designs.
For powers of two the matrix is built by the doubling rule [H H; H -H]. Other orders use known constructions, and an order for which no matrix of this type is available is an error.
Input arguments
n- Order of the matrix. It must be
1,2, or a multiple of4of the form2^e,12*2^eor20*2^e.
Output arguments
H- Matrix satisfying
H'*H == n*eye(n).
Example
Order 4 and its orthogonality
H = hadamard(4)
H' * H
Output
H = 4×4
1 1 1 1
1 -1 1 -1
1 1 -1 -1
1 -1 -1 1
ans = 4×4
4 0 0 0
0 4 0 0
0 0 4 0
0 0 0 4