Outline
4.1 The Fourier Domain
4.2 The DTFT
4.3 DTFTs of Simple Sequences
4.4 DTFT Theorems
4.5 Parseval & Energy Spectrum
4.6 Magnitude, Phase, Group Delay
4.7 Summary
Exercises
DSP Study Guide · Chapter 4

Fourier Domain

From Fourier series to the discrete-time Fourier transform: frequency response, DTFT pairs and theorems, Parseval's relation, and group delay.

4.1 The Fourier Domain

Joseph Fourier (1768–1830) claimed that any function of a variable — continuous or discontinuous — can be expanded in a series of sines of multiples of that variable. The modern statement is more careful about convergence, but the idea survives intact: signals can be represented as sums (or integrals) of sinusoids, and this representation — the Fourier domain(傅立葉域 / 頻域) — is where LTI systems become simple to analyze.

4.1.1 Fourier series and Fourier coefficients

A periodic signal $x(t)$ with period $T$ (fundamental frequency $\Omega_0 = 2\pi/T$) can be approximated by a sum of harmonics(諧波) of the fundamental frequency:

Fourier series (synthesis) $$x(t) = a_0 + \sum_{k=1}^{\infty}\bigl[a_k\cos(k\Omega_0 t) + b_k\sin(k\Omega_0 t)\bigr] = \sum_{k=-\infty}^{\infty} c_k\, e^{jk\Omega_0 t}$$
Fourier coefficients (analysis) $$c_k = \frac{1}{T}\int_{T} x(t)\, e^{-jk\Omega_0 t}\, dt$$

Equivalently, each harmonic pair $a_k\cos + b_k\sin$ can be written as a single sinusoid with an amplitude and a phase shift(相位移): $A_k\cos(k\Omega_0 t + \phi_k)$ with $A_k = \sqrt{a_k^2+b_k^2}$, $\phi_k = -\arctan(b_k/a_k)$. The set $\{c_k\}$ is the signal, viewed in the Fourier domain.

為什麼右邊的和要從 −∞ 加到 +∞?——負頻率與複指數形式(點擊展開)

因為 Euler 公式把每一個實數餘弦拆成一對「反向旋轉的相量」——正頻率一個、負頻率一個。這就是右邊那個和要從 $-\infty$ 加到 $+\infty$ 的原因。

代數推導:把三角函數換成指數

$$\cos(k\Omega_0 t)=\frac{e^{jk\Omega_0 t}+e^{-jk\Omega_0 t}}{2},\qquad \sin(k\Omega_0 t)=\frac{e^{jk\Omega_0 t}-e^{-jk\Omega_0 t}}{2j}$$

代入括號裡那一項,再按 $e^{\pm jk\Omega_0 t}$ 收集:

$$a_k\cos + b_k\sin =\underbrace{\frac{a_k-jb_k}{2}}_{c_k}\,e^{jk\Omega_0 t} +\underbrace{\frac{a_k+jb_k}{2}}_{c_{-k}}\,e^{-jk\Omega_0 t}$$

(用到 $1/j=-j$。)所以第 $k$ 項並沒有消失,只是被劈成兩半放到 $+k$ 和 $-k$ 兩個位置。再加上 $c_0=a_0$,左右兩式就完全相同。

負頻率不是物理上的東西,是記帳方式。 實際訊號當然只有一個頻率 $k\Omega_0$。負頻率項存在的唯一理由,是為了讓虛部自動歸零。這給出一個很重要的條件:

$$x(t)\in\mathbb{R}\iff c_{-k}=c_k^{*}\quad(\text{Hermitian symmetry})$$

也就是振幅頻譜 $|c_k|$ 偶對稱、相位頻譜 $\angle c_k$ 奇對稱。這也是為什麼實訊號的頻譜「一半是多餘的」——SDR 裡做 complex baseband 時只留單邊,資訊量完全沒少。反過來,如果 $c_{-k}\neq c_k^*$,合成出來就是複數訊號(I/Q 訊號),那正是 image rejection 要處理的情境。

三種寫法是同一組資料的三種座標:

表示法 參數 換算
直角 $(a,b)$ $a_k,\ b_k$
極座標 $A_k,\ \phi_k$ $A_k=\sqrt{a_k^2+b_k^2}$
複指數 $c_k$ $c_k=\tfrac{a_k-jb_k}{2}$,故 $A_k=2\lvert c_k\rvert$,$\phi_k=\angle c_k$

注意 $A_k=2|c_k|$ 那個 2:能量被分給了 $\pm k$ 兩根譜線,所以單邊振幅是單根複數係數的兩倍。畫功率譜時漏掉這個 factor 是常見的 3 dB 錯誤。

為什麼工程上偏好複指數那一式:

  1. 係數只要一條積分公式:$c_k=\frac{1}{T}\int_T x(t)\,e^{-jk\Omega_0 t}\,dt$,不用分 $a_k$、$b_k$ 兩條。
  2. $e^{jk\Omega_0 t}$ 是 LTI 系統的特徵函數——過系統只會被乘上 $H(jk\Omega_0)$,不會變波形。用 cos/sin 就得處理它們互相耦合。
  3. 微分變成乘 $jk\Omega_0$,摺積變成相乘,推導全部代數化。
  4. 直接接得上 DFT/FFT,那本來就是複指數基底。
2026-06-12T22:19:56.373591 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ −1.5 −1.0 −0.5 0.0 0.5 1.0 1.5 t −1.0 −0.5 0.0 0.5 1.0 partial sum Fourier-series partial sums of a square wave square wave 1 harmonic 2 harmonics 11 harmonics
Fig. 4-1 — Fourier-series partial sums of a square wave. More harmonics give a better fit, but the overshoot near the jumps (Gibbs phenomenon) never shrinks below about 9%.(方波的傅立葉級數部分和:諧波越多越接近,但跳變處的 Gibbs 過衝不會消失。)
直觀解釋:為什麼要換到頻域?(點擊展開)
時域上看一個訊號,只看到波形隨時間起伏;頻域上看同一個訊號,看到的是「它由哪些頻率的弦波組成、各佔多少」。 對 LTI 系統而言這個視角特別有用:弦波(複指數)通過 LTI 系統後仍是同頻率的弦波,只是振幅與相位改變。 所以複雜的時域卷積,在頻域只是逐頻率的乘法。這就是整章的核心動機。

4.1.2 The Fourier transform and the sinc function

For aperiodic continuous-time signals, the spacing $\Omega_0=2\pi/T$ between harmonics goes to zero as $T\to\infty$ and the sum becomes an integral — the Fourier transform(傅立葉轉換):

Continuous-time Fourier transform pair $$X(j\Omega) = \int_{-\infty}^{\infty} x(t)\,e^{-j\Omega t}\,dt \qquad\Longleftrightarrow\qquad x(t) = \frac{1}{2\pi}\int_{-\infty}^{\infty} X(j\Omega)\,e^{j\Omega t}\,d\Omega$$

The recurring example from the slides: a rectangular pulse of width $T_p$ transforms to the sinc function,

