DIT radix-2

Embed Size (px)

Citation preview

  • 8/22/2019 DIT radix-2

    1/7

    C o n n e x i o n s m o d u l e : m 1 2 0 1 6 1

    D e c i m a t i o n - i n - t i m e ( D I T ) R a d i x - 2 F F T

    V e r s i o n 1 . 7 : S e p 1 5 , 2 0 0 6 7 : 4 6 a m G M T - 5

    D o u g l a s L . J o n e s

    T h i s w o r k i s p r o d u c e d b y T h e C o n n e x i o n s P r o j e c t a n d l i c e n s e d u n d e r t h e

    C r e a t i v e C o m m o n s A t t r i b u t i o n L i c e n s e

    A b s t r a c t

    T h e r a d i x - 2 a l g o r i t h m s a r e t h e s i m p l e s t F F T a l g o r i t h m s . T h e d e c i m a t i o n - i n - t i m e ( D I T ) r a d i x - 2

    F F T r e c u r s i v e l y p a r t i t i o n s a D F T i n t o t w o h a l f - l e n g t h D F T s o f t h e e v e n - i n d e x e d a n d o d d - i n d e x e d t i m e

    s a m p l e s . T h e o u t p u t s o f t h e s e s h o r t e r F F T s a r e r e u s e d t o c o m p u t e m a n y o u t p u t s , t h u s g r e a t l y r e d u c i n g

    t h e t o t a l c o m p u t a t i o n a l c o s t .

    T h e r a d i x - 2 d e c i m a t i o n - i n - t i m e a n d d e c i m a t i o n - i n - f r e q u e n c y

    1

    f a s t F o u r i e r t r a n s f o r m s ( F F T s ) a r e t h e

    s i m p l e s t F F T a l g o r i t h m s

    2

    . L i k e a l l F F T s , t h e y g a i n t h e i r s p e e d b y r e u s i n g t h e r e s u l t s o f s m a l l e r , i n t e r m e d i a t e

    c o m p u t a t i o n s t o c o m p u t e m u l t i p l e D F T f r e q u e n c y o u t p u t s .

    1 D e c i m a t i o n i n t i m e

    T h e r a d i x - 2 d e c i m a t i o n - i n - t i m e a l g o r i t h m r e a r r a n g e s t h e d i s c r e t e F o u r i e r t r a n s f o r m ( D F T ) e q u a t i o n

    3

    i n t o

    t w o p a r t s : a s u m o v e r t h e e v e n - n u m b e r e d d i s c r e t e - t i m e i n d i c e s n = [0, 2, 4, . . . , N 2] a n d a s u m o v e r t h e o d d - n u m b e r e d i n d i c e s n = [1, 3, 5, . . . , N 1] a s i n ( 1 ) :

    X(k) =

    N1

    n=0

    x (n) e(i

    2nkN )

    =

    N2 1

    n=0

    x (2n) e(i

    2(2n)kN )

    +N

    2 1

    n=0

    x (2n + 1) e(i

    2(2n+1)kN )

    =

    N2 1

    n=0

    x (2n) e

    i2nkN2

    + e(i

    2kN )

    N2 1

    n=0

    x (2n + 1) e

    i2nkN2

    = DFTN2

    [[x (0) , x (2) , . . . , x (N 2)]] +WkN

    DFTN2

    [[x (1) , x (3) , . . . , x (N 1)]]

    ( 1 )

    T h e m a t h e m a t i c a l s i m p l i c a t i o n s i n ( 1 ) r e v e a l t h a t a l l D F T f r e q u e n c y o u t p u t s X(k) c a n b e c o m p u t e d a s t h e s u m o f t h e o u t p u t s o f t w o l e n g t h -

    N

    2D F T s , o f t h e e v e n - i n d e x e d a n d o d d - i n d e x e d d i s c r e t e - t i m e s a m p l e s ,

    r e s p e c t i v e l y , w h e r e t h e o d d - i n d e x e d s h o r t D F T i s m u l t i p l i e d b y a s o - c a l l e d t w i d d l e f a c t o r t e r m WkN

    =

    e(i2kN )

    . T h i s i s c a l l e d a d e c i m a t i o n i n t i m e b e c a u s e t h e t i m e s a m p l e s a r e r e a r r a n g e d i n a l t e r n a t i n g

    g r o u p s , a n d a r a d i x - 2 a l g o r i t h m b e c a u s e t h e r e a r e t w o g r o u p s . F i g u r e 1 g r a p h i c a l l y i l l u s t r a t e s t h i s f o r m

    o f t h e D F T c o m p u t a t i o n , w h e r e f o r c o n v e n i e n c e t h e f r e q u e n c y o u t p u t s o f t h e l e n g t h -

    N

    2D F T o f t h e e v e n -

    i n d e x e d t i m e s a m p l e s a r e d e n o t e d G (k) a n d t h o s e o f t h e o d d - i n d e x e d s a m p l e s a s H(k). B e c a u s e o f t h e p e r i o d i c i t y w i t h

    N

    2f r e q u e n c y s a m p l e s o f t h e s e l e n g t h -

    N

    2D F T s , G (k) a n d H(k) c a n b e u s e d t o c o m p u t e t w o

    o f t h e l e n g t h - N D F T f r e q u e n c i e s , n a m e l y X(k) a n d Xk + N

    2

    , b u t w i t h a d i e r e n t t w i d d l e f a c t o r . T h i s

    r e u s e o f t h e s e s h o r t - l e n g t h D F T o u t p u t s g i v e s t h e F F T i t s c o m p u t a t i o n a l s a v i n g s .

    h t t p : / / c r e a t i v e c o m m o n s . o r g / l i c e n s e s / b y / 1 . 0

    1

    " D e c i m a t i o n - i n - F r e q u e n c y ( D I F ) R a d i x - 2 F F T " < h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 1 8 / l a t e s t / >

    2

    " O v e r v i e w o f F a s t F o u r i e r T r a n s f o r m ( F F T ) A l g o r i t h m s " < h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 2 6 / l a t e s t / >

    3

    " D F T D e n i t i o n a n d P r o p e r t i e s " < h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 1 9 / l a t e s t / >

    h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 1 6 / 1 . 7 /

  • 8/22/2019 DIT radix-2

    2/7

    C o n n e x i o n s m o d u l e : m 1 2 0 1 6 2

    F i g u r e 1 : D e c i m a t i o n i n t i m e o f a l e n g t h - N D F T i n t o t w o l e n g t h - N

    2D F T s f o l l o w e d b y a c o m b i n i n g

    s t a g e .

    W h e r e a s d i r e c t c o m p u t a t i o n o f a l l

    ND F T f r e q u e n c i e s a c c o r d i n g t o t h e D F T e q u a t i o n

    4

    w o u l d r e q u i r e

    N2 c o m p l e x m u l t i p l i e s a n d N2 N c o m p l e x a d d i t i o n s ( f o r c o m p l e x - v a l u e d d a t a ) , b y r e u s i n g t h e r e s u l t s o f

    t h e t w o s h o r t - l e n g t h D F T s a s i l l u s t r a t e d i n F i g u r e 1 , t h e c o m p u t a t i o n a l c o s t i s n o w

    N e w O p e r a t i o n C o u n t s

    2N

    2

    2+N= N

    2

    2+ N c o m p l e x m u l t i p l i e s

    2N2

    N

    2 1

    +N = N

    2

    2c o m p l e x a d d i t i o n s

    T h i s s i m p l e r e o r g a n i z a t i o n a n d r e u s e h a s r e d u c e d t h e t o t a l c o m p u t a t i o n b y a l m o s t a f a c t o r o f t w o o v e r d i r e c t

    D F T

    5

    c o m p u t a t i o n !

    2 A d d i t i o n a l S i m p l i c a t i o n

    A b a s i c b u t t e r y o p e r a t i o n i s s h o w n i n F i g u r e 2 , w h i c h r e q u i r e s o n l y

    N

    2t w i d d l e - f a c t o r m u l t i p l i e s p e r

    s t a g e . I t i s w o r t h w h i l e t o n o t e t h a t , a f t e r m e r g i n g t h e t w i d d l e f a c t o r s t o a s i n g l e t e r m o n t h e l o w e r b r a n c h ,

    t h e r e m a i n i n g b u t t e r y i s a c t u a l l y a l e n g t h - 2 D F T ! T h e t h e o r y o f m u l t i - d i m e n s i o n a l i n d e x m a p s

    6

    s h o w s

    t h a t t h i s m u s t b e t h e c a s e , a n d t h a t F F T s o f a n y f a c t o r a b l e l e n g t h m a y c o n s i s t o f s u c c e s s i v e s t a g e s o f

    s h o r t e r - l e n g t h F F T s w i t h t w i d d l e - f a c t o r m u l t i p l i c a t i o n s i n b e t w e e n .

    4

    " D F T D e n i t i o n a n d P r o p e r t i e s " < h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 1 9 / l a t e s t / >

    5

    " D F T D e n i t i o n a n d P r o p e r t i e s " < h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 1 9 / l a t e s t / >

    6

    " M u l t i d i m e n s i o n a l I n d e x M a p s " < h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 2 5 / l a t e s t / >

    h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 1 6 / 1 . 7 /

  • 8/22/2019 DIT radix-2

    3/7

    C o n n e x i o n s m o d u l e : m 1 2 0 1 6 3

    ( a ) ( b )

    F i g u r e 2 : R a d i x - 2 D I T b u t t e r y s i m p l i c a t i o n : b o t h o p e r a t i o n s p r o d u c e t h e s a m e o u t p u t s

    3 R a d i x - 2 d e c i m a t i o n - i n - t i m e F F T

    T h e s a m e r a d i x - 2 d e c i m a t i o n i n t i m e c a n b e a p p l i e d r e c u r s i v e l y t o t h e t w o l e n g t h

    N

    2D F T

    7

    s t o s a v e c o m p u t a -

    t i o n . W h e n s u c c e s s i v e l y a p p l i e d u n t i l t h e s h o r t e r a n d s h o r t e r D F T s r e a c h l e n g t h - 2 , t h e r e s u l t i s t h e r a d i x - 2

    D I T F F T a l g o r i t h m ( F i g u r e 3 ) .

    F i g u r e 3 : R a d i x - 2 D e c i m a t i o n - i n - T i m e F F T a l g o r i t h m f o r a l e n g t h - 8 s i g n a l

    7

    " D F T D e n i t i o n a n d P r o p e r t i e s " < h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 1 9 / l a t e s t / >

    h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 1 6 / 1 . 7 /

  • 8/22/2019 DIT radix-2

    4/7

    C o n n e x i o n s m o d u l e : m 1 2 0 1 6 4

    T h e f u l l r a d i x - 2 d e c i m a t i o n - i n - t i m e d e c o m p o s i t i o n i l l u s t r a t e d i n F i g u r e 3 u s i n g t h e s i m p l i e d b u t t e r i e s

    ( F i g u r e 2 ) i n v o l v e s M = log2N s t a g e s , e a c h w i t h N

    2b u t t e r i e s p e r s t a g e . E a c h b u t t e r y r e q u i r e s 1 c o m p l e x

    m u l t i p l y a n d 2 a d d s p e r b u t t e r y . T h e t o t a l c o s t o f t h e a l g o r i t h m i s t h u s

    C o m p u t a t i o n a l c o s t o f r a d i x - 2 D I T F F T

    N

    2log2N c o m p l e x m u l t i p l i e s

    Nlog2N c o m p l e x a d d s

    T h i s i s a r e m a r k a b l e s a v i n g s o v e r d i r e c t c o m p u t a t i o n o f t h e D F T . F o r e x a m p l e , a l e n g t h - 1 0 2 4 D F T w o u l d

    r e q u i r e 1048576 c o m p l e x m u l t i p l i c a t i o n s a n d 1047552 c o m p l e x a d d i t i o n s w i t h d i r e c t c o m p u t a t i o n , b u t o n l y 5120 c o m p l e x m u l t i p l i c a t i o n s a n d 10240 c o m p l e x a d d i t i o n s u s i n g t h e r a d i x - 2 F F T , a s a v i n g s b y a f a c t o r o f 1 0 0 o r m o r e . T h e r e l a t i v e s a v i n g s i n c r e a s e w i t h l o n g e r F F T l e n g t h s , a n d a r e l e s s f o r s h o r t e r l e n g t h s .

    M o d e s t a d d i t i o n a l r e d u c t i o n s i n c o m p u t a t i o n c a n b e a c h i e v e d b y n o t i n g t h a t c e r t a i n t w i d d l e f a c t o r s ,

    n a m e l y U s i n g s p e c i a l b u t t e r i e s f o r W0N

    , WN

    2

    N, W

    N

    4

    N, W

    N

    8

    N, W

    3N8

    N, r e q u i r e n o m u l t i p l i c a t i o n s , o r f e w e r r e a l

    m u l t i p l i e s t h a n o t h e r o n e s . B y i m p l e m e n t i n g s p e c i a l b u t t e r i e s f o r t h e s e t w i d d l e f a c t o r s a s d i s c u s s e d i n F F T

    a l g o r i t h m a n d p r o g r a m m i n g t r i c k s , t h e c o m p u t a t i o n a l c o s t o f t h e r a d i x - 2 d e c i m a t i o n - i n - t i m e F F T c a n b e

    r e d u c e d t o

    2Nlog2N 7N+ 12 r e a l m u l t i p l i e s 3Nlog2N 3N+ 4 r e a l a d d i t i o n s

    N o t e : I n a d e c i m a t i o n - i n - t i m e r a d i x - 2 F F T a s i l l u s t r a t e d i n F i g u r e 3 , t h e i n p u t i s i n b i t -

    r e v e r s e d o r d e r ( h e n c e " d e c i m a t i o n - i n - t i m e " ) . T h a t i s , i f t h e t i m e - s a m p l e i n d e x n i s w r i t t e n a s a

    b i n a r y n u m b e r , t h e o r d e r i s t h a t b i n a r y n u m b e r r e v e r s e d . T h e b i t - r e v e r s a l p r o c e s s i s i l l u s t r a t e d f o r

    a l e n g t h - N = 8 e x a m p l e b e l o w .

    E x a m p l e 1 : N = 8

    I n - o r d e r i n d e x I n - o r d e r i n d e x i n b i n a r y B i t - r e v e r s e d b i n a r y B i t - r e v e r s e d i n d e x

    0 0 0 0 0 0 0 0

    1 0 0 1 1 0 0 4

    2 0 1 0 0 1 0 2

    3 0 1 1 1 1 0 6

    4 1 0 0 0 0 1 1

    5 1 0 1 1 0 1 5

    6 1 1 0 0 1 1 3

    7 1 1 1 1 1 1 7

    I t i s i m p o r t a n t t o n o t e t h a t , i f t h e i n p u t s i g n a l d a t a a r e p l a c e d i n b i t - r e v e r s e d o r d e r b e f o r e b e g i n n i n g t h e

    F F T c o m p u t a t i o n s , t h e o u t p u t s o f e a c h b u t t e r y t h r o u g h o u t t h e c o m p u t a t i o n c a n b e p l a c e d i n t h e s a m e

    m e m o r y l o c a t i o n s f r o m w h i c h t h e i n p u t s w e r e f e t c h e d , r e s u l t i n g i n a n i n - p l a c e a l g o r i t h m t h a t r e q u i r e s n o

    e x t r a m e m o r y t o p e r f o r m t h e F F T . M o s t F F T i m p l e m e n t a t i o n s a r e i n - p l a c e , a n d o v e r w r i t e t h e i n p u t d a t a

    w i t h t h e i n t e r m e d i a t e v a l u e s a n d n a l l y t h e o u t p u t .

    4 E x a m p l e F F T C o d e

    T h e f o l l o w i n g f u n c t i o n , w r i t t e n i n t h e C p r o g r a m m i n g l a n g u a g e , i m p l e m e n t s a r a d i x - 2 d e c i m a t i o n - i n - t i m e

    F F T . I t i s d e s i g n e d f o r c o m p u t i n g t h e D F T o f c o m p l e x - v a l u e d i n p u t s t o p r o d u c e c o m p l e x - v a l u e d o u t p u t s ,

    h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 1 6 / 1 . 7 /

  • 8/22/2019 DIT radix-2

    5/7

    C o n n e x i o n s m o d u l e : m 1 2 0 1 6 5

    w i t h t h e r e a l a n d i m a g i n a r y p a r t s o f e a c h n u m b e r s t o r e d i n s e p a r a t e d o u b l e - p r e c i s i o n o a t i n g - p o i n t a r r a y s . I t

    i s a n i n - p l a c e a l g o r i t h m , s o t h e i n t e r m e d i a t e a n d n a l o u t p u t v a l u e s a r e s t o r e d i n t h e s a m e a r r a y a s t h e i n p u t

    d a t a , w h i c h i s o v e r w r i t t e n . A f t e r i n i t i a l i z a t i o n s , t h e p r o g r a m r s t b i t - r e v e r s e s t h e d i s c r e t e - t i m e s a m p l e s , a s

    i s t y p i c a l w i t h a d e c i m a t i o n - i n - t i m e a l g o r i t h m ( b u t s e e a l t e r n a t e F F T s t r u c t u r e s

    8

    f o r D I T a l g o r i t h m s w i t h

    o t h e r i n p u t o r d e r s ) , t h e n c o m p u t e s t h e F F T i n s t a g e s a c c o r d i n g t o t h e a b o v e d e s c r i p t i o n .

    I h i s F F T p r o g r a m ( p . 5 ) u s e s a s t a n d a r d t h r e e - l o o p s t r u c t u r e f o r t h e m a i n F F T c o m p u t a t i o n . T h e o u t e r

    l o o p s t e p s t h r o u g h t h e s t a g e s ( e a c h c o l u m n i n F i g u r e 3 ) ; t h e m i d d l e l o o p s t e p s t h r o u g h " i g h t s " ( b u t t e r i e s

    w i t h t h e s a m e t w i d d l e f a c t o r f r o m e a c h s h o r t - l e n g t h D F T a t e a c h s t a g e ) , a n d t h e i n n e r l o o p s t e p s t h r o u g h t h e

    i n d i v i d u a l b u t t e r i e s . T h i s o r d e r i n g m i n i m i z e s t h e n u m b e r o f f e t c h e s o r c o m p u t a t i o n s o f t h e t w i d d l e - f a c t o r

    v a l u e s . S i n c e t h e b i t - r e v e r s e o f a b i t - r e v e r s e d i n d e x i s t h e o r i g i n a l i n d e x , b i t - r e v e r s a l c a n b e p e r f o r m e d f a i r l y

    s i m p l y b y s w a p p i n g p a i r s o f d a t a .

    N o t e : W h i l e o f O (NlogN) c o m p l e x i t y a n d t h u s m u c h f a s t e r t h a n a d i r e c t D F T , t h i s s i m p l e p r o g r a m i s o p t i m i z e d f o r c l a r i t y , n o t f o r s p e e d . A s p e e d - o p t i m i z e d p r o g r a m m a k i n g u s e o f a d d i t i o n a l

    e c i e n t F F T a l g o r i t h m a n d p r o g r a m m i n g t r i c k s

    9

    w i l l c o m p u t e a D F T s e v e r a l t i m e s f a s t e r o n m o s t

    m a c h i n e s .

    / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /

    / * f f t . c * /

    / * ( c ) D o u g l a s L . J o n e s * /

    / * U n i v e r s i t y o f I l l i n o i s a t U r b a n a - C h a m p a i g n * /

    / * J a n u a r y 1 9 , 1 9 9 2 * /

    / * * /

    / * f f t : i n - p l a c e r a d i x - 2 D I T D F T o f a c o m p l e x i n p u t * /

    / * * /

    / * i n p u t : * /

    / * n : l e n g t h o f F F T : m u s t b e a p o w e r o f t w o * /

    / * m : n = 2 * * m * /

    / * i n p u t / o u t p u t * /

    / * x : d o u b l e a r r a y o f l e n g t h n w i t h r e a l p a r t o f d a t a * /

    / * y : d o u b l e a r r a y o f l e n g t h n w i t h i m a g p a r t o f d a t a * /

    / * * /

    / * P e r m i s s i o n t o c o p y a n d u s e t h i s p r o g r a m i s g r a n t e d * /

    / * u n d e r a C r e a t i v e C o m m o n s " A t t r i b u t i o n " l i c e n s e * /

    / * h t t p : / / c r e a t i v e c o m m o n s . o r g / l i c e n s e s / b y / 1 . 0 / * /

    / * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * /

    f f t ( n , m , x , y )

    i n t n , m ;

    d o u b l e x [ ] , y [ ] ;

    {

    i n t i , j , k , n 1 , n 2 ;

    d o u b l e c , s , e , a , t 1 , t 2 ;

    j = 0 ; / * b i t - r e v e r s e * /

    n 2 = n / 2 ;

    f o r ( i = 1 ; i < n - 1 ; i + + )

    8

    " A l t e r n a t e F F T S t r u c t u r e s " < h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 1 2 / l a t e s t / >

    9

    " E c i e n t F F T A l g o r i t h m a n d P r o g r a m m i n g T r i c k s " < h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 2 1 / l a t e s t / >

    h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 1 6 / 1 . 7 /

  • 8/22/2019 DIT radix-2

    6/7

    C o n n e x i o n s m o d u l e : m 1 2 0 1 6 6

    {

    n 1 = n 2 ;

    w h i l e ( j >= n 1 )

    {

    j = j - n 1 ;

    n 1 = n 1 / 2 ;

    }

    j = j + n 1 ;

    i f ( i < j )

    {

    t 1 = x [ i ] ;

    x [ i ] = x [ j ] ;

    x [ j ] = t 1 ;

    t 1 = y [ i ] ;

    y [ i ] = y [ j ] ;

    y [ j ] = t 1 ;

    }

    }

    n 1 = 0 ; / * F F T * /

    n 2 = 1 ;

    f o r ( i = 0 ; i < m ; i + + )

    {

    n 1 = n 2 ;

    n 2 = n 2 + n 2 ;

    e = - 6 . 2 8 3 1 8 5 3 0 7 1 7 9 5 8 6 / n 2 ;

    a = 0 . 0 ;

    f o r ( j = 0 ; j < n 1 ; j + + )

    {

    c = c o s ( a ) ;

    s = s i n ( a ) ;

    a = a + e ;

    f o r ( k = j ; k < n ; k = k + n 2 )

    {

    t 1 = c * x [ k + n 1 ] - s * y [ k + n 1 ] ;

    t 2 = s * x [ k + n 1 ] + c * y [ k + n 1 ] ;

    x [ k + n 1 ] = x [ k ] - t 1 ;

    y [ k + n 1 ] = y [ k ] - t 2 ;

    x [ k ] = x [ k ] + t 1 ;

    y [ k ] = y [ k ] + t 2 ;

    }

    }

    }

    r e t u r n ;

    }

    h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 1 6 / 1 . 7 /

  • 8/22/2019 DIT radix-2

    7/7

    C o n n e x i o n s m o d u l e : m 1 2 0 1 6 7

    h t t p : / / c n x . o r g / c o n t e n t / m 1 2 0 1 6 / 1 . 7 /