Outline
8.1 From the DTFT to the DFT
8.2 The DFT and Its Inverse
8.3 Matrix Form of the DFT
8.4 DFT Properties
8.5 Convolution with the DFT
8.6 Zero Padding, Resolution, Windows
8.7 Chapter Summary
Exercises
DSP Study Guide · Chapter 8

Discrete Fourier Transform

The DFT and IDFT, matrix formulation, properties, circular vs. linear convolution, zero padding, frequency resolution, and windowing for spectral estimation

8.1 From the DTFT to the DFT

8.1.1 The Fourier transform family

Every Fourier representation pairs one domain with another, and discreteness in one domain forces periodicity in the other. The DTFT of Chapter 7 maps a discrete-time sequence to a continuous, periodic function $X(e^{j\omega})$ — useful analytically, but a computer cannot store a continuum of frequencies. The Discrete Fourier Transform(離散傅立葉變換)closes the loop: both domains are discrete and finite, so it is the only member of the family a computer can evaluate exactly.

TransformTime domainFrequency domain
Fourier Series (FS)continuous, periodicdiscrete, aperiodic
Fourier Transform (FT)continuous, aperiodiccontinuous, aperiodic
DTFTdiscrete, aperiodiccontinuous, periodic ($2\pi$)
DFTdiscrete, finite ($N$ points)discrete, finite ($N$ points)
Concept — why we need the DFT
The DTFT $X(e^{j\omega})=\sum_n x[n]e^{-j\omega n}$ requires (i) an infinite sum and (ii) a continuous variable $\omega$. The DFT fixes both problems at once: it takes only $N$ samples of the signal and evaluates the spectrum at only $N$ frequencies $\omega_k = 2\pi k/N$. Everything in this chapter follows from understanding exactly what is gained and what is lost in that step.

8.1.2 Discrete Fourier Series for periodic sequences

Let $\tilde{x}[n]$ be periodic(週期性序列)with period $N$: $\tilde{x}[n] = \tilde{x}[n+N]$ for all $n$. Such a sequence is fully described by one period, and it can be expanded on the $N$ harmonically related complex exponentials $e^{j2\pi kn/N}$, $k = 0,\dots,N-1$. This is the Discrete Fourier Series(離散傅立葉級數, DFS):

DFS analysis / synthesis $$\tilde{X}[k] = \sum_{n=0}^{N-1} \tilde{x}[n]\, e^{-j2\pi kn/N}, \qquad \tilde{x}[n] = \frac{1}{N}\sum_{k=0}^{N-1} \tilde{X}[k]\, e^{j2\pi kn/N}$$

Both $\tilde{x}[n]$ and $\tilde{X}[k]$ are periodic with period $N$. The DFT defined next is numerically identical to one period of the DFS — the only difference is interpretation: the DFT treats $x[n]$ as a finite-length sequence on $0 \le n \le N-1$, while the DFS treats it as one period of an infinitely repeating signal.

Key — the implicit periodicity
The DFT inherits the periodic worldview of the DFS. Whenever a DFT property involves a time shift, a reversal, or a convolution, the operation is performed modulo $N$ — as if the $N$ samples lived on a circle, not a line. This single fact explains circular shift, circular convolution, and time aliasing.
直觀解釋(點擊展開)
DFT 雖然只看 $N$ 個樣本,但它「心裡認定」這 $N$ 個樣本會無限重複下去。想像把這 $N$ 個點貼在一個圓上:向右平移超出邊界的樣本會從左邊「繞回來」,這就是循環位移(circular shift);兩個序列做摺積時也是繞著圓做,這就是循環摺積(circular convolution)。考試中最常見的陷阱都來自忘記這個「繞圈」的本質。

8.1.3 Sampling the DTFT

Take a finite-length sequence $x[n]$, $0 \le n \le L-1$, with DTFT $X(e^{j\omega})$. Evaluate (sample) the DTFT at $N$ equally spaced frequencies $\omega_k = 2\pi k/N$:

DFT = uniform samples of the DTFT $$X[k] = X(e^{j\omega})\Big|_{\omega = \frac{2\pi k}{N}} = \sum_{n=0}^{N-1} x[n]\, e^{-j\frac{2\pi}{N}kn}, \qquad k = 0, 1, \dots, N-1 \quad (\text{valid when } L \le N)$$

Sampling in frequency causes periodization in time — the exact dual of Chapter 4, where sampling in time periodized the spectrum. Inverting the $N$ frequency samples returns not $x[n]$ itself but its periodic superposition:

Time-domain aliasing from frequency sampling $$\tilde{x}[n] = \sum_{r=-\infty}^{\infty} x[n - rN]$$
Warning — frequency sampling is not free
You may sample a DTFT as coarsely as you like and still get a valid set of numbers — but you can only get the original sequence back if you took at least as many frequency samples as the sequence length ($N \ge L$). Sampling the DTFT of an infinite-length sequence (e.g. $a^n u[n]$) always produces time aliasing; see Exercise 4.

8.2 The DFT and Its Inverse

8.2.1 Definition and the twiddle factor $W_N$

Define the twiddle factor(旋轉因子)$W_N$, the principal $N$-th root of unity:

Twiddle factor $$W_N \triangleq e^{-j\frac{2\pi}{N}}, \qquad W_N^{kn} = e^{-j\frac{2\pi}{N}kn}$$

Useful identities, used constantly in derivations and in the FFT of the next chapter:

N-point DFT $$\boxed{\,X[k] = \sum_{n=0}^{N-1} x[n]\, W_N^{kn} = \sum_{n=0}^{N-1} x[n]\, e^{-j\frac{2\pi}{N}kn}, \qquad k = 0,1,\dots,N-1\,}$$

Notation: we write $x[n] \;\overset{\text{DFT}}{\longleftrightarrow}\; X[k]$, and $((n))_N$ means $n$ modulo $N$($n$ 對 $N$ 取餘數).

8.2.2 The inverse DFT

