ThinkDSP
This notebook contains solutions to exercises in Chapter 3: Non-periodic signals
Copyright 2015 Allen Downey
Exercise
Run and listen to the examples in chap03.ipynb. In the leakage example, try replacing the Hamming window with one of the other windows provided by NumPy, and see what effect they have on leakage.
See http://docs.scipy.org/doc/numpy/reference/routines.window.html
Solution
Here's the leakage example:
The following figure shows the effect of 4 different windows.
All four do a good job of reducing leakage. The Bartlett filter leaves some residual "ringing". The Hamming filter dissipates the least amount of energy.
Exercise
Write a class called SawtoothChirp
that extends Chirp
and overrides evaluate to generate a sawtooth waveform with frequency that increases (or decreases) linearly.
Here's what it sounds like.
And here's the spectrogram.
At a relatively low frame rate, you can see the aliased harmonics bouncing off the folding frequency. And you can hear them as a background hiss. If you crank up the frame rate, they go away.
By the way, if you are a fan of the original Star Trek series, you might recognize the sawtooth chirp as the red alert signal:
Exercise
Make a sawtooth chirp that sweeps from 2500 to 3000 Hz, then make a wave with duration 1 and framerate 20 kHz. Draw a sketch of what you think the spectrum will look like. Then plot the spectrum and see if you got it right.
Solution
Since the fundamental sweeps from 2500 to 3000 Hz, I expect to see something like the Eye of Sauron in that range. The first harmonic sweeps from 5000 to 6000 Hz, so I expect a shorter tower in that range, like the Outhouse of Sauron. The second harmonic sweeps from 7500 to 9000 Hz, so I expect something even shorter in that range, like the Patio of Sauron.
The other harmonics get aliased all over the place, so I expect to see some energy at all other frequencies. This distributed energy creates some interesting sounds.
Exercise
In musical terminology, a “glissando” is a note that slides from one pitch to another, so it is similar to a chirp. Find or make a recording of a glissando and plot its spectrogram.
One suggestion: George Gershwin's Rhapsody in Blue starts with a famous clarinet glissando; you can download a recording from http://archive.org/details/rhapblue11924.
Exercise
A trombone player can play a glissando by extending the trombone slide while blowing continuously. As the slide extends, the total length of the tube gets longer, and the resulting pitch is inversely proportional to length. Assuming that the player moves the slide at a constant speed, how does frequency vary with time?
Write a class called TromboneGliss
that extends Chirp
and provides evaluate
. Make a wave that simulates a trombone glissando from F3 down to C3 and back up to F3. C3 is 262 Hz; F3 is 349 Hz.
Plot a spectrogram of the resulting wave. Is a trombone glissando more like a linear or exponential chirp?
Here's the first part of the wave:
And the second part:
Putting them together:
Here's the spectrogram:
Exercise
Make or find a recording of a series of vowel sounds and look at the spectrogram. Can you identify different vowels?
The stripe across the bottom is probably background noise. The peaks in the spectrogram are called "formants".
In general, vowel sounds are distinguished by the amplitude ratios of the first two formants relative to the fundamental. For more, see https://en.wikipedia.org/wiki/Formant
We can see the formats more clearly by selecting a segment during 'ah'.
The fundamental is near 100 Hz. The next highest peaks are at 200 Hz and 700 Hz. People who know more about this than I do can identify vowels by looking at spectrums, but I can't.
The 'eh' segment has a high-amplitude formant near 500 Hz.
The 'ih' segment has no high frequency components.
The 'oh' segment has a high-amplitude formant near 500 Hz, even higher than the fundamental.
The 'oo' segment has a high-amplitude formant near 300 Hz and no high-frequency components