]> Creatis software - CreaPhase.git/blob - octave_packages/communications-1.1.1/@galois/dftmtx.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / communications-1.1.1 / @galois / dftmtx.m
1 ## Copyright (C) 2002 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{d} = } dftmtx (@var{a})
18 ##
19 ## Form a matrix, that can be used to perform Fourier transforms in
20 ## a Galois Field.
21 ##
22 ## Given that @var{a} is an element of the Galois Field GF(2^m), and
23 ## that the minimum value for @var{k} for which @code{@var{a} ^ @var{k}} 
24 ## is equal to one is @code{2^m - 1}, then this function produces a 
25 ## @var{k}-by-@var{k} matrix representing the discrete Fourier transform    
26 ## over a Galois Field with respect to @var{a}. The Fourier transform of
27 ## a column vector is then given by @code{dftmtx(@var{a}) * @var{x}}.
28 ##
29 ## The inverse Fourier transform is given by @code{dftmtx(1/@var{a})}
30 ## @end deftypefn
31
32 function d = dftmtx(a)
33
34   if (nargin != 1)
35     error ("usage: d = dftmtx (a)");
36   endif
37     
38   if (!isgalois(a))
39     error("dftmtx: argument must be a galois variable");
40   endif
41
42   m = a.m;
43   prim = a.prim_poly;
44   n = 2^a.m - 1;
45   if (n > 255)
46     error ([ "dftmtx: argument must be in Galois Field GF(2^m), where" ...
47            " m is not greater than 8"]); 
48   endif
49
50   if (length(a) ~= 1)
51     error ("dftmtx: argument must be a scalar");
52   endif
53
54   mp = minpol(a);
55   if ((mp(1) ~= 1) || !isprimitive(mp))
56     error("dftmtx: argument must be a primitive nth root of unity");
57   endif
58   
59   step = log(a);
60   step = step.x;
61   row = exp(gf([0:n-1], m, prim));
62   d = zeros(n);
63   for i=1:n;
64     d(i,:) = row .^ mod(step*(i-1),n);
65   end
66   
67 endfunction