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