lecture04-dft - university of pennsylvania

11
2/7/18 1 1 Lecture #4 – Converting from time to frequency domain ESE 150 -- Spring 2018 ! Play this on piano: ESE 150 -- Spring 2018 2 3 ! Play 4 quarter notes 1 whole note Cheat: A5, B5, G5, G4, D5 ESE 150 -- Spring 2018 4 ! 1s / quarter note ! 8s of sound ! How many bits to represent 8s of sound with 16b samples and 44KHz sampling? " 44K Hz x 16b/sample x 8s = 5632K =5Mbits ESE 150 -- Spring 2018 5 ! How does musical staff represent sound? " What does vertical position represent? " Note shape? ESE 150 -- Spring 2018 6 ! There are other ways to represent " Frequency representation particularly efficient 880 988 784 392 587 Frequencies in Hertz ESE 150 -- Spring 2018

Upload: others

Post on 11-May-2022

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture04-DFT - University of Pennsylvania

2/7/18  

1  

1

Lecture #4 – Converting from time to frequency domain

ESE 150 -- Spring 2018

!  Play this on piano:

ESE 150 -- Spring 2018

2

3

!  Play

4 quarter notes 1 whole note

Cheat: A5, B5, G5, G4, D5

ESE 150 -- Spring 2018

4

!  1s / quarter note ! 8s of sound !  How many bits to represent 8s of sound with

16b samples and 44KHz sampling? "  44K Hz x 16b/sample x 8s = 5632K =5Mbits

ESE 150 -- Spring 2018

5

!  How does musical staff represent sound? "  What does vertical position represent? "  Note shape?

ESE 150 -- Spring 2018

6

!  There are other ways to represent "  Frequency representation particularly efficient

880 988 784 392 587

Frequencies in Hertz

ESE 150 -- Spring 2018

Page 2: Lecture04-DFT - University of Pennsylvania

2/7/18  

2  

7

!  How much information is this musical staff communicating?

!  How many keys on piano? " bits/note

ESE 150 -- Spring 2018

8

Hamburg Steinway D-274 Piano photo by Karl Kunde

https://commons.wikimedia.org/wiki/File:D274.jpg

ESE 150 -- Spring 2018

9

Larry Solomn: http://solomonsmusic.net/insrange.htm

ESE 150 -- Spring 2018

10

!  How much information is this musical staff communicating?

!  How many keys on piano? " bits/note !  Let’s say 8b duration !  How many bits for 5 notes?

"  (7b/note+8b/duration) x 5 note = 75 bits?

ESE 150 -- Spring 2018

!  You reproduced 800 samples of a 300Hz sine wave at 1000Hz with 8b precision "  6400b

!  What did you need to specify to do that? !  How may bits to represent that?

ESE 150 -- Spring 2018

11

!  Can represent common sounds much more compactly in frequency domain than in time-sample domain "  Frequency domain ~ 75b "  Time-sample domain ~ 5Mb

ESE 150 -- Spring 2018

12

Page 3: Lecture04-DFT - University of Pennsylvania

2/7/18  

3  

!  Teaser: frequency representation !  Where are we on course map? !  What we did in lab last week

"  How it relates to this week

!  The Fourier Series – can represent any signal !  The Discrete Fourier Transform (DFT) – can translate

"  Change of basis

!  Next Lab !  References

13

ESE 150 -- Spring 2018

14

NIC

10101001101

EULA ----------------click OK

NIC

CPU

A/D

sample

domain conversion

MP3 Player / iPhone / Droid

File- System

10101001101

compress freq pyscho-

acoustics

D/A

MIC

speaker

2 4

5,6

3

7,8,9

10

11 13

12

Music

Numbers correspond to course weeks

1

ESE 150 -- Spring 2018

15

A/D

sample

domain conversion

MP3 Player / iPhone / Droid

compress freq

D/A

MIC

speaker

2 4 3

Music

Numbers correspond to course weeks

1

10101001101

10101001101

ESE 150 -- Spring 2018

Analog input

!  Week 1: Converted Sound to analog voltage signal !  a “pressure wave” that changes air molecules w/ respect to time !  a “voltage wave” that changes amplitude w/ respect to time

