0% found this document useful (0 votes)
145 views37 pages

Topic 10: The Fast Fourier Transform: ELEN E4810: Digital Signal Processing

The document discusses the Fast Fourier Transform (FFT) algorithm and the Short-Time Fourier Transform (STFT). It begins by explaining the calculation of the Discrete Fourier Transform (DFT) and its computational complexity of O(N2) operations. It then introduces the FFT algorithm which reduces this complexity to O(NlogN) by decomposing the DFT into smaller DFTs. The document also covers the decimation-in-time implementation and butterfly operations of the FFT. Finally, it discusses the STFT, which applies a short-time Fourier analysis to segments of a signal to analyze its time-varying spectrum, as shown in a spectrogram.

Uploaded by

souvik5000
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
145 views37 pages

Topic 10: The Fast Fourier Transform: ELEN E4810: Digital Signal Processing

The document discusses the Fast Fourier Transform (FFT) algorithm and the Short-Time Fourier Transform (STFT). It begins by explaining the calculation of the Discrete Fourier Transform (DFT) and its computational complexity of O(N2) operations. It then introduces the FFT algorithm which reduces this complexity to O(NlogN) by decomposing the DFT into smaller DFTs. The document also covers the decimation-in-time implementation and butterfly operations of the FFT. Finally, it discusses the STFT, which applies a short-time Fourier analysis to segments of a signal to analyze its time-varying spectrum, as shown in a spectrogram.

Uploaded by

souvik5000
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

ELEN E4810: Digital Signal Processing

Topic 10: The Fast Fourier Transform


1. Calculation of the DFT 2. The Fast Fourier Transform algorithm 3. Short-Time Fourier Transform

Dan Ellis

2013-11-27

1. Calculation of the DFT


! !

Filter design so far has been oriented to time-domain processing - cheaper! But: frequency-domain processing makes some problems very simple:
DFT
!

x[n]

X[k]

Fourier domain Y[k] IDFT processing

y[n]

use all of x[n], or use short-time windows

Need an efficient way to calculate DFT


2013-11-27 2

Dan Ellis

The DFT
!

Recall the DFT:


kn X[k ] = " x[n]WN n =0
!

N !1