N-point IDFT $$\boxed{\,x[n] = \frac{1}{N}\sum_{k=0}^{N-1} X[k]\, W_N^{-kn} = \frac{1}{N}\sum_{k=0}^{N-1} X[k]\, e^{\,j\frac{2\pi}{N}kn}, \qquad n = 0,1,\dots,N-1\,}$$

Proof that IDFT inverts the DFT. Substitute the DFT into the IDFT and swap sums:

$$\frac{1}{N}\sum_{k=0}^{N-1}\left(\sum_{m=0}^{N-1} x[m] W_N^{km}\right) W_N^{-kn} = \sum_{m=0}^{N-1} x[m] \underbrace{\frac{1}{N}\sum_{k=0}^{N-1} W_N^{k(m-n)}}_{=\;\delta[((m-n))_N]} = x[n].$$

The inner sum is the orthogonality identity above — it acts as a Kronecker delta and sifts out exactly the term $m=n$.

Tip — remember the three differences
DFT vs. IDFT differ in exactly three places: (1) the sign of the exponent ($-j$ vs. $+j$), (2) the factor $1/N$ in front of the inverse, (3) which variable is summed over ($n$ vs. $k$). Some texts split the $1/N$ as $1/\sqrt{N}$ on both sides to make the transform unitary; MATLAB and these lecture notes put all of $1/N$ in the inverse.

8.2.3 Basic DFT examples

Example 8-1 — DFT of the unit impulse and of a constant
(a) $x[n] = \delta[n]$: only the $n=0$ term survives, so $X[k] = W_N^{0} = 1$ for all $k$. An impulse is "white" — flat across all $N$ frequency bins.
(b) $x[n] = 1$ for $0\le n \le N-1$: $X[k] = \sum_{n=0}^{N-1} W_N^{kn} = N\,\delta[((k))_N]$, i.e. $X[0]=N$ and $X[k]=0$ otherwise. A constant has all its energy in the DC bin(直流項). Note the duality with (a).
Example 8-2 — DFT of an on-grid complex exponential and cosine
Complex exponential. Let $x[n] = e^{j\frac{2\pi}{N}k_0 n}$ with integer $k_0$. Then $$X[k] = \sum_{n=0}^{N-1} e^{j\frac{2\pi}{N}k_0 n} e^{-j\frac{2\pi}{N}kn} = \sum_{n=0}^{N-1} W_N^{(k-k_0)n} = N\,\delta[((k-k_0))_N].$$ A single spectral line of height $N$ in bin $k_0$.
Cosine. $x[n] = \cos\!\big(\tfrac{2\pi}{N}k_0 n\big) = \tfrac12 e^{j2\pi k_0 n/N} + \tfrac12 e^{-j2\pi k_0 n/N}$, so $$X[k] = \frac{N}{2}\,\delta[((k-k_0))_N] + \frac{N}{2}\,\delta[((k+k_0))_N]$$ — two lines of height $N/2$, at bins $k_0$ and $N-k_0$. This is exactly what Exercise 6 (MATLAB) verifies with $N=100$, $k_0=5$.
Off-grid case. If the frequency does not equal $2\pi k_0/N$ for an integer $k_0$, the line "spills" into all bins — spectral leakage(頻譜洩漏), treated in §8.6.

8.2.4 The periodic sinc (Dirichlet kernel)

The most important transform pair of the chapter: the length-$L$ rectangular pulse $x[n] = 1$, $0\le n\le L-1$. Its DTFT is a geometric series:

Periodic sinc / Dirichlet kernel(週期 sinc) $$X(e^{j\omega}) = \sum_{n=0}^{L-1} e^{-j\omega n} = \frac{1 - e^{-j\omega L}}{1 - e^{-j\omega}} = e^{-j\omega\frac{L-1}{2}}\, \frac{\sin(\omega L/2)}{\sin(\omega/2)}$$

The magnitude $\left|\sin(\omega L/2)/\sin(\omega/2)\right|$ is the periodic sinc: main-lobe peak $L$ at $\omega = 0$, zeros at $\omega = 2\pi m/L$ ($m$ not a multiple of $L$), main-lobe width $4\pi/L$, and — unlike the continuous sinc — it is $2\pi$-periodic and returns to height $L$ at every multiple of $2\pi$.

Now sample it. With $N = L = 8$, every DFT sample except $k=0$ lands exactly on a zero crossing of the periodic sinc — the DFT sees only $X[0]=8$ and looks deceptively like an impulse. With $N = 32$ (zero padding the same 8 samples), the DFT samples trace out the full lobe structure:

2026-06-12T22:18:53.691326 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 2 4 6 8 magnitude N = 8-point DFT samples of the DTFT (L = 8 rectangular pulse) | D T F T |     | ( ) | X e j ω 0.00 0.25 0.50 0.75 1.00 1.25 1.50 1.75 2.00 ω / π (k ↔ ω = 2πk/N) 0 2 4 6 8 magnitude N = 32-point DFT samples of the DTFT (L = 8 rectangular pulse) | D T F T |     | ( ) | X e j ω
Fig. 8-1 — The DTFT magnitude of a length-8 rectangular pulse (grey curve) and its $N$-point DFT samples (red stems). Top: $N=8$ samples all fall on zeros except DC. Bottom: $N=32$ reveals the periodic-sinc lobes(同一個 DTFT,取樣密度不同:$N=8$ 時剛好都取在零點上,$N=32$ 才看得到旁瓣結構).
Warning — the DFT only shows you $N$ samples
Fig. 8-1 (top) is a classic exam trap: an $N$-point DFT can look "clean" purely because the interesting features of the underlying DTFT fall between the samples. The DTFT did not change between the two panels — only the sampling grid did. Zero padding (§8.6.1) is how you refine the grid.

8.3 Matrix Form of the DFT

8.3.1 The DFT matrix

