the discrete fourier transform - mcmaster university

54
The Discrete Fourier Transform Signal Processing PSYCH 711/712 Lecture 3

Upload: others

Post on 05-Jan-2022

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: The Discrete Fourier Transform - McMaster University

The Discrete Fourier Transform

Signal Processing PSYCH 711/712Lecture 3

Page 2: The Discrete Fourier Transform - McMaster University

DFT Properties

• symmetry

• linearity

• shifting

• scaling

Page 3: The Discrete Fourier Transform - McMaster University

Symmetry

0 5 10 15

-10

-50

510

m

X(m)

0 5 10 15

-1.0

-0.5

0.0

0.5

1.0

n

x(n)

X(m) = complex conjugate{ X(N-m) }

Page 4: The Discrete Fourier Transform - McMaster University

DFT of even-symmetric

• for continuous waves:

- even-symmetry: f(t) = f(-t)

• for discrete, sampled waves

- even symmetry: x(n) = x(N-n)

• Fourier transform of even-symmetric waveforms is Real (i.e., Imaginary part is zero)

Page 5: The Discrete Fourier Transform - McMaster University

Even to Even

0 5 10 15

0.0

0.2

0.4

0.6

0.8

1.0

n

x(n)

0 5 10 15

-10

-50

510

m

X(m)

-10 -5 0 5

-10

12

34

5

m

Re{X(m)}

if x(n) is a real, even-symmetric function, then X(m) is a real, even-symmetric function

Page 6: The Discrete Fourier Transform - McMaster University

Odd-symmetry

f(t) = -f(-t), and f(0)=0or

x(n) = -x(N-n), and x(0)=0

0 5 10 15

-10

-50

510

m

X(m)

0 5 10 15

-1.0

-0.5

0.0

0.5

1.0

n

x(n)

Fourier transform of a real, odd-symmetric function is an imaginary, odd-symmetric function

Page 7: The Discrete Fourier Transform - McMaster University

DFT LinearityXsum(m) = X1(m) + X2(m)

0.0 0.2 0.4 0.6 0.8 1.0

-2-1

01

2

t

x(t)

x(t) = cos(2π3t− π/8) + sin(2π10t)

0 5 10 15

-1.5

-1.0

-0.5

0.0

0.5

1.0

1.5

m

phase{X(m)}

phase

0 5 10 15

0.0

0.1

0.2

0.3

0.4

0.5

m

mag{X

(m)}

/ N

magnitude

spectral components (m ≤ 19)

Page 8: The Discrete Fourier Transform - McMaster University

Shifting Property

Xshifted(m) = ej2πkm/NX(m)

if we start to sample x(n) at n=k, rather than n=0, the DFT of the shifted samples will be related to the DFT of the unshifted samples according to the equation:

Page 9: The Discrete Fourier Transform - McMaster University

Linear Phase Shifts

the shifting property implies that the effect of a shift, or delay, is to add a linear phase term to each spectral component:

Xshifted(m) = ej2πkm/NA(m)ejφ(m)

= A(m)ej(φ(m)+2πkm/N)

Page 10: The Discrete Fourier Transform - McMaster University

0 5 10 15

05

10

15

m

2*pi*k*m/N

k = 3; N = 20

!φ(m) =k2π

Nm

Page 11: The Discrete Fourier Transform - McMaster University

Scaling Property

• if the width of a function is increased, its Fourier Transform becomes narrower and taller; if its width is decreased, its transform becomes wider and shorter:

F

[x

(t

b

)]= |b|F (bf)

Page 12: The Discrete Fourier Transform - McMaster University

-4 -2 0 2 4

0.0

0.2

0.4

0.6

0.8

1.0

t

x(t)

0 5 10 15

0.0

0.1

0.2

0.3

0.4

0.5

mmag[X(m)]

Scaling Example

Page 13: The Discrete Fourier Transform - McMaster University

DFT Leakage

Page 14: The Discrete Fourier Transform - McMaster University

DFT of sinusoidal waves that are harmonics of 1/T, where T is the width of the sample, has non-zero magnitude only at spectral components corresponding to ± frequency of pattern

Frequency Representations of Sinusoids

Page 15: The Discrete Fourier Transform - McMaster University

DFT Leakage

Frequency representations of sine waves that are not harmonics of 1/T are represented as the sum of many non-zero spectral components

Page 16: The Discrete Fourier Transform - McMaster University

Why does leakage occur?

Page 17: The Discrete Fourier Transform - McMaster University

-2 -1 0 1 2

0.0

0.2

0.4

0.6

0.8

1.0

f(Hz)

Mag

-2 -1 0 1 2

0.0

0.5

1.0

1.5

2.0

time (sec)

x(t

)

-2 -1 0 1 2

0.0

0.5

1.0

1.5

2.0

time (sec)

x(t

)

fs = 10 Hz

x(t) = 1 + cos(2*pi*t)

-30 -20 -10 0 10 20 30

0.0

0.2

0.4

0.6

0.8

1.0

f (Hz)

Ma

g

continuous time continuous transform

Review Origins of DFT

continuous transformsampled time

Page 18: The Discrete Fourier Transform - McMaster University

Quartz (4) - Inactive

-2 -1 0 1 2

0.0

0.5

1.0

1.5

2.0

time (sec)

x(t

)

-30 -20 -10 0 10 20 30

0.0

0.2

0.4

0.6

0.8

1.0

f (Hz)

Ma

g

frequency representation of finite set of samples is a smeared version of the original

finite set of sampled points continuous transform10 samples

Page 19: The Discrete Fourier Transform - McMaster University

Quartz (4) - Inactive

-2 -1 0 1 2

0.0

0.5

1.0

1.5

2.0

time (sec)

x(t

)

-30 -20 -10 0 10 20 30

0.0

0.2

0.4

0.6

0.8

1.0

f (Hz)

Ma

g

-10 -5 0 5 10

-0.2

0.0

0.2

0.4

0.6

0.8

1.0

f (Hz)

Ma

g

-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10

frequency representation of finite set of samples is a smeared version of the original

finite set of sampled points continuous transform10 samples

Page 20: The Discrete Fourier Transform - McMaster University

where does this smoothing come from?

Page 21: The Discrete Fourier Transform - McMaster University

digression: convolution

Page 22: The Discrete Fourier Transform - McMaster University

Convolution

• A convolution is an integral that expresses the amount of overlap of one function g(t) as it is shifted over another function x(t).

u(t) = f(t) ∗ g(t) =∫ +∞

−∞f(τ)g(t− τ)dτ

Page 23: The Discrete Fourier Transform - McMaster University

Origins of Temporal Smearing

• truncation = multiplication by rect

• rect & sinc functions are related

• multiplication in time domain is equivalent to convolution in the frequency domain

• convolution causes frequency smearing

Page 24: The Discrete Fourier Transform - McMaster University

Convolution

• g(t-τ) is a flipped version of g(t) (i.e., reversed in time) that is centered on t

• the 2 functions are multiplied point-by-point

• the product is integrated, and the result is u(t)

• g(t-τ) is centered on new time t , and the process is repeated

u(t) = f(t) ∗ g(t) =∫ +∞

−∞f(τ)g(t− τ)dτ

Page 25: The Discrete Fourier Transform - McMaster University

u(t) = f(t) ∗ g(t) =∫ +∞

−∞f(τ)g(t− τ)dτ

Page 26: The Discrete Fourier Transform - McMaster University

covolution & smoothing

incr

ease

d sm

ooth

ing

f(x) * h(x) = g(x)

convolution with a delta function

g(x) = f(x)

Page 27: The Discrete Fourier Transform - McMaster University

convolution is linear

g(t) = f(t) * h(t)

replications of h(t) sum of replications

Page 28: The Discrete Fourier Transform - McMaster University

convolution & multiplication

• convolution in the time domain is equivalent to multiplication in the frequency domain

