6.003 signal processing · di er? 6.003 signal processing week 6 lecture a (slide 3) 12 mar 2019....

29
6.003 Signal Processing Week 6, Lecture A: The Discrete Fourier Transform (DFT) Adam Hartz [email protected]

Upload: others

Post on 21-May-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

6.003Signal Processing

Week 6, Lecture A:

The Discrete Fourier Transform (DFT)

Adam [email protected]

Page 2: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

What is 6.003?

What is a signal?Abstractly, a signal is a function that conveys informationSignal processing is about extracting meaningfulinformation from signals, and/or manipulating informationin signals to produce new signals.

What is a transform?Provide multiple views/perspectives on a signalSome information more clearly visible (and/or more easilymanipulable) from one perspective than another.

6.003 Signal Processing Week 6 Lecture A (slide 2) 12 Mar 2019

Page 3: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

Why Fourier?

One reason: Many aspects of human perception are relatedto frequency representation.

Some things apparent in frequency but not in time (andvice versa).

Example: what are the following sounds, and how do theydiffer?

6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019

Page 4: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

So Far

So far, have talked about 4 transforms, useful for analyzingdifferent kinds of signals:

Transform Time Domain Frequency DomainCTFS continuous, periodic discrete, aperiodicDTFS discrete, periodic discrete, periodicCTFT continuous, aperiodic continuous, aperiodicDTFT discrete, aperiodic continuous, periodic

Four transforms already; why introduce another?

6.003 Signal Processing Week 6 Lecture A (slide 4) 12 Mar 2019

Page 5: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

Consider DTFT

DTFT: DT signal, CT spectrum X(Ω)

x[n] =1

∫2π

X(Ω)ejΩndΩ

X(Ω) =∞∑

n=−∞x[n]e−jΩn

Easiest to appreciate when x[n] and X(Ω) are defined asmathematical expressions.

However, it would be great to define the spectrum of asignal x[·] even when x[n] cannot be easily defined by amathematical expression.

Indeed, it would be great to be able to write a computerprogram that could efficiently calculate the spectrum of anarbitrary signal from samples of that signal.

6.003 Signal Processing Week 6 Lecture A (slide 5) 12 Mar 2019

Page 6: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

DFT

DFT (Discrete Fourier Transform) is discrete in bothdomains. Computationally feasible (opens doors toanalyzing complicated signals).

Most modern signal processing is based on the DFT, andwe’ll use the DFT almost exclusively moving forward in6.003.

Sidenote: FFT (Fast Fourier Transform) is an algorithmfor computing the DFT efficiently (lab 6).

6.003 Signal Processing Week 6 Lecture A (slide 6) 12 Mar 2019

Page 7: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

FFT

6.003 Signal Processing Week 6 Lecture A (slide 7) 12 Mar 2019

Page 8: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

Why Bother with the Others?

In part, because they inform our understanding /interpretation of the results of the DFT.

Our common goal with other science / engineeringendeavors is to

• model some aspect of the world

• analyze the model, and

• interpret results to gain better understanding.

Model Result

World New Understanding

(human)

(computer)

(human)

The computer is useless if we can’t interpret the results!

6.003 Signal Processing Week 6 Lecture A (slide 8) 12 Mar 2019

Page 9: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

Today: DFT

Today, we’ll introduce the Discrete Fourier Transform,examine some of its properties, and use it to explore aninteresting problem.

Today’s problem: given a piece of music, determine its key.

6.003 Signal Processing Week 6 Lecture A (slide 9) 12 Mar 2019

Page 10: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

Toward DFT

Starting with the DTFT analysis equation:

X(Ω) =

∞∑n=−∞

x[n]e−jΩn

If our goal is computational feasibility, two things stand inthe way:

• infinite sum

• continuous function of frequency

Solutions:

• only consider a finite number of samples in time, and

• only consider a finite number of frequencies.

6.003 Signal Processing Week 6 Lecture A (slide 10) 12 Mar 2019

Page 11: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

Toward DFT

Starting with the DTFT analysis equation:

X(Ω) =

