+ All Categories
Home > Documents > 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o...

1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o...

Date post: 06-Feb-2018
Category:
Upload: vumien
View: 214 times
Download: 1 times
Share this document with a friend
15
Author: Arkadi Kagan. [email protected] This text do not contain generalized prove of what is FFT, what are requirements and strict limitations for FFT to be a valid approach. What I do describe here is Fast Fourier Transform for Complex and Real Vectors, based on set of Pairwise Orthogonal Functions of the form e j 2 nk N , cos 2 nk N and sin 2 nk N . Else I restrict FFT to the only its “Radix 2” variant. Lets start from reminding Discrete Fourier Transform formulas that can be found in a lot of sources. The forward DFT, given a vector of complex values, compute Fourier coefficients: F k 1 N n 0 N 1 f n e j 2 nk N and corresponding inverse transform: f n 1 N k 0 N 1 F k e j 2 nk N . From the above formulas we get the simplest algorithm to calculate DFT: DFT(N, f) for k = 0 to N-1 S = 0 for n = 0 to N-1 S += f n e j 2 nk N F k 1 N S return F The same algorithm can be written for the inverse transform. This algorithm, sometimes refered as Direct DFT is very simple. However, cosmetic changes will not change a fact that Direct DFT involve N 2 operations loop.
Transcript
Page 1: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

�������������� ������������������������Author: Arkadi Kagan. [email protected]

This text do not contain generalized prove of what is FFT, what are requirements and strict limitationsfor FFT to be a valid approach. What I do describe here is Fast Fourier Transform for Complex and

Real Vectors, based on set of Pairwise Orthogonal Functions of the form ej 2 nk

N ,

cos 2 ! nkN

and sin 2 ! nkN

. Else I restrict FFT to the only its “Radix 2” variant.

Lets start from reminding Discrete Fourier Transform formulas that can be found in a lot of sources.The forward DFT, given a vector of complex values, compute Fourier coefficients:

F k " 1N

#n $ 0

N % 1

f n e% j 2 nk

N

and corresponding inverse transform:

f n " 1N

#k $ 0

N % 1

F k ej 2 nk

N .

From the above formulas we get the simplest algorithm to calculate DFT:DFT(N, f)

for k = 0 to N-1

S = 0

for n = 0 to N-1

S += f n e

% j 2 nkN

F k " 1

NS

return F

The same algorithm can be written for the inverse transform.This algorithm, sometimes refered as Direct DFT is very simple. However, cosmetic changes will notchange a fact that Direct DFT involve N 2 operations loop.

Page 2: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

Equations needed for Fast Transforms.Before getting close to the algorithm itself I want to prove a set of trivial trigonometric equations thatwill have a use in the farther computations.

e & j 2 ' x k ( NN ) e & j 2 ' xk

N * e & j 2 ' x

e & j 2 ' x ) cos 2 + x , j * sin 2 + x by Euler formula.

Remind that cos 2 - x . 1 and sin 2 / x 0 0 for integer x.

Conclusion:

e & j 2 ' x k ( NN 1 e & j 2 ' xk

N for any integer x.

cos 2 2 x k 3 NN

= ( cos 46587 0 cos 4 cos 7 9 sin 4 sin 7 )

= cos 2 : xkN

cos 2 : x ; sin 2 : xkN

sin 2 : x =

cos 2 - x . 1sin 2 - x . 0

} for any integer x = cos 2 : xkN

Conclusion:

cos 2 2 x k 3 NN < cos 2 2 xk

Nfor any integer x.

sin 2 = x k > NN

= ( sin 4�5�7 0 sin 4 cos 7 5 cos 4 sin 7 )

= sin 2 : xkN

cos 2 : x ; cos 2 : xkN

sin 2 : x =

cos 2 - x . 1sin 2 - x . 0

} for any integer x = sin 2 : xkN

Conclusion:

sin 2 = x k > NN ? sin 2 = xk

Nfor any integer x.

Page 3: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

e @ j 2 A x k B N C 2N D e @ j 2 A xk

N E e @ j A x

