EE269 Lecture 2 — Mert Pilanci, Stanford

Discrete Signals
& Quantization

From continuous waves to finite lists of numbers — the tradeoffs that make all of digital signal processing possible.

Prerequisites: Basic algebra + Complex numbers (j = √−1). That's it.
8
Chapters
6+
Simulations
0
Assumed Knowledge

Chapter 0: Why Discrete?

The word digital comes from digitus, Latin for finger. When you count on your fingers, you use discrete values: 1, 2, 3, ... You can't hold up 2.7 fingers. Computers are the same — they store information as lists of numbers, nothing more.

But the world is continuous. Sound pressure varies smoothly over time. Light intensity changes gradually across an image. Temperature flows without jumps. So how does a computer represent a continuous signal?

It doesn't. Not exactly. Instead, it takes samples — snapshots at regular intervals — and quantizes each sample to the nearest allowed level. This introduces two fundamental tradeoffs that define all of digital signal processing:

The two tradeoffs of going digital:
1. Sampling — how often do we measure? (Too rarely → we lose information.)
2. Quantization — how many levels do we allow? (Too few → we lose detail.)

This entire lecture is about understanding these tradeoffs precisely. When can we sample and perfectly reconstruct? When does quantization become visible? What mathematical objects represent these discrete signals?

Signal Processing: The Big Picture

Pilanci defines three terms that frame this course:

Digital
From digitus (finger). Computers store only lists of numbers.
Signal
A function of one or more variables containing information about some phenomenon.
Processing
Algorithms for manipulating digital signals to extract information.

Together: Digital Signal Processing is the art of manipulating sequences of numbers to extract meaning from the world.

Continuous vs. Discrete

The smooth teal curve is a continuous signal. The orange dots are samples taken at regular intervals. Adjust the sampling rate to see when the dots capture the shape well — and when they don't.

Samples 20

With 60 samples, the dots trace the curve almost perfectly. Drop to 4, and you can barely tell what the original signal was. This is the sampling tradeoff in action.

Why can't a computer store a continuous signal exactly?

Chapter 1: Signal Notation

Before we can do anything with signals, we need precise notation. Pilanci distinguishes three types of signals, each mapping from a different domain to a different range:

TypeNotationDomain → RangeExample
Discretex[n]ℤ → ℂ (or ℝ)Average Dow-Jones index in year n
Continuousx(t)ℝ → ℂ (or ℝ)Temperature at time t
Digitalxdig[n]ℤ → ℤ8-bit audio sample at index n
Notation convention: Square brackets x[n] = discrete. Parentheses x(t) = continuous. The argument tells you everything: n ∈ ℤ means integer-indexed, t ∈ ℝ means continuous.

The discrete signal x[n] is a function from the integers to the complex numbers. Each integer n maps to exactly one complex (or real) value. Think of it as an infinite sequence: ..., x[−2], x[−1], x[0], x[1], x[2], ...

The digital signal xdig[n] goes one step further — the output is also restricted to integers. This is what actually lives in computer memory after quantization.

The Delta Sequence δ[n]

The simplest possible discrete signal is the delta sequence (also called the unit impulse):

δ[n] = { 1 if n = 0,   0 if n ≠ 0 }

It's zero everywhere except at n = 0, where it equals 1. Why is this useful? Because any discrete signal can be written as a sum of shifted deltas:

x[n] = ∑k=−∞ x[k] · δ[n − k]

This is called the sifting property. Each term x[k]·δ[n−k] is zero everywhere except at n=k, where it contributes the value x[k]. Sum them all up and you reconstruct the original signal. The deltas form a basis — any signal is a weighted combination of shifted impulses.

The Unit Step u[n]

u[n] = { 1 if n ≥ 0,   0 if n < 0 }

The unit step "turns on" at n = 0. Before zero: silence. After zero: constant 1. It's the switch that says "start now."

Exponential Decay

x[n] = an · u[n],   a ∈ ℂ,   |a| < 1

This signal starts at 1 (when n=0) and decays toward zero. The rate of decay depends on |a|: closer to 1 means slow decay, closer to 0 means fast. The u[n] factor ensures the signal is zero for negative n (it "starts" at the origin).

