Think DSP: Digital Signal Processing in Python

BSCS and BSEE students taking a Signal Processing or Digital Signal Processing elective course can read the complete textbook “Think DSP: Digital Signal Processing in Python” by Allen B. Downey, free from its official source, Green Tea Press. It’s an 11-chapter book that teaches DSP the way a programmer would learn it — by generating, analyzing, and listening to real audio signals in Python, rather than through heavy mathematical derivation alone.

This edition works through a complete DSP toolkit — from harmonics and spectrograms, through the discrete cosine and Fourier transforms, to filtering, convolution, LTI systems, and the sampling theorem — making it a practical, hands-on companion for anyone who already knows some Python and wants to build genuine intuition for how digital audio and signal processing actually work.

Book Overview

CourseSignal Processing / Digital Signal Processing
Degree ProgramsBSCS, BSEE, and any program’s Signal Processing, DSP, or advanced Python elective course
LevelUniversity — intermediate to advanced, assumes working knowledge of Python and basic calculus
Edition1st Edition, Version 1.1.4 (Think DSP, Green Tea Press)
AuthorAllen B. Downey
Structure11 chapters — Chapters 1–5 cover signals, harmonics, and time-domain analysis, Chapters 6–7 build up the DCT and DFT, and Chapters 8–11 cover filtering, calculus in the frequency domain, LTI systems, and sampling
ExercisesEach chapter is built around worked examples with accompanying Jupyter notebooks on the official site
LanguageEnglish
LicenseCreative Commons Attribution-NonCommercial-ShareAlike 4.0 International (CC BY-NC-SA 4.0) — Model: Link-only
FormatFree PDF (Version 1.1.4) and complete browsable HTML edition

Chapter List

Chapter 1: Sounds and signals

Difficulty: Beginner · Signal Processing — Week 1 · Key topics: Sound as a waveform, periodic signals, the Wave and Spectrum objects, sampling rate

This opening chapter introduces sound as a physical waveform — a signal that varies over time — and the book’s own Python library (built on NumPy) for representing, reading, writing, and playing sound as Wave objects. It introduces periodic signals using simple sinusoids as the starting example, and previews the Spectrum object used throughout the rest of the book to view a signal’s frequency-domain content.

Key Points:

  • A sound is represented computationally as a Wave object — a sequence of amplitude values sampled at a fixed sampling rate over time.
  • A periodic signal repeats its pattern at a fixed frequency; this chapter uses simple sinusoids (sine and cosine waves) as the simplest example of a periodic signal.
  • The sampling rate (samples per second) determines how finely a continuous sound wave is captured digitally, and directly limits the highest frequency that can be accurately represented (previewed here, developed fully in the sampling chapter).
  • The book’s own thinkdsp Python module wraps NumPy and SciPy functionality into Wave and Spectrum classes, letting later chapters move fluidly between the time domain (a waveform over time) and the frequency domain (a spectrum of frequencies).
  • This chapter establishes the book’s practical, code-first approach: every signal-processing concept is explored by generating, analyzing, and listening to real audio signals in Python, not just through equations.

Practice Tip: Install the thinkdsp module and generate a few simple sine waves at different frequencies yourself, then listen to them — connecting a frequency value in code to an actual pitch you hear builds intuition that carries through the rest of the book.

Common Mistake: Treating “sample rate” and “frequency” as interchangeable terms — sample rate is a property of how a signal was digitized (how many measurements per second), while frequency is a property of the signal itself (how fast it oscillates); confusing the two leads to serious errors once the sampling theorem is covered later in the book.

Important Questions:

  • Q1: What is a Wave object in the thinkdsp module, and what does it represent? A Wave object represents a sound as a sequence of amplitude values sampled at a fixed sampling rate over time — the digital representation of a physical sound waveform that can be played, plotted, and analyzed in Python.
  • Q2: What distinguishes a periodic signal from a non-periodic one, using this chapter’s simple sinusoid example? A periodic signal repeats an identical pattern at a fixed frequency indefinitely (a sine wave is the simplest example); a non-periodic signal does not repeat a fixed pattern, and is covered in Chapter 3 using examples like chirps whose frequency changes over time.

Chapter 2: Harmonics

Difficulty: Beginner · Signal Processing — Week 1–2 · Key topics: Harmonic structure, mixtures of sinusoids, timbre, real instrument signals, aliasing preview

