10.12.2012 Views

Prime Numbers

Prime Numbers

Prime Numbers

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

9.5 Large-integer multiplication 479<br />

Algorithm 9.5.4 (FFT, recursive form). Given a length-(D =2 d ) signal x<br />

whose DFT (Definition 9.5.3) exists, this algorithm calculates said transform via<br />

a single call FFT(x). We employ the signal-length function len(), and within the<br />

recursion the root g of unity is to have order equal to current signal length.<br />

1. [Recursive FFT function]<br />

FFT(x) {<br />

n = len(x);<br />

if(n == 1) return x;<br />

m = n/2;<br />

X =(x2j) m−1<br />

j=0 ; // The even part of x.<br />

Y =(x2j+1) m−1<br />

j=0 ; // The odd part of x.<br />

X = FFT(X);<br />

Y = FFT(Y ); // Two recursive calls of half length.<br />

U =(Xkmod m) n−1<br />

k=0 ;<br />

V =(g−kYk mod m) n−1<br />

k=0 ; // Use root g of order n.<br />

return U + V ; // Realization of identity (9.22).<br />

}<br />

A little thought shows that the number of operations in the algebraic domain<br />

of interest is<br />

O(D ln D),<br />

and this estimate holds for both multiplies and add/subtracts. The D ln D<br />

complexity is typical of divide-and-conquer algorithms, another example of<br />

which would be the several methods for rapid sorting of elements in a list.<br />

This recursive form is instructive, and does have its applications, but the<br />

overwhelming majority of FFT implementations use a clever loop structure<br />

first achieved in [Cooley and Tukey 1965]. The Cooley–Tukey algorithm uses<br />

the fact that if the elements of the original length-(D = 2 d )signalx are<br />

given a certain “bit-scrambling” permutation, then the FFT can be carried<br />

out with convenient nested loops. The scrambling intended is reverse-binary<br />

reindexing, meaning that xj gets replaced by xk, wherek is the reverse-binary<br />

representation of j. For example, for signal length D =2 5 , the new element<br />

x5 after scrambling is the old x20, because the binary reversal of 5 = 001012<br />

is 101002 = 20. Note that this bit-scrambling of indices could in principle be<br />

carried out via sheer manipulation of indices to create a new, scrambled list;<br />

but it is often more efficient to do the scrambling in place, by using a certain<br />

sequence of two-element transpositions. It is this latter scheme that appears<br />

in the next algorithm.<br />

A most important observation is that the Cooley–Tukey scheme actually<br />

allows the FFT to be performed in place, meaning that an original signal x<br />

is replaced, element by element, with the DFT values. This is an extremely<br />

memory-efficient way to proceed, accounting for a great deal of the popularity<br />

of the Cooley–Tukey and related forms. With bit-scrambling properly done,<br />

the overall Cooley–Tukey scheme yields an in-place, in-order (meaning natural<br />

DFT order) FFT. Historically, the phrase “decimation in time” is attributed to

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!