5. Whirlwind?
We’re going to cover a semester in 3 hours.
We will not achieve deep understanding.
Goals:
1. Overview of the big ideas.
2. Stimulate appetite.
6. Why?
Signal processing is the coolest thing I know.
● It’s useful for many things.
● The algorithm is clever.
● The math is elegant.
● It explains so much.
10. Sound
Because our ears do something similar to FFT.
Vi Hart, “What is up with Noises?
(The Science and Mathematics of Sound, Frequency, and Pitch)”
12. Think DSP
Published by O’Reilly Media,
available under a free license
from Green Tea Press.
13. Starting at the end
1. Clone the repository.
2. Launch Jupyter.
3. Open chap10preview.ipynb
Put in your headphones!
14. Black magic?
Not if you understand
1. Discrete Fourier transform.
2. Convolution theorem.
3. Linear time-invariant theory.
And that’s the plan.
15. thinkdsp.py
Signal represents a continuous mathematical function.
Wave contains an array of discrete samples.
Spectrum contains the discrete Fourier transform of a Wave.
17. The notebooks
1. Open chap01.ipynb
2. Read the text.
3. Run the code.
Stop when you get to “Interaction”.
18. Exercise
Starting with this:
cos_sig = thinkdsp.CosSignal(freq=440, amp=1.0, offset=0)
sin_sig = thinkdsp.SinSignal(freq=880, amp=0.5, offset=0)
wave = mix.make_wave(duration=0.5, start=0, framerate=11025)
Make and plot the spectrum of wave.
19. Spectral analysis
Any signal can be represented as a sum of
single-frequency components.
The spectrum of a signal encodes the amplitude
of each component.
20. DFT
Discrete Fourier Transform of a wave is its spectrum.
Fast Fourier Transform is an efficient algorithm.
(But people use FFT and DFT interchangeably)
21. Opening the hood
Wave.make_spectrum is a wrapper for numpy.fft.rfft
rfft stands for “real FFT”.
The values in the Wave are real (not complex).
22. class Wave:
def make_spectrum(self):
hs = np.fft.rfft(self.ys)
n = len(self.ys) # number of samples
d = 1 / self.framerate # time between samples
fs = np.fft.rfftfreq(n, d)
return Spectrum(hs, fs, self.framerate)
23. How does DFT work?
Computes correlation
between the signal and
sinusoids with different
frequencies.
http://paulbourke.net/miscellaneous/dft/
25. Low-pass filter
Attenuates high frequencies, lets low frequencies pass.
Sounds “muffled”, like under water, through a pillow or wall…
Because everything that transmits sound is a low pass filter.
26. Waveforms and harmonics
1. Open chap02.ipynb.
2. Read and run the first section,
“Waveforms and Harmonics”.
27. Odd harmonics only Even and odd harmonics
Slow
dropoff
Fast
dropoff
?
See chap02soln.ipynb, last exercise.
32. Aliasing
1. Back to chap02.ipynb
2. Jump to “Aliasing interaction”.
3. Explore the spectrum of a sawtooth signal
sampled at different rates.
33. Complex amplitudes
class Wave:
def make_spectrum(self):
hs = np.fft.rfft(self.ys)
n = len(self.ys) # number of samples
d = 1 / self.framerate # time between samples
fs = np.fft.rfftfreq(n, d)
return Spectrum(hs, fs, self.framerate)
39. Chirps
Signals so far don’t change over time.
But most sounds do.
Chirp: Signal with linearly-increasing frequency.
40. Chirps
1. On to chap03.ipynb
2. Read the first section “Chirp”.
3. Skip “Leakage”.
4. Read the third section “Spectrogram”.
5. Stop when you get to “Spectrum of a chirp”.
41. Short Time Fourier Transform
1. Divide a wave into segments.
2. Compute the DFT of each segment.
50. Convolution
1. Multiply the signal by the window elementwise.
2. Add up the product.
3. Record the result.
4. Shift the window one element to the right.
5. Repeat.
51. In Python
smoothed = np.zeros(N) # space to store result
rolled = window.copy() # copy the window
for i in range(N):
smoothed[i] = sum(rolled * segment.ys)
rolled = np.roll(rolled, 1)
52. Smoothing and convolution
1. Open chap08.ipynb.
2. Read and run “Smoothing”.
3. Read and run “Smoothing sound signals”.
63. Convolution theorem
Convolution with a window in the time domain
corresponds to
multiplication by a filter in the frequency domain.
The filter is the DFT of the window.
69. Boxcar window
The boxcar window corresponds to a low-pass filter.
But not a very good one.
Because it looks like a square wave.
Which has slowly-decaying harmonics.
73. Gaussian window
If std is too big, or M is too small:
1. The Gaussian gets cut off,
2. It looks more like a boxcar, and
3. The high frequency bounces come back.
74.
75. LTI Theory
We’ve got DFT and the Convolution Theorem.
All we need now is Linear Time-Invariant Theory!
76. System
A system is anything that takes a signal as input
and produces a signal as output.
An LTI system is...
80. An acoustic system can:
1) Delay a signal and echo.
2) Attenuate some frequencies more than others.
81. But it can’t:
1) Output more energy
than input.
2) Move energy from one
frequency to another.
And that means...
82. System characterization
If we know what a system does to
each frequency component,
we know what it will do to a
signal.
83. How?
You could input one frequency at a time and
record the result.
Or sweep through a range of frequencies.
Or input all the frequencies at the same time!