( WN = e

!j

2" N

discrete transform of discrete sequence


1 1 WN 2 WN . . .
(N 1) WN

WN@2/N WNr has only N distinct values Structure opportunities for efficiency

!
X [N 1] X [0] X [1] X [2] . . .

1 1 1 = . . . 1

Matrix form:
1 2 WN 4 WN . . .
2(N 1) WN

.. .

(N 1) WN 2(N 1) WN . . . (N 1)2 WN

x[N 1]

x[0] x[1] x[2] . . .

Dan Ellis

2013-11-27

Computational Complexity
X[k ] = "
!

N !1 n =0

kn x[n]WN

N complex multiplies + N-1 complex adds per point (k) ! N points (k = 0.. N-1)
!

cpx mult: (a+jb)(c+jd) = ac - bd + j(ad + bc) = 4 real mults + 2 real adds cpx add = 2 real adds

N points: 4N2 real mults, 4N2-2N real adds


2013-11-27 4

Dan Ellis

Goertzels NAlgorithm !1 k! ! Now: X [k ] = " x [! ]W N


!=0 kN = WN

"! x[!]

! k ( N ! !) WN

looks like a convolution

X [k ] = yk [ N ] i.e. where yk [n] = xe [n] ! hk [n]


yk[n] yk[-1] = 0 yk[N] = X[k]
2013-11-27

x[n] 0 ! n < N xe[n] = { 0 n = N WN-kn n " 0 hk[n] = { 0 n < 0

xe[n] + xe[N] = 0 W -k z-1 N


Dan Ellis

Goertzels Algorithm
!

Separate filters for each X[k]


!

can calculate for just a few values of k

! !

No large buffer, no coefficient table Same complexity for full X[k] (4N2 mults, 4N2 - 2N adds)
!

H (z)

k !1 for last step 1 1 ! WN z = = ! k !1 "k z !1 + z !2 2 real mults 1 ! WN z 1 ! 2 cos 2N per step


2013-11-27 6

but: can halve multiplies by making the denominator real: evaluate only

Dan Ellis

2. Fast Fourier Transform FFT


!

Reduce complexity of DFT from O(N2) to O(NlogN)


!

grows more slowly with larger N

Works by decomposing large DFT into several stages of smaller DFTs Often provided as a highly optimized library

Dan Ellis

2013-11-27

Decimation in Time (DIT) FFT


!

Can rearrange DFT formula in 2 halves:


N "1 n =0 N "1 2

nk X [k ] = # x [n] ! WN
k = 0.. N-1

Arrange terms in pairs... Group terms from each pair

= =

m =0 N "1 2 m =0

# ( x[2m ]

2 mk ! WN

+ x [2m + 1] ! WN
N "1 2

(2 m +1) k

mk k mk x 2 m ! W + W x 2 m + 1 ! W ] N # [ ] N N # [
2

X0[<k>N/2] N/2 pt DFT of x for even n


2013-11-27

X1[<k>N/2] N/2 pt DFT of x for odd n


8

m =0

Dan Ellis

Decimation in Time (DIT) FFT


DFTN {x [n]} = DFTN {x0 [n]}
2

x[n] for even n

x[n] for odd n

k + WN DFTN 2

{x1 [n]}

We can evaluate an N-pt DFT as two N/2-pt DFTs (plus a few mults/adds) But if DFTN{} ~ O(N2) then DFTN/2{} ~ O((N/2)2) = 1/4 O(N2) Total computation ~ 2 ! 1/4 O(N2) = 1/2 the computation (+) of direct DFT

Dan Ellis

2013-11-27

One-Stage DIT Flowgraph


X [k ] = X0 k
Even x[0] points x[2] from x[4] x[n] x[6] Odd x[1] points x[3] from x[5] x[n] x[7]

[ ]
N 2

k + WN X1

[ ]
k
N 2

DFTN
2

X0[0] X0[1] X0[2] X0[3] X1[0] X1[1] X1[2] X1[3]

twiddle factors: always apply to odd-terms output NOT mirror-image


0 WN 1 WN 2 WN 3 WN 4 WN 5 WN 6 WN 7 WN

X[0] X[1] X[2] X[3] X[4] Same as X[5] X[0..3] except for X[6] factors on X[7] X1[]

DFTN
2

Classic FFT structure


Dan Ellis 2013-11-27

terms

10

Multiple DIT Stages


!

If decomposing one DFTN into two smaller DFTN/2s speeds things up ... Why not further divide into DFTN/4s ? k i.e. X [k ] = X0 k N + WN X1 k N

[ ] [ ] make: X [k ] = X [ k ] + W X [ k ]
0!k<N
2 2

00

0 ! k < N/2 N/4-pt DFT of even points N/4-pt DFT of odd points from even subset in even subset of x[n]

N 4

N 2

01

N 4

Similarly, X1 [k ] = X10 k
2013-11-27

[ ]
N 4

+ WNk X11 k
2 11

[ ]
N 4

Dan Ellis

Two-Stage DIT Flowgraph


different from before

x[0] x[4] x[2] x[6] x[1] x[5] x[3] x[7]

DFTN X 00
4

0 WN /2

DFTN X01
4

X0[0] X0[1] X0[2] X0[3]

same as before
0 WN 1 WN 2 WN 3 WN 4 WN 5 WN 6 WN 7 WN

DFTN X 10
4

DFTN X11
4

3 WN /2 X1[0] 0 WN/2 X1[1] X1[2] X1[3] 3 WN /2

X[0] X[1] X[2] X[3] X[4] X[5] X[6] X[7]

Dan Ellis

2013-11-27

12

Multi-stage DIT FFT


!

Can keep doing this until we get down to 2-pt DFTs:


butterfly element X[0] = x[0] + x[1] X[1] = x[0] - x[1]

DFT2

" N = 2M-pt DFT reduces to M stages of twiddle factors & summation (O(N2) part vanishes) " real mults < M4N , real adds < 2!M2N " complexity ~ O(NM) = O(Nlog2N)
Dan Ellis 2013-11-27 13

1 = W20 -1 = W21

FFT Implementation Details


!

Basic butterfly (at any stage):


XX0[r] XX1[r] WNr WNr+N/2 XX[r] 2 cpx mults XX[r+N/2] 2 " ( r+ N )
r+ N WN 2

=e

!j !j

N 2 "r N !j 2 "N / 2 N

Can simplify:
XX0[r] XX1[r] XX[r]

=e #e r = !WN

just one cpx mult! WNr -1 XX[r+N/2] i.e. SUB rather than ADD
2013-11-27 14

Dan Ellis

bit-reversed indexing

8-pt DIT FFT Flowgraph


000 100 010 110 001 101 011 111
! ! !

x[0] x[4] x[2] x[6] x[1] x[5] x[3] x[7]

W4 W4

W8 2 W8 3 W8

X[0] X[1] X[2] X[3] X[4] X[5] X[6] X[7]

-1s absorbed into summation nodes WN0 disappears in-place algorithm: sequential stages
2013-11-27 15

Dan Ellis

FFT for Other Values of N


! !

Having N = 2M meant we could divide each stage into 2 halves = radix-2 FFT Same approach works for:
! ! !

N = 3M radix-3 N = 4M radix-4 - more optimized radix-2 etc...

Composite N = abcd " mixed radix (different N/r point FFTs at each stage)
!

.. or just zero-pad to make N = 2M


2013-11-27 16

Dan Ellis

Inverse FFT
!

1 Recall IDFT: x[n] = N Thus: Nx [n] = "


* N !1 k =0

N !1

"

only differences from forward DFT


! nk X [k ]WN

k =0

Forward DFT of x#[n] = X*[k]|k=n i.e. time sequence made from spectrum
! nk * X [k ]WN

) = "X
k =0
Re -1 Im

