1 ## Copyright (C) 2003 David Bateman
3 ## This program is free software; you can redistribute it and/or modify it under
4 ## the terms of the GNU General Public License as published by the Free Software
5 ## Foundation; either version 3 of the License, or (at your option) any later
8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 ## You should have received a copy of the GNU General Public License along with
14 ## this program; if not, see <http://www.gnu.org/licenses/>.
17 ## @deftypefn {Function File} {@var{w} = } gfweight (@var{gen})
18 ## @deftypefnx {Function File} {@var{w} = } gfweight (@var{gen},'gen')
19 ## @deftypefnx {Function File} {@var{w} = } gfweight (@var{par},'par')
20 ## @deftypefnx {Function File} {@var{w} = } gfweight (@var{p},n)
22 ## Calculate the minimum weight or distance of a linear block code. The
23 ## code can be either defined by its generator or parity check matrix, or
24 ## its generator polynomial. By default if the first argument is a matrix,
25 ## it is assumed to be the generator matrix of the code. The type of the
26 ## matrix can be defined by a flag 'gen' for the generator matrix or
27 ## 'par' for the parity check matrix.
29 ## If the first argument is a vector, it is assumed that it defines the
30 ## generator polynomial of the code. In this case a second argument is
31 ## required that defines the codeword length.
34 ## @seealso{hammgen,cyclpoly,bchpoly}
36 function w = gfweight (arg1, arg2)
38 if ((nargin < 1) || (nargin > 2))
39 usage ("gfweight(mat,typ) or gfweight(poly,n)");
44 error ("gfweight: need the codeword length if passing generator polynomial");
46 [ign, gen] = cyclgen(arg2, arg1);
47 elseif (ismatrix(arg1))
50 if (strcmp(arg2,"gen"))
52 elseif (strcmp(arg2,"par"))
55 error ("gfweight: unrecognized string argument");
58 error ("gfweight: if first argument is a matrix, the second must be a string");
64 error ("gfweight: first argument must be a matrix or a vector");
69 error ("gfweight: generator matrix in an illegal form");
72 ## We only need to test codewords 1:2^k-1 against the zero code word
73 ## We do the equivalent of
74 ## w = min(sum((mod(de2bi([1:2^k-1]') * gen, 2))'));
75 ## But in a more memory efficient manner in an oct-file
76 w = __gfweight__(gen);