Rectangle ↔ sinc $$x(t)=\begin{cases}1, & |t|\le T_p/2\\ 0, & \text{otherwise}\end{cases} \qquad\Longrightarrow\qquad X(j\Omega) = T_p\,\frac{\sin(\Omega T_p/2)}{\Omega T_p/2} = T_p\,\operatorname{sinc}\!\Bigl(\tfrac{\Omega T_p}{2\pi}\Bigr)$$

and by duality a sinc in time transforms to a rectangle in frequency — which is exactly why the ideal lowpass filter of §4.3.3 has a sinc impulse response. A pure sine $\sin(\Omega_0 t)$ transforms to a pair of impulses at $\pm\Omega_0$: a single frequency occupies a single point in the Fourier domain.

Concept — narrow in time ↔ wide in frequency
The shorter the pulse $T_p$, the wider its sinc mainlobe ($\propto 1/T_p$)(時域越窄,頻域越寬). This time–frequency tradeoff reappears in windowing, in the uncertainty principle, and in the STFT of Chapter 9.

4.1.3 Eigenfunctions of LTI systems and frequency response

Why are complex exponentials the right building blocks? Feed $x[n] = e^{j\omega n}$ (for all $n$) into an LTI system with impulse response $h[n]$:

Eigenfunction property(特徵函數) $$y[n] = \sum_{k=-\infty}^{\infty} h[k]\,e^{j\omega(n-k)} = e^{j\omega n}\underbrace{\sum_{k=-\infty}^{\infty} h[k]\,e^{-j\omega k}}_{H(e^{j\omega})} = H(e^{j\omega})\,e^{j\omega n}$$

The output is the same exponential scaled by the complex constant $H(e^{j\omega})$ — the frequency response(頻率響應) of the system, which is precisely the DTFT of $h[n]$. So $e^{j\omega n}$ is an eigenfunction of every LTI system, with eigenvalue $H(e^{j\omega})$.

特徵函數性質逐步拆解——為什麼複指數過 LTI 只被乘一個數(點擊展開)

這條式子在證明一件事:把 $e^{j\omega n}$ 丟進任何 LTI 系統,出來的還是同一個 $e^{j\omega n}$,只是被乘上一個複數常數。

逐步拆解。起點是摺積和(LTI 系統的定義式):

$$y[n] = \sum_{k=-\infty}^{\infty} h[k]\, x[n-k]$$

代入 $x[n] = e^{j\omega n}$,所以 $x[n-k] = e^{j\omega(n-k)}$:

$$y[n] = \sum_{k} h[k]\, e^{j\omega(n-k)}$$

關鍵一步是指數律拆項:$e^{j\omega(n-k)} = e^{j\omega n}\cdot e^{-j\omega k}$。因為 $e^{j\omega n}$ 裡完全沒有 $k$,它對求和而言是常數,可以提到 $\sum$ 外面:

$$y[n] = e^{j\omega n} \underbrace{\sum_{k} h[k]\, e^{-j\omega k}}_{H(e^{j\omega})}$$

剩下那個和式只跟 $\omega$ 有關、跟 $n$ 無關——它就是 $h[n]$ 的 DTFT,也就是頻率響應 $H(e^{j\omega})$。

$$\boxed{\;e^{j\omega n} \;\longrightarrow\; \text{LTI} \;\longrightarrow\; H(e^{j\omega})\,e^{j\omega n}\;}$$

為什麼叫「特徵函數」。對照線性代數的 $A\mathbf{v} = \lambda \mathbf{v}$:

  • 特徵函數(eigenfunction):$e^{j\omega n}$(輸入輸出波形長得一樣)
  • 特徵值(eigenvalue):$H(e^{j\omega})$(一個複數,隨 $\omega$ 變化)

系統這個「算子」作用在複指數上,不會改變它的形狀,只做純量縮放。寫成極座標 $H(e^{j\omega}) = |H(e^{j\omega})|\,e^{j\angle H(e^{j\omega})}$ 就更直觀:$|H|$ 是增益(振幅縮放),$\angle H$ 是相位延遲

頻率完全不變。這正是為什麼「LTI 系統不會產生新的頻率成分」——反過來說,只要你在輸出看到輸入沒有的頻率(諧波、交互調變 IM3),系統必定是非線性的。這條界線在 mixer / PA 分析裡就是根本判準。

這條性質的實際價值:

  1. 摺積 → 乘法:任意訊號用 DTFT 拆成複指數的疊加,每個分量各自乘上自己的 $H(e^{j\omega})$,再疊回去。時域的 $\sum h[k]x[n-k]$ 就變成頻域的 $Y = HX$。整個濾波器設計、頻域分析的基礎都在這裡。
  2. 量測方法論:掃頻量 $|H|$ 和 $\angle H$ 就完整刻畫了系統——這就是網路分析儀在做的事。
  3. 實數弦波的推論:因為 $\cos(\omega n) = \frac{1}{2}(e^{j\omega n} + e^{-j\omega n})$,加上 $h[n]$ 為實數時 $H(e^{-j\omega}) = H^*(e^{j\omega})$,可推得 $\cos(\omega n) \to |H(e^{j\omega})|\cos(\omega n + \angle H(e^{j\omega}))$。

兩個容易被略過的前提:

  • 這裡的 $e^{j\omega n}$ 是從 $n = -\infty$ 就存在的雙邊訊號。如果實際上是 $e^{j\omega n}u[n]$(某時刻才開機),輸出會有暫態項,只有穩態部分才等於 $H(e^{j\omega})\,e^{j\omega n}$。
  • $\sum_k |h[k]| < \infty$(BIBO 穩定)才保證 $H(e^{j\omega})$ 收斂存在。
Key — sinusoid in, sinusoid out
For a real LTI system and real input $x[n]=A\cos(\omega_0 n + \phi)$, the steady-state output is $$y[n] = A\,\bigl|H(e^{j\omega_0})\bigr|\cos\!\bigl(\omega_0 n + \phi + \angle H(e^{j\omega_0})\bigr)$$ Magnitude is scaled by $|H|$, phase is shifted by $\angle H$ — the frequency never changes. (弦波進、同頻率弦波出:只改振幅與相位。)This is used directly in Exercise 2(c).

4.2 The Discrete-Time Fourier Transform (DTFT) 🔖

4.2.1 Definition

For a sequence $x[n]$, the discrete-time Fourier transform(離散時間傅立葉轉換) is the continuous, complex-valued function of the normalized angular frequency $\omega$ (rad/sample):

DTFT (analysis equation) $$\boxed{\,X(e^{j\omega}) = \sum_{n=-\infty}^{\infty} x[n]\,e^{-j\omega n}\,}$$

In general $X(e^{j\omega})$ is complex and can be written in rectangular or polar form:

Rectangular / polar form $$X(e^{j\omega}) = X_{re}(e^{j\omega}) + jX_{im}(e^{j\omega}) = \bigl|X(e^{j\omega})\bigr|\,e^{\,j\theta(\omega)}, \qquad \theta(\omega)=\arg\{X(e^{j\omega})\}$$
Warning — why the argument is written $e^{j\omega}$
The notation $X(e^{j\omega})$ (not $X(\omega)$) is deliberate: the transform depends on $\omega$ only through $e^{j\omega}$, which makes the $2\pi$-periodicity explicit and connects directly to the z-transform of Chapter 5 — the DTFT is the z-transform evaluated on the unit circle $z=e^{j\omega}$.(寫成 $e^{j\omega}$ 是刻意的:強調週期性,並對應單位圓上的 z 轉換。)

