]> Creatis software - CreaPhase.git/blob - octave_packages/communications-1.1.1/reedmullergen.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / communications-1.1.1 / reedmullergen.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} {}  reedmullergen (@var{R},@var{M})
18 ##
19 ## Definition type construction of Reed Muller code,
20 ## of order @var{R}, length @math{2^M}. This function
21 ## returns the generator matrix for the said order RM code.
22 ## 
23 ## RM(r,m) codes are characterized by codewords,
24 ## @code{sum ( (m,0) + (m,1) + @dots{} + (m,r)}.
25 ## Each of the codeword is got through spanning the
26 ## space, using the finite set of m-basis codewords.
27 ## Each codeword is @math{2^M} elements long.
28 ## see: Lin & Costello, "Error Control Coding", 2nd Ed.
29 ##
30 ## Faster code constructions (also easier) exist, but since 
31 ## finding permutation order of the basis vectors, is important, we 
32 ## stick with the standard definitions. To use decoder
33 ## function reedmullerdec,  you need to use this specific
34 ## generator function.
35 ##
36 ## @example
37 ## @group
38 ## G=reedmullergen(2,4);
39 ## @end group
40 ## @end example
41 ##
42 ## @end deftypefn
43 ## @seealso{reedmullerdec,reedmullerenc}
44 function G=reedmullergen(R,M)
45     if ( nargin < 2 )
46        print_usage();
47     end
48
49     G=ones(1,2^M);
50     if ( R == 0 )
51         return;
52     end
53     
54     a=[0];
55     b=[1];
56     V=[];
57     for idx=1:M;
58         row=repmat([a,b],[1,2^(M-idx)]);
59         V(idx,:)=row;
60         a=[a,a];
61         b=[b,b];
62     end
63     
64     G=[G; V];
65
66     if ( R == 1 )
67         return
68     else
69         r=2;
70         while r <= R
71             p=nchoosek(1:M,r);
72             prod=V(p(:,1),:).*V(p(:,2),:);
73             for idx=3:r
74                 prod=prod.*V(p(:,idx),:);
75             end
76             G=[G; prod];
77             r=r+1;
78         end
79     end
80     return
81 end