!  Week 2: Sampled voltage, then quantized it to digital sig. "  Sample: Break up independent variable, take discrete ‘samples’ "  Quantize: Break up dependent variable into n-levels (need 2n bits to digitize)

!  Week 3: Compress digital signal "  Use even less bits without using sound quality!

!  Week 4 (upcoming): Before we compress… "  Put our ‘digital’ data into another form…BEFORE we compress…less stuff to compress!

16

ADC Digital Output

compress

ESE 150 -- Spring 2018

Background

17

ESE 150 -- Spring 2018

!  With this compact notation "  Could communicate a sound to pianist "  Much more compact than 44KHz time-sample

amplitudes (fewer bits to represent) "  Represent frequencies

ESE 150 -- Spring 2018 18

Page 4: Lecture04-DFT - University of Pennsylvania

2/7/18  

4  

! 

19

Time domain representation Frequency domain representation

ESE 150 -- Spring 2018

! 

20

Above is called an “amplitude spectrum” plot, we also have “phase spectrum” plots in the frequency domain

ESE 150 -- Spring 2018

! 

ESE 150 -- Spring 2018 21

!  Another example

ESE 150 -- Spring 2018 22

The time domain plot on the right is really the sum of 5 sinusoids, where 5 Hz is the strongest component of the signal

! 

ESE 150 -- Spring 2018 23

The frequency domain &

24

ESE 150 -- Spring 2018

Page 5: Lecture04-DFT - University of Pennsylvania

2/7/18  

5  

!  Fourier series: "  Any periodic signal can

be represented as a sum of simple periodic functions: sin and cos

sin(nt) and cos(nt) where n = 1, 2, 3, …

These are called the harmonics of the signal

ESE 150 -- Spring 2018 25

Jean Baptiste Joseph Fourier, wikipedia

!  States that any PERIODIC function can be written as a sum of sines and cosines! "  This is huge! "  It also gives us a way to breakup a periodic function into its sine/

cosine parts

!  Why do we care? "  Well if music was periodic, we could break it into its sine/cosine

pieces and store only the amp/freq/phase #  Huge storage advantage

"  But also, once we break it down, we could modify them #  Say we want to enhance the bass or treble of a signal? #  By increasing amplitude of bass frequencies, we’ll get more bass

26

ESE 150 -- Spring 2018

!  Other implications… "  If a signal is periodic, we can convert it from time to frequency

!  Imagine anything periodic "  If Earthquake vibrations could be separated into sinusoids…

#  Think vibrations at different speeds and strengths "  We could design buildings/bridges to avoid interacting with the strongest

frequency vibrations (and not just “all of them”)

"  If a radio-wave is our signal and its periodic #  We could hone in on a particular “channel” and listen only to that one…like a radio/TV!

"  It has endless applications in: communications, astronomy, geology, optics

!  There is one problem… "  The above examples aren’t exactly periodic! "  But we’ll address that soon…first let’s see the Fourier series

27

ESE 150 -- Spring 2018

28

The Fourier Theorem states that any periodic function f(t) of period T can be cast in the form:

ESE 150 -- Spring 2018

f (t) = ao + an cos(nω ot) + bn sin(nω ot)( )n=1

•  The cos(nx) and sin(nx) functions form an orthogonal basis: •  allow us to represent any periodic

signal by taking a linear combination •  of the basis functions without

interfering with one another •  AKA: superposition works!

ESE 150 -- Spring 2018 29

!  What is an orthogonal basis? !  Example: 3D space

"  Basis: [i j k] "  Linear combination: xi + yj + zk "  Coordinate representation: [x y z]

!  Example: Quadratic polynomials "  Basis: [x2 x 1] "  Linear combination: ax2 + bx + c "  Coordinate representation: [a b c]

!  All vectors in the space can be represented as sequences of coordinates, or ordered coefficients of the basis vectors "  This is what the Fourier Series does…

#  just uses cos(nt) and sin(nt) as its “Basis”

ESE 150 -- Spring 2018 30

Page 6: Lecture04-DFT - University of Pennsylvania

2/7/18  

6  

"  Consider the xy-plane:

"  We can address a point by its two coordinates (x,y) #  the grey point is located at (10, 3)

31

0 5 10 0

5

10