∞∑n=−∞

x[n]e−jΩn

• only consider N samples

• take N uniformly spaced frequencies from the range0 ≤ Ω ≤ 2π

The DFT:

X[k] =1

NXw

(2πk

N

)=

1

N

N−1∑n=0

x[n]e−j 2πkN n

6.003 Signal Processing Week 6 Lecture A (slide 11) 12 Mar 2019

Page 12: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

DFT: Definition

DFT:

X[k] =1

N

N−1∑n=0

x[n]e−j 2πkN n

x[n] =

N−1∑k=0

X[k]ej2πkN n

Very similar in form to the other transforms we’ve seen(particularly the DTFS).

6.003 Signal Processing Week 6 Lecture A (slide 12) 12 Mar 2019

Page 13: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

DFT: Properties

Very similar in form to the other transforms we’ve seen(particularly the DTFS), so lots of the usual propertieshold.

Property y[n] Y [k]

Linearity Ax1[n] +Bx2[n] AX1[k] +BX2[k]

Time reversal x[−n] X[−k]

Time Delay x[n− n0] e−j 2πkN n0X[k]

Frequency Shift x[n]ej2πk0N n X[k − k0]

Conjugation x∗[n] X∗[−k]

6.003 Signal Processing Week 6 Lecture A (slide 13) 12 Mar 2019

Page 14: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

DFT: Examples

6.003 Signal Processing Week 6 Lecture A (slide 14) 12 Mar 2019

Page 15: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

DFT

Comparison to other Fourier representations.

Analysis Synthesis

DFT: X[k] =1

N

N−1∑n=0

x[n]e−j 2πkN n x[n] =

N−1∑k=0

X[k]ej2πkN n

DTFS: X[k] =1

N

∑n=〈N〉

x[n]e−j 2πkN n x[n] =

∑k=〈N〉

X[k]ej2πkN n

DTFT: X(Ω) =

∞∑n=−∞

x[n]e−jΩn x[n] =1

∫2π

X(Ω)ejΩndΩ

DTFS: x[n] is presumed to be periodic in NDTFT: x[n] is arbitraryDFT: only a portion of an arbitrary x[n] is considered

6.003 Signal Processing Week 6 Lecture A (slide 15) 12 Mar 2019

Page 16: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

DFT and DTFS

If a signal is periodic in the DFT analysis period N , thenthe DFT coefficients are equal to the DTFS coefficients.

Consider x1[n] = cos(2πn64

), then DFT coefficients are:

X1[k] =1

N

N−1∑n=0

x[n]e−j 2πkN n =

1

2δ[k − 1] +

1

2δ[k − 63]

k

X1[k]

0 64

0

12

6.003 Signal Processing Week 6 Lecture A (slide 16) 12 Mar 2019

Page 17: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

DFT and DTFS

If a signal is not periodic in the DFT analysis period N ,then there are no DTFS coefficients to compare.

Consider x2[n] = cos(3πn64

), then DFT coefficients are:

X2[k] =1

N

N−1∑n=0

x[n]e−j 2πkN n

k

X2[k]

0 64

0

12

Even though x2[n] contains a single frequency Ω = 3π/64,there are large components at every component k.

6.003 Signal Processing Week 6 Lecture A (slide 17) 12 Mar 2019

Page 18: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

DFT and DTFS

Although x2[n] = cos 3πn64

was not periodic in N = 64, we candefine a signal x3[n] that is equal to x2[n] for 0 ≤ n < 64 andperiodic in N = 64.

n

x3[n]

0 64 128

DFT coefficients of x2[n] equal the DTFS coefficients ofx3[n]. The large number of non-zero coefficients arenecessary to produce the step discontinuity at n = 64.

k

X2[k]

0 64

0

12

6.003 Signal Processing Week 6 Lecture A (slide 18) 12 Mar 2019

Page 19: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

DFT: Relation to DTFT

n

x[n]

6.003 Signal Processing Week 6 Lecture A (slide 19) 12 Mar 2019

Page 20: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

DFT: Relation to DTFT

n

x[n]

window

