![](http://images-20200215.ebookreading.net/23/1/1/9781482247336/9781482247336__a-computational-introduction__9781482247336__bg21b.png)
The Fast Fourier Transform 521
Python
In : from numpy.fft import fft
In : x = np.arange(2,10)
In : fx = fft(x)
In : print fx
[ 44.+0.j -4.+9.65685425j -4.+4.j -4.+1.65685425j
-4.+0.j -4.-1.65685425j -4.-4.j -4.-9.65685425j]
This agrees—as it should!—with the computations above. Now, for even and odd subarrays:
Python
In : evenx = x[::2]
In : oddx = x[1::2]
In : feven =fft(evenx)
In : fodd = fft(oddx)
In : omega = np.exp(-2.0
*
np.pi
*
1j/8)
In : X1 = feven + omega
**
np.arange(4)
*
fodd
In : X2 = feven + omega
**
np.arange(4,8)
*
fodd
In : np.set
_
printoptions(precision=4)
In : print np.hstack([X1,X2])
[ 44. +0.0000e+00j -4. +9.6569e+00j -4. +4.0000e+00j -4. +1.6569e+00j
-4. -1.0658e-14j -4. -1.6569e+00j -4. -4.0000e+00j -4. -9.6569e+00j]
Note that because of Python’s array indexing starting at zero, the computation of X1 and
X2 is very straightforward.
As with the four-element transform, we can express the eight-element transform by
using a butterfly diagram. Such a diagram, treating the four-element FFT as a “black box,”
is shown in Figure C.4. Note that as in Figure C.3 the order of the original elements is
changed.
If we now replace the black box FFTs from Figure C.4 with the four-element butterfly
diagram of Figure C.3 we obtain a “complete” butterfly diagram for eight elements, which is
given in Figure C.5. To show the structure of the diagram, we have left out the multiplication
factors, which are simply inherited from their respective diagrams.
We have noted that the input values in our butterfly diagrams are not given in their
correct order. The ordering we require can be obtained by binary bit reversal. Suppose we
list the input elements x
i
in order but replace the indices with their binary expansions:
x
0
x
1
x
2
x
3
x
4
x
5
x
6
x
7
= x
000
x
001
x
010
x
011
x
100
x
101
x
110
x
111
Now we replace each index with the reversal of its bits, and go back to decimal:
x
000
x
100
x
010
x
110
x
001
x
101
x
011
x
111
= x
0
x
4
x
2
x
6
x
1
x
5
x
3
x
7
and now we have the new order for input into the FFT.
The particular form of the FFT we have developed here is known as the “decimation in
time, 2 radix” FFT. We can describe its general workings as follows:
1. Re-order the initial 2
n
vector elements by binary bit reversal
2. Butterfly the elements two at a time, using scaling factors 1 and −1