]> Creatis software - CreaPhase.git/blob - octave_packages/communications-1.1.1/@galois/fft.m
Add a useful package (from Source forge) for octave
[CreaPhase.git] / octave_packages / communications-1.1.1 / @galois / fft.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} {} fft (@var{x})
18 ##
19 ## If @var{x} is a column vector, finds the FFT over the primitive element
20 ## of the Galois Field of @var{x}. If @var{x} is in the Galois  Field
21 ## GF(2^@var{m}), then @var{x} must have @code{2^@var{m} - 1} elements.
22 ## @end deftypefn
23
24 function y = fft(x)
25
26   if (nargin != 1)
27     error ("usage: y = fft (x)");
28   endif
29     
30   if (!isgalois(x))
31     error("fft: argument must be a galois variable");
32   endif
33
34   n = 2^x.m - 1;
35   if (n > 255)
36     error ([ "fft: argument must be in Galois Field GF(2^m), where", ...
37            " m is not greater than 8"]); 
38   endif
39   
40   alph = gf(2, x.m, x.prim_poly);
41   [nr,nc] = size(x);
42   if ((nc == 1) && (nr == n))
43     y = dftmtx(alph) * x;
44   elseif ((nc == n) && (nr == 1))
45     y = (dftmtx(alph) * x')';
46   else
47     error ("fft: argument must be a vector in GF(2^m) of length 2^m-1");
48   endif
49     
50 endfunction