From: <car...@us...> - 2012-08-21 00:59:55
|
Revision: 10892 http://octave.svn.sourceforge.net/octave/?rev=10892&view=rev Author: carandraug Date: 2012-08-21 00:59:49 +0000 (Tue, 21 Aug 2012) Log Message: ----------- egolayenc/egolaydec/egolaygen: follow some Octave coding standards Modified Paths: -------------- trunk/octave-forge/main/comm/inst/egolaydec.m trunk/octave-forge/main/comm/inst/egolayenc.m trunk/octave-forge/main/comm/inst/egolaygen.m Modified: trunk/octave-forge/main/comm/inst/egolaydec.m =================================================================== --- trunk/octave-forge/main/comm/inst/egolaydec.m 2012-08-21 00:32:36 UTC (rev 10891) +++ trunk/octave-forge/main/comm/inst/egolaydec.m 2012-08-21 00:59:49 UTC (rev 10892) @@ -14,23 +14,24 @@ ## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {} egolaydec (@var{R}) +## @deftypefn {Function File} {[@var{C}, @var{err}] =} egolaydec (@var{R}) +## Decode Extended Golay code. ## ## Given @var{R}, the received Extended Golay code, this function tries to -## decode @var{R} using the Extended Golay code parity check matrix. -## Extended Golay code (24,12) which can correct upto 3 errors. +## decode it using the Extended Golay code parity check matrix. +## Extended Golay code (24,12) which can correct up to 3 errors. ## ## The received code @var{R}, needs to be of length Nx24, for encoding. We can -## decode several codes at once, if they are stacked as a matrix of 24columns, +## decode several codes at once, if they are stacked as a matrix of 24 columns, ## each code in a separate row. ## -## The generator G used in here is same as obtained from the -## function egolaygen. +## The generator used in here is same as obtained from the function +## @code{egolaygen}. ## -## The function returns the error-corrected code word from the received -## word. If decoding failed, the second return value is 1, otherwise it is 0. +## The function returns @var{C}, the error-corrected code word from the received +## word. If decoding failed, @var{err} value is 1, otherwise it is 0. ## -## Extended Golay code (24,12) which can correct upto 3 +## Extended Golay code (24,12) which can correct up to 3 ## errors. Decoding algorithm follows from Lin & Costello. ## ## Ref: Lin & Costello, pg 128, Ch4, 'Error Control Coding', 2nd ed, Pearson. @@ -44,80 +45,82 @@ ## @end group ## @end example ## +## @seealso{egolaygen,egolayenc} ## @end deftypefn -## @seealso{egolaygen,egolayenc} -function [C,dec_error]=egolaydec(R) +function [C, dec_error] = egolaydec (R) - if ( nargin < 1 ) - error('usage: C=egolaydec(R)'); - elseif ( columns(R) ~= 24 ) - error('extended golay code is (24,12), use rx codeword of 24 bit column size'); - end + if (nargin != 1) + print_usage; + elseif (columns (R) != 24) + error ("extended golay code is (24,12), use rx codeword of 24 bit column size"); + endif - I=eye(12); + I = eye (12); %P is 12x12 matrix - P=[1 0 0 0 1 1 1 0 1 1 0 1; - 0 0 0 1 1 1 0 1 1 0 1 1; - 0 0 1 1 1 0 1 1 0 1 0 1; - 0 1 1 1 0 1 1 0 1 0 0 1; - 1 1 1 0 1 1 0 1 0 0 0 1; - 1 1 0 1 1 0 1 0 0 0 1 1; - 1 0 1 1 0 1 0 0 0 1 1 1; - 0 1 1 0 1 0 0 0 1 1 1 1; - 1 1 0 1 0 0 0 1 1 1 0 1; - 1 0 1 0 0 0 1 1 1 0 1 1; - 0 1 0 0 0 1 1 1 0 1 1 1; - 1 1 1 1 1 1 1 1 1 1 1 0;]; + P = [1 0 0 0 1 1 1 0 1 1 0 1; + 0 0 0 1 1 1 0 1 1 0 1 1; + 0 0 1 1 1 0 1 1 0 1 0 1; + 0 1 1 1 0 1 1 0 1 0 0 1; + 1 1 1 0 1 1 0 1 0 0 0 1; + 1 1 0 1 1 0 1 0 0 0 1 1; + 1 0 1 1 0 1 0 0 0 1 1 1; + 0 1 1 0 1 0 0 0 1 1 1 1; + 1 1 0 1 0 0 0 1 1 1 0 1; + 1 0 1 0 0 0 1 1 1 0 1 1; + 0 1 0 0 0 1 1 1 0 1 1 1; + 1 1 1 1 1 1 1 1 1 1 1 0;]; - H=[I; P]; %partiy check matrix transpose. + H = [I; P]; %partiy check matrix transpose. - dec_error=[]; - C=zeros(size(R)); + dec_error = []; + C = zeros (size (R)); - for rspn=1:rows(R) - RR=R(rspn,:); - S=mod(RR*H,2); - wt=sum(S); - done=0; - E=[S, zeros(1,12)]; + for rspn = 1:rows (R) + RR = R(rspn,:); + S = mod (RR*H, 2); + wt = sum (S); + done = 0; + E = [S, zeros(1, 12)]; if (wt <= 3) - E=[S, zeros(1,12)]; - done=1; + E = [S, zeros(1, 12)]; + done = 1; else - SP = mod(repmat(S,[12, 1])+P,2); - idx = find( sum(SP,2) <= 2 ); - if ( idx ) - idx=idx(1); %pick first of matches. - Ui=zeros(1,12); Ui(idx)=1; - E=[SP(idx,:),Ui]; - done=1; - end - end + SP = mod (repmat (S, [12, 1]) + P, 2); + idx = find (sum (SP, 2) <= 2); + if (idx) + idx = idx(1); %pick first of matches. + Ui = zeros (1, 12); + Ui(idx) = 1; + E = [SP(idx, :), Ui]; + done = 1; + endif + endif - if ( ~done ) - X=mod(S*P,2); - wt=sum(X); + if (!done) + X = mod (S*P, 2); + wt = sum (X); if (wt==2 || wt==3) - E=[zeros(1,12), X]; - done=1; + E = [zeros(1, 12), X]; + done = 1; else - SP = mod(repmat(X,[12, 1])+P,2); - idx = find( sum(SP,2) == 2 ); - if ( idx ) - idx=idx(1); - Ui=zeros(1,12); Ui(idx)=1; - E=[Ui,SP(idx,:)]; - done=1; - end - end - end + SP = mod (repmat(X, [12, 1]) + P, 2); + idx = find (sum(SP, 2) == 2); + if (idx) + idx = idx(1); + Ui = zeros (1, 12); + Ui(idx) = 1; + E = [Ui, SP(idx, :)]; + done = 1; + endif + endif + endif - dec_error=[dec_error; 1-done]; - C(rspn,:)=mod(E+RR,2); - end + dec_error = [dec_error; 1-done]; + C(rspn, :) = mod (E+RR, 2); + endfor - return; -end +endfunction + %!assert(egolaydec([1 1 1 zeros(1,21)]),zeros(1,24)) %!assert(egolaydec([1 0 1 zeros(1,20) 1]),zeros(1,24)) Modified: trunk/octave-forge/main/comm/inst/egolayenc.m =================================================================== --- trunk/octave-forge/main/comm/inst/egolayenc.m 2012-08-21 00:32:36 UTC (rev 10891) +++ trunk/octave-forge/main/comm/inst/egolayenc.m 2012-08-21 00:59:49 UTC (rev 10892) @@ -14,57 +14,51 @@ ## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {} egolayenc (@var{M}) +## @deftypefn {Function File} {@var{C} =} egolayenc (@var{M}) +## Encode with Extended Golay code. ## -## -## Given @var{M}, encode M using the Extended Golay code. -## ## The message @var{M}, needs to be of size Nx12, for encoding. ## We can encode several messages, into codes at once, if they ## are stacked in the order suggested. ## -## The generator G used in here is same as obtained from the -## function egolaygen. Extended Golay code (24,12) which can correct +## The generator used in here is same as obtained from the +## function @code{egolaygen}. Extended Golay code (24,12) which can correct ## upto 3 errors. ## ## @example ## @group ## M=(rand(10,12)>0.5); ## C=egolayenc(M) -## ## @end group ## @end example ## -## @end deftypefn ## @seealso{egolaygen,egolaydec} +## @end deftypefn -function C=egolayenc(M) - if ( nargin < 1 ) - error('usage: C=egolayenc(M)'); - elseif ( columns(M) ~= 12 ) - error('extended golay code is (24,12), use message of column size 12'); - end +function C = egolayenc (M) - I=eye(12); - P=[1 0 0 0 1 1 1 0 1 1 0 1; - 0 0 0 1 1 1 0 1 1 0 1 1; - 0 0 1 1 1 0 1 1 0 1 0 1; - 0 1 1 1 0 1 1 0 1 0 0 1; - 1 1 1 0 1 1 0 1 0 0 0 1; - 1 1 0 1 1 0 1 0 0 0 1 1; - 1 0 1 1 0 1 0 0 0 1 1 1; - 0 1 1 0 1 0 0 0 1 1 1 1; - 1 1 0 1 0 0 0 1 1 1 0 1; - 1 0 1 0 0 0 1 1 1 0 1 1; - 0 1 0 0 0 1 1 1 0 1 1 1; - 1 1 1 1 1 1 1 1 1 1 1 0;]; - G=[P I]; %generator. + if (nargin < 1) + print_usage; + elseif (columns (M) != 12) + error("extended golay code is (24,12), use message of column size 12"); + endif - ##for rowi=1:rows(M) - ## C(rowi,:)=mod(M(rowi,:)*G,2); %code. - ##end + I = eye (12); + P = [1 0 0 0 1 1 1 0 1 1 0 1; + 0 0 0 1 1 1 0 1 1 0 1 1; + 0 0 1 1 1 0 1 1 0 1 0 1; + 0 1 1 1 0 1 1 0 1 0 0 1; + 1 1 1 0 1 1 0 1 0 0 0 1; + 1 1 0 1 1 0 1 0 0 0 1 1; + 1 0 1 1 0 1 0 0 0 1 1 1; + 0 1 1 0 1 0 0 0 1 1 1 1; + 1 1 0 1 0 0 0 1 1 1 0 1; + 1 0 1 0 0 0 1 1 1 0 1 1; + 0 1 0 0 0 1 1 1 0 1 1 1; + 1 1 1 1 1 1 1 1 1 1 1 0;]; + G = [P I]; %generator. - C=mod(M*repmat(G,[1,rows(M)]),2); - C=C(:,1:24); + C = mod (M * repmat (G, [1, rows(M)]), 2); + C = C(:, 1:24); -end +endfunction Modified: trunk/octave-forge/main/comm/inst/egolaygen.m =================================================================== --- trunk/octave-forge/main/comm/inst/egolaygen.m 2012-08-21 00:32:36 UTC (rev 10891) +++ trunk/octave-forge/main/comm/inst/egolaygen.m 2012-08-21 00:59:49 UTC (rev 10892) @@ -14,28 +14,34 @@ ## this program; if not, see <http://www.gnu.org/licenses/>. ## -*- texinfo -*- -## @deftypefn {Function File} {} egolaygen () +## @deftypefn {Function File} {[@var{G}, @var{P}]} = egolaygen () +## Extended Golay code generator matrix. ## -## Returns the Extended Golay code (24,12) generator matrix, -## which can correct upto 3 errors. The second argument is the partiy +## Returns @var{G}, the Extended Golay code (24,12) generator matrix, +## which can correct up to 3 errors. @var{P} is the partiy ## check matrix, for this code. ## +## @seealso{egolaydec,egolayenc} ## @end deftypefn -## @seealso{egolaydec,egolayenc} -function [G,P]=egolaygen() - I=eye(12); - P=[1 0 0 0 1 1 1 0 1 1 0 1; - 0 0 0 1 1 1 0 1 1 0 1 1; - 0 0 1 1 1 0 1 1 0 1 0 1; - 0 1 1 1 0 1 1 0 1 0 0 1; - 1 1 1 0 1 1 0 1 0 0 0 1; - 1 1 0 1 1 0 1 0 0 0 1 1; - 1 0 1 1 0 1 0 0 0 1 1 1; - 0 1 1 0 1 0 0 0 1 1 1 1; - 1 1 0 1 0 0 0 1 1 1 0 1; - 1 0 1 0 0 0 1 1 1 0 1 1; - 0 1 0 0 0 1 1 1 0 1 1 1; - 1 1 1 1 1 1 1 1 1 1 1 0;]; - G=[P I]; %generator. -end +function [G, P] = egolaygen () + + if (nargin != 0) + print_usage; + endif + + I = eye (12); + P = [1 0 0 0 1 1 1 0 1 1 0 1; + 0 0 0 1 1 1 0 1 1 0 1 1; + 0 0 1 1 1 0 1 1 0 1 0 1; + 0 1 1 1 0 1 1 0 1 0 0 1; + 1 1 1 0 1 1 0 1 0 0 0 1; + 1 1 0 1 1 0 1 0 0 0 1 1; + 1 0 1 1 0 1 0 0 0 1 1 1; + 0 1 1 0 1 0 0 0 1 1 1 1; + 1 1 0 1 0 0 0 1 1 1 0 1; + 1 0 1 0 0 0 1 1 1 0 1 1; + 0 1 0 0 0 1 1 1 0 1 1 1; + 1 1 1 1 1 1 1 1 1 1 1 0;]; + G = [P I]; %generator. +endfunction This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |