Eng. 100: Music Signal Processing DSP Lecture 4 Lab 3 .

Transcription

Eng. 100: Music Signal ProcessingDSP Lecture 4Lab 3: Signal SpectraCuriosity (musical style modulation) nouncements: HW2 online, due Thu. Oct. 8 in class. No labs this week: focus on Project 1 and HW2. Project 1 presentations in discussion sections this week. Start reading Lab 3 for next week— it is longer!1

Outline The spectrum of a signal Part 1. Why we need spectra Part 2. Periodic signals Part 3. Band-limited signals Methods for computing spectra By hand by solving systems of equations Using general Fourier series solution Using fast Fourier transform (FFT), e.g., in Matlab Using a signal’s spectrum to determine note frequencies to remove unwanted noise to visualize frequency content (spectrogram) Lab 32(first lecture)(second lecture)(third lecture)

Part 1. Why we need spectra3

Project 1 Transcriber for ideal sinusoidSinusoidal signal:1S 8000 Hzf 400 Hzx(t)0.50play 0.5 100.0010.0020.0030.0040.005t 0.005t [sec]0.0060.0070.0080.0090.01frequency estimate [Hz]405400395Method: Sx[n 1] x[n 1]arccosf .2π2x[n]4

Project 1: Transcriber limitationsWhat are limitations of transcribers implemented in Project 1?We need more sophisticated method(s)for finding the (fundamental) frequency of a music signal.5

Project 1 Transcriber for noisy sinusoidSinusoidal signal with noise (e.g., in any audio recording):1S 8000 Hzf 400 Hzx(t)0.50 0.5 100.0010.0020.0030.0040.005t 0.005t [sec]0.0060.0070.0080.0090.01frequency estimate [Hz]600400200Method: Sx[n 1] x[n 1]f arccos.2π2x[n]6play

Project 1 Transcriber for clarinetClarinet signal (roughly G below middle C):play1S 11025 Hzf ? Hzx(t)0.50 0.5 100.0050.010.0150.010.015t [sec]frequency estimate [Hz]200015001000500000.005t [sec]Method: Sx[n 1] x[n 1]f arccos.2π2x[n]7

Even more challenging caseClarinet and guitar duet:play1x(t)0.50 0.5 10.30.3050.310.315t [sec] Methods that use the “time domain” are very unlikely to work whentwo instruments play simultaneously. We need to use the “frequency domain”aka the spectrum of a signal. (Human ears work this way!) The concept of spectra is used widely in engineering.8

Divide and conquerClarinet1S 11025 Hzf ? Hzx(t)0.50 0.5 100.0050.010.015t [sec]This signal x(t) looks complicated.(Bamboo reed vibrations are approximately a square wave.)Engineering strategy: Make complicated things by combining simpler things. Use tools from mathematics (and physics) as needed.Mathematics provides us with a perfect tool in this case:Fourier series.9

Part 2. Spectra of periodic signals10

Joseph FourierJoseph Fourier, 1768-1830He died after falling down the stairs at his home. [wiki] Fourier series theory developed circa 1807(Modern compared to our trigonometry method.) Motivating application: heat propagation in metal plates.11

Periodic signalsClarinet1S 11025 Hzf ? Hzx(t)0.50 0.5 100.0050.010.015t [sec]Key property of musical signals (over short time intervals):periodicity.A periodic signal (aka repeating signal) with period T satisfiesx(t) x(t T ) x(t 2T ) · · · for all t.Example: x(t) cos(2π9t) is periodic with period T 1/9 sec.It is also periodic with period T 1/3 sec.The smallest period (T 1/9 sec here) is the fundamental period.12

ExerciseWhat is the (approximate) period of the clarinet signalshown on the previous slide? ?13

Fourier series of periodic signalsAmazing fact #1 (discovered by Joseph Fourier 200 years ago):Any real-world periodic signal with period T can be expanded(i.e., expressed mathematically as a sum) as follows: kx(t) c0 ck cos 2π t θkTk 1 12 {z}c0 c1 cos 2π t θ1 c2 cos 2π t θ2 · · ·TT {z} {z}DC termDC valueDC constantfundamentalperiod Tfrequency 1/T(first) harmonicperiod T /2frequency 2/T {ck } called amplitudes {k/T } called frequencies {θk } called phasesWe can write even a “complicated” clarinet or guitar signalusing such a “simple” sum of sinusoidalsignals.14

Example: Triangle wavecos(t) cos(3t)/32cos(t)1100 1 1051021502100 1 11015cos(t) . cos(9*t)/915102cos(t) cos(3t)/3 cos(5*t)/505150cos(t) . cos(19*t)/19251015cos(t) . cos(99*t)/9921x(t)10 10 1051015051015tMore terms in sum closer approximation to triangle wave.15

Example: Square wavesin(t)sin(t) sin(3t)/31100 1 10510150sin(t) sin(3t)/3 sin(5*t)/5100 1 15101015sin(t) . sin(15*t)/15105150sin(t) . sin(49*t)/4951015sin(t) . sin(999*t)/9991x(t)10 10 10510150510tSums of sinusoids can make “interesting” signals.What is T in this example? ?1615