N !1

nk [k ]WN

Hence, use FFT to calculate IFFT:


N 1 *
pure real flowgraph

x [n] =

1 N

X [k ]
*

nk WN

k =0

Re{X[k]} Im{X[k]}
2013-11-27

DFT

Re Im

1/N

-1/N

Re{x[n]} Im{x[n]}
17

Dan Ellis

DFT of Real Sequences


! ! !

If x[n] is pure-real, DFT wastes mults Real x[n] " Conj. symm. X[k] = X*[-k] Given two real sequences, x[n] and w[n] call y[n] = jw[n] , v[n] = x[n] + y[n] N-pt DFT V[k] = X[k] + Y[k] X[k] -Y[k] but: V[k]+V*[-k] = X[k]+X*[-k]+Y[k]+Y*[-k] X[k]=1/2(V[k]+V*[-k]) , W[k]=-j/2(V[k]-V*[-k]) i.e. compute DFTs of two N-pt real sequences with a single N-pt DFT
2013-11-27 18

Dan Ellis

3. Short-Time Fourier Transform (STFT)


! ! !

Fourier Transform (e.g. DTFT) gives spectrum of an entire sequence: How to see a time-varying spectrum? e.g. slow AM of a sinusoid carrier:
2 1 0 -1 -2 0 200 400 600 800 1000

# 2"n & x [n] = %1 ! cos ( cos ) 0 n $ N '

x[n]

n
19

Dan Ellis

2013-11-27

Fourier Transform of AM Sine


!

X[k] Spectrum of 400 whole sequence 200 indicates modulation 0 0 0.02 indirectly... Nsin2kn ... as N cancellation between -Nsin2(k-1)n closely2 N tuned -Nsin2(k+1)n sines 2 N
1 0.5 0 -0.5 -1 1 0.5 0 -0.5 -1 1 0.5 0 -0.5 -1

600

N N/2

2cAcB = cA+B +cA-B

0.04

0.06

0.08