Because the DFT is a linear map from $N$ samples to $N$ coefficients, it is a matrix–vector product. Stack the signal into $\mathbf{x} = \begin{bmatrix} x[0] & x[1] & \cdots & x[N-1]\end{bmatrix}^{T}$ and define the $N \times N$ DFT matrix $\mathbf{W}_N$ with entries $[\mathbf{W}_N]_{k,n} = W_N^{kn}$:

DFT as a matrix product $$\mathbf{X} = \mathbf{W}_N\,\mathbf{x}, \qquad \mathbf{W}_N = \begin{bmatrix} 1 & 1 & 1 & \cdots & 1\\ 1 & W_N & W_N^{2} & \cdots & W_N^{N-1}\\ 1 & W_N^{2} & W_N^{4} & \cdots & W_N^{2(N-1)}\\ \vdots & \vdots & \vdots & \ddots & \vdots\\ 1 & W_N^{N-1} & W_N^{2(N-1)} & \cdots & W_N^{(N-1)^2} \end{bmatrix}$$

$\mathbf{W}_N$ is a symmetric Vandermonde matrix(symmetric:$\mathbf{W}_N^{T} = \mathbf{W}_N$,因為 $W_N^{kn}=W_N^{nk}$). For example,

$$\mathbf{W}_4 = \begin{bmatrix} 1 & 1 & 1 & 1\\ 1 & -j & -1 & j\\ 1 & -1 & 1 & -1\\ 1 & j & -1 & -j \end{bmatrix} \qquad (W_4 = e^{-j\pi/2} = -j).$$

8.3.2 The IDFT matrix

From the orthogonality identity, the rows of $\mathbf{W}_N$ are orthogonal with norm-squared $N$, so the inverse needs no Gaussian elimination:

IDFT matrix $$\mathbf{x} = \mathbf{W}_N^{-1}\mathbf{X}, \qquad \boxed{\,\mathbf{W}_N^{-1} = \frac{1}{N}\,\mathbf{W}_N^{*} = \frac{1}{N}\,\mathbf{W}_N^{H}\,}$$

Equivalently $\frac{1}{\sqrt{N}}\mathbf{W}_N$ is a unitary matrix(么正矩陣). Two consequences:

Concept — cost of the matrix DFT
A direct matrix–vector DFT costs $N^2$ complex multiplications and $N(N-1)$ complex additions — $\mathcal{O}(N^2)$. For $N = 10^6$ that is $10^{12}$ multiplies. The FFT (next chapter) exploits the periodicity and symmetry of $W_N^{kn}$ to reduce this to $\mathcal{O}(N\log_2 N)$, which is why the DFT — not the DTFT — is the workhorse of practical DSP.

8.3.3 DFT in MATLAB

MATLAB computes the DFT with fft and the IDFT with ifft (both use FFT algorithms regardless of whether $N$ is a power of two). Key conventions to remember:

Tip — sanity checks for any fft result
(1) X(1) must equal sum(x). (2) For real $x$, X(N-k+1) = conj(X(k+1)) — magnitude plots must be symmetric about $N/2$. (3) sum(abs(x).^2) must equal sum(abs(X).^2)/N (Parseval). If any of these fail, the bug is in your indexing.

8.4 DFT Properties

8.4.1 Linearity and circular shifts

Linearity(線性). If both sequences are defined on the same $N$-point grid, $a\,x_1[n] + b\,x_2[n] \;\longleftrightarrow\; a\,X_1[k] + b\,X_2[k]$. If lengths differ, zero-pad both to a common $N$ first.

Circular time shift(循環時間位移). Because the DFT views $x[n]$ as one period of a periodic sequence, "shifting" means rotating the samples around a circle of circumference $N$:

Circular time shift $$x[((n-m))_N] \;\longleftrightarrow\; W_N^{km}\,X[k] = e^{-j\frac{2\pi}{N}km}\,X[k]$$

Magnitude is untouched; only a linear phase ramp is added — exactly like the DTFT shift theorem, but with the shift interpreted modulo $N$. Samples pushed past $n = N-1$ wrap around to $n = 0$:

2026-06-12T22:18:53.903900 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 1 2 3 4 5 6 7 n 0 2 4 6 8 x[n] 0 1 2 3 4 5 6 7 n 0 2 4 6 8 x [ ( ( n 2 ) ) ]     ( c i r c u l a r   s h i f t   b y   2 ) 8
Fig. 8-2 — Circular shift by $m=2$ of an 8-point sequence. The two samples pushed off the right edge re-enter from the left(被推出右邊界的樣本從左邊繞回來;想像 8 個點貼在圓周上整體旋轉 2 格).

Circular frequency shift / modulation(調變). The dual statement:

Circular frequency shift $$W_N^{-ln}\,x[n] = e^{\,j\frac{2\pi}{N}ln}\,x[n] \;\longleftrightarrow\; X[((k-l))_N]$$

8.4.2 Reversal and conjugate symmetry

Circular time reversal(循環時間反轉). Reversal modulo $N$ keeps $x[0]$ in place and reverses the rest: $x[((-n))_N] = x[((N-n))_N]$, i.e. $\{x[0], x[N-1], x[N-2], \dots, x[1]\}$.

Circular reversal and conjugation $$x[((-n))_N] \;\longleftrightarrow\; X[((-k))_N], \qquad x^{*}[n] \;\longleftrightarrow\; X^{*}[((-k))_N]$$

Conjugate symmetry for real signals(實數訊號的共軛對稱). Combining the two: if $x[n]$ is real, then

Conjugate symmetry (real x[n]) $$X[k] = X^{*}[((-k))_N] = X^{*}[N-k] \;\;\Longrightarrow\;\; |X[k]| = |X[N-k]|, \quad \angle X[k] = -\angle X[N-k]$$

So a real $N$-point signal has only about $N/2$ independent spectral values: bins $k$ and $N-k$ are mirror images. $X[0]$ is always real, and for even $N$ so is $X[N/2]$.

8.4.3 Duality and Parseval

