Farrukh Jabeen Algorthms 51 Assgnment #2 Due Date: June 15, 29. Assgnment # 2 Chapter 3 Dscrete Fourer Transforms Implement the FFT for the DFT. Descrbed n sectons 3.1 and 3.2. Delverables: 1. Concse descrpton of the problem. 2. Defne all the varables, ncludng nputs and outputs. 3. Provde an FFT soluton. 4. Analyze the run tme. 5. Gve 2 eamples, wth specfc values for the varables, showng each step of the algorthm. 6. Implement a software smulaton (any programmng language). a) user nputs values for the ntal varables (or read from a fle). b) soluton s prnted out. c) dscusson of the plausblty of the solutons (are they correct?). d) graphc dsplay (etra credt). 1. Concse descrpton of the problem. Polynomal: p + 2 3 4 ( = 5 + 2 + 8 + 3 4 n general p( = a p( 1 n 1 = or = + a + a 2 a 2 + L+ a n 1 n 1 Horner s Rule: Gven coeffcents (a,a 1,a 2,,a n-1 ), defnng polynomal
p( n = 1 = a Gven, we can evaluate p( n O(n) tme usng the equaton p( = a + ( a + 1 ( a + 2 L + ( a + n 2 an 1) L)) Gven coeffcents (a,a 1,a 2,,a n-1 ) and (b,b 1,b 2,,b n-1 ) defnng two polynomals, p() and q(), and number, compute p(q(. Horner s rule doesn t help, snce p( q( n = 1 = c Where c = j= a b j j A straghtforward evaluaton would take O(n 2 ) tme. The magcal FFT wll do t n O(n log n) tme Gven a set of n ponts n the plane wth dstnct -coordnates, there s eactly one (n-1)-degree polynomal gong through all these ponts. Alternate approach to computng p(q(: Calculate p() on 2n -values,, 1,, 2n-1. Calculate q() on the same 2n values. Fnd the (2n-1)-degree polynomal that goes through the ponts {(,p( )q( )), ( 1,p( 1 )q( 1 )),, ( 2n-1,p( 2n-1 )q( 2n-1 ))}. Unfortunately, a straghtforward evaluaton would stll take O(n 2 ) tme, as we would need to apply an O(n)-tme Horner s Rule evaluaton to 2n dfferent ponts. The magcal FFT wll do t n O(n log n) tme, by pckng 2n ponts that are easy to evaluate. Cooley-Tukey FFT algorthm The Cooley-Tukey algorthm, named after J.W. Cooley and John Tukey, s the most common fast Fourer transform (FFT) algorthm. It re-epresses the dscrete Fourer transform (DFT) of an arbtrary composte sze N = N1N2 n terms of smaller DFTs of szes N1 and N2, recursvely, n order to reduce the computaton tme to O(N log N) for hghly-composte N (smooth numbers). Because the Cooley-Tukey algorthm breaks the DFT nto smaller DFTs, t can be combned arbtrarly wth any other algorthm for the DFT. The rad-2 DIT case A rad-2 decmaton-n-tme (DIT) FFT s the smplest and most common form of the Cooley-Tukey algorthm. Rad-2 DIT dvdes a DFT of sze N nto two nterleaved DFTs (hence the name "rad-2") of sze N/2 wth each recursve stage.
The DFT s defned by the formula: where k s an nteger rangng from to N 1. Rad-2 DIT frst computes the Fourer transforms of the even-ndeed numbers ( ) and of the odd-ndeed numbers ( ), and then combnes those two results to produce the Fourer transform of the whole sequence. Ths dea can then be performed recursvely to reducee the overall runtme to O(N log N). Ths smplfed form assumes that N s a power of two; snce the number of sample ponts N can usually be chosen freely by the applcaton, ths s often not an mportant restrcton. More eplctly, let us wrte M = N / 2 and denote the DFT of the even-ndeed numbers 2m by E j and the DFT of the odd-ndeed numbers 2m + 1 by O j (m =,...,M 1, j =,...,M 1). Then t follows: Here we have used the crtcal fact that E k + M = E k and O k + M = O k, so that these DFTs, n addton to havng only M sample ponts, need only be evaluated for M values of k. The orgnal DFT has thus been dvded nto two DFTs of sze N/2. Ths process s an eample of the general technque of dvde and conquer algorthms; n many tradtonal mplementatons, however, the eplct recurson s avoded, and nstead one traverses the computatonal tree n breadth-frst fashon. The above re-epresson of a sze-nn DFT as two sze-n/2 DFTs s sometmes called the Danelson-Lanczos lemma, snce the dentty was noted by those two. They appled ther lemma n a "backwards" recursve fashon, repeatedly doublng the DFT sze untl the transform spectrum converged. The Danelson- (possbly Lanczos work predated wdespreadd avalablty of computers and requred hand calculaton wth mechancal ads such as addng machnes); they reported a computaton tme of 14 mnutes for a sze-64 DFT operatng on real nputs to 3-5 sgnfcant dgts. Cooley and Tukey's 1965 paper reported a runnng tme of.2 mnutes for a sze-248 comple DFT on an IBM 794 (probably n 36-bt sngle precson, ~8 dgts). Rescalng the tme by the number of operatons, ths corresponds roughly to a speedup factor of around 8,. (14 mnutes for sze 64 may sound lke a long tme, but t corresponds to an average of at most 16 seconds per floatng-pont operaton, around 2% of whch are multplcatons...ths s a farly mpressve rate for a human beng to sustan for over two hours.
More generally, Cooley-Tukey algorthms recursvely re-epress a DFT of a composte sze N = N 1 N 2 as: 1. Perform N 1 DFTs of sze N 2. Multply by comple roots of unty called twddle factors. 2. Perform N 2 DFTs of sze N 1. Typcally, ether N 1 or N 2 s a small factor (not necessarly prme), called the rad (whch can dffer between stages of the recurson). If N 1 s the rad, t s called a decmaton n tme (DIT) algorthm, whereas f N 2 s the rad, t s decmaton n frequency (DIF, also called the Sande-Tukey algorthm). The verson presented above was a rad-2 DIT algorthm; n the fnal epresson, the phase multplyng the odd transform s the twddle factor, and the +/- combnaton (butterfly) of the even and odd transforms s a sze-2 DFT. (The rad's small DFT s sometmes known as a butterfly, so-called because of the shape of the dataflow dagram for the rad-2 case.) 2.Defne all the varables, ncludng nputs and outputs.3. Provde an FFT soluton.4. Analyze the run tme.5. Gve 2 eamples, wth specfc values for the varables, showng each step of the algorthm. Inputs: length N comple sequence. Or we can say compute the FFT of [], assumng ts length s a power of 2 outputs : y = fft( the followng mplementaton runs n O(N log N) tme Eample 1: N=4 fft of even terms Comple[] even = new Comple[N/2]; for (nt k = ; k < N/2; k++) { even[k] = [2*k]; } Comple[] q = fft(even);
fft of odd terms Comple[] odd = even; // reuse the array for (nt k = ; k < N/2; k++) { odd[k] = [2*k + 1]; } Comple[] r = fft(odd); combne Comple[] y = new Comple[N]; for (nt k = ; k < N/2; k++) { double kth = -2 * k * Math.PI / N; Comple wk = new Comple(Math.cos(kth), Math.sn(kth)); y[k] = q[k].plus(wk.tmes(r[k])); y[k + N/2] = q[k].mnus(wk.tmes(r[k])); Eample 2: For second eample we can take N=8 because ths algorthm works only for N s a power of two. 6. Implement a software smulaton (any programmng language).a) user nputs values for the ntal varables (or read from a fle).b) soluton s prnted out.c) dscusson of the plausblty of the solutons (are they correct?).d) graphc dsplay (etra credt). Please see java fles n the folder FFT on my web page. For N=4 ------------------- Absoulte Mnmum = 1.E-12.964925473156612.834229714597234.36455598316777.1915951989722586 y = fft( ------------------- Absoulte Mnmum = 1.E-12 1.432639475182664.6369491399835 -.6426345156247726 1.226898964844113.6369491399835 +.6426345156247726 We can check our soluton by takng fft
z = fft(y) ------------------- Absoulte Mnmum = 1.E-12.964925473156611.83422971459724.364555983167765.1915951989722514 References: webhome.csc.uvc.ca/~ruskey/classes/326/sldes/chpt1fft.ppt http://www.jmloy.com/algebra/roots.htm http://www.cs.ptt.edu/~krk/cs151/anmatons/fft.html http://en.wkpeda.org/wk/cooley-tukey_fft_algorthm http://www.cs.prnceton.edu/ntrocs/97data/fft.java.html