This chapter examines real, non-sinusoidal periodic signals — like a violin or trumpet note — and shows how they decompose into a fundamental frequency plus a series of harmonics (integer multiples of the fundamental). It explains how the relative strength of different harmonics gives an instrument its characteristic timbre, distinguishing two notes played at the same pitch but on different instruments, and introduces aliasing as a preview of a topic that recurs later in the book.

Key Points:

  • A real musical note is not a pure sinusoid: it is a mixture of a fundamental frequency plus harmonics at integer multiples of that fundamental, each with its own amplitude.
  • Timbre — the quality that distinguishes a violin from a trumpet playing the identical pitch — comes from the relative strengths of these different harmonics, not from the fundamental frequency itself.
  • Analyzing a real recorded instrument’s spectrum reveals its specific harmonic “fingerprint”: which harmonics are strong, which are weak or absent, and how that pattern differs between instruments.
  • Aliasing (distortion introduced when a signal’s higher-frequency content is sampled too slowly) is previewed here as an artifact that can appear when a harmonic’s frequency approaches or exceeds half the sampling rate.
  • This chapter reinforces the book’s time-domain/frequency-domain duality: the same musical note looks like a repeating but non-sinusoidal wiggle in the time domain, and like a small number of sharp spikes at the fundamental and its harmonics in the frequency domain.

Memory Tip: Remember timbre with a simple rule: same fundamental frequency, same pitch; different harmonic amplitudes, different timbre. Two instruments playing the identical note can sound completely different because they excite different harmonics at different strengths.

Common Mistake: Assuming a musical instrument’s note is a pure sine wave at its fundamental frequency — real instrument tones are mixtures of the fundamental plus many harmonics, and it’s precisely this harmonic mixture, not the fundamental alone, that determines how the note actually sounds.

Important Questions:

  • Q1: What is a “harmonic,” and how does the harmonic content of a musical note relate to its fundamental frequency? A harmonic is a frequency component at an integer multiple of a signal’s fundamental frequency (2x, 3x, 4x, and so on). A real musical note’s spectrum consists of energy at the fundamental plus a series of these harmonics, each with its own amplitude.
  • Q2: Why can two instruments playing the exact same musical pitch sound completely different? Because their timbre — determined by the relative amplitudes of their harmonics above the shared fundamental frequency — differs between instruments, even though the fundamental frequency (and therefore the perceived pitch) is identical.

Chapter 3: Non-periodic signals

Difficulty: Intermediate · Signal Processing — Week 2 · Key topics: Chirps, spectrograms, time-varying frequency content, the short-time Fourier transform idea

This chapter moves beyond strictly periodic signals to non-periodic ones, using chirps (signals whose frequency changes continuously over time) as the main example. Since a single spectrum cannot capture a frequency that changes over the course of a signal, the chapter introduces the spectrogram — computed by taking the spectrum of many short overlapping segments of a signal in sequence — as a way to visualize how frequency content evolves over time.

Key Points:

  • A chirp is a signal whose instantaneous frequency changes continuously over time (sweeping upward or downward), making it a clear example of a genuinely non-periodic signal.
  • A single Fourier spectrum, computed over an entire chirp, cannot show how its frequency changes over time — it only shows which frequencies were present somewhere in the signal, not when.
  • A spectrogram addresses this by computing the spectrum of many short, overlapping time segments (windows) of the signal in sequence, producing a 2D image of frequency (vertical axis) versus time (horizontal axis).
  • The spectrogram makes an unavoidable trade-off between time resolution and frequency resolution: shorter windows give better time resolution but worse frequency resolution, and vice versa.
  • This chapter’s spectrogram technique is the same fundamental tool used in real applications like speech recognition, music analysis, and audio fingerprinting, where frequency content genuinely varies over time.

Practice Tip: Generate a chirp signal yourself and plot both its waveform and its spectrogram side by side — seeing the diagonal line of a chirp’s changing frequency in the spectrogram, invisible in a plain waveform plot, makes the value of the spectrogram immediately concrete.

Common Mistake: Trying to read a chirp’s time-varying frequency content directly off a single overall spectrum plot — a plain spectrum shows only which frequencies occurred somewhere in the signal, with no information about when, so a spectrogram (not a single spectrum) is required to see the frequency-over-time structure.

