]> Creatis software - CreaPhase.git/blob - octave_packages/communications-1.1.1/gen2par.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / communications-1.1.1 / gen2par.m
1 ## Copyright (C) 2003 David Bateman
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} {@var{par} =} gen2par (@var{gen})
18 ## @deftypefnx {Function File} {@var{gen} =} gen2par (@var{par})
19 ##
20 ## Converts binary generator matrix @var{gen} to the parity chack matrix
21 ## @var{par} and visa-versa. The input matrix must be in standard form.
22 ## That is a generator matrix must be k-by-n and in the form [eye(k) P]
23 ## or [P eye(k)], and the parity matrix must be (n-k)-by-n and of the
24 ## form [eye(n-k) P'] or [P' eye(n-k)].
25 ##
26 ## @end deftypefn
27 ## @seealso{cyclgen,hammgen}
28
29 function par = gen2par (gen)
30
31   if (nargin != 1)
32     usage (" par = gen2par (gen)");
33   endif
34
35   [gr, gc] = size(gen);
36
37   if (gr > gc)
38     error ("gen2par: input matrix must be in standard form");
39   endif
40
41   ## Identify where is the identity matrix
42   if (isequal(gen(:,1:gr),eye(gr)))
43     par = [gen(:,gr+1:gc)', eye(gc-gr)];
44   elseif (isequal(gen(:,gc-gr+1:gc),eye(gr)))
45     par = [eye(gc-gr), gen(:,1:gc-gr)'];
46   else
47     error ("gen2par: input matrix must be in standard form");
48   endif
49
50 endfunction