4.2.2 Periodicity of the DTFT

Because $n$ is an integer, $e^{-j(\omega+2\pi)n} = e^{-j\omega n}e^{-j2\pi n} = e^{-j\omega n}$. The periodicity is implicit in the definition:

Implicit periodicity $$X\bigl(e^{j(\omega+2\pi k)}\bigr) = X(e^{j\omega})\qquad\text{for any integer } k$$
Key — one period tells all
Every DTFT is periodic in $\omega$ with period $2\pi$. We therefore only ever need one period, conventionally $-\pi \le \omega < \pi$ or $0 \le \omega < 2\pi$. High frequencies live near $\omega=\pm\pi$, low frequencies near $\omega = 0$.(DTFT 一定以 $2\pi$ 為週期,看一個週期就夠; $\omega=0$ 附近是低頻,$\pm\pi$ 附近是最高頻。)In Exercise 3 the spectra are plotted over $0\le\omega\le 6\pi$ precisely to make this periodicity visible — you will see three identical copies.

4.2.3 Inverse DTFT

The DTFT can be inverted by integrating over any one period. Multiply $X(e^{j\omega})$ by $e^{j\omega n}$ and integrate:

Inverse DTFT (synthesis equation) $$\boxed{\,x[n] = \frac{1}{2\pi}\int_{-\pi}^{\pi} X(e^{j\omega})\,e^{j\omega n}\,d\omega\,}$$

The proof rests on the orthogonality of complex exponentials over one period:

Orthogonality $$\frac{1}{2\pi}\int_{-\pi}^{\pi} e^{j\omega(n-m)}\,d\omega = \frac{\sin\pi(n-m)}{\pi(n-m)} = \delta[n-m] \quad{\scriptstyle\textcolor{gray}{\text{(integer } n,m\text{)}}}$$

Substituting the analysis equation into the synthesis integral and swapping sum and integral, every term dies except $m=n$, returning $x[n]$ exactly. The pair (analysis, synthesis) says: $x[n]$ is a superposition of exponentials $e^{j\omega n}$ over a continuum of frequencies, weighted by $X(e^{j\omega})\,d\omega/2\pi$.

中文推導:為什麼反轉換成立(點擊展開)
把 $X(e^{j\omega})=\sum_m x[m]e^{-j\omega m}$ 代入反轉換積分: $$\frac{1}{2\pi}\int_{-\pi}^{\pi}\Bigl(\sum_m x[m]e^{-j\omega m}\Bigr)e^{j\omega n}d\omega =\sum_m x[m]\cdot\frac{1}{2\pi}\int_{-\pi}^{\pi}e^{j\omega(n-m)}d\omega$$ 當 $m\ne n$ 時,$e^{j\omega(n-m)}$ 在一個完整週期內正負抵消、積分為 0; 只有 $m=n$ 時被積函數恆為 1,積分得 $2\pi$。所以整串和只剩下 $x[n]$。 這正是「正交性」:不同頻率的複指數在一個週期上互相垂直。

4.2.4 Convergence

The DTFT is an infinite sum, so existence is a real question. Three regimes (三種收斂情形):

Condition on $x[n]$Convergence of $X(e^{j\omega})$Example
Absolutely summable: $\sum_n |x[n]| < \infty$ Uniform convergence; $X$ is continuous in $\omega$ $a^n\mu[n]$, $|a|<1$; any stable $h[n]$
Square summable only: $\sum_n |x[n]|^2 < \infty$ Mean-square convergence; $X$ may be discontinuous (Gibbs ripples at jumps) ideal LPF $h_{lp}[n]=\sin(\omega_c n)/\pi n$
Neither (power signals, periodic signals) Only in the distribution sense — Dirac impulses $\delta(\omega)$ allowed $x[n]=1$, $e^{j\omega_0 n}$, $\cos(\omega_0 n)$, $\mu[n]$
Tip — stability ⇔ frequency response exists
An LTI system is BIBO stable iff $h[n]$ is absolutely summable — which is exactly the condition for $H(e^{j\omega})$ to exist as an ordinary (uniformly convergent) function. A stable system always has a well-defined frequency response.(穩定 ⇔ $h[n]$ 絕對可和 ⇔ 頻率響應存在且連續。)

4.3 DTFTs of Simple Sequences

4.3.1 Common DTFT pairs

$x[n]$$X(e^{j\omega})$, one period $|\omega|\le\pi$Note
$\delta[n]$$1$flat spectrum — contains all frequencies equally
$\delta[n-n_0]$$e^{-j\omega n_0}$pure linear phase, $|X|=1$
$1$ (all $n$)$2\pi\,\delta(\omega)$DC only (distribution sense)
$e^{j\omega_0 n}$$2\pi\,\delta(\omega-\omega_0)$single spectral line
$\cos(\omega_0 n)$$\pi\bigl[\delta(\omega-\omega_0)+\delta(\omega+\omega_0)\bigr]$two lines at $\pm\omega_0$
$a^n \mu[n],\ |a|<1$$\dfrac{1}{1-a\,e^{-j\omega}}$geometric series — see Example 4-A
$\mu[n]$$\dfrac{1}{1-e^{-j\omega}} + \pi\,\delta(\omega)$limit $a\to 1$ plus DC impulse
rect: $x[n]=1,\ 0\le n\le M-1$$\dfrac{\sin(\omega M/2)}{\sin(\omega/2)}\,e^{-j\omega(M-1)/2}$Dirichlet kernel — §4.3.2
$\dfrac{\sin(\omega_c n)}{\pi n}$$\begin{cases}1,&|\omega|\le\omega_c\\0,&\omega_c<|\omega|\le\pi\end{cases}$ideal LPF — §4.3.3
Example 4-A — DTFT of the exponential sequence $x[n]=a^n\mu[n]$

Assume $|a|<1$ so the sequence is absolutely summable.

Insert into the definition and recognize a geometric series: $$X(e^{j\omega}) = \sum_{n=0}^{\infty} a^n e^{-j\omega n} = \sum_{n=0}^{\infty}\bigl(a\,e^{-j\omega}\bigr)^n = \frac{1}{1-a\,e^{-j\omega}} \quad{\scriptstyle\textcolor{gray}{|a e^{-j\omega}| = |a| < 1}}$$
Magnitude and phase (rationalize with the conjugate): $$\bigl|X(e^{j\omega})\bigr| = \frac{1}{\sqrt{1-2a\cos\omega+a^2}},\qquad \theta(\omega) = -\arctan\frac{a\sin\omega}{1-a\cos\omega}$$
Sanity check(合理性驗証): for $0<a<1$, $|X|$ is largest at $\omega=0$ (value $\tfrac{1}{1-a}$) and smallest at $\omega=\pi$ (value $\tfrac{1}{1+a}$) — a lowpass shape, consistent with a slowly decaying, smooth time sequence. See Fig. 4-4 for $a=\tfrac12$.

4.3.2 The rectangular pulse and the Dirichlet kernel

Example 4-B — DTFT of a length-$M$ rectangular pulse

Let $x[n]=1$ for $0\le n\le M-1$ and zero elsewhere — a finite geometric sum:

