1
<?xml version="1.0" encoding="UTF-8"?>
3
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4
* Copyright (C) 1997 - INRIA
5
* Copyright (C) 2012 - Serge Steer - INRIA
7
* This file must be used under the terms of the CeCILL.
8
* This source file is licensed as described in the file COPYING, which
9
* you should have received as part of this distribution. The terms
10
* are also available at
11
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
14
<refentry xmlns="http://docbook.org/ns/docbook"
15
xmlns:xlink="http://www.w3.org/1999/xlink"
16
xmlns:svg="http://www.w3.org/2000/svg"
17
xmlns:mml="http://www.w3.org/1998/Math/MathML"
18
xmlns:db="http://docbook.org/ns/docbook"
19
version="5.0-subset Scilab" xml:lang="en" xml:id="fft">
21
<refname>fft</refname>
22
<refpurpose>fast Fourier transform.</refpurpose>
24
<refnamediv xml:id="ifft">
25
<refname>ifft</refname>
26
<refpurpose>fast Fourier transform.</refpurpose>
29
<title>Calling Sequence</title>
30
<synopsis>X=fft(A [,sign] [,option])
31
X=fft(A,sign,selection [,option])
32
X=fft(A,sign,dims,incr [,option] )
36
<title>Arguments</title>
41
<para>a real or complex vector or real or complex array
42
(vector, matrix or N-D array.
49
a real or complex array with same shape as <literal>A</literal>.
55
an integer. with possible values <literal>1</literal> or
56
<literal>-1</literal>. Select direct or inverse
57
transform. The default value is <literal>-1</literal>
64
a character string. with possible values
65
<literal>"symmetric"</literal> or
66
<literal>"nonsymmetric"</literal>. Indicates if
67
<literal>A</literal> is symmetric or not. If this argument
68
is omitted the algorithm automatically determines if
69
<literal>A</literal> is symmetric or not. See the
70
Description part for details.
74
<term>selection</term>
76
a vector containing index on <literal>A</literal> array
77
dimensions. See the Description part for details.
84
a vector of positive numbers with integer values, or a
85
vector of positive integers. See the Description part for details.
87
Each element must be a divisor
88
of the total number of elements of <literal>A</literal>.
91
The product of the elements must be less than the total
92
number of elements of <literal>A</literal>.
99
a vector of positive numbers with integer values, or a
100
vector of positive integers. See the Description part for
103
<literal>incr</literal> must have the same number of
104
elements than <literal>dims</literal>.
107
Each element must be a divisor of the total number of
108
elements of <literal>A</literal>.
111
The <literal>incr</literal> elements must be in strictly
119
<title>Description</title> This function realizes direct or
120
inverse 1-D or N-D Discrete Fourier Transforms.
123
<term>Short syntax </term>
129
<literal>X=fft(A,-1 [,option])</literal> or
130
<literal>X=fft(A [,option])</literal> gives a direct
134
<term>single variate</term>
137
If <literal>A</literal> is a vector a
138
single variate direct FFT is computed that
143
$x(k) = \sum_{m=1}^n {a(m)*e^{-\frac{2i*\pi}{n}
148
(the <literal>-1</literal> argument refers
149
to the sign of the exponent..., NOT to
156
<term>multivariate</term>
159
If <literal>A</literal> is a matrix or
160
a multidimensional array a multivariate direct
173
<literal>X=fft(A,1)</literal> or
174
<literal>X=ifft(A)</literal>performs the inverse
175
normalized transform, such
176
that<literal>A==ifft(fft(A))</literal>.
180
<term>single variate</term>
182
If <literal>A</literal> is a vector a single
183
variate inverse FFT is computed
187
{a(m)*e^{+\frac{2i*\pi}{n} (m-1) (k-1)}$
193
<term>multivariate</term>
196
If <literal>a</literal> is a matrix or or
197
a multidimensional array a multivariate inverse
210
<term>Long syntax for FFT along specified dimensions</term>
215
<literal>X=fft(A,sign,selection [,option])</literal>
216
allows to perform efficiently all direct or inverse
217
fft of the "slices" of <literal>A</literal> along
221
For example, if <literal>A</literal> is a 3-D array
222
<literal>X=fft(A,-1,2)</literal> is equivalent to:
224
<programlisting role=""><![CDATA[
227
X(i1,:,i3)=fft(A(i1,:,i3),-1);
232
and <literal>X=fft(A,-1,[1 3])</literal> is equivalent to:
234
<programlisting role=""><![CDATA[
236
X(:,i2,:)=fft(A(:,i2,:),-1);
242
<literal>X=fft(A,sign,dims,incr [,option])</literal> is
243
a previous syntax that also allows to perform all direct or
244
inverse fft of the slices of <literal>A</literal> along
248
For example, if <literal>A</literal> is an array with
249
<literal>n1*n2*n3</literal> elements
250
<literal>X=fft(A,-1,n1,1)</literal> is equivalent to
251
<literal>X=fft(matrix(A,[n1,n2,n3]),-1,1)</literal>.
252
and <literal>X=fft(A,-1,[n1 n3],[1 n1*n2])</literal>
254
<literal>X=fft(matrix(A,[n1,n2,n3]),-1,[1,3])</literal>.
261
<term>Using option argument</term> This argument can be used
262
to inform the fft algorithm about the symmetry of
263
<literal>A</literal> or of all its "slices". An N-D array
264
<literal>B</literal> with dimensions <literal>n1</literal>,
265
..., <literal>np</literal> is conjugate symmetric for the fft
266
if and only if <literal>B==conj(B([1 n1:-1:2],[1
267
n2:-1:2],...,[1 np:-1:2]))
270
result <literal>X</literal> is real and an efficient specific
271
algorithm can be used.
275
<term>"symmetric"</term> that value causes fft to treat
276
<literal>A</literal> or all its "slices" conjugate
277
symmetric. This option is useful to avoid automatic
278
determination of symmetry or if <literal>A</literal> or
279
all its "slices" are not exactly symmetric because of
283
<term>"nonsymmetric"</term> that value causes fft not to
284
take care of symmetry. This option is useful to avoid
285
automatic determination of symmetry.
288
<term>unspecified</term> If the option is omitted the
289
fft algorithm automatically checks for exact symmetry.
296
<term>Optimizing fft</term>
299
Remark: fftw function automatically stores his last
300
parameters in memory to re-use it in a second time. This
301
improves greatly the time computation when consecutives
302
calls (with same parameters) are performed.
305
It is possible to go further in fft optimization using
306
<link linkend="get_fftw_wisdom">get_fftw_wisdom</link>, <link
307
linkend="set_fftw_wisdom">set_fftw_wisdom</link> functions.
314
<title>Algorithms</title>
316
This function uses the <ulink url="http://www.fftw.org/">fftw3</ulink> library.
320
<title>Examples</title>
322
<programlisting role="example"><![CDATA[
323
//Frequency components of a signal
324
//----------------------------------
325
// build a noised signal sampled at 1000hz containing to pure frequencies
328
t = 0:1/sample_rate:0.6;
329
N=size(t,'*'); //number of samples
330
s=sin(2*%pi*50*t)+sin(2*%pi*70*t+%pi/4)+grand(1,N,'nor',0,1);
334
//s is real so the fft response is conjugate symmetric and we retain only the first N/2 points
335
f=sample_rate*(0:(N/2))/N; //associated frequency vector
341
<programlisting role="example"><![CDATA[
342
----------------------------------
345
X = fftshift(fft(A));
346
set(gcf(),"color_map",jetcolormap(128));
347
clf;grayplot(0:255,0:255,abs(X)')
349
<para>mupliple fft</para>
350
<programlisting role="example"><![CDATA[
351
//simple case, 3 1-D fft at a time
353
t=linspace(0,10,2048);
354
A=[2*sin(2*%pi*3*t)+ sin(2*%pi*3.5*t)
356
sin(2*%pi*0.5*t)+4*sin(2*%pi*0.8*t)];
360
f=fs*(0:(N/2))/N; //associated frequency vector
361
clf;plot(f(1:100)',abs(X(:,1:100))')
362
legend(["3 and 3.5 Hz","8 Hz","0.5 and 0.8 Hz"],"in_upper_left")
364
// 45 3-D fft at a time
366
A=matrix(rand(1,prod(Dims)),Dims);
370
//equivalent (but less efficient code)
374
ind=list(i1,:,i3,:,:);
375
y1(ind(:))=fft(A(ind(:)),-1);
380
<programlisting role="example"><![CDATA[
381
//Using explicit formula for 1-D discrete Fourier transform
382
//------------------------------------------------
383
function xf=DFT(x,flag);
385
//Compute the n by n Fourier matrix
386
if flag==1 then,//backward transformation
387
am=exp(2*%pi*%i*(0:n-1)'*(0:n-1)/n);
388
else //forward transformation
389
am=exp(-2*%pi*%i*(0:n-1)'*(0:n-1)/n);
391
xf=am*matrix(x,n,1);//dft
392
xf=matrix(xf,size(x));//reshape
393
if flag==1 then,xf=xf/n;end
396
//Comparison with the fast Fourier algorithm
398
norm(DFT(a,1) - fft(a,1))
399
norm(DFT(a,-1) - fft(a,-1))
401
timer();DFT(a,-1);timer()
402
timer();fft(a,-1);timer()
405
<refsection role="see also">
406
<title>See Also</title>
407
<simplelist type="inline">
409
<link linkend="corr">corr</link>
412
<link linkend="fftw_flags">fftw_flags</link>
415
<link linkend="get_fftw_wisdom">get_fftw_wisdom</link>
418
<link linkend="set_fftw_wisdom">set_fftw_wisdom</link>
421
<link linkend="fftw_forget_wisdom">fftw_forget_wisdom</link>
426
<title>Bibliography</title>
428
Matteo Frigo and Steven G. Johnson, "FFTW Documentation" <ulink url="http://www.fftw.org/#documentation">http://www.fftw.org/#documentation</ulink>