•  In Fourier series, we have a basis with infinite dimension! •  so we sum up over an infinite number of harmonics •  harmonics are 1, cos(t), cos(2t), cos(3t), …, sin(t), sin(2t),

ESE 150 -- Spring 2018

! 

ESE 150 -- Spring 2018

32 €

n→∞

ESE 150 -- Spring 2018 33

(falstad.com/fourier/) ESE 150 -- Spring 2018

34

(falstad.com/fourier/)

!  The idea of the series: "  Any PERIODIC wave can be represented as simple sum

of sine waves !  2 Caveats:

"  Linearity: # The series only holds while the system it is describing is linear

because it relies on the superposition principle #  -aka – adding up all the sine waves is superposition in action

"  Periodicity: # The series only holds if the waves it is describing are periodic # Non-periodic waves are dealt with by the Fourier Transform

$  We will examine that in the 2nd half of lecture

35

ESE 150 -- Spring 2018

!  Remember we said we needed to sample at twice the maximum frequency "  Now see all signals can be represented as a linear sum

of frequencies

"  …and the frequency components are orthogonal # Can be extracted and treated independently

ESE 150 -- Spring 2018

36

Page 7: Lecture04-DFT - University of Pennsylvania

2/7/18  

7  

!  Close Encounters Mothership !  https://www.youtube.com/watch?

v=S4PYI6TzqYk

ESE 150 -- Spring 2018

37 38

ESE 150 -- Spring 2018

!  In the first half of the lecture we introduced: "  The idea of frequency domain "  The Fourier Series

!  In the second half of the lecture: "  Fourier Transform "  See how to perform this time-frequency translation "  Examples

ESE 150 -- Spring 2018 39

!  Compute Dot Products with frequencies "  (equivalently, compute Fourier Components)

ESE 150 -- Spring 2018

40

i 0 1 2 3 4 5 6 7 8 9 10 time 0.0 0.1 0.2 0.3 0.4

0.5

0.6 0.7 0.8 0.9 1.0

Sample 0 0.95 0.59 -0.59 -0.95 0 0.95 0.59 -0.59 -0.95 0

i 0 1 2 3 4 5 6 7 8 9 10 k=1 0.00 0.59 0.95 0.95 0.59 0.00 -0.59 -0.95 -0.95 -0.59 0.00 k=2 0.00 0.95 0.59 -0.59 -0.95 0.00 0.95 0.59 -0.59 -0.95 0.00 k=3 0.00 0.95 -0.59 -0.59 0.95 0.00 -0.95 0.59 0.59 -0.95 0.00 k=4 0.00 0.59 -0.95 0.95 -0.59 0.00 0.59 -0.95 0.95 -0.59 0.00 k=5 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00

2N

Sample[i] × sin 2πkiN

⎝ ⎜

⎠ ⎟

i=0

N∑

!  Can identify frequencies with dot product "  Identifying projection onto each basis vector

in Fourier Series

!  Works because they are orthogonal

!  Performing a change of basis "  From time-sample basis "  To Fourier (sine, cosine) basis

ESE 150 -- Spring 2018

41 42

ESE 150 -- Spring 2018

Another choice of bases. Change of basis.

Page 8: Lecture04-DFT - University of Pennsylvania

2/7/18  

8  

43

Euler’s Identity: Fourier Series:

Euler’s Identity in the Fourier Series:

ESE 150 -- Spring 2018

f (t) = ao + an cos(nω ot) + bn sin(nω ot)( )n=1

44

Fourier Series

Fourier Transform – for continuous functions: Input: Time Domain Output: Frequency Domain

ESE 150 -- Spring 2018

!  Instead of thinking only in sinusoids… "  Complex sinusoids can be thought of as cycles… "  Let’s visual complex #s a bit… "  http://betterexplained.com/examples/fourier/

45

ESE 150 -- Spring 2018

!  How to make a song appear “periodic:” "  Treat the entire song as 1 period of a very complicated

sinusoid! "  This is the assumption of the Fourier Transform

46

ESE 150 -- Spring 2018

47

Fourier Series – decomposes f(t) into a “weighted sum” of sine waves We only need to store amplitude and frequency of each harmonic of the fund. freq.

Fourier Series says it can be broken into simple sine waves

Fourier Series for this f(t):

Fourier Series in general form:

ESE 150 -- Spring 2018

