/usr/share/octave/packages/communications-1.1.1/systematize.m is in octave-communications-common 1.1.1-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 | ## Copyright (C) 2007 Muthiah Annamalai <muthiah.annamalai@uta.edu>
##
## This program is free software; you can redistribute it and/or modify it under
## the terms of the GNU General Public License as published by the Free Software
## Foundation; either version 3 of the License, or (at your option) any later
## version.
##
## This program is distributed in the hope that it will be useful, but WITHOUT
## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
## details.
##
## You should have received a copy of the GNU General Public License along with
## this program; if not, see <http://www.gnu.org/licenses/>.
## -*- texinfo -*-
## @deftypefn {Function File} {} systematize (@var{G})
##
## Given @var{G}, extract P partiy check matrix. Assume row-operations in GF(2).
## @var{G} is of size KxN, when decomposed through row-operations into a @var{I} of size KxK
## identity matrix, and a parity check matrix @var{P} of size Kx(N-K).
##
## Most arbitrary code with a given generator matrix @var{G}, can be converted into its
## systematic form using this function.
##
## This function returns 2 values, first is default being @var{Gx} the systematic version of
## the @var{G} matrix, and then the parity check matrix @var{P}.
##
## @example
## @group
## G=[1 1 1 1; 1 1 0 1; 1 0 0 1];
## [Gx,P]=systematize(G);
##
## Gx = [1 0 0 1; 0 1 0 0; 0 0 1 0];
## P = [1 0 0];
## @end group
## @end example
##
## @end deftypefn
## @seealso{bchpoly,biterr}
function [G,P]=systematize(G)
if ( nargin < 1 )
print_usage();
end
[K,N]=size(G);
if ( K >= N )
error('G matrix must be ordered as KxN, with K < N');
end
%
% gauss-jordan echelon formation,
% and then back-operations to get I of size KxK
% remaining is the P matrix.
%
for row=1:K
%
%pick a pivot for this row, by finding the
%first of remaining rows that have non-zero element
%in the pivot.
%
found_pivot=0;
if ( G(row,row) > 0 )
found_pivot=1;
else
%
% next step of Gauss-Jordan, you need to
% re-sort the remaining rows, such that their
% pivot element is non-zero.
%
for idx=row+1:K
if ( G(idx,row) > 0 )
tmp=G(row,:);
G(row,:)=G(idx,:);
G(idx,:)=tmp;
found_pivot=1;
break;
end
end
end
%
%some linearly dependent problems:
%
if ( ~found_pivot )
error('cannot systematize matrix G');
return
end
%
% Gauss-Jordan method:
% pick pivot element, then remove it
% from the rest of the rows.
%
for idx=row+1:K
if( G(idx,row) > 0 )
G(idx,:)=mod(G(idx,:)+G(row,:),2);
end
end
end
%
% Now work-backward.
%
for row=K:-1:2
for idx=row-1:-1:1
if( G(idx,row) > 0 )
G(idx,:)=mod(G(idx,:)+G(row,:),2);
end
end
end
%I=G(:,1:K);
P=G(:,K+1:end);
return;
end
|