Duality(對偶性). The DFT and IDFT have nearly the same form, so transforming twice almost returns the signal:

Duality $$\text{If } x[n] \longleftrightarrow X[k], \text{ then } X[n] \longleftrightarrow N\,x[((-k))_N]$$

Example: $\delta[n] \leftrightarrow 1$ (all $k$), and dually the all-ones sequence $\leftrightarrow N\delta[k]$ — exactly Examples 8-1(a) and (b).

Parseval's relation(能量守恆). Direct consequence of $\frac{1}{\sqrt N}\mathbf{W}_N$ being unitary:

Parseval $$\sum_{n=0}^{N-1} |x[n]|^2 = \frac{1}{N}\sum_{k=0}^{N-1} |X[k]|^2, \qquad \sum_{n=0}^{N-1} x[n]\,y^{*}[n] = \frac{1}{N}\sum_{k=0}^{N-1} X[k]\,Y^{*}[k]$$

8.4.4 Property summary table

PropertyTime domainFrequency domain
Linearity$a x_1[n] + b x_2[n]$$a X_1[k] + b X_2[k]$
Circular time shift$x[((n-m))_N]$$W_N^{km} X[k]$
Circular frequency shift$W_N^{-ln} x[n]$$X[((k-l))_N]$
Circular time reversal$x[((-n))_N]$$X[((-k))_N]$
Conjugation$x^{*}[n]$$X^{*}[((-k))_N]$
Duality$X[n]$$N\,x[((-k))_N]$
Circular convolution$x_1[n] \circledast x_2[n]$$X_1[k]\, X_2[k]$
Multiplication$x_1[n]\, x_2[n]$$\tfrac{1}{N}\, X_1[k] \circledast X_2[k]$
Conjugate symmetry (real $x$)$x[n]$ real$X[k] = X^{*}[N-k]$
Parseval$\sum_n |x[n]|^2$$= \tfrac{1}{N}\sum_k |X[k]|^2$

8.5 Convolution with the DFT

8.5.1 Circular convolution

What time-domain operation corresponds to multiplying two DFTs? Not linear convolution — because of the implicit periodicity, it is circular convolution(循環摺積), written $\circledast$ or $\overset{N}{\circledast}$:

N-point circular convolution $$y[n] = x_1[n] \circledast x_2[n] \triangleq \sum_{m=0}^{N-1} x_1[m]\; x_2[((n-m))_N], \qquad \boxed{\;x_1[n] \circledast x_2[n] \;\longleftrightarrow\; X_1[k]\,X_2[k]\;}$$

Mechanically it is the same flip-shift-multiply-sum recipe as linear convolution, except the flip and shift are circular: $x_2$ is reversed around the circle and rotated by $n$ positions. Both sequences must be defined on (or zero-padded to) the same length $N$, and the output also has length $N$.

Example 8-3 — 4-point circular convolution

Let $x_1[n] = \{1, 1, 1, 1\}$ and $x_2[n] = \{1, 2, 3, 4\}$, $N = 4$.

Step 1. Since $x_1[m] = 1$ for all $m$, every output sample is just the sum of one full rotation of $x_2$: $y[n] = \sum_{m=0}^{3} x_2[((n-m))_4] = 1+2+3+4 = 10$ for every $n$.
Step 2. So $y[n] = \{10, 10, 10, 10\}$. Frequency check: $X_1[k] = \{4,0,0,0\}$, $X_2[k] = \{10, -2+2j, -2, -2-2j\}$, product $= \{40, 0,0,0\}$, whose IDFT is the constant $10$. ✓
Step 3. Compare: the linear convolution is $\{1,3,6,10,9,7,4\}$ (length 7). Circular convolution gave something completely different — see why below.

8.5.2 Circular vs. linear convolution: time aliasing

Let $x_1$ have length $L$ and $x_2$ length $P$. Their linear convolution $y_{\text{lin}}[n] = x_1[n] * x_2[n]$ has length $L + P - 1$. The $N$-point circular convolution is the linear result wrapped around a circle of length $N$:

Circular = aliased linear convolution $$y_c[n] = \sum_{r=-\infty}^{\infty} y_{\text{lin}}[n + rN], \qquad 0 \le n \le N-1$$

If $N \ge L+P-1$ nothing wraps and $y_c = y_{\text{lin}}$. If $N$ is too small, the tail of $y_{\text{lin}}$ folds back onto its head — time aliasing again, this time caused by multiplying spectra sampled too coarsely.

2026-06-12T22:18:54.148296 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 1 2 3 4 5 6 n 0 2 4 6 8 10 12 Linear conv x₁[n]∗x₂[n] (length 7) 0 1 2 3 4 5 6 n 0 2 4 6 8 10 12 4-point circular conv (aliased!) 0 1 2 3 4 5 6 n 0 2 4 6 8 10 12 7-point circular conv (= linear)
Fig. 8-3 — $x_1 = \{1,1,1,1\}$, $x_2 = \{1,2,3,4\}$. Left: linear convolution, length $4+4-1=7$. Middle: 4-point circular convolution — the tail $\{9,7,4\}$ has folded onto the head $\{1,3,6\}$ giving $\{10,10,10\}$ and the untouched $10$. Right: 7-point circular convolution equals the linear result exactly(中:長度不夠,尾巴繞回來疊在前面=時域混疊;右:補零到 $N\ge L+P-1$ 後循環摺積=線性摺積).
Key — the zero-padding rule for convolution
To compute a linear convolution of a length-$L$ and a length-$P$ sequence with DFTs, zero-pad both to $$N \ge L + P - 1$$ then $\mathrm{IDFT}\{\,\mathrm{DFT}\{x_1\}\cdot\mathrm{DFT}\{x_2\}\,\} = x_1 * x_2$ exactly. In practice choose the next power of two $\ge L+P-1$ for FFT efficiency.

8.5.3 Linear convolution via the DFT