Basic Discrete Signals

Toggle between δ[n], u[n], and exponential decay. For the exponential, adjust the decay rate |a|.

Key insight: The delta sequence is the "atom" of discrete signals. Every signal x[n] is just a weighted sum of shifted deltas — this is the sifting property. Understanding this means understanding that discrete signals are inherently built from simple building blocks.
What is the value of δ[3]?

Chapter 2: Complex Exponentials & Periodicity

The most important signal in all of signal processing is the complex exponential:

x[n] = A ej(ω0n + φ)

where:

By Euler's formula, the real part gives us a cosine:

x[n] = A cos(ω0n + φ) = (A/2) ej(ω0n+φ) + (A/2) e−j(ω0n+φ)

The frequency in cycles per sample is f = ω0 / (2π). This tells you how many full oscillations occur per sample index.

When Is a Discrete Sinusoid Periodic?

In continuous time, every sinusoid cos(Ω0t) is periodic with period 2π/Ω0. But in discrete time, something surprising happens: not all sinusoids are periodic!

A discrete signal x̃[n] is periodic with period N if there exists an integer N > 0 such that:

x̃[n] = x̃[n − N]   for all n
Periodicity Theorem (Pilanci, Lecture 2): A discrete sinusoid x[n] = cos(ω0n) is periodic if and only if its frequency ω0 is π times a rational number:

ω0 = (M/N) · π,   M, N ∈ ℤ

Derivation

For cos(ω0n) to be periodic with period N, we need:

cos(ω0(n + N)) = cos(ω0n)   for all n

This requires ω0N = 2πk for some integer k (a full number of cycles in N samples). Solving:

ω0 = 2πk / N = (2k/N) · π

Setting M = 2k, we get ω0 = (M/N)π where M and N are integers. Conversely, if ω0 = (M/N)π, then the period is N/gcd(M,N) (the smallest N that works).

Why This Doesn't Happen in Continuous Time

In continuous time, for any Ω0, the period T = 2π/Ω0 is a valid real number. But in discrete time, the period N must be a positive integer. That constraint forces ω0 to be a rational multiple of π.

Example: x[n] = cos(n). Here ω0 = 1. Is 1/π rational? No! So cos(n) is not periodic as a discrete signal, even though the continuous version cos(t) is periodic with period 2π.

Example: x[n] = cos(πn/4). Here ω0 = π/4 = (1/4)π. Since 1/4 is rational, this IS periodic. The period is N = 2π/(π/4) · (1/(2π)) · N... more directly: we need (π/4)N = 2πk, so N = 8k. Smallest period: N = 8.

Periodicity Explorer

Set the frequency ω0. When ω0/π is rational, the signal repeats (shown in green). When irrational, it never repeats exactly (red).

ω0 1/4
Is x[n] = cos(3πn/7) periodic? If so, what's the period?

Chapter 3: Sampling & Aliasing

We have a continuous signal xa(t) — maybe a sound wave, maybe a voltage from a sensor. To get it into a computer, we sample it at regular intervals:

x[n] = xa(nT),   −∞ < n < ∞

where T is the sampling period (seconds between samples) and 1/T is the sampling frequency (samples per second, in Hz).

The critical question: can we recover xa(t) from x[n]? Under what conditions is no information lost?

The Nyquist-Shannon Sampling Theorem

Nyquist-Shannon Theorem: If a continuous signal xa(t) contains no frequencies higher than B hertz, it is completely determined by its samples x[n] taken at intervals T = 1/(2B) seconds apart.

Equivalently: the sampling frequency must be at least 2B (twice the highest frequency in the signal). This minimum rate is called the Nyquist rate.

"Completely determined" means you can perfectly reconstruct the original continuous signal from the samples alone. No information is lost. This is remarkable — infinitely many values of xa(t) are captured by a countable set of samples.

What Happens When You Violate Nyquist?

If you sample too slowly (T > 1/(2B), or equivalently, sampling rate < 2B), you get aliasing: different continuous signals produce the same samples. The high-frequency content "folds over" and masquerades as a lower frequency. Once aliased, the information is permanently lost — no algorithm can undo it.