$$X(e^{j\omega}) = \sum_{n=0}^{M-1} e^{-j\omega n} = \frac{1-e^{-j\omega M}}{1-e^{-j\omega}}$$
Factor half-angle exponentials from numerator and denominator: $$X(e^{j\omega}) = \frac{e^{-j\omega M/2}\bigl(e^{j\omega M/2}-e^{-j\omega M/2}\bigr)} {e^{-j\omega/2}\bigl(e^{j\omega/2}-e^{-j\omega/2}\bigr)} = \underbrace{\frac{\sin(\omega M/2)}{\sin(\omega/2)}}_{\text{Dirichlet kernel}}\; e^{-j\omega(M-1)/2}$$
The linear-phase factor $e^{-j\omega(M-1)/2}$ just reflects that the pulse is centered at $n=(M-1)/2$. Zeros of $|X|$ fall at $\omega = 2\pi k/M$, $k=1,\dots,M-1$; the mainlobe width is $4\pi/M$ — longer pulse, narrower mainlobe.
2026-06-12T22:19:56.495291 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ −π −π/2 0 π/2 π ω (rad/sample) 0 2 4 6 8 |X(e^jω)| zeros at ω = 2πk/M |X(e^jω)| of length-8 rectangular pulse (Dirichlet kernel)
Fig. 4-2 — Magnitude of the DTFT of a length-8 rectangular pulse: the Dirichlet kernel $\left|\sin(\omega M/2)/\sin(\omega/2)\right|$, the discrete-time analogue of the sinc. Peak value $M$ at $\omega=0$; zeros at $\omega=2\pi k/M$. (長度 8 矩形脈衝的 DTFT 幅度 — Dirichlet 核,離散版的 sinc。)

4.3.3 The ideal lowpass filter and the sinc sequence

Going the other way — specify a perfect rectangle in frequency and ask what sequence produces it. With cutoff $\omega_c$:

Ideal lowpass filter(理想低通濾波器) $$H_{lp}(e^{j\omega}) = \begin{cases}1, & |\omega|\le\omega_c\\ 0, & \omega_c<|\omega|\le\pi\end{cases} \qquad\Longrightarrow\qquad h_{lp}[n] = \frac{1}{2\pi}\int_{-\omega_c}^{\omega_c} e^{j\omega n}\,d\omega = \frac{\sin(\omega_c n)}{\pi n},\quad -\infty<n<\infty$$

At $n=0$ the value is $h_{lp}[0]=\omega_c/\pi$ (take the limit). The impulse response is a sampled sinc.

2026-06-12T22:19:56.612945 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ −20 −15 −10 −5 0 5 10 15 20 n −0.05 0.00 0.05 0.10 0.15 0.20 0.25 h_lp[n] Ideal lowpass filter impulse response, ω_c = π/4 (sinc envelope dashed)
Fig. 4-3 — Impulse response of the ideal lowpass filter with $\omega_c=\pi/4$: $h_{lp}[n]=\sin(\omega_c n)/\pi n$, a two-sided, infinitely long sinc sequence (dashed: continuous sinc envelope).(理想低通的脈衝響應是雙邊無限長的 sinc 序列。)
Warning — the ideal LPF is unrealizable
$h_{lp}[n]$ is noncausal (nonzero for $n<0$) and decays only like $1/n$, so it is not absolutely summable — the ideal LPF is unstable and cannot be implemented exactly. Its DTFT converges only in the mean-square sense, with Gibbs ripples appearing whenever the sinc is truncated. All of filter design (Chapters 13–14) is the art of approximating this ideal with realizable systems.(理想低通非因果、不絕對可和,只能近似,不能實現。)

4.4 DTFT Theorems and Properties

4.4.1 Property table

Let $x[n]\leftrightarrow X(e^{j\omega})$, $g[n]\leftrightarrow G(e^{j\omega})$. All transforms below are $2\pi$-periodic, so frequency shifts wrap around.

PropertySequenceDTFT
Linearity(線性)$\alpha x[n]+\beta g[n]$$\alpha X(e^{j\omega})+\beta G(e^{j\omega})$
Time shift(時移)$x[n-n_0]$$e^{-j\omega n_0}\,X(e^{j\omega})$
Frequency shift / modulation(調變)$e^{j\omega_0 n}\,x[n]$$X\bigl(e^{j(\omega-\omega_0)}\bigr)$
Time reversal(時間反轉)$x[-n]$$X(e^{-j\omega})$
Conjugation(共軛)$x^*[n]$$X^*(e^{-j\omega})$
Frequency differentiation$n\,x[n]$$j\,\dfrac{dX(e^{j\omega})}{d\omega}$
Convolution(卷積)$x[n]\ast g[n]$$X(e^{j\omega})\,G(e^{j\omega})$
Multiplication / windowing(加窗)$x[n]\,g[n]$$\dfrac{1}{2\pi}\displaystyle\int_{-\pi}^{\pi} X(e^{j\theta})\,G\bigl(e^{j(\omega-\theta)}\bigr)\,d\theta$
Parseval(能量守恆)$\displaystyle\sum_{n=-\infty}^{\infty} x[n]\,g^*[n] = \frac{1}{2\pi}\int_{-\pi}^{\pi} X(e^{j\omega})\,G^*(e^{j\omega})\,d\omega$
Tip — time shift only rotates the phase
$|e^{-j\omega n_0}X| = |X|$: delaying a sequence never changes its magnitude spectrum, it only adds linear phase with slope $-n_0$.(時移不改變幅度頻譜,只加上斜率 $-n_0$ 的線性相位。) This is the cleanest way to remember what "linear phase = pure delay" means in §4.6.

4.4.2 Symmetry relations and real sequences

Define the conjugate-symmetric / conjugate-antisymmetric parts (共軛對稱/反對稱部分) of a sequence and of a spectrum:

Conjugate-symmetric decomposition $$x_{cs}[n] = \tfrac{1}{2}\bigl(x[n]+x^*[-n]\bigr),\qquad x_{ca}[n] = \tfrac{1}{2}\bigl(x[n]-x^*[-n]\bigr),\qquad X_{cs}(e^{j\omega}) = \tfrac{1}{2}\bigl(X(e^{j\omega})+X^*(e^{-j\omega})\bigr)$$

From the table (time reversal + conjugation, proved in Exercise 1) follow the pairings:

SequenceDTFT
$x[-n]$$X(e^{-j\omega})$
$x^*[n]$$X^*(e^{-j\omega})$
$x^*[-n]$$X^*(e^{j\omega})$
$\mathrm{Re}\{x[n]\}$$X_{cs}(e^{j\omega})$
$j\,\mathrm{Im}\{x[n]\}$$X_{ca}(e^{j\omega})$
$x_{cs}[n]$$\mathrm{Re}\{X(e^{j\omega})\}$
$x_{ca}[n]$$j\,\mathrm{Im}\{X(e^{j\omega})\}$
Key — DTFT of a real sequence
If $x[n]$ is real, then $X(e^{j\omega}) = X^*(e^{-j\omega})$ (conjugate symmetry). Hence $$|X(e^{j\omega})| = |X(e^{-j\omega})| \;{\scriptstyle\textcolor{gray}{\text{(even)}}},\qquad \arg X(e^{j\omega}) = -\arg X(e^{-j\omega}) \;{\scriptstyle\textcolor{gray}{\text{(odd)}}}$$ Real part and $|X|$ are even functions of $\omega$; imaginary part and phase are odd. For real signals, the half-band $0\le\omega\le\pi$ carries all the information. (實數序列的頻譜共軛對稱:幅度偶、相位奇,看 $0$ 到 $\pi$ 就夠。)

