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} {} egolaydec (@var{R})
19 ## Given @var{R}, the received Extended Golay code, this function tries to
20 ## decode @var{R} using the Extended Golay code parity check matrix.
21 ## Extended Golay code (24,12) which can correct upto 3 errors.
23 ## The received code @var{R}, needs to be of length Nx24, for encoding. We can
24 ## decode several codes at once, if they are stacked as a matrix of 24columns,
25 ## each code in a separate row.
27 ## The generator G used in here is same as obtained from the
28 ## function egolaygen.
30 ## The function returns the error-corrected code word from the received
31 ## word. If decoding failed, the second return value is 1, otherwise it is 0.
33 ## Extended Golay code (24,12) which can correct upto 3
34 ## errors. Decoding algorithm follows from Lin & Costello.
36 ## Ref: Lin & Costello, pg 128, Ch4, 'Error Control Coding', 2nd ed, Pearson.
40 ## M=[rand(10,12)>0.5];
42 ## C1(:,1)=mod(C1(:,1)+1,2)
48 ## @seealso{egolaygen,egolayenc}
50 function [C,dec_error]=egolaydec(R)
53 error('usage: C=egolaydec(R)');
54 elseif ( columns(R) ~= 24 )
55 error('extended golay code is (24,12), use rx codeword of 24 bit column size');
60 P=[1 0 0 0 1 1 1 0 1 1 0 1;
61 0 0 0 1 1 1 0 1 1 0 1 1;
62 0 0 1 1 1 0 1 1 0 1 0 1;
63 0 1 1 1 0 1 1 0 1 0 0 1;
64 1 1 1 0 1 1 0 1 0 0 0 1;
65 1 1 0 1 1 0 1 0 0 0 1 1;
66 1 0 1 1 0 1 0 0 0 1 1 1;
67 0 1 1 0 1 0 0 0 1 1 1 1;
68 1 1 0 1 0 0 0 1 1 1 0 1;
69 1 0 1 0 0 0 1 1 1 0 1 1;
70 0 1 0 0 0 1 1 1 0 1 1 1;
71 1 1 1 1 1 1 1 1 1 1 1 0;];
73 H=[I; P]; %partiy check matrix transpose.
87 SP = mod(repmat(S,[12, 1])+P,2);
88 idx = find( sum(SP,2) <= 2 );
90 idx=idx(1); %pick first of matches.
91 Ui=zeros(1,12); Ui(idx)=1;
104 SP = mod(repmat(X,[12, 1])+P,2);
105 idx = find( sum(SP,2) == 2 );
108 Ui=zeros(1,12); Ui(idx)=1;
115 dec_error=[dec_error; 1-done];
116 C(rspn,:)=mod(E+RR,2);
122 %!assert(egolaydec([1 1 1 zeros(1,21)]),zeros(1,24))
123 %!assert(egolaydec([1 0 1 zeros(1,20) 1]),zeros(1,24))