Example: Cosine Signal

Consider xa(t) = cos(2πf0t). Its bandwidth is B = f0. Nyquist says: sample at rate ≥ 2f0, i.e., T ≤ 1/(2f0).

If we sample at exactly the Nyquist rate, T = 1/(2f0):

x[n] = cos(2πf0 · n/(2f0)) = cos(πn)

which alternates between +1 and −1 — just barely capturing the oscillation.

If we under-sample (say T = 1/f0):

x[n] = cos(2πf0 · n/f0) = cos(2πn) = 1   for all n

The cosine looks like a constant! All oscillation information is lost.

The Wagon-Wheel Effect

You've seen this in movies: a wheel spinning at high speed appears to rotate slowly backward, or even stand still. This is aliasing in action. Film cameras sample at ~24 frames per second. If the spokes of a wheel rotate at nearly 24 Hz (or a multiple), the discrete samples can't distinguish the true rotation from a much slower (or reversed) one.

The human eye has a similar "sampling rate" of approximately T = 1/25 seconds. Stroboscopic lighting exploits this same effect.

Aliasing Demonstration

The teal curve is the true signal cos(2πf0t). The orange dots are samples. The dashed red curve is the aliased frequency that the samples "see." When sampling rate ≥ 2f0, no alias appears.

Signal freq f0 3.0 Hz
Sample rate fs 20 Hz
✓ Nyquist satisfied (fs ≥ 2f0)
Anti-aliasing in practice: Before sampling, real systems apply a low-pass anti-aliasing filter that removes frequencies above fs/2. This guarantees the Nyquist condition is met, preventing aliasing artifacts. In images, this is why cameras have optical low-pass filters. NVIDIA's DLSS (Deep Learning Super Sampling) is a learned approach to the same problem.
A signal has bandwidth B = 4 kHz. What is the minimum sampling rate to avoid aliasing?

Chapter 4: Quantization

Sampling converts a continuous-time signal to discrete-time. But the amplitude is still continuous — each sample x[n] can be any real number. A computer can't store infinitely precise real numbers. It must quantize: map each continuous amplitude to the nearest value from a finite set of allowed levels.

xdig[n] = Q(x[n])   where Q maps ℝ → {L0, L1, ..., L2B−1}

With B bits, we have 2B levels. The more bits, the finer the resolution:

Bits (B)Levels (2B)Application
12Binary image (black/white)
38Heavily compressed audio (lo-fi)
8256Standard grayscale image, telephone audio
1665,536CD-quality audio
2416,777,216Professional audio (studio)

Uniform Quantizer

The simplest quantizer divides the amplitude range [−Xmax, Xmax] into 2B equal intervals. Each interval maps to its midpoint. The step size (distance between adjacent levels) is:

Δ = 2Xmax / 2B

The quantization error (the difference between the true value and the quantized value) is bounded by ±Δ/2. As B increases, Δ shrinks and the error becomes negligible.

Visual Examples

Quantizing images: A standard grayscale image uses 8 bits per pixel (256 shades). Drop to 4 bits (16 shades) and you see banding — smooth gradients become visible steps. Drop to 1 bit and you get pure black-and-white.

Quantizing audio: 24-bit audio is indistinguishable from analog for human ears. 8-bit audio has audible "graininess" (think retro video game sounds). 3-bit audio is barely recognizable — extreme distortion.

Quantization Visualizer

The smooth teal curve is the original signal. The orange staircase is the quantized version. Reduce bits to see increasing distortion.

Bits (B) 4 (16 levels)
Sampling vs. Quantization: Sampling discretizes the time axis (horizontal). Quantization discretizes the amplitude axis (vertical). Together they turn a fully continuous signal into a fully digital one: xdig[n] : ℤ → ℤ.
How many quantization levels does a 6-bit quantizer have?

Chapter 5: Change of Basis

A finite-length signal of length N is just a vector in ℂN (or ℝN). And vectors can be expressed in different bases. The signal doesn't change — only its representation changes.

x[n] = ∑k=0M−1 c[k] · y(k)[n]