k/(N/2)

128

256

384

512

640

768

896

Dan Ellis

2013-11-27

20

Fourier Transform of AM Sine


!

Sometimes wed rather separate modulation and carrier: x[n] = A[n]cos0n


!

A[n]

A[n] varies on a different (slower) timescale

One approach:
! ! !

chop x[n] into short sub-sequences .. .. where slow modulator is ~ constant DFT spectrum of pieces " show variation
2013-11-27 21

Dan Ellis

FT of Short Segments
!

Break up x[n] into successive, shorter chunks of length NFT, then DFT each:
2 1 0 -1

x[n]

NFT -2 = N/8 0 128 256 384 512 640 768 896 1024 = N x0[n] x1[n] x2[n] x3[n] x4[n] x5[n] x6[n] x7[n]
100 50 0

X0[k] X1[k] X2[k] X3[k] X4[k] X5[k] X6[k] X7[k]


0

64

Shows amplitude modulation of 0 energy


Dan Ellis

k0 = 0 NFT 2
2013-11-27

22

The Spectrogram
!

Plot successive DFTs in time-frequency:


X0[k] X1[k] X2[k] X3[k] X4[k] X5[k] X6[k] X7[k] k k
120 100 80 60 40 5 0 0 128 256 384 512 640 768 896 1024 20 0

Xi[k] X[k,n]
15

10

This image is called the Spectrogram


2013-11-27 23

time hopsize (between successive frames) = 128 points

Dan Ellis

Short-Time Fourier Transform


! !

Spectrogram = STFT magnitude plotted on time-frequency plane STFT is (DFT form): X [k , n0 ] =


N FT "1 n =0

$ x[n0 + n] ! w[n] ! e
window

2 #kn " jN FT

frequency time index index


!

NFT points of x starting at n0

DFT kernel

intensity as a function of time & frequency


2013-11-27 24

Dan Ellis

STFT Window Shape


!

w[n] provides time localization of STFT


!

e.g. rectangular selects x[n], n0 ! n < n0+NW

w[n]

DTFT form of STFT