4.4.3 The convolution theorem

Convolution theorem $$y[n] = x[n]\ast h[n] \qquad\Longleftrightarrow\qquad \boxed{\,Y(e^{j\omega}) = X(e^{j\omega})\,H(e^{j\omega})\,}$$

Proof sketch. Take the DTFT of the convolution sum and swap the order of summation:

Derivation $$Y(e^{j\omega}) = \sum_n\Bigl(\sum_k x[k]\,h[n-k]\Bigr)e^{-j\omega n} = \sum_k x[k]\,e^{-j\omega k}\sum_m h[m]\,e^{-j\omega m} = X(e^{j\omega})\,H(e^{j\omega}) \quad{\scriptstyle\textcolor{gray}{m=n-k}}$$

Convolution in time becomes multiplication in frequency(時域卷積=頻域相乘). This is the practical payoff of the whole chapter: instead of sliding and summing, multiply two spectra pointwise and (if needed) invert. Exercise 3 verifies this numerically in MATLAB — the convolution result and the IDTFT of $X\cdot H$ agree to machine precision.

Example 4-C — convolution via the DTFT

Let $h[n]=\bigl(\tfrac12\bigr)^n\mu[n]$ and $x[n]=\delta[n]-\tfrac12\delta[n-1]$. Find $y[n]=x[n]\ast h[n]$.

Transform each: $H(e^{j\omega}) = \dfrac{1}{1-\frac12 e^{-j\omega}}$ (Example 4-A), and $X(e^{j\omega}) = 1-\tfrac12 e^{-j\omega}$ (linearity + shift of $\delta$).
Multiply: $$Y(e^{j\omega}) = \bigl(1-\tfrac12 e^{-j\omega}\bigr)\cdot\frac{1}{1-\frac12 e^{-j\omega}} = 1$$
Invert by inspection: $y[n]=\delta[n]$. The FIR sequence $x[n]$ is the inverse system of the IIR system $h[n]$ — a cancellation that is nearly invisible in the time domain but trivial in the Fourier domain.(頻域一眼看出兩系統互為反系統。)

4.4.4 Modulation and windowing

The dual of convolution: multiplying two sequences convolves their spectra (periodic convolution, over one period):

Modulation / windowing theorem $$w[n] = x[n]\,g[n] \qquad\Longleftrightarrow\qquad W(e^{j\omega}) = \frac{1}{2\pi}\int_{-\pi}^{\pi} X(e^{j\theta})\,G\bigl(e^{j(\omega-\theta)}\bigr)\,d\theta$$

Two standard uses:

4.5 Parseval's Relation and the Energy Density Spectrum

4.5.1 Parseval's relation

Parseval's relation(能量守恆) $$\boxed{\;\mathcal{E}_x=\sum_{n=-\infty}^{\infty} \bigl|x[n]\bigr|^2 = \frac{1}{2\pi}\int_{-\pi}^{\pi} \bigl|X(e^{j\omega})\bigr|^2\,d\omega\;}$$

Energy computed sample-by-sample in time equals energy computed frequency-by-frequency — the DTFT neither creates nor destroys energy, it only reorganizes it. (This is the $g=x$ special case of the general inner-product form in the table of §4.4.1.)

4.5.2 Energy density spectrum and autocorrelation

Energy density spectrum(能量密度頻譜) $$S_{xx}(\omega) = \bigl|X(e^{j\omega})\bigr|^2 \qquad\Longrightarrow\qquad \mathcal{E}_x = \frac{1}{2\pi}\int_{-\pi}^{\pi} S_{xx}(\omega)\,d\omega$$

$S_{xx}(\omega)$ tells how the signal's energy is distributed over frequency. It connects back to the time domain through the autocorrelation sequence(自相關序列):

EDS ↔ autocorrelation $$r_{xx}[\ell] = \sum_{n=-\infty}^{\infty} x[n]\,x^*[n-\ell] = x[\ell]\ast x^*[-\ell] \qquad\Longleftrightarrow\qquad S_{xx}(\omega) = X(e^{j\omega})\,X^*(e^{j\omega}) = \bigl|X(e^{j\omega})\bigr|^2$$

(Apply the convolution theorem with $g[n]=x^*[-n]\leftrightarrow X^*(e^{j\omega})$, using the symmetry proved in Exercise 1(c).) The EDS is the DTFT of the autocorrelation — phase information is gone; only energy-vs-frequency remains. Note $r_{xx}[0]=\mathcal{E}_x$, recovering Parseval.

Concept — through an LTI system
Since $Y(e^{j\omega})=H(e^{j\omega})X(e^{j\omega})$, energy spectra multiply by the magnitude squared of the frequency response: $$S_{yy}(\omega) = \bigl|H(e^{j\omega})\bigr|^2\,S_{xx}(\omega)$$ The system reshapes the energy distribution by $|H|^2$ — the phase of $H$ does not affect where the energy sits, which is why $|H|$ alone decides "lowpass / highpass / bandpass". (通過 LTI 系統,能量頻譜乘上 $|H|^2$;相位不影響能量分佈。)

4.6 Magnitude, Phase, and Group Delay

4.6.1 Magnitude–phase representation of the frequency response

Writing $H(e^{j\omega}) = |H(e^{j\omega})|\,e^{j\theta(\omega)}$ splits the action of an LTI system on each frequency into a gain $|H|$(增益)and a phase shift $\theta(\omega)$(相位移). For the first-order system of Example 4-A:

2026-06-12T22:19:56.755044 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0.75 1.00 1.25 1.50 1.75 2.00 |H(e^jω)| Frequency response of h[n] = (1/2)ⁿ μ[n] −π −π/2 0 π/2 π ω (rad/sample) −0.4 −0.2 0.0 0.2 0.4 arg H(e^jω) (rad)
Fig. 4-4 — Magnitude (top) and phase (bottom) of $H(e^{j\omega}) = 1/(1-\tfrac12 e^{-j\omega})$, i.e. $h[n]=(1/2)^n\mu[n]$. Lowpass: gain 2 at DC, gain 2/3 at $\omega=\pi$; magnitude even, phase odd — as required for a real $h[n]$. (一階系統的幅度/相位響應:幅度為偶函數、相位為奇函數。)
Warning — phase is only known modulo $2\pi$
Numerical routines (MATLAB angle, NumPy np.angle) return the principal value $\arg H \in (-\pi,\pi]$, producing artificial $2\pi$ jumps in plots (visible in the Exercise 3 phase plots). The continuous "unwrapped" phase (unwrap) is needed before differentiating to get group delay. (數值相位是主值,會出現 $2\pi$ 跳變;算群延遲前要先 unwrap。)

4.6.2 Group delay