The fast-convolution recipe(快速摺積流程):

  1. Zero-pad $x_1[n]$ (length $L$) and $x_2[n]$ (length $P$) to $N \ge L+P-1$.
  2. Compute $X_1[k] = \mathrm{FFT}\{x_1\}$ and $X_2[k] = \mathrm{FFT}\{x_2\}$.
  3. Multiply bin-by-bin: $Y[k] = X_1[k]\,X_2[k]$.
  4. $y[n] = \mathrm{IFFT}\{Y[k]\}$; take the real part if the inputs were real (imaginary residue is round-off).

Cost: three FFTs plus $N$ multiplies $\approx \tfrac{3}{2}N\log_2 N + N$ complex multiplications, versus $LP$ for direct convolution — a huge win when both sequences are long. In MATLAB: y = ifft( fft(x1,N) .* fft(x2,N) ).

8.5.4 Overlap-add convolution

Filtering a very long (possibly streaming) signal $x[n]$ with a length-$P$ FIR impulse response $h[n]$ cannot wait for the whole signal. Overlap-add(重疊相加法)processes it block by block:

  1. Cut $x[n]$ into non-overlapping blocks $x_r[n]$ of length $L$.
  2. Convolve each block with $h[n]$ using an $N$-point FFT, $N \ge L+P-1$ → each output block $y_r[n]$ has length $L+P-1$.
  3. Each output block is $P-1$ samples longer than its input block, so consecutive output blocks overlap by $P-1$ samples. Add the overlapping tails: $y[n] = \sum_r y_r[n - rL]$.

Linearity of convolution guarantees the sum is exactly $x[n]*h[n]$: since $x[n] = \sum_r x_r[n-rL]$, convolving term by term gives $y[n] = \sum_r (x_r * h)[n-rL]$.

x[n], cut into length-L blocks: x₀[n] x₁[n] x₂[n] ··· each block: N-point FFT · H[k] · IFFT (N ≥ L + P − 1) y_r[n] = x_r[n] ∗ h[n], length L+P−1: y₀[n] y₁[n] y₂[n] P−1 overlap add overlapping tails → y[n] = x[n] ∗ h[n]
Fig. 8-4 — Overlap-add: input blocks of length $L$ do not overlap, but each filtered block grows to $L+P-1$, so output blocks overlap by $P-1$ samples (yellow) and are summed(輸入不重疊、輸出重疊 $P-1$ 點相加).
Tip — overlap-add vs. overlap-save
A sibling method, overlap-save, instead overlaps the input blocks by $P-1$ samples, computes $N$-point circular convolutions, and discards the first $P-1$ (aliased) output samples of each block. Both cost the same asymptotically; overlap-add is easier to reason about because no output sample is ever wrong, only ever incomplete until its tail arrives.

8.6 Zero Padding, Resolution, and Windows

8.6.1 Zero padding and the frequency grid

Appending zeros to a length-$L$ signal before taking an $N$-point DFT ($N > L$) does not change its DTFT at all — the extra terms contribute nothing to the sum. It only changes where the DTFT is sampled: the grid spacing shrinks from $2\pi/L$ to $2\pi/N$. Zero padding(補零)therefore:

Resolution vs. grid spacing $$\underbrace{\Delta f_{\text{grid}} = \frac{F_s}{N}}_{\text{DFT bin spacing — set by total DFT length } N} \qquad \underbrace{\Delta f_{\text{res}} \approx \frac{F_s}{L}}_{\text{resolution — set by the number of actual data samples } L}$$

Resolution is governed by the window's main-lobe width: a length-$L$ rectangular window has main-lobe width $4\pi/L$ (rad/sample), so two real tones closer than about $F_s/L$ Hz produce overlapping main lobes that merge into one bump. More data — not more zeros — is the only cure:

2026-06-12T22:18:54.431950 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 5 10 15 |X| N = 32 samples, 32-point DFT — the two tones merge 0 5 10 15 |X| Same 32 samples zero-padded to 256 — finer grid, SAME resolution 0 5 10 15 20 25 30 frequency (Hz) (f₁ = 10 Hz, f₂ = 12 Hz, fs = 64 Hz) 0 20 40 60 |X| N = 128 samples (longer record), 256-point DFT — tones resolved
Fig. 8-5 — Two tones at 10 Hz and 12 Hz, $F_s = 64$ Hz. Top: 32 data samples, 32-point DFT — unresolved. Middle: the same 32 samples zero-padded to 256 — the curve is smoother but still one merged bump(補零只是把同一條 DTFT 取樣得更密). Bottom: 128 data samples — now $F_s/L = 0.5$ Hz $\ll 2$ Hz and the tones separate(增加實際資料長度才能提升解析度).
Warning — classic exam question
"Does zero padding improve frequency resolution?" No. It improves the apparent resolution (denser frequency grid, $F_s/N$) but the true resolution is fixed by the data record length ($\approx F_s/L$ for a rectangular window, worse for tapered windows). Be ready to state both formulas and the distinction.

8.6.2 Truncation and window functions

What if the signal is not time-limited? Keeping only $N$ samples is equivalent to multiplying by a window(窗函數): $x_w[n] = x[n]\,w[n]$. By the multiplication property, the spectrum becomes a convolution:

Windowing smears the spectrum $$x_w[n] = x[n]\,w[n] \;\;\Longrightarrow\;\; X_w(e^{j\omega}) = \frac{1}{2\pi}\, X(e^{j\omega}) \,*\, W(e^{j\omega})$$

Each spectral line of $x[n]$ is replaced by a copy of the window's frequency response $W(e^{j\omega})$ — main lobe (width = blur) plus sidelobes (leakage). The windows highlighted in the lecture:

Window ($0 \le n \le N-1$)$w[n]$Main-lobe widthPeak sidelobe
Rectangular(矩形窗)$1$$4\pi/N$$-13$ dB
Triangular / Bartlett(三角窗)$1 - \dfrac{\left|\,n - \frac{N-1}{2}\right|}{\frac{N-1}{2}}$$8\pi/N$$-27$ dB
Generalized Hanning(廣義漢寧窗)$\alpha - (1-\alpha)\cos\dfrac{2\pi n}{N-1}$$8\pi/N$
  · Hann ($\alpha = 0.5$)$0.5 - 0.5\cos\dfrac{2\pi n}{N-1}$$8\pi/N$$-31$ dB
  · Hamming ($\alpha = 0.54$)$0.54 - 0.46\cos\dfrac{2\pi n}{N-1}$$8\pi/N$$-41$ dB
Concept — the fundamental window trade-off
For fixed $N$, narrowing the main lobe (better resolution) and lowering the sidelobes (less leakage) pull in opposite directions. The rectangular window has the narrowest possible main lobe but the worst sidelobes; tapered windows (Hann, Hamming) double the main-lobe width in exchange for 20–30 dB less leakage. The only way to win on both axes is to increase $N$.

8.6.3 Spectral leakage and resolution in practice

The spectrum of a windowed sinewave is the window response shifted to the tone frequency. For closely spaced sinewaves there is leakage(洩漏)between their spectra: the sidelobes of a strong tone can completely bury a nearby weak tone. The lecture's example — three sinewaves analyzed with rectangular vs. Hamming windows — reproduced numerically:

2026-06-12T22:18:54.665345 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ −80 −60 −40 −20 0 dB Rectangular window (N = 64): sidelobe leakage buries the weak tone 0.0 0.1 0.2 0.3 0.4 0.5 normalized frequency f (cycles/sample) −80 −60 −40 −20 0 dB Hamming window (N = 64): lower sidelobes reveal the tone at f = 0.27
Fig. 8-6 — Three tones ($f = 0.20$, $0.25$ with amplitude 1, and a weak $f = 0.27$ at amplitude 0.05; $N = 64$, zero-padded DFT shown in dB). Top: rectangular window — the $-13$ dB sidelobes of the strong tones bury the weak one. Bottom: Hamming window — wider main lobes, but $-41$ dB sidelobes let the weak tone at $0.27$ emerge(強音的旁瓣會淹沒弱音;換 Hamming 窗犧牲一點主瓣寬度換取低旁瓣).

Computational cost? Applying a window costs only $N$ extra multiplications before the FFT — negligible compared to the $\frac{N}{2}\log_2 N$ butterflies of the transform itself. Window choice is essentially free performance.

8.7 Chapter Summary

Definitions

$X[k] = \sum_{n=0}^{N-1} x[n] W_N^{kn}$, $\;x[n] = \frac{1}{N}\sum_{k=0}^{N-1} X[k] W_N^{-kn}$, with $W_N = e^{-j2\pi/N}$. The DFT equals the DTFT sampled at $\omega_k = 2\pi k/N$ (exact iff signal length $\le N$), and equals one period of the DFS.

Matrix view

$\mathbf{X} = \mathbf{W}_N \mathbf{x}$ with $[\mathbf{W}_N]_{kn} = W_N^{kn}$; symmetric, and $\mathbf{W}_N^{-1} = \mathbf{W}_N^{*}/N$, so $\mathbf{W}_N/\sqrt{N}$ is unitary. Direct cost $\mathcal{O}(N^2)$; the FFT brings it to $\mathcal{O}(N\log_2 N)$.

Properties (all modulo N)

Shift → phase ramp $W_N^{km}X[k]$; reversal/conjugation flip $k$; real signals give $X[k]=X^*[N-k]$; duality $X[n] \leftrightarrow N x[((-k))_N]$; Parseval $\sum|x|^2 = \frac{1}{N}\sum|X|^2$.

Convolution

$X_1[k]X_2[k] \leftrightarrow$ circular convolution = linear convolution aliased mod $N$. For linear convolution zero-pad to $N \ge L+P-1$. Long signals: overlap-add with length-$L$ blocks, $N$-point FFTs, add the $P-1$ overlapping tail samples.

Zero padding

Refines the frequency grid to $F_s/N$ (interpolates the same DTFT) but resolution stays $\approx F_s/L$, set by the actual data length $L$. More data, not more zeros, separates close tones.

Windows & leakage

Truncation multiplies by $w[n]$ → spectrum convolved with $W(e^{j\omega})$. Rectangular: narrowest main lobe ($4\pi/N$), $-13$ dB sidelobes. Hann/Hamming: $8\pi/N$ main lobe, $-31$/$-41$ dB sidelobes. Trade resolution for leakage suppression.

Exercises

Exercise 1 — 4-point DFT by hand

Problem: Compute the 4-point DFT of $x[n] = \{1, 2, 3, 4\}$ using the DFT matrix $\mathbf{W}_4$. Verify your answer with Parseval's relation, and state which symmetry property your result must satisfy and check it.

Click to reveal solution

With $W_4 = e^{-j\pi/2} = -j$:

$$\mathbf{X} = \begin{bmatrix} 1 & 1 & 1 & 1\\ 1 & -j & -1 & j\\ 1 & -1 & 1 & -1\\ 1 & j & -1 & -j \end{bmatrix} \begin{bmatrix}1\\2\\3\\4\end{bmatrix} = \begin{bmatrix} 10\\ (1-3) + (-2+4)j\\ 1-2+3-4\\ (1-3) + (2-4)j \end{bmatrix} = \begin{bmatrix}10\\ -2+2j\\ -2\\ -2-2j\end{bmatrix}$$

Parseval check: $\sum_n |x[n]|^2 = 1+4+9+16 = 30$, and $\frac{1}{4}\sum_k |X[k]|^2 = \frac{1}{4}(100 + 8 + 4 + 8) = \frac{120}{4} = 30$. ✓

Symmetry check: $x[n]$ is real, so we need $X[k] = X^{*}[4-k]$: indeed $X[1] = -2+2j = (X[3])^{*} = (-2-2j)^{*}$ ✓, and $X[0]=10$, $X[2]=-2$ are both real as required. Also $X[0] = \sum_n x[n] = 10$ ✓.