- Fourier Transform{x(n) * y(n)} = X(m) Y(m)

• convolution in the frequency domain is equivalent to multiplication in the time domain

- Fourier Transform{x(n) y(n)} = X(m) * Y(m)

Page 29: The Discrete Fourier Transform - McMaster University

What does this have to do with spectral

smoothing?

Page 30: The Discrete Fourier Transform - McMaster University

Quartz (4) - Inactive

-2 -1 0 1 2

0.0

0.5

1.0

1.5

2.0

time (sec)

x(t

)

X =

-2 -1 0 1 2

0.0

0.5

1.0

1.5

2.0

time (sec)

x(t

)

Temporal Truncation

Using a finite set of discrete values is equivalent to multiplying the original infinite set of samples by a rect function

-2 -1 0 1 2

0.0

0.2

0.4

0.6

0.8

1.0

time (sec)

x(t

)

Page 31: The Discrete Fourier Transform - McMaster University

rect(t)0.0

0.2

0.4

0.6

0.8

1.0

rect(t)

t

x(t)

-2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0

width = 1

Page 32: The Discrete Fourier Transform - McMaster University

0.0

0.2

0.4

0.6

0.8

1.0

rect(t-1)

t

x(t)

-2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0

0.0

0.2

0.4

0.6

0.8

1.0

rect(t/2)

t

x(t)

-2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0

0.0

0.2

0.4

0.6

0.8

1.0

rect((t-1)/2)

t

x(t)

-2.0 -1.5 -1.0 -0.5 0.0 0.5 1.0 1.5 2.0

rect(t-1)

rect(t/2)

rect((t-1)/2)

Page 33: The Discrete Fourier Transform - McMaster University

Multiplication & Convolution

• x(t) was multiplied by rect(t)

• equivalent to X(f) * Y(f)

- * is “convolution”

- Y(f) is Fourier Transform{rect(t)}

• Fourier Transform{rect(t)} = sinc(m)

• in this case, X(f) consists of sets of 3 delta functions centered on kfs

• so, X(f) * sinc(f) creates a series of sinc functions centered on each delta function

Page 34: The Discrete Fourier Transform - McMaster University

sinc(x) =sin(xπ)

sinc(t)=0 for all integer values of t except t=0, where sinc(0)=1

-20 -10 0 10 20

-0.2

0.0

0.2

0.4

0.6

0.8

1.0

sinc function

t

sinc(t)

Page 35: The Discrete Fourier Transform - McMaster University

-2 -1 0 1 2

0.0

0.2

0.4

0.6

0.8

1.0

time (sec)

x(t

)

rectangle wave

-4 -2 0 2 4

-0.2

0.0

0.2

0.4

0.6

0.8

1.0

f (Hz)

Am

plit

ude

sinc function

-4 -2 0 2 4

-0.2

0.0

0.2

0.4

0.6

0.8

1.0

f (Hz)

Mag

abs(sinc) function

Rect & Sinc are Fourier Transform Pairs

Fourier Transform {rect(x)} = sinc(f)

Page 36: The Discrete Fourier Transform - McMaster University

Fourier Transform Pairs

Fourier Transform {rect(x)} = sinc(f)Fourier Transform {sinc(x)} = rect(f)

-2 -1 0 1 2

0.0

0.2

0.4

0.6

0.8

1.0

time (sec)

x(t

)

rect(t)

-4 -2 0 2 4

-0.2

0.2

0.6

1.0

f (Hz)

Am

plit

ude

sinc(f)

-4 -2 0 2 4

-0.2

0.2

0.6

1.0

time (sec)

x(t

)

sinc(t)

-2 -1 0 1 2

0.0

0.2

0.4

0.6

0.8

1.0

f (Hz)

Am

plit

ude

rect(f)

Page 37: The Discrete Fourier Transform - McMaster University

Multiplication & Convolution

• x(t) rect(t) = X(f) * sinc(f)

• but, X(f) consists of sets of 3 delta functions centered on kfs