Example: Sawtooth wavecomponent1sum1b1 sin(2π 1/T 100-1-12.55t [msec]7.50b5 sin(2π 5/T t)0play1017.50b4 sin(2π 4/T t)0play1b3 sin(2π 3/T t)07.51b2 sin(2π 2/T t)1play7.5play0Does the pitch of the sound change? ?Fundamental frequency? ?172.55t [msec]7.5

The spectrum of a periodic signalEvery periodic signal can be written in the same form! x(t) c0 c1 cos 2π T1 t θ1 c2 cos 2π T2 t θ2 · · ·So how do electric guitar and clarinet signals differ? ?18

The spectrum of a periodic signalEvery periodic signal can be written in the same form! x(t) c0 c1 cos 2π T1 t θ1 c2 cos 2π T2 t θ2 · · ·So how do electric guitar and clarinet signals differ? ?Definition. The spectrum of a signal x(t) is just a stem plot ofthe amplitudes {ck } versus the frequencies {k/T } in Hertz. The phases θk are unimportant for monophonic music. The DC term c0 cannot be produced or heard either. Coefficients {ck } define timbre (TAM-ber) of sound19

Spectra of periodic signalsIn Eng. 100, we define spectra only of periodic signals. Why? Musical instruments produce approximately periodic signals. Definition and computation are much easier. Real-world non-periodic signals can be viewed as partof a periodic signal with a very long period.20

Example: AM Radio SignalTwo Michigan AM Radio stations are: WSDS, 1480 kHz, 3800W, Salem Township WABJ, 1490 kHz, 1000W, Adrian, MIIf WSDS broadcasts a 3000 Hz sinusoidal test toneand WABJ broadcasts a 2000 Hz sinusoidal test tone, then(you can learn in EECS 216) that an antenna in Salinethat can pick up both stations would receive this signal:x(t) 40 cos(2π1480000t) 20 cos(2π1483000t) 20 cos(2π1477000t) 10 cos(2π1490000t) 5 cos(2π1492000t) 5 cos(2π1488000t) .What is the spectrum of this signal?21

Example: AM Radio Signal SpectrumAM radio signal (expressed as mathematical formula):x(t) 40 cos(2π1480000t) 20 cos(2π1483000t) 20 cos(2π1477000t) 10 cos(2π1490000t) 5 cos(2π1492000t) 5 cos(2π1488000t) .Spectrum of this signal x(t):So the spectrum of a signal is a graphical representation.Graphical representations are often desirable.22

ExerciseFind a formula for the signal that has the following spectrum.Could an audio signal (music) have this spectrum?(Working forwards and backwards.)23play

Spectrum of a general periodic signalamplitudeA periodic signal with period T has a spectrum that looks like:c1c2c00“DC”c31T2T3Tc4c54T5T. The frequency components are 0, 1/T, 2/T, . . . The height of each line in the spectrum is an amplitude ck 21Ignoring phase: x(t) c0 c1 cos 2π T t c2 cos 2π T t · · ·What units are along the horizontal axis for a spectrum? ?24f [Hz]

Example: Clarinet spectrumClarinet signal1x(t)0.50 0.5 1024681012141618t [msec]Clarinet spectrumSpectrum of x(t)0.40.30.20.100 19558597517552535f [Hz]playFirst significant peak: fundamental frequency 1/T 195 Hz(Perfectly) periodic signals have (perfect) line spectra.25

Example: Clarinet synthesized1x(t)0.50 0.5 1024681012141618t [msec]Spectrum peaks of x(t)0.40.30.20.100 19558597517552535f [Hz]Synthesized using 8 largest peaks in spectrum.Sounds more interesting than Project 1 synthesizer? Why?26play

Example: Clarinet Fourier seriesExpressing a complicated signal in terms of simple signals:x(t) 0.382 cos(2π 195.0t 1.35) 0.237 cos(2π 584.9t 0.48) 0.169 cos(2π 974.8t 0.30) 0.151 cos(2π 1754.6t 1.35) 0.066 cos(2π 2534.5t 1.41) 0.061 cos(2π 2144.6t 2.40) 0.057 cos(2π 2339.5t 0.40) 0.041 cos(2π 1364.7t 1.32) Guitar signal would have different amplitudes and phases,even if playing the same note. MP3 audio coding exploits the “line” nature of music spectra. But how did I make the spectrum plot on previous slide? And how did I get all the numbersabove?27

Part 3: Band-limited signals:towards computing a signal’s spectrum28

Fourier Series: Trigonometric formFourier Series: Sinusoidal form: 12x(t) c0 c1 cos 2π t θ1 c2 cos 2π t θ2 · · ·TTFourier Series: Trigonometric form: 21x(t) a0 a1 cos 2π t a2 cos 2π t · · ·T T 12 b1 sin 2π t b2 sin 2π t · · ·TTCoefficients in these two forms are related by:a0 c0ak ck cos θkbk cqk sin θkck a2k b2ktan θk bk /ak(need this to plot spectra)because (Lab 1): cos(t θ ) cos(θ ) cos(t) sin(θ ) sin(t)We will focus on finding the ak and bk values for music signals.29

About those dots: · · ·Example.If x(t) has period T 0.01 seconds then x(t) has expansion:x(t) a0 a1 cos(2π100t) a2 cos(2π200t) a3 cos(2π300t) · · · b1 sin(2π100t) b2 sin(2π200t) b3 sin(2π300t) · · ·fundamentalfirst harmonicsecond harmonic(DC)(100 Hz)(200 Hz)(300 Hz) Mathematical perspective: What does “· · · ” mean? ? Engineering perspective:Practical signals are, or can be made to be, band limited. Physical limits Perception limits Anti-alias filters in A/D converters30

Band-limited signalsDefinition. A signal is band-limited to B Hz if it has no frequencycomponents higher than B Hz.Example.If x(t) has period T 0.01 seconds and is band-limited to 800 Hzthen x(t) has (finite!) Fourier series expansion:x(t) a0 a1 cos(2π100t) a2 cos(2π200t) · · · b1 sin(2π100t) b2 sin(2π200t) · · · fundamentalfirst harmonic(DC)(100 Hz)(200 Hz)a8 cos(2π800t)b8 sin(2π800t)highest harm.(800 Hz)8Finite sum: x(t) a0 ak cos(2π100kt) bk sin(2π100kt)k 1This periodic, band-limited signal is “characterized completely”by the frequency (100 Hz) and just 17 other numbers:{a0, a1, a2, a3, a4, a5, a6, a7, a8, b1, b2, b3, b4, b5, b6, b7, b8}.How do we find those values, called coefficients?31

ExerciseA periodic signal x(t) has period T 0.02 seconds and is known to beband-limited to 200 Hz.How many (possibly nonzero) Fourier series coefficients does it have(in trigonometric form), including the DC coefficient?Recall: 12x(t) a0 a1 cos 2π t a2 cos 2π t · · ·T T 12 b1 sin 2π t b2 sin 2π t · · ·TT32

How many coefficients?In general, if a signal has period T and is band-limited to B Hz, howmany Fourier series coefficients {a0, a1, b1, a2, b2, . . .} are needed?33

Spectrum of a band-limited periodic signalA periodic signal with period T , that is band-limited to B Hz,has a spectrum that looks like: No frequency components above B HzNo lines in spectrum past B HzK BT if it is an integer(units of BT ?)bxc largest integer that is xK bBT c more generally,bxc called floor function (below) Example: T 0.01 s and B 360 Hz K b3.6c 334

Spectrum review: A non-music exampleThe following figure / demo illustrates a hypocycloidthat is one special case of a spirograph.5x(t)Hypocycloid, R 5, r 16demo: fig spirograph1.m04 500.20.40.60.81t05 2Recall: a signal is any time-varying quantity. 4 6 6 4 20x246y(t)y2Formula: x(t) (R r) cos(2πt) r cos 2π R rtr R ry(t) (R r) sin(2πt) r sin 2π r tHere, R 5 (outer circle)and r 1 (inner circle).0 500.20.40.6t350.81Exercise.Sketch spectrum of x(t) (or y(t)). ?Is x(t) band-limited? ?What is the band-limit B? ?

Computing a signal’s spectrum36

Signal samplingIdea. To determine 2BT 1 Fourier coefficients of a signal with periodT that is band-limited to B Hz, we try taking at least N 2BT 1samples of the signal over one period, e.g., [0, T ].In other words, take N 2BT samples: x[0], x[1], . . . , x[N 1].TT1What will be the sampling interval? .N 2BT 2B# of samples N 2BTThe sampling rate is: S 2B.time interval TTSample faster than twice the maximum frequency: S 2B.37

2B or not 2BThe formula S 2B is one of the most important in DSP.It is the foundation for all digital audio and video and more.CD players use a sampling rate of 44.1 kHz. Why? ?Where did T go?The period T need not affect the sampling rate!We can choose T arbitrarily large.Amazing fact #2 (discovered by Claude Shannon 60 years ago):Sampling theorem:If we sample a band-limited signal x(t) at a rate S 2B, thenwe can recover the signal from its samples x[n] x(n/S). (EECS 216)Conversely:sampling too slowly can cause bad effects called aliasing.Example: wagon wheels in Western movies.38

Claude Shannon: Father of information theory1916-2001Born in Petosky, raised in Gaylord [wiki]UM EE Class of 1936.Bust outside cession/102665758 circa 1980cf. finite element models used by, e.g., mechanical and aero engineers39

Clarinet and guitar duet: play. 0.3 0.305 0.31 0.315-1-0.5 0 0.5 1 t [sec] x(t) Methods that use the \time domain" are very unlikely to work when two instruments play simultaneously. We need to use the \frequency domain" aka the spectrum of a signal. (Human ears work this way!) The concept of spectra is used widely in engineering. 8