Here y(0)[n], ..., y(M−1)[n] are the basis signals, and c[0], ..., c[M−1] are the expansion coefficients — the coordinates of x in this new basis.

The Standard (Delta) Basis

The collection of shifted deltas δ[n], δ[n−1], ..., δ[n−(N−1)] is a basis. If we set c[m] = x[m]:

x[n] = ∑m=0N−1 x[m] · δ[n − m]

This is the standard basis (or canonical basis). The coefficients are just the signal values themselves. It's also orthonormal — the deltas are mutually orthogonal and each has norm 1.

Why Change Basis?

Pilanci gives four powerful motivations:

Compression
Want c[k] to have many small/zero values (so we can throw them away).
Classification
Want c[k] to spike in different locations for different classes (e.g., different speakers have different frequency profiles).
Source Separation
Want c[k] to isolate different sources (e.g., air pollution from different factories).
Reconstruction
Want c[k] to capture the most important structure (e.g., edges in medical images → wavelets/curvelets).

Orthonormal Bases and the Expansion Formula

If our basis y(0)[n], ..., y(N−1)[n] is orthonormal — meaning all basis vectors are mutually orthogonal and have norm 1:

⟨y(k)[n], y(ℓ)[n]⟩ = 0 for k ≠ ℓ,   ‖y(k)[n]‖ = 1 for all k

— then computing the coefficients is trivial: just take inner products!

c[k] = ⟨y(k)[n], x[n]⟩

And reconstruction is:

x[n] = ∑k=0N−1 ⟨y(k)[n], x[n]⟩ · y(k)[n]

Example: Hadamard Basis in ℝ2

For length-2 signals, the standard basis is δ0 = [1, 0]T, δ1 = [0, 1]T. Another basis (the Hadamard basis):

x0 = [1, 1]T,   x1 = [−1, 1]T

These are orthogonal (inner product = −1+1 = 0) but not norm-1. Normalizing: divide each by ‖xi‖ = √2.

The Fourier Basis

The most important orthonormal basis for length-N complex signals:

wm[n] = (1/√N) · ej(2π/N)nm,   n = 0,...,N−1,   m = 0,...,N−1

This is the normalized Fourier basis. Each basis vector wm oscillates at a different frequency. The expansion coefficients c[m] = ⟨wm, x⟩ are the Discrete Fourier Transform (DFT) of x. They tell you "how much" of each frequency is present in the signal.

Change of Basis Explorer (SHOWCASE)

Create a signal in the standard basis (click to set sample values). Then view its representation in the Hadamard or Fourier basis. The signal is the same — only the coordinates change.

Signal length N 8
The power of basis choice: A signal that looks complex in one basis might be simple in another. A pure cosine needs N values in the standard basis but only 2 non-zero coefficients in the Fourier basis. This is why JPEG (which uses a cosine basis) can compress images 10:1 — natural images are "sparse" in the frequency domain.
If you have an orthonormal basis, how do you find the coefficient c[k] for basis vector y(k)?

Chapter 6: Energy & Inner Products

How "big" is a signal? We need a way to measure the total content of a signal — its energy.

Energy of a Discrete Signal

Ex = ∑n=−∞ |x[n]|2

This is the sum of squared magnitudes over all samples. If this sum converges (is finite), we call x[n] square summable — it lives in the space ℓ2.

Example: The exponential decay x[n] = 0.5n u[n] has energy E = ∑n=0 0.25n = 1/(1−0.25) = 4/3. Finite!

Example: The unit step u[n] has energy E = ∑n=0 1 = ∞. Not square summable.

Power of a Signal

For signals with infinite energy (like u[n] or periodic signals), we define power as energy per unit time:

Px = limN→∞ (1/(2N+1)) ∑n=−NN |x[n]|2
Key relationship: Finite-energy signals always have zero power (the energy is finite but spread over infinite time, so power → 0). Signals with finite non-zero power have infinite energy (they keep going forever). These are two disjoint classes.

Inner Product in ℂN

For finite-length signals (vectors in ℂN), the inner product is:

⟨x, y⟩ = ∑k=0N−1 x*[k] · y[k]