• so, X(f) * sinc(f) creates a series of sinc functions centered on each delta function

Page 38: The Discrete Fourier Transform - McMaster University

-10 -5 0 5 10

-0.2

0.0

0.2

0.4

0.6

0.8

1.0

f (Hz)

Ma

g

-10 -9 -8 -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4 5 6 7 8 9 10

sum

-30 -20 -10 0 10 20 30

0.0

0.2

0.4

0.6

0.8

1.0

f (Hz)

Ma

g

Spectral Smoothing

• x(t) rect(t) = X(f) * sinc(f)

• X(f) is a series of delta functions

• so, X(f) * sinc(f) is a series of sinc functions

close up of smoothed spectrum that shows 3 individual sinc functions, one for each delta function, as well as the sum of the sinc functions.

Page 39: The Discrete Fourier Transform - McMaster University

• sampling x(t) creates periodic X(m)

• truncating x(t) creates smoothed X(m)

• but, we are using sampled (i.e., discrete) versions of X(m)

• consequences of sampling X(m)?

Page 40: The Discrete Fourier Transform - McMaster University

periodic x(t)

• sampling x(t) creates a periodic X(m)

- if sampling interval is ts, then replicates of X(m) are separated by fs = 1/ts

• and sampling X(m) creates a periodic x(t)

- sample frequency spectrum at sampling interval fs=1, then replicates of x(t) separated by 1/fs = 1 s

0.0 0.2 0.4 0.6 0.8 1.0

0.0

0.5

1.0

1.5

2.0

t

x(t)

0 1 2 3 4 5

0.0

0.5

1.0

1.5

2.0

t

x(t)

x(t) x(t) after sampling frequency spectrum

Page 41: The Discrete Fourier Transform - McMaster University

what does this have to do with DFT leakage?

Page 42: The Discrete Fourier Transform - McMaster University

non-harmonic frequencies

• leakage occurs when f is not an integer multiple of the number of samples

• when we concatenate the samples to create a periodic waveform, do we get a sine wave?

Page 43: The Discrete Fourier Transform - McMaster University

0 10 20 30 40 50

0.0

0.5

1.0

1.5

2.0

seq(0, 49)

tmp

0 1 2 3 4 5

0.0

0.5

1.0

1.5

2.0

t

x(t)

-2 -1 0 1 2

0.0

0.5

1.0

1.5

2.0

time (sec)

x(t

)

-2 -1 0 1 2

0.0

0.5

1.0

1.5

2.0

time (sec)

x(t

)

1.5 Hz sine wave

sampled & truncated

concatenated waveforms are periodic, but not sinusoidal

Page 44: The Discrete Fourier Transform - McMaster University

non-harmonic frequencies

• leakage occurs when f is not an integer multiple of the number of samples

• when we concatenate the samples to create a periodic waveform, do we get a sine wave?

• no, the periodic waveform is not sinusoidal and therefore the spectrum of that waveform will not be the same as a spectrum of a sine wave

• this is one explanation for why the spectrum of a non-harmonic sine wave looks strange

• another explanation can be found by inspecting the sampled spectrum itself

Page 45: The Discrete Fourier Transform - McMaster University

sampled spectra

-10 -5 0 5 10

-0.2

0.2

0.6

1.0

f

X(f)

signal f = 4 Hz

-10 -5 0 5 10

-0.2

0.2

0.6

1.0

f

X(f)

signal f = 4.5 Hz

leakage occurs as a result of sampling a continuous sinc(f) function that is centered on non-integer values of f

Page 46: The Discrete Fourier Transform - McMaster University

sampling frequency spectra

• cos(2 pi f0 t) rect(t) has a spectrum that consists of sinc functions centered on ±f0

• sinc(f0) is zero whenever f = f0 ± n

- n = 1, 2, 3, ... etc

• when f0 is an integer, X(m) will be exactly zero at all integer frequencies, m ≠ ±f0

- X(m) = 0 for all integer m ≠ ±f0

