ThinkDSP
This notebook contains code examples from Chapter 1: Sounds and Signals
Copyright 2015 Allen Downey
Read a wave
read_wave
reads WAV files. The WAV examples in the book are from freesound.org. In the contributors section of the book, I list and thank the people who uploaded the sounds I use.
I pulled out a segment of this recording where the pitch is constant. When we plot the segment, we can't see the waveform clearly, but we can see the "envelope", which tracks the change in amplitude during the segment.
Spectrums
Wave provides make_spectrum
, which computes the spectrum of the wave.
Spectrum provides plot
The frequency components above 10 kHz are small. We can see the lower frequencies more clearly by providing an upper bound:
Spectrum provides low_pass
, which applies a low pass filter; that is, it attenuates all frequency components above a cutoff frequency.
The result is a spectrum with fewer components.
We can convert the filtered spectrum back to a wave:
Now we can listen to the original segment and the filtered version.
The original sounds more complex, with some high-frequency components that sound buzzy.
The filtered version sounds more like a pure tone, with a more muffled quality.
The cutoff frequency I chose, 3000 Hz, is similar to the quality of a telephone line, so this example simulates the sound of a violin recording played over a telephone.
Interaction
The following shows the same example using interactive IPython widgets.
Adjust the sliders to control the start and duration of the segment and the cutoff frequency applied to the spectrum.