Important Questions:

  • Q1: Why can’t a single Fourier spectrum adequately represent a chirp signal? Because a chirp’s frequency changes continuously over the duration of the signal, but a single overall spectrum only reports which frequencies were present in the signal as a whole, with no information about when each frequency occurred during the signal.
  • Q2: What fundamental trade-off does choosing a spectrogram’s window length involve? A trade-off between time resolution and frequency resolution: a shorter window gives better time resolution (can localize a frequency change more precisely in time) but worse frequency resolution, while a longer window gives better frequency resolution but worse time resolution.

Chapter 4: Noise

Difficulty: Intermediate · Signal Processing — Week 3 · Key topics: White noise, pink/Brownian noise, power spectral density, 1/f noise in nature

This chapter studies noise signals — random signals with no clear periodic structure — by examining their power spectral density (how a signal’s power is distributed across frequencies) rather than looking for specific frequency spikes as in earlier chapters. It contrasts white noise (equal power at every frequency) with pink and Brownian (red) noise, whose power falls off at higher frequencies according to a power-law relationship, and notes how 1/f -style noise appears surprisingly often in natural and man-made systems.

Key Points:

  • White noise has equal power spectral density across all frequencies — no frequency range is stronger than any other, giving it a flat spectrum.
  • Pink noise’s power spectral density falls off proportionally to 1/f (inversely with frequency), giving it relatively more low-frequency content than white noise; Brownian (red) noise falls off even faster, proportional to 1/f².
  • Power spectral density is a way of describing a signal’s frequency content statistically (how power is distributed across frequency bands on average) rather than as sharp spikes at exact frequencies, appropriate for signals with no clean periodic structure.
  • 1/f-style noise appears in a surprisingly wide range of natural and man-made phenomena beyond audio — from certain biological signals to some financial and electronic systems — making it a recurring pattern worth recognizing outside signal processing narrowly.
  • This chapter connects to Chapter 8 (Filtering) and to spectral concepts from earlier chapters: even though noise has no clean spectral spikes, its overall spectral shape (flat, or falling off as 1/f or 1/f²) is still a meaningful, measurable, and useful property.

Memory Tip: Remember the noise-color naming convention by its spectral slope: white noise is flat (equal power at every frequency, like white light containing all colors equally), pink noise falls off as 1/f, and Brownian/red noise falls off even faster as 1/f².

Common Mistake: Assuming “noise” means a signal has no measurable structure at all — while noise lacks a clean periodic spectrum with sharp spikes, its power spectral density (how its power is distributed across frequency, on average) is a real, measurable, and often very structured property that distinguishes white, pink, and Brownian noise from one another.

Important Questions:

  • Q1: How does white noise’s power spectral density differ from pink noise’s? White noise has equal power spectral density at every frequency (a flat spectrum), while pink noise’s power spectral density falls off proportionally to 1/f, meaning it has relatively more power at lower frequencies than white noise does.
  • Q2: Why is power spectral density a more appropriate way to describe noise than looking for specific frequency spikes, as in earlier chapters? Because noise, by definition, lacks the clean periodic structure that produces sharp spectral spikes; power spectral density instead describes, statistically, how a noise signal’s power is distributed across frequency bands on average, which is a meaningful property even when no individual frequency dominates.

Chapter 5: Autocorrelation

Difficulty: Intermediate · Signal Processing — Week 4 · Key topics: The autocorrelation function, pitch tracking, detecting periodicity, correlation between a signal and shifted copies of itself

This chapter introduces autocorrelation — correlating a signal with time-shifted copies of itself — as a way to detect periodicity directly in the time domain, complementing the frequency-domain methods from earlier chapters. It applies autocorrelation to pitch tracking (or “pitch perception”): finding the fundamental period of a signal, like a spoken vowel sound or a musical note, by locating the time-shift that produces the strongest self-correlation.

Key Points:

  • Autocorrelation measures how similar a signal is to a delayed (time-shifted) copy of itself, computed across a whole range of possible delays.
  • For a periodic signal, autocorrelation peaks sharply at delays equal to the signal’s period (and its integer multiples), since at those delays the shifted copy lines up almost exactly with the original.
  • Pitch tracking uses this property directly: the delay at which autocorrelation peaks most strongly corresponds to the signal’s fundamental period, and thus its fundamental frequency (pitch), often more robustly than reading the fundamental directly off a noisy spectrum.
  • Autocorrelation works in the time domain and is a genuinely different technique from the Fourier-based frequency-domain methods used elsewhere in the book, even though the two approaches are mathematically related.
  • Autocorrelation-based pitch detection is used in real speech-processing and music-analysis applications precisely because it can be more robust to certain kinds of noise and harmonics than naively picking the strongest peak in a spectrum.

Practice Tip: Compute the autocorrelation of a simple periodic signal (like a sine wave) yourself and plot it against delay — seeing the clear repeating peaks at multiples of the true period makes the pitch-tracking application immediately intuitive.

Common Mistake: Assuming pitch detection always requires looking at a signal’s Fourier spectrum — autocorrelation is a genuine time-domain alternative that can detect a signal’s fundamental period directly, without ever computing a Fourier transform, and is sometimes more robust for real, noisy recorded signals.

Important Questions:

  • Q1: What does the autocorrelation function measure, and why does it peak at a periodic signal’s period? It measures how similar a signal is to a time-shifted copy of itself, computed across a range of possible delays. For a periodic signal, shifting by exactly one period (or an integer multiple of it) lines the shifted copy up almost exactly with the original, producing a strong correlation peak at that specific delay.
  • Q2: Why might autocorrelation-based pitch tracking be preferred over simply picking the strongest peak in a signal’s Fourier spectrum? Because autocorrelation directly targets the signal’s fundamental period in the time domain, which can be more robust to noise and to cases where a strong harmonic, rather than the fundamental itself, happens to dominate the raw spectrum.

Chapter 6: Discrete cosine transform

Difficulty: Intermediate · Signal Processing — Week 5 · Key topics: The Discrete Cosine Transform (DCT), signal synthesis from basis functions, analysis versus synthesis, compression intuition

This chapter introduces the Discrete Cosine Transform (DCT) by building it up conceptually: first synthesis (constructing a signal as a weighted sum of cosine basis functions of different frequencies), then analysis (finding the weights, or coefficients, that best reconstruct a given signal from those same basis functions). The DCT is presented as an accessible stepping stone toward the more general Discrete Fourier Transform covered in the next chapter, and previews the compression intuition behind formats like JPEG and MP3, which rely on similar transforms.

Key Points:

  • Synthesis means constructing a signal as a weighted sum of a fixed set of basis functions (here, cosines of different frequencies); analysis means the reverse: computing the weights that best reproduce a given signal from those same basis functions.
  • The DCT represents a signal using only cosine basis functions (real-valued), which makes it more intuitive to build up from first principles than the complex-exponential-based Discrete Fourier Transform covered next.
  • Many DCT coefficients for a typical real signal end up small or negligible, meaning the signal’s important information is concentrated in relatively few coefficients — the core insight behind DCT-based compression techniques.
  • This concentration-of-information property is the same underlying idea used by real compression formats like JPEG (for images) and MP3 (for audio), which discard small, perceptually unimportant transform coefficients to reduce file size.
  • The chapter’s synthesis-then-analysis approach to building up the DCT is deliberately used as a scaffold for understanding the more general and more widely used Discrete Fourier Transform in the very next chapter.

Memory Tip: Keep synthesis and analysis straight as reverse operations of each other: synthesis builds a signal up from basis-function coefficients, while analysis works backward from a signal to find those same coefficients — every transform in this book is really just one direction or the other of this same basic relationship.

Common Mistake: Assuming that discarding small transform coefficients in DCT-based compression throws away “random” information indiscriminately — in fact the DCT is specifically chosen because a typical real signal’s important structure concentrates in relatively few coefficients, so discarding the smallest ones removes primarily redundant or perceptually unimportant information, not signal content at random.

Important Questions:

  • Q1: What is the difference between “synthesis” and “analysis” as used in this chapter’s introduction to the DCT? Synthesis is constructing a signal as a weighted sum of basis functions (here, cosines) given their weights/coefficients. Analysis is the reverse process: starting from a given signal and computing the coefficients that, when used in synthesis, best reconstruct that signal.
  • Q2: Why does the DCT’s tendency to concentrate a signal’s information in relatively few coefficients matter for compression? Because it means many of a typical signal’s DCT coefficients are small enough to discard with little perceptual loss, letting a compressed representation store far fewer numbers than the original signal while still reconstructing something close to it — the same basic idea used by real compression formats like JPEG and MP3.

Chapter 7: Discrete Fourier Transform

Difficulty: Advanced · Signal Processing — Week 6 · Key topics: Complex exponentials, deriving the DFT from the DCT, the Fast Fourier Transform (FFT), computational efficiency

This chapter generalizes the previous chapter’s DCT to the full Discrete Fourier Transform (DFT), using complex exponentials as basis functions instead of only real-valued cosines, which lets the DFT represent both a frequency’s magnitude and its phase. It also covers the Fast Fourier Transform (FFT), the standard efficient algorithm for computing a DFT, and explains why the FFT’s computational efficiency (compared to a naive DFT implementation) made frequency-domain signal processing practical for real, large signals.

Key Points:

  • The DFT uses complex exponentials (combining a cosine and a sine component via Euler’s formula) as its basis functions, rather than only real cosines, which lets it represent both the amplitude and the phase of each frequency component.
  • Phase information — which the DCT from the previous chapter cannot represent — matters for many signal-processing applications, including reconstructing a signal exactly, not just its power spectrum.
  • A naive direct computation of the DFT takes time proportional to N² for a signal of length N, which becomes impractically slow for large, real-world signals.
  • The Fast Fourier Transform (FFT) computes the exact same DFT result using a divide-and-conquer algorithm that takes time proportional to N log N — a dramatic efficiency improvement that made frequency-domain methods computationally practical at scale.
  • The relationship between the DCT and DFT covered in these two chapters mirrors a common pattern in this book: introduce a simpler, more intuitive special case first (DCT, real-valued), then generalize to the more powerful but more abstract full version (DFT, complex-valued).

Memory Tip: Remember the FFT’s practical significance in one line: it computes the identical mathematical result as a naive DFT, just far faster (N log N instead of N²) — it is a computational shortcut, not a different or approximate transform.

Common Mistake: Confusing the DFT (the mathematical transform) with the FFT (a fast algorithm for computing that same transform) — the FFT does not compute something different or approximate; it computes the exact DFT result, just far more efficiently than a naive direct calculation.

Important Questions:

  • Q1: What can the DFT represent about a signal’s frequency components that the DCT from the previous chapter cannot? Phase information. The DFT uses complex exponential basis functions (combining cosine and sine components), which let it represent both the amplitude and the phase of each frequency component, while the DCT’s purely real cosine basis functions can only capture amplitude-like information.
  • Q2: Why was the Fast Fourier Transform (FFT) algorithm significant for making frequency-domain signal processing practical? Because it computes the exact same result as a naive direct DFT calculation, but in time proportional to N log N instead of N² for a signal of length N — a dramatic speedup that made frequency-domain analysis computationally feasible for large, real-world signals rather than only small toy examples.

Chapter 8: Filtering and Convolution

Difficulty: Advanced · Signal Processing — Week 7 · Key topics: Convolution, the convolution theorem, smoothing filters, window functions

This chapter covers convolution — combining a signal with a filter’s impulse response to produce a filtered output — and the convolution theorem, which states that convolution in the time domain corresponds to simple multiplication in the frequency domain. It applies this to smoothing filters (like a moving average), showing how a filter’s effect on a signal’s frequency content can be understood and designed by examining the filter’s own frequency response.

Key Points:

  • Convolution combines an input signal with a filter’s impulse response, sliding the filter across the signal and computing a weighted sum at each position, to produce a filtered output signal.
  • The convolution theorem states that convolving two signals in the time domain is mathematically equivalent to simply multiplying their spectra in the frequency domain — a deep and practically useful equivalence.
  • A moving-average smoothing filter, viewed in the frequency domain via the convolution theorem, reveals itself to be a low-pass filter that attenuates higher frequencies — explaining why averaging smooths out fast fluctuations while preserving slower trends.
  • Because convolution in the time domain equals multiplication in the frequency domain, a filter’s effect on a signal can often be understood and predicted more easily by examining the filter’s own frequency response than by reasoning about the time-domain convolution operation directly.
  • This chapter ties together several of the book’s core themes: filters can be designed and understood entirely through their frequency-domain behavior, using exactly the FFT machinery introduced in the previous chapter.

Memory Tip: Remember the convolution theorem as a shortcut for intuition: whenever a time-domain filtering operation seems hard to reason about directly, ask what it looks like in the frequency domain instead — convolution there becomes simple multiplication, which is usually much easier to picture.

Common Mistake: Trying to predict a filter’s effect on a signal purely by inspecting the filter’s time-domain shape (like a moving-average window) — the convolution theorem shows that a filter’s frequency-domain response (which frequencies it attenuates or passes) is usually the more direct and intuitive way to understand and predict what the filter actually does to a signal’s content.

Important Questions:

  • Q1: State the convolution theorem in your own words. Convolving two signals in the time domain is mathematically equivalent to simply multiplying their spectra (Fourier transforms) in the frequency domain. This lets a time-domain filtering operation be understood and computed as a much simpler frequency-domain multiplication.
  • Q2: Why does a moving-average smoothing filter reduce fast fluctuations in a signal while preserving slower trends? Viewed through the convolution theorem in the frequency domain, a moving-average filter acts as a low-pass filter — it attenuates higher-frequency components (fast fluctuations) more strongly than lower-frequency components (slow trends), which is why averaging smooths out rapid noise while leaving the underlying slow-moving signal largely intact.

Chapter 9: Differentiation and Integration

Difficulty: Advanced · Signal Processing — Week 8 · Key topics: Spectral differentiation and integration, the relationship between a signal and its derivative/integral in the frequency domain

This chapter shows how differentiation and integration of a signal can be performed in the frequency domain, rather than only via time-domain numerical methods, by exploiting a simple relationship between a signal’s Fourier coefficients and those of its derivative or integral. It connects this to real, intuitive examples like the relationship between a sound’s waveform, its velocity, and its acceleration.

Key Points:

  • Differentiating a signal in the time domain corresponds to multiplying each frequency component’s coefficient by a factor proportional to that frequency in the frequency domain — higher frequencies get amplified more by differentiation.
  • Integrating a signal correspondingly divides each frequency component’s coefficient by a factor proportional to that frequency — lower frequencies dominate more after integration, which is why integration tends to smooth a signal out.
  • This spectral relationship explains, in frequency-domain terms, a pattern also observable directly in the time domain: differentiation emphasizes rapid changes (and amplifies noise, which is concentrated at high frequencies), while integration suppresses them.
  • Because differentiation amplifies high-frequency content, differentiating a noisy signal directly can dramatically amplify that noise — a genuine practical hazard that spectral differentiation makes clearly visible.
  • This chapter reinforces the book’s recurring theme that time-domain operations (like calculus operations) often have simple, illuminating equivalents in the frequency domain, once you know where to look.

Memory Tip: Remember the direction of the effect: differentiation amplifies high frequencies (and any noise riding on them), while integration amplifies low frequencies and smooths a signal out — the two operations act as opposite spectral “tilts.”

Common Mistake: Applying numerical differentiation directly to a noisy real-world signal without considering its frequency-domain effect — since differentiation amplifies high-frequency content more strongly, and noise is often concentrated at high frequencies, naive differentiation can turn a modestly noisy signal into a wildly noisy derivative.

Important Questions:

  • Q1: What happens to a signal’s frequency-domain coefficients when the signal is differentiated? Each frequency component’s coefficient is multiplied by a factor proportional to that frequency — meaning higher-frequency components are amplified more strongly by differentiation than lower-frequency ones.
  • Q2: Why can differentiating a noisy real-world signal be practically risky? Because differentiation amplifies high-frequency content, and noise in real signals is often concentrated at higher frequencies. Differentiating such a signal directly can dramatically amplify that noise, producing a derivative that is far noisier, proportionally, than the original signal.

Chapter 10: LTI systems

Difficulty: Advanced · Signal Processing — Week 9 · Key topics: Linear time-invariant (LTI) systems, characterizing a system by its impulse response, transfer functions

This chapter introduces Linear Time-Invariant (LTI) systems — systems whose behavior can be fully characterized by a single impulse response, from which the system’s output for any input signal can be predicted via convolution. It covers the transfer function (the frequency-domain counterpart of the impulse response) and shows how, together, these two ideas complete the book’s framework for understanding filters and systems from earlier chapters as instances of this more general LTI concept.

Key Points:

  • A system is linear if scaling or adding inputs scales or adds outputs correspondingly, and time-invariant if its behavior does not change over time — together these properties define an LTI system.
  • An LTI system is fully characterized by its impulse response: the system’s output when the input is a single, idealized impulse. Once known, the impulse response predicts the system’s output for any input via convolution (Chapter 8’s operation).
  • The transfer function is the Fourier transform of the impulse response — it describes, directly in the frequency domain, how the system amplifies or attenuates each frequency, playing the same role for an LTI system that a filter’s frequency response played in Chapter 8.
  • Every filter discussed in earlier chapters (like the moving-average smoothing filter) is itself an example of an LTI system, and can be fully described by its own impulse response or, equivalently, its transfer function.
  • This chapter’s LTI framework is the general theory underlying real-world applications like audio equalizers, room acoustics modeling, and control systems, unifying the book’s filtering and convolution material under one formal umbrella.

Memory Tip: Remember the two defining LTI properties as a package — linear (scaling and adding inputs scales and adds outputs) and time-invariant (behavior doesn’t change over time) — and that together they guarantee a single impulse response is enough to predict the system’s response to any input whatsoever.

Common Mistake: Assuming a system’s impulse response only describes its behavior for impulse-like inputs — for an LTI system specifically, the impulse response fully determines the system’s output for ANY input signal, via convolution, not merely for inputs that resemble an impulse.

Important Questions:

  • Q1: What two properties define a Linear Time-Invariant (LTI) system? Linearity (scaling or adding inputs scales or adds the corresponding outputs) and time-invariance (the system’s behavior does not change over time — the same input produces the same output regardless of when it’s applied).
  • Q2: Why is an LTI system’s impulse response so significant — what can be computed from it alone? Because for an LTI system, the impulse response alone is sufficient to predict the system’s output for any arbitrary input signal, via convolution — a single measurement (the impulse response) fully characterizes the system’s behavior for every possible input.

Chapter 11: Modulation and sampling

Difficulty: Advanced · Signal Processing — Week 10 · Key topics: Amplitude modulation, the sampling theorem, the Nyquist frequency, aliasing

This closing chapter covers amplitude modulation (shifting a signal’s frequency content by multiplying it with a carrier wave, the basis of AM radio) and the sampling theorem, which states that a continuous signal can be perfectly reconstructed from its samples only if it was sampled at more than twice its highest frequency (the Nyquist rate). It revisits aliasing, first previewed in Chapter 2, now explained rigorously as what happens when a signal violates this sampling requirement.

Key Points:

  • Amplitude modulation multiplies a signal by a higher-frequency carrier wave, shifting the signal’s frequency content up to surround the carrier frequency — the basic principle behind AM radio transmission.
  • The sampling theorem states that a continuous signal can be perfectly reconstructed from discrete samples only if the sampling rate exceeds twice the signal’s highest frequency component — this threshold is called the Nyquist frequency.
  • Aliasing occurs when a signal is sampled below its Nyquist rate: frequency components above half the sampling rate get folded back and misrepresented as lower, incorrect frequencies in the sampled signal.
  • This chapter’s rigorous treatment of aliasing directly explains the aliasing artifact previewed informally back in Chapter 2, now grounded in the precise mathematical statement of the sampling theorem.
  • Understanding the sampling theorem and Nyquist frequency is essential for any real digital audio or signal-processing application, since choosing too low a sampling rate irreversibly corrupts a signal’s high-frequency content rather than merely losing it.

Memory Tip: Remember the Nyquist rule as “more than double”: a signal must be sampled at a rate greater than twice its highest frequency component to be reconstructed perfectly — sampling at exactly twice, or slower, risks aliasing.

Common Mistake: Assuming that sampling a signal too slowly simply “loses” its high-frequency content, as if it were cleanly filtered out — aliasing is worse than simple loss: those high frequencies don’t disappear, they get misrepresented as different, incorrect lower frequencies that then permanently corrupt the sampled signal.

