]> Creatis software - CreaPhase.git/blob - octave_packages/communications-1.1.1/reedmullerenc.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / communications-1.1.1 / reedmullerenc.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} {}  reedmullerenc (@var{MSG},@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 ## Encodes the given message word/block, of column size k, 
24 ## corresponding to the RM(@var{R},@var{M}), and outputs a
25 ## code matrix @var{C}, on each row with corresponding codeword.
26 ## The second return value is the @var{G}, which is generator matrix
27 ## used for this code.
28 ##
29 ## @example
30 ## @group
31 ## MSG=[rand(10,11)>0.5];
32 ## [C,G]=reedmullerenc(MSG,2,4);
33 ##
34 ## @end group
35 ## @end example
36 ## 
37 ## @end deftypefn
38 ## @seealso{reedmullerdec,reedmullergen}
39 function [C,G]=reedmullerenc(MSG,R,M)
40       if ( nargin < 3 )
41          print_usage();
42       end
43      G=reedmullergen(R,M);
44      if ( columns(MSG) ~= rows(G) )
45         error('MSG size must be corresponding to (R,M) message size');
46      end
47      C=zeros(rows(MSG),2.^M);
48      for idx=1:rows(MSG)
49          C(idx,:)=mod(MSG(idx,:)*G,2);
50      end
51      return
52 end