comparison toolbox/hadamard.m @ 2:c124219d7bfa draft

Re-add the 1995 toolbox after noticing the statement in the ~higham/mctoolbox/ webpage.
author Antonio Pino Robles <data.script93@gmail.com>
date Thu, 07 May 2015 18:36:24 +0200
parents 8f23314345f4
children
comparison
equal deleted inserted replaced
1:e471a92d17be 2:c124219d7bfa
1 function H = hadamard(n)
2 %HADAMARD Hadamard matrix.
3 % HADAMARD(N) is a Hadamard matrix of order N, that is,
4 % a matrix H with elements 1 or -1 such that H*H' = N*EYE(N).
5 % An N-by-N Hadamard matrix with N>2 exists only if REM(N,4) = 0.
6 % This function handles only the cases where N, N/12 or N/20
7 % is a power of 2.
8
9 % Reference:
10 % S.W. Golomb and L.D. Baumert, The search for Hadamard matrices,
11 % Amer. Math. Monthly, 70 (1963) pp. 12-17.
12
13 % History:
14 % NJH (11/14/91), revised by CBM, 6/24/92,
15 % comment lines revised by NJH, August 1993.
16
17 [f,e] = log2([n n/12 n/20]);
18 k = find(f==1/2 & e>0);
19 if isempty(k)
20 error(['N, N/12 or N/20 must be a power of 2.']);
21 end
22 e = e(k)-1;
23
24 if k == 1 % N = 1 * 2^e;
25 H = [1];
26
27 elseif k == 2 % N = 12 * 2^e;
28 H = [ones(1,12); ones(11,1) ...
29 toeplitz([-1 -1 1 -1 -1 -1 1 1 1 -1 1],[-1 1 -1 1 1 1 -1 -1 -1 1 -1])];
30
31 elseif k == 3 % N = 20 * 2^e;
32 H = [ones(1,20); ones(19,1) ...
33 hankel([-1 -1 1 1 -1 -1 -1 -1 1 -1 1 -1 1 1 1 1 -1 -1 1], ...
34 [1 -1 -1 1 1 -1 -1 -1 -1 1 -1 1 -1 1 1 1 1 -1 -1])];
35 end
36
37 % Kronecker product construction.
38 for i = 1:e
39 H = [H H
40 H -H];
41 end