1FFT(3) User Contributed Perl Documentation FFT(3)
2
3
4
6 PDL::FFT - FFTs for PDL
7
9 FFTs for PDL. These work for arrays of any dimension, although ones
10 with small prime factors are likely to be the quickest.
11
12 For historical reasons, these routines work in-place and do not
13 recognize the in-place flag. That should be fixed.
14
16 use PDL::FFT qw/:Func/;
17
18 fft($real, $imag);
19 ifft($real, $imag);
20 realfft($real);
21 realifft($real);
22
23 fftnd($real,$imag);
24 ifftnd($real,$imag);
25
26 $kernel = kernctr($image,$smallk);
27 fftconvolve($image,$kernel);
28
30 The underlying C library upon which this module is based performs FFTs
31 on both single precision and double precision floating point piddles.
32 Performing FFTs on integer data types is not reliable. Consider the
33 following FFT on piddles of type 'double':
34
35 $r = pdl(0,1,0,1);
36 $i = zeroes($r);
37 fft($r,$i);
38 print $r,$i;
39 [2 0 -2 0] [0 0 0 0]
40
41 But if $r and $i are unsigned short integers (ushorts):
42
43 $r = pdl(ushort,0,1,0,1);
44 $i = zeroes($r);
45 fft($r,$i);
46 print $r,$i;
47 [2 0 65534 0] [0 0 0 0]
48
49 This used to occur because PDL::PP converts the ushort piddles to
50 floats or doubles, performs the FFT on them, and then converts them
51 back to ushort, causing the overflow where the amplitude of the
52 frequency should be -2.
53
54 Therefore, if you pass in a piddle of integer datatype (byte, short,
55 ushort, long) to any of the routines in PDL::FFT, your data will be
56 promoted to a double-precision piddle. If you pass in a float, the
57 single-precision FFT will be performed.
58
60 For even-sized input arrays, the frequencies are packed like normal for
61 FFTs (where N is the size of the array and D is the physical step size
62 between elements):
63
64 0, 1/ND, 2/ND, ..., (N/2-1)/ND, 1/2D, -(N/2-1)/ND, ..., -1/ND.
65
66 which can easily be obtained (taking the Nyquist frequency to be
67 positive) using
68
69 $kx = $real->xlinvals(-($N/2-1)/$N/$D,1/2/$D)->rotate(-($N/2 -1));
70
71 For odd-sized input arrays the Nyquist frequency is not directly
72 acessible, and the frequencies are
73
74 0, 1/ND, 2/ND, ..., (N/2-0.5)/ND, -(N/2-0.5)/ND, ..., -1/ND.
75
76 which can easily be obtained using
77
78 $kx =
79 $real->xlinvals(-($N/2-0.5)/$N/$D,($N/2-0.5)/$N/$D)->rotate(-($N-1)/2);
80
82 Various other modules - such as PDL::FFTW and PDL::Slatec - contain FFT
83 routines. However, unlike PDL::FFT, these modules are optional, and so
84 may not be installed.
85
87 fft()
88 Complex FFT of the "real" and "imag" arrays [inplace].
89
90 fft($real,$imag);
91
92 ifft()
93 Complex inverse FFT of the "real" and "imag" arrays [inplace].
94
95 ifft($real,$imag);
96
97 realfft()
98 One-dimensional FFT of real function [inplace].
99
100 The real part of the transform ends up in the first half of the array
101 and the imaginary part of the transform ends up in the second half of
102 the array.
103
104 realfft($real);
105
106 realifft()
107 Inverse of one-dimensional realfft routine [inplace].
108
109 realifft($real);
110
111 fftnd()
112 N-dimensional FFT (inplace)
113
114 fftnd($real,$imag);
115
116 ifftnd()
117 N-dimensional inverse FFT
118
119 ifftnd($real,$imag);
120
121 fftconvolve()
122 N-dimensional convolution with periodic boundaries (FFT method)
123
124 $kernel = kernctr($image,$smallk);
125 fftconvolve($image,$kernel);
126
127 fftconvolve works inplace, and returns an error array in kernel as an
128 accuracy check -- all the values in it should be negligible.
129
130 See also PDL::ImageND::convolveND, which performs speed-optimized
131 convolution with a variety of boundary conditions.
132
133 The sizes of the image and the kernel must be the same. kernctr
134 centres a small kernel to emulate the behaviour of the direct
135 convolution routines.
136
137 The speed cross-over between using straight convolution
138 (PDL::Image2D::conv2d()) and these fft routines is for kernel sizes
139 roughly 7x7.
140
141 convmath
142 Signature: ([o,nc]a(m); [o,nc]b(m))
143
144 Internal routine doing maths for convolution
145
146 convmath does not process bad values. It will set the bad-value flag
147 of all output piddles if the flag is set for any of the input piddles.
148
149 cmul
150 Signature: (ar(); ai(); br(); bi(); [o]cr(); [o]ci())
151
152 Complex multiplication
153
154 cmul does not process bad values. It will set the bad-value flag of
155 all output piddles if the flag is set for any of the input piddles.
156
157 cdiv
158 Signature: (ar(); ai(); br(); bi(); [o]cr(); [o]ci())
159
160 Complex division
161
162 cdiv does not process bad values. It will set the bad-value flag of
163 all output piddles if the flag is set for any of the input piddles.
164
166 Where the source is marked `FIX', could re-implement using phase-shift
167 factors on the transforms and some real-space bookkeeping, to save some
168 temporary space and redundant transforms.
169
171 This file copyright (C) 1997, 1998 R.J.R. Williams
172 (rjrw@ast.leeds.ac.uk), Karl Glazebrook (kgb@aaoepp.aao.gov.au), Tuomas
173 J. Lukka, (lukka@husc.harvard.edu). All rights reserved. There is no
174 warranty. You are allowed to redistribute this software / documentation
175 under certain conditions. For details, see the file COPYING in the PDL
176 distribution. If this file is separated from the PDL distribution, the
177 copyright notice should be included in the file.
178
179
180
181perl v5.12.3 2011-03-31 FFT(3)