Exercise 2 — DFT properties

Problem: Let $X[k]$ be the $N$-point DFT of a real sequence $x[n]$. Express in terms of $X[k]$: (a) the DFT of $y_1[n] = x[((n-2))_N]$; (b) the DFT of $y_2[n] = x[((-n))_N]$; (c) the DFT of $y_3[n] = (-1)^n x[n]$ for even $N$; (d) the value of $\sum_{k=0}^{N-1} X[k]$.

Click to reveal solution

(a) Circular shift property with $m=2$: $Y_1[k] = W_N^{2k} X[k] = e^{-j4\pi k/N}\,X[k]$. Same magnitude, linear phase added.

(b) Circular reversal: $Y_2[k] = X[((-k))_N] = X[N-k]$. Since $x[n]$ is real, $X[N-k] = X^{*}[k]$, so $Y_2[k] = X^{*}[k]$.

(c) $(-1)^n = e^{j\pi n} = e^{j\frac{2\pi}{N}\cdot\frac{N}{2}n} = W_N^{-\frac{N}{2}n}$, so by the circular frequency-shift property $Y_3[k] = X[((k - N/2))_N]$ — the spectrum rotated by half: low and high frequency bins swap.

(d) From the IDFT at $n=0$: $x[0] = \frac{1}{N}\sum_k X[k]$, hence $\sum_{k=0}^{N-1} X[k] = N\,x[0]$. (Dual of $X[0] = \sum_n x[n]$.)

Exercise 3 — circular vs. linear convolution

Problem: Let $x_1[n] = \{1, 1, 1, 1\}$ and $x_2[n] = \{1, 2, 3, 4\}$. (a) Compute the linear convolution $y_{\text{lin}}[n] = x_1[n] * x_2[n]$. (b) Compute the 4-point circular convolution and explain its values using the time-aliasing relation $y_c[n] = \sum_r y_{\text{lin}}[n+rN]$. (c) What is the minimum DFT length $N$ for which the circular convolution equals the linear one? Verify for that $N$.

Click to reveal solution

(a) $x_1$ is a length-4 moving-sum window over $x_2$: $$y_{\text{lin}}[n] = \{1,\; 1{+}2,\; 1{+}2{+}3,\; 1{+}2{+}3{+}4,\; 2{+}3{+}4,\; 3{+}4,\; 4\} = \{1, 3, 6, 10, 9, 7, 4\}$$ of length $L+P-1 = 7$.

(b) With $N=4$, fold the linear result modulo 4 ($y_c[n] = y_{\text{lin}}[n] + y_{\text{lin}}[n+4]$):

$n$$y_{\text{lin}}[n]$$y_{\text{lin}}[n+4]$$y_c[n]$
01910
13710
26410
31010

So $y_c[n] = \{10,10,10,10\}$ — matching Example 8-3 and the middle panel of Fig. 8-3. The tail $\{9,7,4\}$ wrapped onto the head $\{1,3,6\}$.

(c) Need $N \ge L+P-1 = 7$. With $N=7$, zero-pad both to length 7; no term wraps ($y_{\text{lin}}[n+7] = 0$ for $0 \le n \le 6$), so the 7-point circular convolution is exactly $\{1,3,6,10,9,7,4\}$ — the right panel of Fig. 8-3.

Exercise 4 — sampling an overlength DTFT

Problem: Let $x[n] = a^n u[n]$ with $|a| < 1$ — an infinite-length sequence with DTFT $X(e^{j\omega}) = \dfrac{1}{1 - a e^{-j\omega}}$. Sample the DTFT at $\omega_k = 2\pi k/N$ to obtain $N$ numbers $X[k] = X(e^{j2\pi k/N})$, then take the $N$-point IDFT. Find a closed form for the resulting sequence $\hat{x}[n]$, $0 \le n \le N-1$, and compare it with $x[n]$.

Click to reveal solution

Frequency sampling periodizes time: the IDFT of the samples is $$\hat{x}[n] = \sum_{r=-\infty}^{\infty} x[n - rN] = \sum_{r \le 0} a^{\,n-rN}\,u[n-rN].$$ For $0 \le n \le N-1$ the step is satisfied for all $r \le 0$ (i.e. shifts by $0, N, 2N, \dots$ to the left bring copies of the tail into the window), so with $m = -r \ge 0$: $$\hat{x}[n] = \sum_{m=0}^{\infty} a^{\,n+mN} = a^n \sum_{m=0}^{\infty} (a^N)^m = \boxed{\;\frac{a^n}{1 - a^N}, \qquad 0 \le n \le N-1.\;}$$

Comparison: $\hat{x}[n] = x[n]/(1-a^N) > x[n]$ — every sample is inflated by the folded-in tail of the infinite sequence. This is pure time aliasing: $x[n]$ has length $> N$ (infinite), so $N$ frequency samples cannot represent it. The error factor $\frac{1}{1-a^N} \to 1$ as $N \to \infty$ (or as $|a|^N \to 0$), so taking enough frequency samples makes the aliasing negligible. E.g. $a = 0.9$, $N = 10$: $a^N \approx 0.349$, a 54% inflation at every sample; $N = 100$: $a^N \approx 2.7\times 10^{-5}$, negligible.

Exercise 5 — resolution and zero padding

Problem: A signal sampled at $F_s = 8$ kHz contains two sinusoids at $1000$ Hz and $1025$ Hz. (a) Using a rectangular window, estimate the minimum number of data samples $L$ needed to resolve the two tones. (b) If you capture only $L = 256$ samples but compute a $4096$-point DFT (zero padding), will the tones be resolved? Explain. (c) Repeat (a) for a Hamming window (main-lobe width $8\pi/L$). (d) What bin spacing (in Hz) does the 4096-point DFT give, and what is it good for here?

Click to reveal solution