But: resulting spectrum has same problems as windowing for FIR design: j! X e , n0 = DTFT{x [n0 + n] " w[n]}

&$ % e

j#n 0

X e

( )W (e
j#

j (! $# )

)d#

spectrum of short-time window is convolved with (twisted) parent spectrum


Dan Ellis 2013-11-27 25

STFT Window Shape


!

e.g. if x[n] is a pure sinusoid,


X(ej)

W(ej)


blurring (mainlobe) + ghosting (sidelobes)


W(ej)

Hence, use tapered window for w[n]


w[n]

e.g. Hamming

w[n] = n ) 0.54 + 0.46 cos(2! 2 M +1


-10 -5 0 5 10

sidelobes < -40 dB



26

Dan Ellis

2013-11-27

STFT Window Length


!

Length of w[n] sets temporal resolution


0.2 0.1 0 -0.1

x[n]

wS [n]

0.2 0.1 0

x[n]

wL[n]

short window measures only local properties


!
1 0.5

200

400

600

800

1000

-0.1

Window length " 1/(Mainlobe width)


wS[n]
N1 pts
0 -100 -50 0 20

longer window averages spectral character


WS(ej)

200

400

600

800

1000

10

n
100

zero at 4 N1
-0.5 0

wL[n]
N2 pts

50

0 - 20


1 0.5 0 10

WL(ej)
zero at 4 N2

0.5

shorter window " more blurred spectrum

n
-100 -50 0 50 100

more time detail

0 -


less frequency detail


27

-0.5

0.5

Dan Ellis

2013-11-27

STFT Window Length


!

Can illustrate time-frequency tradeoff on the time-frequency plane:


250 200 150 100 50 0 1 0.5 00 100 200 300

disks show blurring due to window length; area of disk is constant ! Uncertainty principle:

ft ! k
n

Alternate tilings of time-freq:


half-length window " half as many DFT samples
2013-11-27 28

Dan Ellis

Spectrograms of Real Sounds


0.1 0

time-domain
10 0

freq / Hz

4000

3000 -10 2000 -20 -30 1000 -40 0 2.35 4000 2.4 2.45 2.5 2.55 2.6 -50

successive short DFTs

intensity / dB

time / s

freq / Hz

3000

2000

1000

individual t-f cells merge into continuous image


0 0.5 1 1.5 2 2.5

time / s

Dan Ellis

2013-11-27

29

Narrowband vs. Wideband


!

Effect of varying window length:


0.2 0 4000

Window = 256 pt Narrowband

freq / Hz

3000

2000

10 0

1000 -10 0 -20 -30 -40 -50 2000

Window = 48 pt Wideband

freq / Hz

4000

3000

level / dB

1000

1.4

1.6

1.8

2.2

2.4

2.6

time / s

Dan Ellis

2013-11-27

30

Spectrogram in Matlab
>> >> >> >> >>
8000
Frequency

[d,sr]=wavread(mpgr1_sx419.wav'); (hann) window length Nw=256; specgram(d,Nw,sr) actual sampling rate caxis([-80 0]) (to label time axis) colorbar
0 -20 -40 -60 0.5 1 1.5 Time 2 2.5 3 -80

dB

6000 4000 2000 0

Dan Ellis

2013-11-27

31

STFT as a Filterbank
!

Consider one row of STFT: X k [n0 ] = $ x [n0 + n] ! w[n] ! e


N "1
kn " j 2# N

just one freq.

n =0 " ( N "1) m =0

$ hk [m ] x[n0 " m ]
1

convolution with complex IR


Im{x[n]}

where hk [n] = w[!n] " e


!

kn j 2# N

-1 -60 -40 0 -20 0 -1

Each STFT row is output of a filter (subsampled by the STFT hop size)
2013-11-27 32

Re{x[n]}

Dan Ellis

STFT as a Filterbank
!

If hk [n] = w[(!)n] " e then H k e

kn j 2# N

( ) = W (e
j!
H2(ej)

#k (" ) j (! " 2N )

shift-in-

Each STFT row is the same bandpass response defined by W(ej), frequency-shifted to a given DFT bin:
H1(ej)

W(ej)

A bank of identical, frequency-shifted bandpass filters: filterbank


33

Dan Ellis

2013-11-27

STFT Analysis-Synthesis
!

IDFT of STFT frames can reconstruct (part of) original waveform e.g. if X [k , n0 ] = DFT{x [n0 + n] ! w[n]} then IDFT{X [k , n0 ]} = x [n0 + n] ! w[n] ^ [n]: Can shift by n0, combine, to get x
^[n] x
n0

x[n]w[n-n0] n

Could divide by w[n-n0] to recover x[n]...


2013-11-27 34

Dan Ellis

STFT Analysis-Synthesis
! !

Dividing by small values of w[n] is bad


x[n]w[n-rH]

Prefer to overlap windows:

^[n] x n

i.e. sample X[k,n0] at n0 = rH where H = N/2 (for example)


hopsize window length
!

Then x [n] = "r x [n]w[n ! rH ] = x [n] if # w[n ! rH ] = 1


"r
2013-11-27 35

Dan Ellis

STFT Analysis-Synthesis
Hann or Hamming windows w[n] + w[n-N/2] with 50% overlap w[n] w[n-N/2] sum to constant n) 0.54 + 0.46 cos(2 ! ( N )
!
1 0.8 0.6 0.4 0.2 0 0 20 40 60 80

+ 0.54 + 0.46 cos(2!


!

n" N 2 N

) = 1.08

Can modify individual frames of X[k,n] and then reconstruct


! !

complex, time-varying modifications tapered overlap makes things OK


2013-11-27 36

Dan Ellis

STFT Analysis-Synthesis
!

e.g. Noise reduction:


STFT of original speech Speech corrupted by white noise Energy threshold mask
k
120 100 80 60 40 20 100 200 300

r
37

Dan Ellis

2013-11-27

You might also like