Important Questions:

  • Q1: State the sampling theorem, including the role of the Nyquist frequency. A continuous signal can be perfectly reconstructed from its discrete samples only if it was sampled at a rate greater than twice its highest frequency component. This threshold — twice the signal’s highest frequency — is called the Nyquist frequency.
  • Q2: What actually happens to a signal’s high-frequency content when it is sampled below the Nyquist rate, rather than it simply being lost? Frequency components above half the sampling rate get “folded back” and misrepresented as different, incorrect lower frequencies within the sampled signal — this is aliasing, and it actively corrupts the sampled signal rather than merely discarding information cleanly.

Download Think DSP PDF (Free)

This book is free from its official source — author Allen B. Downey publishes this edition under a Creative Commons licence. Download the complete PDF below, or read the free HTML edition on the official site.

↓ Download PDF

How to Study This Book

This book is organized to build progressively: Chapters 1–5 (Sounds and signals through Autocorrelation) build core time-domain and frequency-domain intuition using real audio signals, and should be read in order.

Chapters 6–7 (Discrete cosine transform, Discrete Fourier Transform) build up the book’s central mathematical tool step by step — the simpler, real-valued DCT first, then the more general complex-valued DFT and its efficient FFT implementation — and should not be skipped or reordered.

Chapters 8–11 (Filtering and Convolution through Modulation and sampling) apply the DFT/FFT machinery to filtering, calculus, general LTI systems, and sampling theory, and can be read somewhat more selectively depending on your course’s focus.

This book teaches by running code — installing the thinkdsp module and generating, analyzing, and listening to real audio signals in Python, not just reading the text, is essential to how the material is meant to be used.

This book assumes working knowledge of Python and basic calculus; readers newer to Python may want to work through the author’s companion introductory book, Think Python, first.


Used In These Programs

This book is used as a Signal Processing or DSP elective text in: BSCS, Programming, and Python-based Signal Processing coursework. Browse all Python books or all Computer Science category books.

Who Should Read This

Think DSP is written for students and self-learners who already know some Python and basic calculus and want to learn digital signal processing — spectra, filtering, sampling, and LTI systems — by writing code on real audio signals rather than through heavy mathematical derivation alone. It suits BSCS and BSEE students taking a Signal Processing or DSP elective, and is especially useful for anyone who wants to hear, not just see, what a Fourier transform, a filter, or aliasing actually does to a sound.


Applicable Universities

This book is useful for students at Pakistani universities offering BSCS or BSEE programs with a Signal Processing, Digital Signal Processing, or advanced Python elective course, including Punjab University, Virtual University, COMSATS, FAST, UET, NUST, GIKI, and other HEC-recognized institutions, and for self-learners who already know Python and want a free, code-first introduction to DSP.

FAQs

Is Think DSP free?

Yes. The complete edition is free from its official source, published by the author, Allen B. Downey, under a Creative Commons licence, as both a downloadable PDF and a browsable HTML edition.

Do I need prior signal processing knowledge before reading this book?

No formal prior signal-processing course is required — the book builds up spectra, transforms, and filtering from first principles using real audio examples. Working knowledge of Python and basic calculus is assumed.

What Python tools does this book use?

The book’s own thinkdsp module (built on NumPy and SciPy) provides Wave and Spectrum classes used throughout, letting you generate, analyze, filter, and play real audio signals directly in Python.

What is the difference between the DCT and the DFT covered in this book?

The DCT (Chapter 6) uses only real-valued cosine basis functions and is introduced first as an accessible stepping stone. The DFT (Chapter 7) generalizes this using complex exponentials, letting it represent both a frequency’s amplitude and its phase, and is computed efficiently via the FFT algorithm.

Is there a newer edition of Think DSP?

A second edition is under active development by the author (allendowney.github.io/ThinkDSP2/), but it is not yet complete or officially published. This page covers the current, complete 1st edition (Version 1.1.4).

Does this book cover real applications like AM radio or MP3 compression?

Yes, at the conceptual level — Chapter 6 previews the compression intuition behind formats like JPEG and MP3, and Chapter 11 covers amplitude modulation, the basic principle behind AM radio transmission.

Related Books

Think DSP is a free, code-first introduction to digital signal processing — spectra, filtering, sampling, and LTI systems — taught by generating, analyzing, and listening to real audio signals in Python. Browse more Computer Science books for the rest of your semester.

Think DSP: Digital Signal Processing in Python, by Allen B. Downey. Free under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 licence. Access for free at https://greenteapress.com/wp/think-dsp/