n

xw[n] = x[n]w[n]

0 N−1

6.003 Signal Processing Week 6 Lecture A (slide 20) 12 Mar 2019

Page 21: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

DFT: Relation to DTFT

n

x[n]

window

n

xw[n] = x[n]w[n]

0 N−1

DTFT

Ω

Xw(Ω)

−π 0 π

6.003 Signal Processing Week 6 Lecture A (slide 21) 12 Mar 2019

Page 22: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

DFT: Relation to DTFT

n

x[n]

window

n

xw[n] = x[n]w[n]

0 N−1

DTFT

Ω

Xw(Ω)

−π 0 π

k

1NXw

(2πkN

)

-N20 N

2

sample: Ω → 2πkN

scale: 1/N

6.003 Signal Processing Week 6 Lecture A (slide 22) 12 Mar 2019

Page 23: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

DFT: Relation to DTFT

n

x[n]

window

DFT

n

xw[n] = x[n]w[n]

0 N−1

DTFT

Ω

Xw(Ω)

−π 0 π

k

1NXw

(2πkN

)

-N20 N

2

sample: Ω → 2πkN

scale: 1/N

6.003 Signal Processing Week 6 Lecture A (slide 23) 12 Mar 2019

Page 24: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

Two Ways To Think About DFT

1. The DFT is equal to the DTFS of the periodicextension of the first N samples of a signal.

2. The DFT is equal to scaled samples of the DTFT of a“windowed” version of the original signal.

These views are equivalent – but they highlight differentphenomena.

6.003 Signal Processing Week 6 Lecture A (slide 24) 12 Mar 2019

Page 25: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

Check Yourself!

Consider a waveform containing a single, pure sinusoid.This waveform was recorded with a sampling rate of 8kHz,and we have 60 samples of the waveform. Computing theDFT magnitudes, we find:

0 10 20 30 40 50 60

0.0

0.1

0.2

0.3

0.4

0.5

What note is being played?How accurately can we tell?

6.003 Signal Processing Week 6 Lecture A (slide 25) 12 Mar 2019

Page 26: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

Frequency Resolution

We only have N distinct frequency “bins”.

Ω

k

f

π−π

N/2−N/2

fs/2−fs/2

We’re uniformly breaking up a range of 2π into N discretesamples: each “bin” has a “width” of 2π

N.

In Hz, each bin has a width of fs/N .The kth coefficient isassociated with a frequency of kfs/N .

Fundamental trade-off: increasing frequency resolutionnecessarily requires considering more samples of the signal(i.e., increasing N).

6.003 Signal Processing Week 6 Lecture A (slide 26) 12 Mar 2019

Page 27: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

Check Yourself!

For the previous example (pure sinusoid, fs = 8kHz), howmany samples do we need to consider in order to be able todetermine the frequency of the tone to within 1Hz? Within0.1Hz?

6.003 Signal Processing Week 6 Lecture A (slide 27) 12 Mar 2019

Page 28: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

Check Yourself!

For a portion of the Chopin song containing only onechord, 250332 samples long, and recorded with a samplingrate of 48kHz, the DFT magnitudes look like:

0 2000 4000 6000 8000 100000.000

0.002

0.004

0.006

0.008

Peaks in magnitude aroundk ≈ 1021, 1282, 1715, 2037, 2576, 3062, . . .

What are the frequencies (in Hz) of the notes being played?What chord does this correspond to?

6.003 Signal Processing Week 6 Lecture A (slide 28) 12 Mar 2019

Page 29: 6.003 Signal Processing · di er? 6.003 Signal Processing Week 6 Lecture A (slide 3) 12 Mar 2019. So Far So far, have talked about 4 transforms, useful for analyzing di erent kinds

Summary

New transform: DFT (discrete in both time and frequency)

Closely related to both DTFS and DTFT.

Enables computational analysis of complicated signals.

Recitation: Practice with DFT, analyzing tunes

PSet: Practice with DFT

Lab: Implement FFT

6.003 Signal Processing Week 6 Lecture A (slide 29) 12 Mar 2019