Monday, January 12, 2015

Think DSP Chapter 3: Chirps

In my ongoing celebration of DSP month, I am posting excerpts from Think DSP, my new introduction to Digital Signal Processing.  Here are links to the previous installments:

Chapter 1
Chapter 2

Today's installment is Chapter 3, of course.  But right now I am in the process of finishing Chapter 9, which is about signals and linear, time-invariant (LTI) systems.   I just finished one of the coolest examples in the book, and I can't resist jumping ahead a little.  So, before we get to Chapter 3, please check out this IPython notebook, and then come right back.

Chapter 3

Welcome back.  I hope you like the "violin in a firing range" example, and I hope it makes you want to stick around and see how it works.  Chapter 3 might not be quite as cool, but it has some good stuff, too, like chirps and the Eye of Sauron.  Here's the introduction:

"The signals we have worked with so far are periodic, which means that they repeat forever. It also means that the frequency components they contain do not change over time. In this chapter, we consider non-periodic signals, whose frequency components do change over time. In other words, pretty much all sound signals.

"We’ll start with a chirp, which is a signal with variable frequency. Here is a class that represents a chirp:

class Chirp(Signal):
    
    def __init__(self, start=440, end=880, amp=1.0):
        self.start = start
        self.end = end
        self.amp = amp

"start and end are the frequencies, in Hz, at the start and end of the chirp. amp is amplitude."

You can see (and hear) the examples from Chapter 3 in this IPython notebook.  It includes this figure:



Which is the spectrum of a chirp that sweeps from 220 Hz to 440 Hz.  The spectrum shows a "blur" of frequencies in that range, but because of leakage, it has a cool pattern across the top that looks a little bit like this:

Sauron eye barad dur

That's the Eye of Sauron at the top of Barad-dûr (a tower in the Lord of the Rings, in case you didn't know).

Chapter 3 also presents spectrograms, which are visualizations of the short-time Fourier transform (STFT).  A STFT breaks a wave up into short intervals and computes the Fourier transform of each interval.  The visualization shows time on the x-axis and frequency on the y-axis.  This example shows the spectrogram of a chirp that sweeps from 220 to 440 Hz:


This chapter also features one of my favorite exercises, the sawtooth chirp:

"Write a class called SawtoothChirp that extends Chirp and overrides evaluate to generate a sawtooth waveform with frequency that increases (or decreases) linearly.

"Draw a sketch of what you think the spectrogram of this signal looks like, and then plot it. The effect of aliasing should be visually apparent, and if you listen carefully, you can hear it."

This exercise has a punchline: if you implement the sawtooth chirp correctly, it should sound familiar, at least to viewers of a certain age.  Hint.

You can read the rest of Chapter 3 here.  In a few days I will post Chapter 4: Noise!


1 comment:

Note: Only a member of this blog may post a comment.