<s>
It	O
re-expresses	O
the	O
discrete	B-Algorithm
Fourier	I-Algorithm
transform	I-Algorithm
(	O
DFT	O
)	O
of	O
an	O
arbitrary	O
composite	O
size	O
in	O
terms	O
of	O
N1	O
smaller	O
DFTs	O
of	O
sizes	O
N2	O
,	O
recursively	O
,	O
to	O
reduce	O
the	O
computation	O
time	O
to	O
O(N log N )	O
for	O
highly	O
composite	O
N	O
(	O
smooth	O
numbers	O
)	O
.	O
</s>
<s>
The	O
discrete	B-Algorithm
Fourier	I-Algorithm
transform	I-Algorithm
(	O
DFT	O
)	O
is	O
defined	O
by	O
the	O
formula	O
:	O
</s>
<s>
Note	O
that	O
final	O
outputs	O
are	O
obtained	O
by	O
a	O
+	O
/	O
−	O
combination	O
of	O
and	O
,	O
which	O
is	O
simply	O
a	O
size-2	O
DFT	O
(	O
sometimes	O
called	O
a	O
butterfly	B-Application
in	O
this	O
context	O
)	O
;	O
when	O
this	O
is	O
generalized	O
to	O
larger	O
radices	O
below	O
,	O
the	O
size-2	O
DFT	O
is	O
replaced	O
by	O
a	O
larger	O
DFT	O
(	O
which	O
itself	O
can	O
be	O
evaluated	O
with	O
an	O
FFT	O
)	O
.	O
</s>
<s>
This	O
process	O
is	O
an	O
example	O
of	O
the	O
general	O
technique	O
of	O
divide	B-Algorithm
and	I-Algorithm
conquer	I-Algorithm
algorithms	I-Algorithm
;	O
in	O
many	O
conventional	O
implementations	O
,	O
however	O
,	O
the	O
explicit	O
recursion	O
is	O
avoided	O
,	O
and	O
instead	O
one	O
traverses	O
the	O
computational	O
tree	O
in	O
breadth-first	B-Algorithm
fashion	O
.	O
</s>
<s>
The	O
above	O
re-expression	O
of	O
a	O
size-N	O
DFT	O
as	O
two	O
size-N/2	O
DFTs	O
is	O
sometimes	O
called	O
the	O
Danielson	B-Algorithm
–	I-Algorithm
Lanczos	I-Algorithm
lemma	I-Algorithm
,	O
since	O
the	O
identity	O
was	O
noted	O
by	O
those	O
two	O
authors	O
in	O
1942	O
(	O
influenced	O
by	O
Runge	O
's	O
1903	O
work	O
)	O
.	O
</s>
<s>
Cooley	O
and	O
Tukey	O
's	O
1965	O
paper	O
reported	O
a	O
running	O
time	O
of	O
0.02	O
minutes	O
for	O
a	O
size-2048	O
complex	O
DFT	O
on	O
an	O
IBM	B-Device
7094	I-Device
(	O
probably	O
in	O
36-bit	O
single	B-Algorithm
precision	I-Algorithm
,	O
~	O
8	O
digits	O
)	O
.	O
</s>
<s>
(	O
To	O
put	O
the	O
time	O
for	O
the	O
hand	O
calculation	O
in	O
perspective	O
,	O
140	O
minutes	O
for	O
size	O
64	O
corresponds	O
to	O
an	O
average	O
of	O
at	O
most	O
16	O
seconds	O
per	O
floating-point	B-Algorithm
operation	O
,	O
around	O
20%	O
of	O
which	O
are	O
multiplications	O
.	O
)	O
</s>
<s>
In	O
pseudocode	B-Language
,	O
the	O
below	O
procedure	O
could	O
be	O
written	O
:	O
</s>
<s>
Here	O
,	O
ditfft2(x,N,1 )	O
,	O
computes	O
X	O
=D	O
FT(x )	O
out-of-place	B-Algorithm
by	O
a	O
radix-2	O
DIT	O
FFT	O
,	O
where	O
N	O
is	O
an	O
integer	O
power	O
of	O
2	O
and	O
s=	O
1	O
is	O
the	O
stride	B-Data_Structure
of	O
the	O
input	O
x	O
array	B-Data_Structure
.	O
</s>
<s>
x+s	O
denotes	O
the	O
array	B-Data_Structure
starting	O
with	O
xs	O
.	O
</s>
<s>
(	O
The	O
results	O
are	O
in	O
the	O
correct	O
order	O
in	O
X	O
and	O
no	O
further	O
bit-reversal	B-Algorithm
permutation	I-Algorithm
is	O
required	O
;	O
the	O
often-mentioned	O
necessity	O
of	O
a	O
separate	O
bit-reversal	B-Algorithm
stage	O
only	O
arises	O
for	O
certain	O
in-place	B-Algorithm
algorithms	I-Algorithm
,	O
as	O
described	O
below	O
.	O
)	O
</s>
<s>
High-performance	O
FFT	O
implementations	O
make	O
many	O
modifications	O
to	O
the	O
implementation	O
of	O
such	O
an	O
algorithm	O
compared	O
to	O
this	O
simple	O
pseudocode	B-Language
.	O
</s>
<s>
For	O
example	O
,	O
one	O
can	O
use	O
a	O
larger	O
base	O
case	O
than	O
N	O
=	O
1	O
to	O
amortize	O
the	O
overhead	O
of	O
recursion	O
,	O
the	O
twiddle	O
factors	O
can	O
be	O
precomputed	O
,	O
and	O
larger	O
radices	O
are	O
often	O
used	O
for	O
cache	B-General_Concept
reasons	O
;	O
these	O
and	O
other	O
optimizations	O
together	O
can	O
improve	O
the	O
performance	O
by	O
an	O
order	O
of	O
magnitude	O
or	O
more	O
.	O
</s>
<s>
(	O
In	O
many	O
textbook	O
implementations	O
the	O
depth-first	B-Algorithm
recursion	O
is	O
eliminated	O
in	O
favor	O
of	O
a	O
nonrecursive	O
breadth-first	B-Algorithm
approach	O
,	O
although	O
depth-first	B-Algorithm
recursion	O
has	O
been	O
argued	O
to	O
have	O
better	O
memory	B-General_Concept
locality	I-General_Concept
.	O
)	O
</s>
<s>
The	O
version	O
presented	O
above	O
was	O
a	O
radix-2	O
DIT	O
algorithm	O
;	O
in	O
the	O
final	O
expression	O
,	O
the	O
phase	O
multiplying	O
the	O
odd	O
transform	O
is	O
the	O
twiddle	O
factor	O
,	O
and	O
the	O
+	O
/	O
-	O
combination	O
(	O
butterfly	B-Application
)	O
of	O
the	O
even	O
and	O
odd	O
transforms	O
is	O
a	O
size-2	O
DFT	O
.	O
</s>
<s>
(	O
The	O
radix	O
's	O
small	O
DFT	O
is	O
sometimes	O
known	O
as	O
a	O
butterfly	B-Application
,	O
so-called	O
because	O
of	O
the	O
shape	O
of	O
the	O
dataflow	B-Application
diagram	I-Application
for	O
the	O
radix-2	O
case	O
.	O
)	O
</s>
<s>
(	O
On	O
present-day	O
computers	O
,	O
performance	O
is	O
determined	O
more	O
by	O
cache	B-General_Concept
and	O
CPU	B-General_Concept
pipeline	I-General_Concept
considerations	O
than	O
by	O
strict	O
operation	O
counts	O
;	O
well-optimized	O
FFT	O
implementations	O
often	O
employ	O
larger	O
radices	O
and/or	O
hard-coded	O
base-case	O
transforms	O
of	O
significant	O
size	O
.	O
</s>
<s>
The	O
net	O
result	O
of	O
all	O
of	O
these	O
transpositions	O
,	O
for	O
a	O
radix-2	O
algorithm	O
,	O
corresponds	O
to	O
a	O
bit	B-Algorithm
reversal	I-Algorithm
of	O
the	O
input	O
(	O
DIF	O
)	O
or	O
output	O
(	O
DIT	O
)	O
indices	O
.	O
</s>
<s>
If	O
,	O
instead	O
of	O
using	O
a	O
small	O
radix	O
,	O
one	O
employs	O
a	O
radix	O
of	O
roughly	O
and	O
explicit	O
input/output	O
matrix	O
transpositions	O
,	O
it	O
is	O
called	O
a	O
four-step	O
algorithm	O
(	O
or	O
six-step	O
,	O
depending	O
on	O
the	O
number	O
of	O
transpositions	O
)	O
,	O
initially	O
proposed	O
to	O
improve	O
memory	B-General_Concept
locality	I-General_Concept
,	O
e.g.	O
</s>
<s>
for	O
cache	B-General_Concept
optimization	O
or	O
out-of-core	B-Application
operation	O
,	O
and	O
was	O
later	O
shown	O
to	O
be	O
an	O
optimal	O
cache-oblivious	B-Application
algorithm	I-Application
.	O
</s>
<s>
That	O
is	O
,	O
it	O
re-indexes	O
the	O
input	O
(	O
n	O
)	O
and	O
output	O
(	O
k	O
)	O
as	O
N1	O
by	O
N2	O
two-dimensional	O
arrays	O
in	O
column-major	B-Data_Structure
and	O
row-major	B-Data_Structure
order	I-Data_Structure
,	O
respectively	O
;	O
the	O
difference	O
between	O
these	O
indexings	O
is	O
a	O
transposition	O
,	O
as	O
mentioned	O
above	O
.	O
</s>
<s>
Cooley	O
and	O
Tukey	O
originally	O
assumed	O
that	O
the	O
radix	O
butterfly	B-Application
required	O
O(r2 )	O
work	O
and	O
hence	O
reckoned	O
the	O
complexity	O
for	O
a	O
radix	O
r	O
to	O
be	O
O( 	O
r2N/rlogrN	O
)	O
=	O
O(Nlog2(N )	O
r/log2r	O
)	O
;	O
from	O
calculation	O
of	O
values	O
of	O
r/log2r	O
for	O
integer	O
values	O
of	O
r	O
from	O
2	O
to	O
12	O
the	O
optimal	O
radix	O
is	O
found	O
to	O
be	O
3	O
(	O
the	O
closest	O
integer	O
to	O
e	O
,	O
which	O
minimizes	O
r/log2r	O
)	O
.	O
</s>
<s>
This	O
analysis	O
was	O
erroneous	O
,	O
however	O
:	O
the	O
radix-butterfly	O
is	O
also	O
a	O
DFT	O
and	O
can	O
be	O
performed	O
via	O
an	O
FFT	O
algorithm	O
in	O
O(r log r )	O
operations	O
,	O
hence	O
the	O
radix	O
r	O
actually	O
cancels	O
in	O
the	O
complexity	O
O(rlog(r )	O
N/rlogrN	O
)	O
,	O
and	O
the	O
optimal	O
r	O
is	O
determined	O
by	O
more	O
complicated	O
considerations	O
.	O
</s>
<s>
the	O
large	O
number	O
of	O
processor	B-General_Concept
registers	I-General_Concept
on	O
modern	O
processors	O
,	O
and	O
even	O
an	O
unbounded	O
radix	O
r	O
=	O
also	O
achieves	O
O(NlogN )	O
complexity	O
and	O
has	O
theoretical	O
and	O
practical	O
advantages	O
for	O
large	O
N	O
as	O
mentioned	O
above	O
.	O
</s>
<s>
Of	O
special	O
interest	O
is	O
the	O
problem	O
of	O
devising	O
an	O
in-place	B-Algorithm
algorithm	I-Algorithm
that	O
overwrites	O
its	O
input	O
with	O
its	O
output	O
data	O
using	O
only	O
O(1 )	O
auxiliary	O
storage	O
.	O
</s>
<s>
The	O
most	O
well-known	O
reordering	O
technique	O
involves	O
explicit	O
bit	B-Algorithm
reversal	I-Algorithm
for	O
in-place	B-Algorithm
radix-2	O
algorithms	O
.	O
</s>
<s>
Bit	B-Algorithm
reversal	I-Algorithm
is	O
the	O
permutation	B-Algorithm
where	O
the	O
data	O
at	O
an	O
index	O
n	O
,	O
written	O
in	O
binary	O
with	O
digits	O
b4b3b2b1b0	O
(	O
e.g.	O
</s>
<s>
Consider	O
the	O
last	O
stage	O
of	O
a	O
radix-2	O
DIT	O
algorithm	O
like	O
the	O
one	O
presented	O
above	O
,	O
where	O
the	O
output	O
is	O
written	O
in-place	B-Algorithm
over	O
the	O
input	O
:	O
when	O
and	O
are	O
combined	O
with	O
a	O
size-2	O
DFT	O
,	O
those	O
two	O
values	O
are	O
overwritten	O
by	O
the	O
outputs	O
.	O
</s>
<s>
However	O
,	O
the	O
two	O
output	O
values	O
should	O
go	O
in	O
the	O
first	O
and	O
second	O
halves	O
of	O
the	O
output	O
array	B-Data_Structure
,	O
corresponding	O
to	O
the	O
most	O
significant	O
bit	O
b4	O
(	O
for	O
N	O
=	O
32	O
)	O
;	O
whereas	O
the	O
two	O
inputs	O
and	O
are	O
interleaved	O
in	O
the	O
even	O
and	O
odd	O
elements	O
,	O
corresponding	O
to	O
the	O
least	O
significant	O
bit	O
b0	O
.	O
</s>
<s>
And	O
for	O
next	O
recursive	O
stage	O
,	O
those	O
4	O
least	O
significant	O
bits	O
will	O
become	O
b1b4b3b2	O
,	O
If	O
you	O
include	O
all	O
of	O
the	O
recursive	O
stages	O
of	O
a	O
radix-2	O
DIT	O
algorithm	O
,	O
all	O
the	O
bits	O
must	O
be	O
reversed	O
and	O
thus	O
one	O
must	O
pre-process	O
the	O
input	O
(	O
or	O
post-process	O
the	O
output	O
)	O
with	O
a	O
bit	B-Algorithm
reversal	I-Algorithm
to	O
get	O
in-order	O
output	O
.	O
</s>
<s>
(	O
If	O
each	O
size-N/2	O
subtransform	O
is	O
to	O
operate	O
on	O
contiguous	O
data	O
,	O
the	O
DIT	O
input	O
is	O
pre-processed	O
by	O
bit-reversal	B-Algorithm
.	O
)	O
</s>
<s>
Correspondingly	O
,	O
if	O
you	O
perform	O
all	O
of	O
the	O
steps	O
in	O
reverse	O
order	O
,	O
you	O
obtain	O
a	O
radix-2	O
DIF	O
algorithm	O
with	O
bit	B-Algorithm
reversal	I-Algorithm
in	O
post-processing	O
(	O
or	O
pre-processing	O
,	O
respectively	O
)	O
.	O
</s>
<s>
The	O
following	O
is	O
pseudocode	B-Language
for	O
iterative	O
radix-2	O
FFT	O
algorithm	O
implemented	O
using	O
bit-reversal	B-Algorithm
permutation	I-Algorithm
.	O
</s>
<s>
input	O
:	O
Array	B-Data_Structure
a	O
of	O
n	O
complex	O
values	O
where	O
n	O
is	O
a	O
power	O
of	O
2	O
.	O
</s>
<s>
output	O
:	O
Array	B-Data_Structure
A	O
the	O
DFT	O
of	O
a	O
.	O
</s>
<s>
input	O
:	O
Array	B-Data_Structure
a	O
of	O
n	O
complex	O
values	O
where	O
n	O
is	O
a	O
power	O
of	O
2	O
.	O
</s>
<s>
output	O
:	O
Array	B-Data_Structure
A	O
of	O
size	O
n	O
.	O
</s>
<s>
Alternatively	O
,	O
some	O
applications	O
(	O
such	O
as	O
convolution	O
)	O
work	O
equally	O
well	O
on	O
bit-reversed	O
data	O
,	O
so	O
one	O
can	O
perform	O
forward	O
transforms	O
,	O
processing	O
,	O
and	O
then	O
inverse	O
transforms	O
all	O
without	O
bit	B-Algorithm
reversal	I-Algorithm
to	O
produce	O
final	O
results	O
in	O
the	O
natural	O
order	O
.	O
</s>
<s>
Many	O
FFT	O
users	O
,	O
however	O
,	O
prefer	O
natural-order	O
outputs	O
,	O
and	O
a	O
separate	O
,	O
explicit	O
bit-reversal	B-Algorithm
stage	O
can	O
have	O
a	O
non-negligible	O
impact	O
on	O
the	O
computation	O
time	O
,	O
even	O
though	O
bit	B-Algorithm
reversal	I-Algorithm
can	O
be	O
done	O
in	O
O(N )	O
time	O
and	O
has	O
been	O
the	O
subject	O
of	O
much	O
research	O
.	O
</s>
<s>
Also	O
,	O
while	O
the	O
permutation	B-Algorithm
is	O
a	O
bit	B-Algorithm
reversal	I-Algorithm
in	O
the	O
radix-2	O
case	O
,	O
it	O
is	O
more	O
generally	O
an	O
arbitrary	O
(	O
mixed-base	O
)	O
digit	O
reversal	O
for	O
the	O
mixed-radix	O
case	O
,	O
and	O
the	O
permutation	B-Algorithm
algorithms	O
become	O
more	O
complicated	O
to	O
implement	O
.	O
</s>
<s>
To	O
these	O
ends	O
,	O
a	O
number	O
of	O
alternative	O
implementation	O
schemes	O
have	O
been	O
devised	O
for	O
the	O
Cooley	O
–	O
Tukey	O
algorithm	O
that	O
do	O
not	O
require	O
separate	O
bit	B-Algorithm
reversal	I-Algorithm
and/or	O
involve	O
additional	O
permutations	B-Algorithm
at	O
intermediate	O
stages	O
.	O
</s>
<s>
The	O
problem	O
is	O
greatly	O
simplified	O
if	O
it	O
is	O
out-of-place	B-Algorithm
:	O
the	O
output	O
array	B-Data_Structure
is	O
distinct	O
from	O
the	O
input	O
array	B-Data_Structure
or	O
,	O
equivalently	O
,	O
an	O
equal-size	O
auxiliary	O
array	B-Data_Structure
is	O
available	O
.	O
</s>
<s>
The	O
algorithm	O
performs	O
every	O
stage	O
of	O
the	O
FFT	O
out-of-place	B-Algorithm
,	O
typically	O
writing	O
back	O
and	O
forth	O
between	O
two	O
arrays	O
,	O
transposing	O
one	O
"	O
digit	O
"	O
of	O
the	O
indices	O
with	O
each	O
stage	O
,	O
and	O
has	O
been	O
especially	O
popular	O
on	O
SIMD	B-Device
architectures	O
.	O
</s>
<s>
Even	O
greater	O
potential	O
SIMD	B-Device
advantages	O
(	O
more	O
consecutive	O
accesses	O
)	O
have	O
been	O
proposed	O
for	O
the	O
Pease	O
algorithm	O
,	O
which	O
also	O
reorders	O
out-of-place	B-Algorithm
with	O
each	O
stage	O
,	O
but	O
this	O
method	O
requires	O
separate	O
bit/digit	O
reversal	O
and	O
O(N log N )	O
storage	O
.	O
</s>
<s>
One	O
can	O
also	O
directly	O
apply	O
the	O
Cooley	O
–	O
Tukey	O
factorization	O
definition	O
with	O
explicit	O
(	O
depth-first	B-Algorithm
)	O
recursion	O
and	O
small	O
radices	O
,	O
which	O
produces	O
natural-order	O
out-of-place	B-Algorithm
output	O
with	O
no	O
separate	O
permutation	B-Algorithm
step	O
(	O
as	O
in	O
the	O
pseudocode	B-Language
above	O
)	O
and	O
can	O
be	O
argued	O
to	O
have	O
cache-oblivious	B-Application
locality	O
benefits	O
on	O
systems	O
with	O
hierarchical	B-General_Concept
memory	I-General_Concept
.	O
</s>
<s>
A	O
typical	O
strategy	O
for	O
in-place	B-Algorithm
algorithms	I-Algorithm
without	O
auxiliary	O
storage	O
and	O
without	O
separate	O
digit-reversal	O
passes	O
involves	O
small	O
matrix	O
transpositions	O
(	O
which	O
swap	O
individual	O
pairs	O
of	O
digits	O
)	O
at	O
intermediate	O
stages	O
,	O
which	O
can	O
be	O
combined	O
with	O
the	O
radix	O
butterflies	B-Application
to	O
reduce	O
the	O
number	O
of	O
passes	O
over	O
the	O
data	O
.	O
</s>