A pure delay $h[n]=\delta[n-n_0]$ has $H(e^{j\omega})=e^{-j\omega n_0}$ — linear phase with slope $-n_0$. Generalizing, the local slope of the (unwrapped) phase measures how much each narrowband group of frequencies is delayed:

Group delay(群延遲) $$\tau_g(\omega) = -\frac{d}{d\omega}\,\theta(\omega) \qquad{\scriptstyle\textcolor{gray}{\theta(\omega)=\text{unwrapped }\arg H(e^{j\omega})}}$$

Interpretation: a narrowband signal centered at $\omega_0$ (a slowly varying envelope on a carrier) comes out with its envelope delayed by $\tau_g(\omega_0)$ samples and its carrier phase shifted by $\theta(\omega_0)$. If $\tau_g$ is constant — linear phase — every group is delayed equally and the waveform shape is preserved; if $\tau_g$ varies with $\omega$, different frequency components arrive at different times and the waveform is dispersed(相位失真/色散).

2026-06-12T22:19:56.902735 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 π/2 π ω −2 −1 0 1 arg H(e^jω) (rad) 5-pt moving average: phase 0 π/2 π ω 0 1 2 3 4 group delay τ(ω) (samples) Group delay comparison MA(5): τ(ω) = 2 IIR, a = 0.8
Fig. 4-5 — Left: phase of the 5-point moving average $H(e^{j\omega})=\frac{1}{5}\sum_{k=0}^{4}e^{-j\omega k}$ — piecewise linear with slope $-2$ ($\pi$ jumps occur where the real Dirichlet factor changes sign). Right: its group delay is exactly $\tau_g=2$ samples at all frequencies (linear phase), while the first-order IIR system $1/(1-0.8e^{-j\omega})$ has frequency-dependent group delay — low frequencies are delayed up to 4 samples, high frequencies barely at all.(線性相位 FIR 群延遲恆定;IIR 群延遲隨頻率變化, 造成波形失真。)
Key — linear phase ⇔ constant group delay
$\theta(\omega) = -\omega n_0 \iff \tau_g(\omega)=n_0$: the system behaves (in phase) like a pure $n_0$-sample delay. Symmetric FIR filters ($h[n]=h[M-1-n]$, like the moving average) achieve this exactly with $n_0=(M-1)/2$; causal IIR filters never can. This is the central selling point of FIR filters in Chapter 14.(線性相位=常數群延遲;對稱 FIR 可精確達成,因果 IIR 不行。)

4.7 Summary

The transform pair
$X(e^{j\omega})=\sum_n x[n]e^{-j\omega n}$;  $x[n]=\frac{1}{2\pi}\int_{-\pi}^{\pi}X(e^{j\omega})e^{j\omega n}d\omega$. Always $2\pi$-periodic; one period suffices. Exists uniformly iff $\sum|x[n]|<\infty$.
Eigenfunctions & frequency response
$e^{j\omega n}$ in → $H(e^{j\omega})\,e^{j\omega n}$ out. Sinusoid in → same-frequency sinusoid out, scaled by $|H|$, shifted by $\angle H$. $H(e^{j\omega})$ = DTFT of $h[n]$; exists for every stable system.
Pairs to memorize
$\delta[n]\!\leftrightarrow\!1$;  $\delta[n-n_0]\!\leftrightarrow\!e^{-j\omega n_0}$;  $a^n\mu[n]\!\leftrightarrow\!\frac{1}{1-ae^{-j\omega}}$;  rect$_M\!\leftrightarrow$ Dirichlet $\frac{\sin(\omega M/2)}{\sin(\omega/2)}$;  $\frac{\sin\omega_c n}{\pi n}\!\leftrightarrow$ ideal LPF.
Theorems
Shift → linear phase $e^{-j\omega n_0}$; modulation → spectrum shift; convolution → multiplication; multiplication → periodic convolution; real $x[n]$ → conjugate-symmetric $X$ ($|X|$ even, phase odd).
Energy
Parseval: $\sum|x[n]|^2=\frac{1}{2\pi}\int_{-\pi}^{\pi}|X|^2 d\omega$. EDS $S_{xx}=|X|^2$ = DTFT of autocorrelation $r_{xx}[\ell]$; through a system, $S_{yy}=|H|^2 S_{xx}$.
Phase & group delay
$\tau_g(\omega)=-d\theta/d\omega$ = envelope delay per frequency group. Linear phase ⇔ constant $\tau_g$ ⇔ shape-preserving delay; symmetric FIR achieves it, causal IIR cannot.

Exercises

All three problems of Homework 4 (ICE503 DSP), with full worked solutions.

Exercise 1 — DTFT symmetry proofs

Problem: Let $X(e^{j\omega})$ denote the DTFT of $x[n]$, $X(e^{j\omega})=\sum_{n=-\infty}^{\infty}x[n]e^{-j\omega n}$. Prove that

  1. the DTFT of $x[-n]$ is $X(e^{-j\omega})$;
  2. the DTFT of $x^*[n]$ is $X^*(e^{-j\omega})$;
  3. the DTFT of $x^*[-n]$ is $X^*(e^{j\omega})$;
  4. the DTFT of $\mathrm{Re}\{x[n]\}$ is $X_{cs}(e^{j\omega})$;
  5. the DTFT of $x_{cs}[n]$ is $\mathrm{Re}\{X(e^{j\omega})\}$.
Click to reveal solution

(a) Substitute and change the summation index $m=-n$ (the sum runs over all integers either way):

$$\mathcal{F}\{x[-n]\} = \sum_{n=-\infty}^{\infty} x[-n]\,e^{-j\omega n} = \sum_{m=-\infty}^{\infty} x[m]\,e^{-j(-\omega)m} = X(e^{-j\omega})\qquad\blacksquare$$

(b) Conjugate the whole sum, twice (conjugating twice changes nothing), and pull one conjugation outside:

$$\mathcal{F}\{x^*[n]\} = \sum_{n} x^*[n]\,e^{-j\omega n} = \Bigl(\sum_{n} x[n]\,e^{+j\omega n}\Bigr)^{\!*} = \Bigl(\sum_{n} x[n]\,e^{-j(-\omega)n}\Bigr)^{\!*} = X^*(e^{-j\omega})\qquad\blacksquare$$

(c) Combine (a) and (b): apply (b) to the sequence $x[-n]$, whose DTFT is $X(e^{-j\omega})$ by (a). Replacing $\omega\to-\omega$ inside the conjugate of (a)'s result:

$$\mathcal{F}\{x^*[-n]\} = \sum_{n} x^*[-n]\,e^{-j\omega n} \;\overset{m=-n}{=}\; \sum_{m} x^*[m]\,e^{j\omega m} = \Bigl(\sum_{m} x[m]\,e^{-j\omega m}\Bigr)^{\!*} = X^*(e^{j\omega})\qquad\blacksquare$$

(d) Write the real part as $\mathrm{Re}\{x[n]\}=\tfrac12\bigl(x[n]+x^*[n]\bigr)$ and use linearity with (b):

$$\mathcal{F}\bigl\{\mathrm{Re}\{x[n]\}\bigr\} = \tfrac12\Bigl(X(e^{j\omega}) + X^*(e^{-j\omega})\Bigr) \;\stackrel{\text{def}}{=}\; X_{cs}(e^{j\omega})\qquad\blacksquare$$

