1 ## Copyright (C) 2007 Muthiah Annamalai <muthiah.annamalai@uta.edu>
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} {} egolayenc (@var{M})
20 ## Given @var{M}, encode M using the Extended Golay code.
22 ## The message @var{M}, needs to be of size Nx12, for encoding.
23 ## We can encode several messages, into codes at once, if they
24 ## are stacked in the order suggested.
26 ## The generator G used in here is same as obtained from the
27 ## function egolaygen. Extended Golay code (24,12) which can correct
32 ## M=(rand(10,12)>0.5);
39 ## @seealso{egolaygen,egolaydec}
41 function C=egolayenc(M)
43 error('usage: C=egolayenc(M)');
44 elseif ( columns(M) ~= 12 )
45 error('extended golay code is (24,12), use message of column size 12');
49 P=[1 0 0 0 1 1 1 0 1 1 0 1;
50 0 0 0 1 1 1 0 1 1 0 1 1;
51 0 0 1 1 1 0 1 1 0 1 0 1;
52 0 1 1 1 0 1 1 0 1 0 0 1;
53 1 1 1 0 1 1 0 1 0 0 0 1;
54 1 1 0 1 1 0 1 0 0 0 1 1;
55 1 0 1 1 0 1 0 0 0 1 1 1;
56 0 1 1 0 1 0 0 0 1 1 1 1;
57 1 1 0 1 0 0 0 1 1 1 0 1;
58 1 0 1 0 0 0 1 1 1 0 1 1;
59 0 1 0 0 0 1 1 1 0 1 1 1;
60 1 1 1 1 1 1 1 1 1 1 1 0;];
64 ## C(rowi,:)=mod(M(rowi,:)*G,2); %code.
67 C=mod(M*repmat(G,[1,rows(M)]),2);