• but, when f0 is not an integer, the sampled spectrum X(m) will not be zero at m ≠ f0

Page 47: The Discrete Fourier Transform - McMaster University

coarse frequency sampling

• Continuous frequency spectra of truncated data always contain the fingerprints of sinc functions

• we sometimes fail to see them because of the coarse sampling of the frequency spectrum (fs=1)

• but we can get a better look by increasing the rate at which the frequency spectrum is sampled...

Page 48: The Discrete Fourier Transform - McMaster University

increasing frequency resolution

• Suppose we record 1s worth of data sampled at 10 Hz:- T = 1s; ts = 0.1 s; n=(0...9); N = 10

- The spectral components m=1 and m=2 are complex exponentials with frequencies of 1 & 2 cycles per second

- or 1 and 2 Hz

• Let’s increase T to 2s:- T = 2s; ts = 0.1 s; n=(0...19); N = 20

- The spectral components m=1 and m=2 have frequencies of 1 & 2 cycles per two seconds

- ... or 0.5 and 1 Hz

• doubling N doubled our frequency resolution

Page 49: The Discrete Fourier Transform - McMaster University

0.0 0.5 1.0 1.5 2.0

-1.0

-0.5

0.0

0.5

1.0

f = 1.5 Hz

t

x(t)

0.0 0.5 1.0 1.5 2.0

-1.0

-0.5

0.0

0.5

1.0

f = 1.5 Hz

t

x(t)

0 5 10 15

02

46

810

m

mag[X(m)]

0 5 10 15

02

46

810

m

mag[X(m)]

f = m fs / N = msampling rate = fs = 10 HzN = 10

sampling rate = fs = 10 HzN = 20 f = m fs / N = m/2

Page 50: The Discrete Fourier Transform - McMaster University

0 1 2 3 4

-1.0

-0.5

0.0

0.5

1.0

f = 1.25 Hz

t

x(t)

0 1 2 3 4

-1.0

-0.5

0.0

0.5

1.0

f = 1.25 Hz

t

x(t)

0 10 20 30 40

05

10

15

20

m

mag[X(m)]

0 5 10 15

05

10

15

20

m

mag[X(m)]

Page 51: The Discrete Fourier Transform - McMaster University

0 5 10 15 20

-1.0

-0.5

0.0

0.5

1.0

f = 1.25 Hz

t

x(t)

0 1 2 3 4

-1.0

-0.5

0.0

0.5

1.0

f = 1.25 Hz

t

x(t)

zero stuffing(also improves frequency resolution)

0 50 100 150 200

05

10

15

20

m

mag[X(m)]

0 1 2 3 4 5 6 7 8 9 10

N.B. Amplitude of X(m) not altered by zero stuffing.

0 10 20 30 40

05

10

15

20

m

mag[X(m)]

0 1.25 2.5 3.75 5 6.25 7.5 8.75 10

continuous abs(sinc(m)) function

Page 52: The Discrete Fourier Transform - McMaster University

0.0 0.5 1.0 1.5 2.0

-1.0

0.0

0.5

1.0

t

x(t)

Hanning Window

0.0 0.5 1.0 1.5 2.0

-1.0

0.0

0.5

1.0

t

x(t)

Hamming Window

0.0 0.5 1.0 1.5 2.0

-1.0

0.0

0.5

1.0

t

x(t)

0.0 0.5 1.0 1.5 2.0

-1.0

0.0

0.5

1.0

t

x(t)

Triangle Window

Application of Windows

Page 53: The Discrete Fourier Transform - McMaster University

0 5 10 15 20

-1.0

-0.5

0.0

0.5

1.0

n

x(n)

0 5 10 15

02

46

810

m

mag[X(m)]

0 5 10 15

02

46

810

m

mag[X(m)]

Windows Reduce Frequency Spread

0 5 10 15 20

-1.0

-0.5

0.0

0.5

1.0

n

x(n)

Hamming Window

Page 54: The Discrete Fourier Transform - McMaster University

the end