— the conjugate-symmetric part of the spectrum (取實部 ⇒ 頻譜的共軛對稱部分).

(e) Write the conjugate-symmetric part $x_{cs}[n]=\tfrac12\bigl(x[n]+x^*[-n]\bigr)$ and use linearity with (c):

$$\mathcal{F}\{x_{cs}[n]\} = \tfrac12\Bigl(X(e^{j\omega}) + X^*(e^{j\omega})\Bigr) = \mathrm{Re}\{X(e^{j\omega})\}\qquad\blacksquare$$

Parts (d) and (e) are duals: Re in one domain ↔ conjugate-symmetric part in the other. Setting $x[n]$ real in (b) gives the cornerstone result $X(e^{j\omega})=X^*(e^{-j\omega})$ of §4.4.2.

Exercise 2 — First-order LTI system in the Fourier domain

Problem: An LTI system is described by $h[n]=\bigl(\tfrac12\bigr)^n\mu[n]$.

  1. Determine the frequency response $H(e^{j\omega})$.
  2. If the input is $x[n]=\delta[n]-4\delta[n-2]$, determine $X(e^{j\omega})$ and the DTFT $Y(e^{j\omega})$ of the output $y[n]=x[n]\ast h[n]$.
  3. If the input is $x[n]=\cos\bigl(\tfrac{\pi n}{5}\bigr)$, determine $X(e^{j\omega})$ and $Y(e^{j\omega})$.
Click to reveal solution

(a) Geometric series with ratio $\tfrac12 e^{-j\omega}$ (Example 4-A with $a=\tfrac12$; converges since $|\tfrac12 e^{-j\omega}|=\tfrac12<1$):

$$H(e^{j\omega}) = \sum_{n=0}^{\infty}\Bigl(\tfrac12\Bigr)^n e^{-j\omega n} = \boxed{\dfrac{1}{1-\frac{1}{2}e^{-j\omega}}}$$

(b) By linearity and the time-shift theorem ($\delta[n-n_0]\leftrightarrow e^{-j\omega n_0}$):

$$X(e^{j\omega}) = 1 - 4e^{-j2\omega}$$

By the convolution theorem, $Y = X\cdot H$:

$$Y(e^{j\omega}) = X(e^{j\omega})H(e^{j\omega}) = \boxed{\dfrac{1-4e^{-j2\omega}}{1-\frac{1}{2}e^{-j\omega}}}$$

Cross-check in the time domain(時域驗算): convolving directly, $y[n]=\bigl(\tfrac12\bigr)^n\mu[n]-4\bigl(\tfrac12\bigr)^{n-2}\mu[n-2]$; its DTFT is $\frac{1}{1-\frac12 e^{-j\omega}}-\frac{4e^{-j2\omega}}{1-\frac12 e^{-j\omega}}$ — the same. Note also $1-4e^{-j2\omega}=(1-2e^{-j\omega})(1+2e^{-j\omega})$, so for $n\ge 2$, $y[n]=(\tfrac12)^n(1-16)= -15\,(\tfrac12)^n$, with $y[0]=1$, $y[1]=\tfrac12$.

(c) The cosine is a power signal — its DTFT exists in the distribution sense (§4.2.4). Using $\cos(\omega_0 n)=\tfrac12(e^{j\omega_0 n}+e^{-j\omega_0 n})$ and $e^{j\omega_0 n}\leftrightarrow 2\pi\delta(\omega-\omega_0)$, with $\omega_0=\pi/5$:

$$X(e^{j\omega}) = \pi\sum_{k=-\infty}^{\infty}\Bigl[\delta\bigl(\omega-\tfrac{\pi}{5}+2\pi k\bigr) +\delta\bigl(\omega+\tfrac{\pi}{5}+2\pi k\bigr)\Bigr] \;\;{\scriptstyle\textcolor{gray}{=\;\pi[\delta(\omega-\frac{\pi}{5})+\delta(\omega+\frac{\pi}{5})]\ \text{on } |\omega|\le\pi}}$$

Multiplying by $H$: the impulses sample $H$ at $\pm\pi/5$ (sifting property):

$$Y(e^{j\omega}) = \pi\Bigl[H\bigl(e^{j\pi/5}\bigr)\,\delta\bigl(\omega-\tfrac{\pi}{5}\bigr) + H\bigl(e^{-j\pi/5}\bigr)\,\delta\bigl(\omega+\tfrac{\pi}{5}\bigr)\Bigr], \qquad |\omega|\le\pi$$

Evaluating $H$ at $\omega=\pi/5$: $1-\tfrac12 e^{-j\pi/5} = 1-\tfrac12\cos\tfrac{\pi}{5}+\tfrac{j}{2}\sin\tfrac{\pi}{5} = 0.5955+j0.2939$, so

$$\bigl|H(e^{j\pi/5})\bigr| = \frac{1}{|0.5955+j0.2939|} \approx 1.506,\qquad \angle H(e^{j\pi/5}) \approx -0.4585\ \text{rad}$$

and since $h[n]$ is real, $H(e^{-j\pi/5})=H^*(e^{j\pi/5})$. By the eigenfunction property (§4.1.3) the time-domain output is the same-frequency sinusoid

$$y[n] \approx 1.506\,\cos\Bigl(\tfrac{\pi n}{5} - 0.4585\Bigr)$$
Exercise 3 — MATLAB DTFT simulation

Problem: An LTI system is described by $h[n]=\bigl(\tfrac13\bigr)^n\mu[n]$ and the input sequence is $x[n]=2\delta[n]-\tfrac23\delta[n-1]$.

  1. Use stem to plot $x[n]$ and $h[n]$ for $0\le n\le 99$ ($x$ in subplot(2,1,1), $h$ in subplot(2,1,2), axes labeled).
  2. Use the definition to calculate the DTFTs $X(e^{j\omega})=\sum_n x[n]e^{-j\omega n}$ and $H(e^{j\omega})=\sum_n h[n]e^{-j\omega n}$ for $\omega = 0:\frac{\pi}{100}:6\pi$.
  3. Calculate $Y(e^{j\omega})=X(e^{j\omega})H(e^{j\omega})$ in the frequency domain; plot magnitude and angle of $X$, $H$, $Y$ in a $3\times2$ subplot grid over $\omega=0:\frac{\pi}{100}:6\pi$.
  4. Compute $y[n]=x[n]\ast h[n]$ by convolution, then compute the IDTFT $\hat{y}[n]=\frac{1}{2\pi}\int_{-\pi}^{\pi}Y(e^{j\omega})e^{j\omega n}d\omega$ numerically; stem-plot $y[n]$ and $\hat{y}[n]$ for $0\le n\le 99$.
Click to reveal solution

Analytical setup(先手算). Closed-form DTFTs (geometric series + shift theorem):

$$X(e^{j\omega}) = 2-\tfrac23 e^{-j\omega},\qquad H(e^{j\omega}) = \frac{1}{1-\frac13 e^{-j\omega}},\qquad Y(e^{j\omega}) = \frac{2-\frac23 e^{-j\omega}}{1-\frac13 e^{-j\omega}}$$

In MATLAB the infinite DTFT sums are simply evaluated by these closed forms. Cleaned-up script (from DSP_HW4_tony.m):