48

Periodic Function in Time Domain

Fourier Series for this f(t):

Alternate view of Fourier Series …converting signals in the “time domain” to the “frequency domain”

Periodic Function in Frequency Domain

1st Fundamental amplitude: 0.5 2nd Fundamental amplitude: 1 And so on…

Store only frequency information:

ESE 150 -- Spring 2018

Page 9: Lecture04-DFT - University of Pennsylvania

2/7/18  

9  

! 

49

Discrete Time to Frequency:

Frequency back to Time:

ESE 150 -- Spring 2018

!  A DFT transforms N samples of a signal in time domain "  into a (periodic) frequency representation with N samples "  So we don’t have to deal with real signals anymore

!  We work with sampled signals (quantized in time), "  and the frequency representation we get is also quantized in time!

ESE 150 -- Spring 2018

50 (sepwww.stanford.edu/oldsep/hale/FftLab.html)

Music Signal in Discrete Time !

Music Signal “Transformed” To Frequency Domain !

!  A smaller sampling period means: -> more points to represent the signal larger N -> more harmonics used in DFT N harmonics -> Smaller error compared to actual analog

signal we capture/produce !  DFTs are extensively used in practice, since

computers can handle them ESE 150 -- Spring 2018

51

!  A signal sampled in time can be approximated arbitrarily closely from the time-sampled values

!  With a DFT, each sample gives us knowledge of one harmonic

!  Each harmonic is a component used in the reconstruction of the signal

!  The more harmonics we use, the better the reconstruction

ESE 150 -- Spring 2018 52

{ Cos[0t], Sin[1t], Cos[1t] , Sin[2t], Cos[2t] , Sin[3t], Cos[3t] }

ESE 150 -- Spring 2018

53

7 Samples; 7 Harmonics 11 Samples 15 Samples; 15 Harmonics ; 11 Harmonics

DFT DFT DFT

54

t

v

Measured Data:

Sampled Signal:

ESE 150 -- Spring 2018

Page 10: Lecture04-DFT - University of Pennsylvania

2/7/18  

10  

!  Approximate Reconstruction "  although always achievable "  may require a lot of samples "  to get good performance

Sometimes time is better than frequency!

ESE 150 -- Spring 2018 55

15 Samples & Harmonics

21 Samples & Harmonics

31 Samples & Harmonics

!  However, N can get very large "  e.g., with a sampling rate of 48,000Hz "  How big is N for a 4 minute song?

!  How many operations does this translate to? "  To compute one frequency component? "  To compute all N frequency components?

!  This is not practical. Instead, we use a window of values to which we apply the transform "  Typical size: …, 512, 1024, 2048, …

ESE 150 -- Spring 2018 56

!  In the example below, we traverse the signal but only look at 64 samples at a time

ESE 150 -- Spring 2018 57

Time

Freq

(sepwww.stanford.edu/oldsep/hale/FftLab.html)

!  Not really connect-the-dots in time !  Recall near Nyquist rate

"  Could often miss the peak "  Get poor sine waves

# …look like peak moves around even if sampled above Nyquist rate

!  Better reconstruction "  Convert to frequency

# Which can perfectly represent up to half sampling rate

"  Reconstruct from frequency basis

ESE 150 -- Spring 2018

58

!  Can represent signals in frequency domain "  Different basis – basis vectors of sines and cosines

!  Often more convenient and efficient than time domain "  Remember musical staff

!  Can convert between time and frequency domain "  Using a dot-product to calculate time or frequency

components

ESE 150 -- Spring 2018

59

!  Lab 4: "  You will identify Frequency components using FFT in

Matlab

!  Remember: "  Lab 3 report is due on Friday

ESE 150 -- Spring 2018 60

Page 11: Lecture04-DFT - University of Pennsylvania

2/7/18  

11  

!  ESE325 – whole course on Fourier Analysis !  ESE224 – signal processing !  ESE215, 319, 419 – reason about behavior of

circuits in time and frequency domains

ESE 150 -- Spring 2018

61

!  S. Smith, “The Scientists and Engineer’s Guide to Digital Signal Processing,” 1997.

!  https://betterexplained.com/articles/an-interactive-guide-to-the-fourier-transform/

62

ESE 150 -- Spring 2018