By Euler formula e F j G x H cos I x J j K sin I x H cos I x since sin L x M 0 for anyinteger x. This mean:

e N j O x P { Q 1 for x odd integer1 for x even integer

Conclusion:

e R j 2 S x k T N U 2N V { W e R j 2 S xk

N for x odd integer

X e R j 2 S xkN for x even integer

cos 2 Y x k Z N [ 2N

= ( cos \ X^] V cos \ cos ] W sin \ sin ] )

= cos 2 _ xkN

cos _ x ` sin 2 _ xkN

sin _ x =

(sin a x b 0 for any integer x

cos a x = { c 1 for odd integer x1 for even integer x

) = cos 2 _ xkN

cos _ x

Conclusion:

cos 2 d x k e N f 2N

= {g cos 2 d xk

Nfor odd integer x

e cos 2 d xkN

for even integer x

sin 2 h x k i N j 2N

= ( sin k6l8m n sin k cos m l cos k sin m )

= sin 2 o xkN

cos o x p cos 2 o xkN

sin o x =

( since sin q x n 0 ) = sin 2 o xkN

cos o x

Conclusion:

sin 2 o x k p N r 2N

= {s sin 2 o xk

Nfor odd integer x

p sin 2 o xkN

for even integer x

Page 4: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

Fast Transform.Fast Transform algorithm can be of two kinds: Decimation In Time (DIT) and Decimation InFrequency (DIF). Decimation In Time FFT is a bit simpler for understanding and that for I will startfrom this variant.

Recall Forward DFT formula:

F k t 1N

un v 0

N w 1

f n e x j 2 y nkN

The form of DFT formula is a sum of N elements. Split this summation to the odd and even elements:

F k z 1N

{n | 0

N2 } 1

f 2n e ~ j 2 � 2n kN ���

n � 0

N2 � 1

f 2n � 1 e � j 2 � 2n � 1 kN .

�n � 0

N2 � 1

f 2n e � j 2 � 2n kN ���

n � 0

N2 � 1

f 2n e � j 2 � nkN � 2 .

Notice that last summation is factored DFT. Introduce new variables:f e n � f 2n

F e k � 1N � 2

�n � 0

N2 � 1

f e n e � j 2 � nkN � 2

Here F e is DFT of even members of the vector f , marked f e . There is exactly N2

even

elements of vector f, if N is an even number. It is common to restrict FFT to work with values of N thatare power of 2. In this case there is no problem of odd N.

�n   0

N2 ¡ 1

f 2n ¢ 1 e £ j 2 ¤ 2n ¥ 1 kN ¦�§

n ¨ 0

N2 © 1

f 2n ª 1 e « j 2 ¬ 2nkN e ­ j 2 ® k

N =

¯n ° 0

N2 ± 1

f 2n ² 1 e ³ j 2 ´ nkN µ 2 e ¶ j 2 · k

N

Define variables for odd elements of vector f:f o n ¸ f 2n ¹ 1

F o k º 1N » 2

¼n ½ 0

N2 ¾ 1

f o n e ¿ j 2 À nkN Á 2

Page 5: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

Finally we get

F k  12

F e k à 12

F o k e Ä j 2 Å kN

This equation allow to write the basic loop of DIT FFT algorithm:

for k = 0 to N-1

F k Æ 1

2F e k Ç 1

2F o k e È j 2 É k

N

This loop is computing right F(k), but unfortunately only for k Ê N2

. Lets compute F k Ë N2

to get the reminded values.

F k Ì N2 Í

1N

( În Ï 0

N Ð 2 Ñ 1

f 2n e Ò j 2 Ó 2n k Ô N Õ 2N +

Ön × 0

N Ø 2 Ù 1

f 2n Ú 1 e Û j 2 Ü 2n Ý 1 k Þ N ß 2N )

Remind that: for even x à 2n e á j 2 â x k ã N ä 2N å e æ j 2 ç xk

N è e é j 2 ê 2n kN

and for odd x ë 2n ì 1 e í j 2 î x k ï N ð 2N ñ�ò e ó j 2 ô xk

N õ÷ö e ø j 2 ù 2n ú 1 kN .

By using notation of F e and F o we can rewrite:

F k û N ü 2 ý 12

F e k þ 12

F o k e ÿ j 2 � kN

Page 6: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

The remainder of the algorithm is to supply particles to the main loop:DIT N , f if N is equal to1 then return f

for n � 0 to N2� 1

f e n � f 2n f o n � f 2n � 1

F e � DIT N2

, f e

F o � DIT N2

, f o

for k � 0 to N2 1

F k 12

F e k � 12

F o k e� j 2 k

N

F k � N�2 � 1

2F e k � 1

2F o k e

� j 2 � kN

return FThis is the basic DIT-FFT algorithm.It can be optimized in a lot of ways and there are a lot of variants exist already.Reverse FFT is symmetric to the forward FFT. Recall IDFT formula:

f n � �k � 0

N � 1

F k ej 2 � nk

N

By using the same semantics we can write the main loop of the reverse DIT FFT like this:

for n � 0 to N2 � 1

f n � 12

f e n � 12

f o n ej 2 � n

N

f n � N � 2 12

f e n ! 12

f o n ej 2 " n

N

Page 7: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

The whole DIT IFFT algorithm can be rewritten this way:IDIT N , F if N is equal to1 then return F

for k # 0 to N2 $ 1

F e k % F 2k F o k & F 2k ' 1

f e ( IDIT N2

, F e

f o ) IDIT N2

, F o

for n * 0 to N2 + 1

f n , 12

f e n - 12

f o n ej 2 . n

N

f n / N 0 2 1 12

f e n 2 12

f o n ej 2 3 n

N

return fFor this algorithm we can apply the same optimizations that can be used for the forward transform.

Decimation In Frequency.

The second variant of FFT algorithm is Decimation In Frequency (DIF).Recall forward DFT formula:

F k 4 1N

5n 6 0

N 7 1

f n e 8 j 2 9 nkN

Instead of dividing the sum to the odd and even addendums, the sum can be divided simple by its

summation from 0 to N2 : 1 and from

N2

to N ; 1 :

Page 8: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

F k < 1N

=n > 0

N ? 1

f n e @ j 2 A nkN =

=1N

Bn C 0

N2 D 1

f n e E j 2 F nkN G H

n I N2

N J 1

f n e K j 2 L nkN =

=1N

Mn N 0

N2 O 1

f n e P j 2 Q nkN RTS

n U 0

N2 V 1

f n W N2

e X j 2 Y n Z N2

k

N =

=1N

[n \ 0

N2 ] 1

f n ^ f n _ N2

e ` j a k e b j 2 c nkN