where x*[k] is the complex conjugate of x[k]. Two vectors are orthogonal (x ⊥ y) when ⟨x, y⟩ = 0.

The Norm

‖x‖ = √(⟨x, x⟩) = (∑k=0N−1 |x[k]|2)1/2

This is the 2-norm (or 2-norm). In ℝ2, it's just the length of the vector — the distance from the origin.

Geometric Interpretation

For real vectors in ℝ2, the inner product relates to the angle θ between vectors:

⟨x, y⟩ = ‖x‖ · ‖y‖ · cosθ

When θ = π/2 (perpendicular), cosθ = 0, so the inner product is zero. This is the geometric meaning of orthogonality.

Cauchy-Schwarz Inequality

|⟨x, y⟩| ≤ ‖x‖ · ‖y‖

The inner product can never exceed the product of norms. Equality holds only when x and y are parallel (one is a scalar multiple of the other). This bounds how "aligned" two signals can be.

Parseval's Theorem (Preview)

A deep result we'll prove in a later lecture: for an orthonormal basis, the energy in the original domain equals the energy in the transformed domain:

n |x[n]|2 = ∑k |c[k]|2

Changing basis doesn't create or destroy energy — it just redistributes it among coefficients. This is Parseval's theorem, and it's why the Fourier transform "preserves" signal energy.

Inner Product & Orthogonality

Drag the two vectors and observe their inner product. When perpendicular, the inner product is zero. The Cauchy-Schwarz bound is shown as a ceiling.

Angle θ 60°
A signal x[n] has finite energy. What is its power?

Chapter 7: Mastery

You've covered the foundations of discrete signals. Let's consolidate everything into reference cards you can return to.

Notation Reference Card

SymbolMeaning
x[n]Discrete signal, domain ℤ, range ℂ or ℝ
x(t)Continuous signal, domain ℝ, range ℂ or ℝ
xdig[n]Digital signal, domain ℤ, range ℤ
δ[n]Delta (impulse): 1 at n=0, 0 elsewhere
u[n]Unit step: 1 for n≥0, 0 for n<0
e0nComplex exponential at frequency ω0 rad/sample
⟨x, y⟩Inner product = ∑ x*[k]y[k]
‖x‖Norm = √⟨x,x⟩
TSampling period (seconds)
1/T = fsSampling frequency (Hz)
BBits per sample (quantization)

Periodicity Quick-Calculator

Periodicity Calculator

Enter ω0 as a fraction of π. The tool tells you if the signal is periodic and what the fundamental period is.

ω0 = / · π

Nyquist Rule Cheat Sheet

The Nyquist Rule:
• Signal bandwidth = B Hz
• Minimum sampling rate = 2B Hz (the Nyquist rate)
• Maximum sampling period = 1/(2B) seconds
• If fs < 2B ⇒ aliasing (high frequencies fold into low frequencies, irreversible)
• In practice: sample at 2.5× to 4× bandwidth for safety margin

Key Theorems Summary

TheoremStatement
Periodicitycos(ω0n) periodic iff ω0 = (M/N)π, M,N ∈ ℤ
Nyquist-ShannonBandwidth B ⇒ sample at ≥ 2B for perfect reconstruction
Sifting Propertyx[n] = ∑ x[k]δ[n−k] (any signal = sum of shifted impulses)
Cauchy-Schwarz|⟨x,y⟩| ≤ ‖x‖·‖y‖
Parseval∑|x[n]|² = ∑|c[k]|² in any orthonormal basis

What Comes Next

Lecture 3 will dive deeper into quantization noise — modeling the error introduced by quantization as a random process, and analyzing its statistics (mean, variance, power spectrum). We'll also explore the Discrete Fourier Transform in detail and see how the Fourier basis enables spectral analysis.

Connections:
• Lecture 3: Quantization noise analysis, DFT
• Lecture 4: Convolution and filtering
• The Fourier basis from Chapter 5 is the foundation of the entire FFT algorithm
• Sampling theory connects directly to information theory (Shannon's other great theorem)
A discrete signal x[n] = cos(πn/3) has frequency ω0 = π/3. Is it periodic, and if so, what is its fundamental period?