
Eng. 100: Music Signal Processing DSP Lecture 6 Lab 3: Spectra/Spectrogram (Continued) • Curiosity: • http://www.soundhound.com • http://dx.doi.org/10.1109/MSPEC.2015.7049439 • Read Lab 3! • HW 3 on Canvas, due Thu. Oct. 15 Mon Tue Wed Thu Fri Oct 05 Oct 06 Oct 07 Oct 08 Oct 09 (no lab) HW2 due Lab 3a Oct 12 Oct 13 Oct 14 Oct 15 Oct 16 Lab 3a Ethics & HW3 due Lab 3b Review Review • DSP schedule: Oct 19 Oct 20 Oct 21 Oct 22 Oct 23 No lab No class No lab Break Break Exam 1 Oct 26 Oct 27 Oct 28 Oct 29 Oct 30 Lab 3b Lab 3 due / P2 Nov 02 ... Lab 3 due / P2 ... 1 Outline • The spectrum of a signal (first class) ◦ Part 1. Why we need spectra ◦ Part 2. Periodic signals ◦ Part 3. Band-limited signals • Methods for computing spectra (second class) ◦ Part 4. Sampling rate S > 2B ◦ Part 5. By hand by solving systems of equations ◦ Part 6. Using general Fourier series solution ◦ Part 7. Using fast Fourier transform (FFT), e.g., in Matlab • Using a signal's spectrum (third class) ◦ to determine note frequencies ◦ to remove unwanted noise ◦ to visualize frequency content (spectrogram) ◦ Lab 3 2 Summary of previous lecture(s) T-periodic, band-limited signals have finite Fourier series: • Sinusoidal form: 1 2 K x(t) = c0 +c1 cos 2p t − q1 +c2 cos 2p t − q2 +··· + cK cos 2p t − qK |{z} T T T DC | {z } | {z } fundamental harmonics • Trigonometric form: 1 2 K x(t) = a + a cos 2p t +a cos 2p t +··· + a cos 2p t 0 1 T 2 T K T 1 2 K + b sin 2p t +b sin 2p t +··· + b sin 2p t 1 T 2 T K T • Coefficients in these two forms are related by q 2 2 a0 = c0 ak = ck cosqk ck = ak + bk b = 0; b = c sinq ; 0 k k k tanqk = bk=ak p because acos(f)+bsin(f) = a2 + b2 cos(f − arctan(b=a)) and ccos(f − q) = (ccosq)cosf + (csinq)sinf • We can use the fast Fourier transform (FFT) method (Matlab's fft function) to compute these coefficients very quickly from signal samples if S > 2B: 3 FFT summary 0 1 N−1 For an array x of length N with signal samples x = x S x S ··· x S taken from a signal x(t) that is periodic and band-limited with S > 2B: disp((2/N)*real(fft(x))) gives [2a0 a1 a2 ::: aN=2−2 aN=2−1 aN=2 aN=2−1 aN=2−2 ::: a2 a1] | {z } | {z } disp((-2/N)*imag(fft(x))) gives [0 b1 b2 ::: bN=2−2 bN=2−1 0 −bN=2−1 − bN=2−2 ::: − b2 − b1] | {z } | {z } disp((2/N)*abs(fft(x))) gives (we usually use this one!) [2c0 c1 c2 ::: cN=2−2 cN=2−1 cN=2 cN=2−1 cN=2−2 ::: c2 c1] | {z } | {z } disp(angle(fft(x))) gives [0(or p) −q1 ::: −qN=2−1 0(or p) qN=2−1 ::: q2 q1] | {z } | {z } k Frequency associated with kth term (Matlab index k + 1) is f = S: N 4 FFT: Why the mirrored coefficients? p Complex-exponential form of Fourier series of any T-periodic signal: (ı = −1) ¥ −ı2p k t x(t) = ∑ Xk e T : k=−¥ For a T-periodic signal band-limited to B = K=T: K −ı2p k t x(t) = ∑ Xk e T : k=−K 0 1 N−1 For an array x of length N with signal samples x = x S x S ··· x S taken from a signal x(t) that is periodic and band-limited with S > 2B: disp((1/N)*fft(x)) gives [X0 X1 X2 ::: XN=2−2 XN=2−1 X−N=2 X−N=2+1 X−N=2+2 ::: X−2 X−1] | {z } | {z } positive k negative k because 1 1 cos(t) = eıt + e−ıt : 2 2 We will not use the complex-exponential form in ENGN 100. (See EECS 216.) 5 k FFT: Why f = NS ? Recall sinusoidal form of Fourier series of T-periodic signal with band-limit B: K k x(t) = c0 + ∑ ck cos 2p t − qk k=1 T k Frequency of kth term in sum is f = : T But for unknown pitches we do not know the fundamental period T! k So the formula f = T is not immediately useful with the FFT. 6 k FFT: Why f = NS ? Imagine repeating a segment of audio over and over: t This thought experiment yields a periodic signal with period T = ND = N=S where N is the number of samples. k Substituting T = N=S into the formula f = T and simplifying yields k f = S: N • This formula works perfectly when the unknown frequency f is an integer multiple of S=N. • If f is not exactly an integer multiple of S=N, then we will see a \bump" in the FFT spectrum instead of a single line. 7 Line spectra • Spectrum of a T-periodic, band-limited signal 1 2 K x(t) = c + c cos 2p t − q +c cos 2p t − q +··· + c cos 2p t − q 0 1 T 1 2 T 2 K T K • More generally, line spectra of band-limited signals look something like this: Formula: x(t) = c0 + c1 cos(2p f1t)+··· + c4 cos(2p f4t) (We assumed qk = 0 in this formula because phase is unspecified in spectrum.) • In physics, often only the frequencies of atomic spectra are shown, not the amplitudes: [wiki] 8 Exercise Draw the spectrum of this signal: x(t) = 20sin2(2p50t)+30cos(2p200t): 2 1 1 Hint: sin (f) = 2 − 2 cos(2f) \power reduction formula" 9 DSP, FFT and \Stairway to heaven" 0.2 0.1 0 x(n/S) −0.1 play −0.2 0 0.5 1 1.5 2 2.5 3 3.5 4 4 n x 10 0.05 0 x(n/S) play −0.05 4000 4200 4400 4600 4800 5000 5200 5400 5600 5800 6000 n 0.02 0.015 0.01 spectrum 0.005 0 111 221 331 441 551 661 771 881 991 k+1 k 110 Fundamental frequency of first note: f = NS = 20008000 = 440Hz: What is the lowest (nonzero) frequency one could find here??? 10 Listening and seeing 1 0.5 0 0 400 4000 play 1 0.5 0 play 400 713 1 0.5 play 0 400 800 1200 1600 2000 2400 1 0.5 play 0 400 800 1200 1600 2000 2400 f [Hz] Why is the lowest note on a tuba (or large pipe organ) C0 = 16.35 Hz??? [wiki] 11 Application: Removing noise from signals (Lab 3) 12 Removing noise from signals • Given: signal = desired signal + noise signal y(t) = x(t) + e(t) • Goal: reduce (\filter out") as much noise as possible • Assume/know: signal is band limited to B Hz • Idea: eliminate frequencies above B Hz (must be noise) • Analog approach: use electrical circuit (e.g., treble control) (See EECS 215/216) • Digital approach: ◦ sample signal ◦ compute spectrum using FFT ◦ set to zero portions of the spectrum that are just noise ◦ use inverse FFT (ifft) to synthesize improved signal ◦ (Many more ways described in DSP course EECS 351.) 13 Removing noise digitally: Details • sample using S > 2B k • Recall f = N S and disp((2/N)*abs(fft(x))) gives: [2c0 c1 ::: cK−1 cK :::cN=2−1 cN=2 cN=2−1 :::cK cK−1 :::c1] | {z } | {z } |{z} | {z } | {z } low high highest high low | {z } mirror • Find index K such that (K − 1)S=N = B. Then we want: [2c0 c1 ::: cK−1 0:::0 0 0:::0 cK−1 :::c1] | {z } | {z } |{z} | {z } | {z } low high highest high low | {z } mirror • remove frequency components above B using fft, synthesize \improved" signal using ifft: (review a(k) = 0;) Yf = fft(y); Zf = Yf; Zf(K+1:N+1-K) = 0; z = real(ifft(Zf)); • This is called low pass filtering (via FFT). 14 Example: Low-pass filtering a noisy EKG signal • EKG=Electrocardiogram (heart) electric signal. • Periodic (we hope!) with period about 1 second (60 beats per minute = 1 beat per second). • Components at 1;2;3;::: Hz up to about 7 Hz. • So: We eliminate all frequencies above 7 Hz. • Result: high-frequency noise eliminated, but low frequency noise remains. • See next slide for signals and their spectra. 15 Example: Low-pass filtering a noisy EKG signal t [sec] f [Hz] 16 Example: Removing noise from mystery signal 20 10 0 y(t) −10 −20 0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1 t [sec] • Known: N = 8000 samples at S = 8000 Hz • What is the signal x(t) buried in this noise? • How do we recover it from y(t)? • (cf. restoring old analog recordings, movies, etc.) 17 Spectrum of mystery signal 1.2 1 0.8 0.6 spectrum of y 0.4 0.2 0 1 8000 frequency index k + 1 • stem(2/N*abs(fft(y))) • This spectrum also looks like random noise!? • Look at vertical scale: large peaks near 1 and 8000. • Zoom in to see exactly where the peaks are (next slide) 18 Spectrum of mystery signal: Zoomed 1.2 1.2 1 1 0.8 0.8 0.6 0.6 0.4 0.4 0.2 0.2 0 0 1 6 19 7996 8000 k + 1 k + 1 • Large peaks at Matlab array index 6 and 7996 = 8000+1−(6−1) • (If we counted from 0, then peaks at k = 5 and N − k = 8000 − 5 = 7995.) • Sinusoid frequency (6 − 1)S=N = 5(8000)=8000 = 5 Hz • Now filter out all other frequencies (all but 6 and 7996).
Details
-
File Typepdf
-
Upload Time-
-
Content LanguagesEnglish
-
Upload UserAnonymous/Not logged-in
-
File Pages36 Page
-
File Size-