]> Creatis software - CreaPhase.git/blob - octave_packages/communications-1.1.1/egolayenc.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / communications-1.1.1 / egolayenc.m
1 ## Copyright (C) 2007 Muthiah Annamalai <muthiah.annamalai@uta.edu>
2 ##
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
6 ## version.
7 ##
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
11 ## details.
12 ##
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/>.
15
16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {}  egolayenc (@var{M})
18 ## 
19 ## 
20 ## Given @var{M}, encode M using the Extended Golay code.
21 ##
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.
25 ##
26 ## The generator G used in here is same as obtained from the
27 ## function egolaygen. Extended Golay code (24,12) which can correct
28 ## upto 3 errors.
29 ##
30 ## @example
31 ## @group
32 ## M=(rand(10,12)>0.5);
33 ## C=egolayenc(M)
34 ##
35 ## @end group
36 ## @end example
37 ##
38 ## @end deftypefn
39 ## @seealso{egolaygen,egolaydec}
40
41 function C=egolayenc(M)
42   if ( nargin < 1 )
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');
46   end
47
48   I=eye(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;];
61   G=[P I]; %generator.
62
63   ##for rowi=1:rows(M)
64   ##   C(rowi,:)=mod(M(rowi,:)*G,2); %code.
65   ##end
66
67   C=mod(M*repmat(G,[1,rows(M)]),2);
68   C=C(:,1:24);
69
70 end