The last summation is looking like a kind of Fourier Transform, however it is not, since N d N2

.

It was found that there are exist two cases and both afford to the recursive processing:

F 2k e 12

1N f 2

gn h 0

N2 i 1

f n j f n k N2

e l j 2 m k e n j 2 o nkN p 2 =

e q j 2 r k s cos2 tvu jsin2 w k x 1

=12

1N y 2

zn { 0

N2 | 1

f n } f n ~ N2

e � j 2 � nkN � 2

F 2k � 1 � 12

1N � 2

�n � 0

N2 � 1

f n � f n � N2

e � j 2 � k e � j � e � j 2 � n 2k � 1N =

e � j ��� cos �v� jsin �v��� 1

=12

1N � 2

�n � 0

N2 � 1

f n � f n   N2

e ¡ j 2 ¢ nkN £ 2 e ¤ j 2 ¥ n

N

Page 9: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

Here is the DIF FFT algorithm:DIF N , f if N is equal to1 then return f

for n ¦ 0 to N2 § 1

f e n ¨ f n © f n ª N2

12

f o n « f n ¬ f n ­ N2

12

e ® j ¯ nN

F e ° DIFN2

, f e

F o ± DIF N2

, f o

return Merge F e , F o // merge odd and even cooffecientsThis is the basic algorithm and there are a lot of possibilities to improve its performance. Else, asknown, it is always possible to replace recursion by loops.The inverse DIF is absolutely symmetric to the forward transform.Recall inverse DFT:

