From octave-sources-request at bevo dot che dot wisc dot edu Fri Apr 4 00:21:25 2003 Subject: hadamard.m From: "Quentin H. Spencer" To: octave-sources at bevo dot che dot wisc dot edu Date: Thu, 3 Apr 2003 23:16:41 -0600 This is a multi-part message in MIME format. --------------090704000409030305090801 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit I just noticed Octave does not have the function hadamard.m for generating Hadamard matrices, so I wrote it. For those interested in duplicating the organization of "the leading brand" software, I believe this is in the statistics toolbox. I don't know whether this should be added directly to octave or octave-forge. By the way, what is the general philosophy on this (adding contributed functions to octave or octave-forge)? regards, Quentin Spencer --------------090704000409030305090801 Content-Type: text/plain; name="hadamard.m" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="hadamard.m" ## Copyright (C) 2003, Quentin H. Spencer ## ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## -*- texinfo -*- ## at deftypefn {Function File} {} hadamard(@var{N}) ## ## Generate a Hadamard matrix of dimension at var{N} dot While Hadamard ## matrices exist for at var{N}=2, and 4*K for integer values of K, ## this function only supports values of at var{N} where @var{N}, ## at var{N}/12, or @var{N}/20 is a power of 2. ## at end deftypefn function H = hadamard(N); H2 = [1, 1; 1,-1]; if(2^(logN=floor(log2(N)))==N) H = H2; for n = 1:logN-1 H = kron(H,H2); end elseif(2^(logN=floor(log2(N/12)))*12==N) H =[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, 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