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