f n ² 1N

³k ´ 0

N µ 1

F k ej 2 ¶ nk

N

Or after splitting to the odd/even parts:

f 2n · 12

1N ¸ 2

¹k º 0

N2 » 1

F k ¼ F k ½ N2

ej 2 ¾ nk

N ¿ 2

f 2n À 1 Á 12

1N Â 2

Ãk Ä 0

N2 Å 1

F k Æ F k Ç N2

ej 2 È nk

N É 2 ej 2 Ê k

N

Page 10: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

From here we get the basic DIF IFFT:IDIF N , F if N is equal to1 return F

for k Ë 0 to N2 Ì 1

F e k Í F k Î F k Ï N2

12

F o k Ð F k Ñ F k Ò N2

12

ej Ó k

N

f e Ô IDIFN2

, F e

f o Õ IDIF N2

, F o

return Merge f e , f o // merge odd and even values

Page 11: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

Fast Cosine/Sine Transform.Remind formulas of Discrete Cosine/Sine Transforms:Cosine Transform:

f m Ö F 02 × Øn Ù 1

N Ú 1

F n cos 2 Û mnN

F m Ü 2N

Ýn Þ 0

N ß 1

f x cos 2 à mnN

Sine Transform:

f m áãân ä 1

N å 1

F n sin 2 æ mnN

( remind that sin 0 ç 0 )

F m è 2N

én ê 0

N ë 1

f x sin 2 ì mnN

Given this formulas we can try to build DIT (“Decimation In Time”) algorithm the same way we didfor Discrete Fourier Transform.í

n î 0

N ï 1

F n cos 2 ð mnN

=

= ñn ò 0

N2 ó 1

F 2n cos 2 ô mnN õ 2 ö ÷n ø 0

N2 ù 1

F 2n ú 1 cos 2 û m 2n ü 1N

=

cos ýÿþ�� � cos � cos � � sin � sin �= �

n 0

N2 1

F 2n cos 2 � mnN � 2 cos 2 � m

N

�n � 0

N2 � 1

F 2n � 1 cos 2 � mnN � 2 -

-sin 2 � mN

�n � 0

N2 � 1

F 2n � 1 sin 2 � mnN � 2

For large m the formula maignt be quit similar. Lets replace m by m � N � 2 .

Remind that cos 2 � m � N 2 nN