clc; clear;
n = 0:99;

% sequences
x = 2*(n==0) - (2/3)*(n==1);     % x[n] = 2*delta[n] - (2/3)*delta[n-1]
h = (1/3).^n;                    % h[n] = (1/3)^n * mu[n], n >= 0

%% (a) stem plots of x[n] and h[n]
figure;
subplot(2,1,1); stem(n, x, 'filled');
xlabel('n'); ylabel('x[n]'); title('x[n]');
subplot(2,1,2); stem(n, h, 'filled');
xlabel('n'); ylabel('h[n]'); title('h[n]');

%% (b) DTFTs by definition (closed-form geometric sums)
omega = 0 : pi/100 : 6*pi;
X = 2 - (2/3)*exp(-1j*omega);            % finite sum: two terms
H = 1 ./ (1 - (1/3)*exp(-1j*omega));     % geometric series, |1/3| < 1

%% (c) frequency-domain product, magnitude / phase plots
Y = X .* H;
figure;
subplot(3,2,1); plot(omega, abs(X));   xlabel('\omega'); ylabel('|X(e^{j\omega})|');
subplot(3,2,2); plot(omega, angle(X)); xlabel('\omega'); ylabel('arg X(e^{j\omega})');
subplot(3,2,3); plot(omega, abs(H));   xlabel('\omega'); ylabel('|H(e^{j\omega})|');
subplot(3,2,4); plot(omega, angle(H)); xlabel('\omega'); ylabel('arg H(e^{j\omega})');
subplot(3,2,5); plot(omega, abs(Y));   xlabel('\omega'); ylabel('|Y(e^{j\omega})|');
subplot(3,2,6); plot(omega, angle(Y)); xlabel('\omega'); ylabel('arg Y(e^{j\omega})');

%% (d) time-domain convolution vs numerical IDTFT
y = conv(x, h);
y = y(1:100);                            % keep 0 <= n <= 99

w = -pi : pi/2000 : pi;                  % IDTFT must integrate ONE period
Yw = (2 - (2/3)*exp(-1j*w)) ./ (1 - (1/3)*exp(-1j*w));
y_hat = zeros(1, length(n));
for k = 1:length(n)
    y_hat(k) = real( trapz(w, Yw .* exp(1j*w*n(k))) / (2*pi) );
end

figure;
subplot(2,1,1); stem(n, y, 'filled');
xlabel('n'); ylabel('y[n]');     title('y[n] = conv(x,h)');
subplot(2,1,2); stem(n, y_hat, 'filled');
xlabel('n'); ylabel('y\^[n]');   title('y\^[n] from IDTFT of Y(e^{j\omega})');

max(abs(y - y_hat))                      % ~1e-16: identical
Warning — bug fixed from the original script
The original DSP_HW4_tony.m evaluated the IDTFT integral with trapz(omega, ...) over $0\le\omega\le 6\pi$ — that is three periods, so dividing by $2\pi$ gives $3\,y[n]$, three times too large (and it also used $x[n]=\delta[n]-\tfrac12\delta[n-1]$ instead of the assigned input). The IDTFT must integrate over exactly one period, e.g. $-\pi\le\omega\le\pi$ as in the formula. The script above fixes both. (原始程式在 $0$–$6\pi$ 上積分 — 共三個週期 — 再除以 $2\pi$,結果是正確值的 3 倍;反轉換只能積一個週期。)

(a) $x[n]$ has only two nonzero samples ($x[0]=2$, $x[1]=-\tfrac23$); $h[n]$ decays geometrically and is visually zero after $n\approx 10$:

2026-06-12T22:19:57.060242 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 20 40 60 80 100 n 0 1 2 x[n] x[n] = 2δ[n] − (2/3)δ[n−1] 0 20 40 60 80 100 n 0.00 0.25 0.50 0.75 1.00 h[n] h[n] = (1/3)ⁿ μ[n]
Fig. 4-6 — Exercise 3(a): stem plots of $x[n]=2\delta[n]-\frac{2}{3}\delta[n-1]$ (top) and $h[n]=(1/3)^n\mu[n]$ (bottom), $0\le n\le 99$.

(b), (c) The spectra over $0\le\omega\le 6\pi$ show three identical periods — the implicit $2\pi$-periodicity of §4.2.2 made visible. $|H|$ peaks at $\omega=0,2\pi,4\pi,6\pi$ (value $\tfrac{1}{1-1/3}=1.5$): a lowpass response. The phase plots use the principal value, hence the sawtooth-like behavior:

2026-06-12T22:19:57.344261 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 π 1.5 2.0 2.5 |X(e^jω)| 0 π −0.2 0.0 0.2 arg X(e^jω) 0 π 0.8 1.0 1.2 1.4 |H(e^jω)| 0 π −0.2 0.0 0.2 arg H(e^jω) 0 π ω 1.90 1.95 2.00 2.05 2.10 |Y(e^jω)| 0 π ω −5 0 5 arg Y(e^jω) 1e−17
Fig. 4-7 — Exercise 3(c): magnitude (left column) and phase (right column) of $X(e^{j\omega})$, $H(e^{j\omega})$, $Y(e^{j\omega})=XH$ over $\omega = 0:\pi/100:6\pi$. Three identical periods confirm DTFT periodicity. (三個完全相同的週期,驗證 DTFT 的 $2\pi$ 週期性。)Note $|Y| = 2$ exactly, and $\arg Y$ is pure numerical noise at the $10^{-17}$ level — see part (d): $Y(e^{j\omega})\equiv 2$.

(d) Convolution in time vs multiplication in frequency followed by the numerical IDTFT — the two stem plots are indistinguishable ($\max_n|y[n]-\hat{y}[n]|\approx 2.9\times10^{-16}$, machine precision), a numerical proof of the convolution theorem:

2026-06-12T22:19:57.615504 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 20 40 60 80 100 n 0.0 0.5 1.0 1.5 2.0 y[n] y[n] = x[n] ∗ h[n] (conv) 0 20 40 60 80 100 n 0.0 0.5 1.0 1.5 2.0 ŷ[n] ŷ[n] from numerical IDTFT of Y(e^jω)
Fig. 4-8 — Exercise 3(d): $y[n]$ by time-domain convolution (top) and $\hat{y}[n]$ by numerical IDTFT of $Y(e^{j\omega})$ (bottom). Identical to machine precision(兩者到機器精度完全一致 — 卷積定理的數值驗證).

Analytically: $y[n]=2(\tfrac13)^n\mu[n]-\tfrac23(\tfrac13)^{n-1}\mu[n-1]$, i.e. $y[0]=2$ and $y[n]=0$ for $n\ge1$... check: for $n\ge 1$, $y[n]=2(\tfrac13)^n-\tfrac23(\tfrac13)^{n-1}=2(\tfrac13)^n-2(\tfrac13)^n=0$. Indeed $Y(e^{j\omega})=\frac{2(1-\frac13 e^{-j\omega})}{1-\frac13 e^{-j\omega}}=2$, so $y[n]=2\delta[n]$ — $x[n]$ is (twice) the inverse system of $h[n]$, exactly the structure of Example 4-C. The stem plots confirm it: a single spike of height 2 at $n=0$.