(a) Two tones separated by $\Delta f = 25$ Hz need the main lobes to be distinguishable, requiring approximately $$\Delta f \ge \frac{F_s}{L} \;\Longrightarrow\; L \ge \frac{F_s}{\Delta f} = \frac{8000}{25} = 320 \text{ samples}.$$

(b) No. With $L = 256 < 320$, the underlying windowed DTFT already has the two main lobes merged ($F_s/L = 31.25$ Hz $> 25$ Hz). Zero padding to 4096 samples that same merged DTFT on a finer grid — it draws the single bump more smoothly but cannot split it. Resolution depends on $L$, not $N$.

(c) The Hamming main lobe is twice as wide ($8\pi/L$ instead of $4\pi/L$), so roughly $$L \ge \frac{2F_s}{\Delta f} = \frac{2 \times 8000}{25} = 640 \text{ samples}.$$ The reward for the doubled length requirement is $-41$ dB sidelobes instead of $-13$ dB — essential if the two tones have very different amplitudes (cf. Fig. 8-6).

(d) Bin spacing $= F_s/N = 8000/4096 \approx 1.95$ Hz. Once the tones are resolved (with $L$ large enough), this fine grid lets you locate each peak to within $\pm 1$ Hz without interpolation — that is the legitimate use of zero padding.

Exercise 6 — MATLAB: DFT matrix of a sampled cosine

Problem: A 5 Hz cosine is sampled at $F_s = 100$ Hz for exactly 1 second ($N = 100$ samples): $x[n] = \cos(2\pi \cdot 5 \cdot nT)$, $T = 1/F_s$. (a) Build the $N \times N$ DFT matrix from the twiddle factor and use it to compute $X[k]$. (b) Build the IDFT matrix from it and reconstruct $x[n]$. (c)–(d) Repeat with MATLAB's fft / ifft and confirm the results agree. (e) Plot $|X[k]|$ and the reconstructed $x[n]$ with stem. Predict analytically where the spectral peaks occur and their heights, and explain why the spectrum is so clean.

Click to reveal solution

Analytical prediction. The digital frequency is $\omega_0 = 2\pi f/F_s = 2\pi\cdot 5/100 = 2\pi\cdot\frac{5}{100}$, i.e. exactly $k_0 = 5$ periods fit in the $N=100$ window — the tone is on-grid. From Example 8-2: $$X[k] = \frac{N}{2}\delta[((k-5))_{100}] + \frac{N}{2}\delta[((k+5))_{100}] \;\Longrightarrow\; |X[5]| = |X[95]| = 50, \text{ all other bins } 0.$$ The spectrum is clean (no leakage) precisely because the observation window holds an integer number of periods; if $f$ were, say, 5.3 Hz, the line would leak into all bins. The IDFT matrix $\mathbf{W}^{*}/N$ must reconstruct $x[n]$ to machine precision since $\mathbf{W}^{-1} = \mathbf{W}^{*}/N$ exactly.

Cleaned-up MATLAB code:

clc; clear; close all;

% Signal: 5 Hz cosine, sampled at 100 Hz for 1 s
Fs = 100;  T = 1/Fs;
t  = 0:T:1-T;
f  = 5;
x  = cos(2*pi*f*t);

% (a) DFT via DFT matrix
N = length(x);
n = 0:N-1;  k = 0:N-1;
W = exp(-1j*2*pi/N);          % twiddle factor W_N
DFT_matrix = W .^ (n' * k);   % [W_N]^(nk), N x N
X_a = DFT_matrix * x.';       % X[k]

% (b) IDFT via matrix: W^(-1) = conj(W)/N
IDFT_matrix = conj(DFT_matrix) / N;
x_a = IDFT_matrix * X_a;      % reconstructed x[n]

% (c)-(d) Same with fft / ifft
X_c = fft(x);
x_c = ifft(X_c);

% (e) Stem plots
figure;
subplot(2,2,1); stem(k, abs(X_a),  'filled','b');
title('|X[k]| (DFT matrix)');  xlabel('k'); ylabel('|X[k]|');
subplot(2,2,2); stem(n, real(x_a),'filled','b');
title('reconstructed x[n] (IDFT matrix)'); xlabel('n'); ylabel('x[n]');
subplot(2,2,3); stem(k, abs(X_c),  'filled','b');
title('|X[k]| (fft)');         xlabel('k'); ylabel('|X[k]|');
subplot(2,2,4); stem(n, real(x_c),'filled','b');
title('reconstructed x[n] (ifft)'); xlabel('n'); ylabel('x[n]');

% Checks
max(abs(X_a.' - X_c))   % matrix DFT vs fft  : ~1e-12
max(abs(x_a.' - x))     % reconstruction err : ~1e-14

Result (regenerated numerically): peaks of height $50.0000$ at $k = 5$ and $k = 95$, all other bins at round-off level; maximum reconstruction error $\approx 3.6\times 10^{-14}$.

2026-06-12T22:18:54.969059 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 20 40 60 80 100 k 0 20 40 |X[k]| |X[k]| via DFT matrix — peaks at k = 5 and k = 95, height N/2 = 50 0 20 40 60 80 100 n −1.0 −0.5 0.0 0.5 1.0 x[n] Reconstructed x[n] via IDFT matrix (real part)
Fig. 8-7 — DFT-matrix computation of the sampled cosine. Top: $|X[k]|$ shows the two conjugate-symmetric lines at $k=5$ and $k=N-5=95$ with height $N/2 = 50$. Bottom: IDFT-matrix reconstruction is exact(峰值在 $k=5$ 與 $k=95$、高度 $N/2$;因為觀測窗剛好含整數個週期,所以沒有洩漏).

Bin-to-Hz mapping: $f_k = k F_s / N = k\cdot 100/100 = k$ Hz, so bin 5 is literally 5 Hz, and bin 95 represents $-5$ Hz (i.e. $95 - 100$). With fftshift the two lines would sit symmetrically at $\pm 5$ Hz.