= {! cos 2 " mn

Nfor odd integer x

# cos 2 $ mnN

for even integer x

Page 12: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

and sin 2 % m & N ' 2 nN

= {( sin 2 ) mn

Nfor odd integer x

* sin 2 + mnN

for even integer x.

Therefore,n - 0

N . 1

F n cos 2 / m 0 N 1 2 nN

=

= 2n 3 0

N2 4 1

F 2n cos 2 5 mnN 6 2 7 cos 2 8 m

N

9n : 0

N2 ; 1

F 2n < 1 cos 2 = mnN > 2 +

+sin 2 ? mN

@n A 0

N2 B 1

F 2n C 1 sin 2 D mnN E 2

Symetrically we can compute sum of F n sin 2 F mnN

:

Gn H 0

N I 1

F n sin 2 J mnN

=

= Kn L 0

N2 M 1

F 2n sin 2 N mnN O 2 P Q

n R 0

N2 S 1

F 2n T 1 sin 2 U m 2n V 1N

=

sin WYX[Z \ sin ] cos ^ _ cos ` sin a= b

n c 0

N2 d 1

F 2n sin 2 e mnN f 2 g cos 2 h m

N

in j 0

N2 k 1

F 2n l 1 sin 2 m mnN n 2 +

+sin 2 o mN

pn q 0

N2 r 1

F 2n s 1 cos 2 t mnN u 2

Page 13: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

This equations can be used to compute Fast Cosine/Sine Transform based on DIT approach.

DIT-COS(N, f)

if N is equal 1

then return f

for n = 0 to N2 v 1

f e n w f 2n

f o n x f 2n y 1

F e z DIT-COS N2

, f e

F o1 { DIT-COS N2

, f o

F o2 | DIT-SIN N2

, f o

for k = 0 to N2 } 1

F k ~ F e k � cos 2 � kN

F o1 k � sin 2 � kN

F o2 k

F k � N � 2 � F e k � cos 2 � kN

F o1 k � sin 2 � kN

F o2 k

return F

Page 14: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

DIT-SIN(N, f)

if N is equal 1

then return {0}

for n = 0 to N2 � 1

f e n � f 2n

f o n � f 2n � 1

F e � DIT-SIN N2

, f e

F o1 � DIT-SIN N2

, f o

F o2 � DIT-COS N2

, f o

for k = 0 to N2 � 1

F k � F e k � cos 2 � kN

F o1 k � sin 2 � kN

F o2 k

F k � N � 2 � F e k � cos 2 � kN

F o1 k � sin 2 � kN

F o2 k

return F

This two functions provide single recursion for fast computation of Fast Cosine/Sine Transformsummation. Notice that computed sums are shifted Cosine/Sine Transforms.To compute real DCT some adjustment is needed:

FCT-DIT-COS(N, f) forward FCT

F = DIT-COS(N, f)

for n = 0 to N-1

F n � 2N

F n

return F

Page 15: 1 N F k N - SourceForgearkadianalysis.sourceforge.net/FFT.pdf · f n / N 0 2 1 1 2 f e n 2 1 2 f o n e j 2 3 n N return f For this algorithm we can apply the same optimizations that

IFCT-DIT-COS(N, F) inverse FCT

f = DIT-COS(N, F)

for n = 0 to N – 1

f n � f n   F 02

return f

The Sine Transform (DST) is quit similar:

FST-DIT-SIN(N, f) forward FST

F = DIT-SIN(N, f)

for n = 0 to N-1

F n ¡ 2N

F n

return F

Calling IFST-DIT-SIN(N, F) is equivalent to DIT-SIN(N, F).

The resulting algorithm FCT or FST have one advanced loop that is absent in the original ComplexFFT – instead of 2 N log2 N summations we have N ¢ 6 N log3 N summations. Thepossibilities to optimize FFT or FCT/FST are desired for separate discussion and this is out of scope.

TODO: Compute FCT/FST using DIF (“Decimation In Frequency”) approach.I will update this article when more free time will be available.

References:£¥¤§¦©¨«ª­¬©¬®¦­¯«ª±°³²µ´·¶¹¸©º³¸®ª©»¼¤½©¾§¿ ¸ ¾ ª³ª·ÀÁ¸ ¾§¿Ã À¹Ä©»®Å«Æ®¶§¸±ÇÁ¸®¶·²È¦§Ä³Ä§É§´Ëʳ¶³»¼¤ ¨§¶³¶ÍÌÏÎÑгзҳҩÒÓ¤ÔªÍ̧¶³Ä©Ä§É§´Õ¤ÖÆÍÄ·°¹Ð§¶ ¾ Ю¦§×©×³×³£©Ð¹Ø·Ù®¯ ½®Ú ¤ÜÛ³¦ÍÝ2. Fourier and the Frequency Domain

The University of Strathclyde http://www.spd.eee.strath.ac.uk/~interact/FFT/fourier.htmlÞÕߧà©áÁâ©ãåäÓßYäÁæ§â³ç³ç·è§æ³â·éêßìëîíÁâ§ç®ã·á¹æ®è§æ­ï©ð®ñ©áÁâ®æÍáÃò©áÁó±éôç®õ®ðÍá®ö÷ßøëùßïÍá¹ð±ö úüû«ýøþ ÿ ������� ��� ������������ ����� �������������� �!�"�"�#%$'&�& �(� ")!�* ������+,� * �����-���.�/�0����� &)1�2 �)����� " �3�)�� 2 ���4�����5�������)�6� !�" �7�

4. Fast Fourier transform. From Wikipedia, the free encyclopedia.http://en.wikipedia.org/wiki/Fast_Fourier_transform


Recommended