Outline
3.1 LCCDEs
3.2 Solving LCCDEs
3.3 Zero-Input / Zero-State
3.4 Impulse Response
3.5 Stability
3.6 Block Diagrams
3.7 Correlation
3.8 Summary
Exercises
DSP Study Guide · Chapter 3

Discrete-Time Systems II — Difference Equations & Correlation

Linear constant-coefficient difference equations: solving them, impulse responses, FIR/IIR, stability, block-diagram realizations — plus cross- and autocorrelation of sequences.

3.1 Linear Constant-Coefficient Difference Equations

Chapter 2 described an LTI system by its impulse response $h[n]$ and the convolution sum. A second — and computationally far cheaper — description is the linear constant-coefficient difference equation(線性常係數差分方程, LCCDE): the present output is computed from a finite number of past outputs, the present input, and past inputs.

3.1.1 General form

LCCDE — general N-th order form $$\sum_{k=0}^{N} a_k\, y[n-k] \;=\; \sum_{k=0}^{M} b_k\, x[n-k], \qquad a_0 = 1$$

Solving for the present output gives the recursive computational form:

Recursive form (a₀ normalized to 1) $$y[n] \;=\; -\sum_{k=1}^{N} a_k\, y[n-k] \;+\; \sum_{k=0}^{M} b_k\, x[n-k]$$
Why LCCDEs matter
Convolution with an infinitely long $h[n]$ needs infinitely many multiplications per output sample. An LCCDE produces the same output with only $N + M + 1$ multiplications per sample. Every practical IIR digital filter is implemented as an LCCDE, never as a literal convolution.
Initial conditions decide everything
An LCCDE alone does not define a unique system — you must also specify the initial conditions(初始條件)$y[-1], \dots, y[-N]$. The system is LTI and causal only if it is initially at rest(初始鬆弛, initially relaxed): $y[-1] = \dots = y[-N] = 0$. With nonzero initial conditions the system is neither linear nor time-invariant (it violates homogeneity: zero input does not give zero output).
但這只針對「輸入 → 全部輸出」這個映射。總響應永遠可拆成 零輸入響應(zero-input response, ZIR,只由初始條件產生)零狀態響應(zero-state response, ZSR,初始鬆弛下只由輸入產生):$y[n] = y_{\text{zi}}[n] + y_{\text{zs}}[n]$。就算初始條件非零、整體系統不是 LTI,它的零狀態部分($x[n]\to y_{\text{zs}}[n]$)仍然是 LTI 且因果的 —— 這正是可以定義 $h[n]$、用卷積 $y_{\text{zs}}[n]=x[n]*h[n]$ 的原因。非線性只來自那個固定的 ZIR 偏置項。

3.1.2 Recursive vs non-recursive systems

Non-recursive(非遞迴)Recursive(遞迴)
Condition$N = 0$: no feedback terms$N \ge 1$: output feeds back
Form$y[n] = \sum_{k=0}^{M} b_k\,x[n-k]$$y[n] = -\sum_{k=1}^{N} a_k y[n-k] + \sum_{k=0}^{M} b_k x[n-k]$
Impulse responseFinite length $M+1$ → FIRGenerally infinite → IIR
Memory neededPast inputs onlyPast inputs and past outputs
Examplemoving averageaccumulator $y[n]=y[n-1]+x[n]$

A classic non-recursive example is the $L$-point moving average(移動平均), used everywhere for smoothing noisy data:

Moving-average filter $$y[n] = \frac{1}{L}\sum_{k=0}^{L-1} x[n-k]$$
2026-06-12T22:20:00.277402 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ −1 0 1 x[n] Noisy input x[n] underlying cos(2πn/30) 0 10 20 30 40 50 60 n −1.5 −1.0 −0.5 0.0 0.5 1.0 y[n] 5-point moving-average output y[n] (non-recursive FIR)
Fig. 3-1 — A 5-point moving average applied to a noisy cosine. Each output sample averages the 5 most recent inputs, so rapid noise fluctuations cancel while the slow underlying waveform passes through (with a small delay of $(L-1)/2 = 2$ samples).(5 點移動平均:雜訊被平均掉,緩慢變化的訊號保留,輸出整體延遲 2 個樣本。)

3.2 Solving LCCDEs

The direct method(直接法)solves an LCCDE in the time domain by splitting the total solution into two parts:

Total solution structure $$y[n] \;=\; \underbrace{y_c[n]}_{\text{complementary / homogeneous}} \;+\; \underbrace{y_p[n]}_{\text{particular}}$$
求輸出時,直接用遞迴式往前算最保險嗎?(點擊展開)

看你要什麼。直接法($y_c+y_p$)和遞迴前推是兩種目的不同的工具:

只要「有限幾個數值」$y[0], y[1], \dots, y[n_0]$($n_0$ 不大)→ 遞迴前推最保險。只要給了初始條件 $y[-1],\dots,y[-N]$,把 LCCDE 解成遞迴計算式

$$y[n] = \frac{1}{a_0}\!\left(\sum_{k=0}^{M} b_k\,x[n-k] \;-\; \sum_{k=1}^{N} a_k\,y[n-k]\right)$$

從 $n=0$ 一格一格代下去即可。它不用猜特解型式、不用解特徵根、不用聯立求 $C_k$ —— 少掉所有代數出錯點,對遞迴/IIR 系統一樣有效。唯一要小心:初始條件代對、index 不要錯位。

要「任意 $n$ 的封閉解 $y[n]$」或看漸近/穩定行為 → 只能用直接法。遞迴前推只給你一串數值,給不出 symbolic 通式,也看不出 $n\to\infty$ 的趨勢。這時老實走 $y_c[n]+y_p[n]$:特徵方程求根 → 定特解 → 用初始條件解 $C_k$。

實務建議:需要通式就解 $y_c+y_p$,解完再用遞迴前幾項驗算(把 $n=0,1,2$ 代回封閉解,對照遞迴結果是否一致)—— 這是最穩的雙保險。考試若只問某個具體且 $n$ 小的 $y[n_0]$,直接遞迴最快、最不易錯。

3.2.1 Complementary (homogeneous) solution

The complementary solution(齊次解 / 互補解) $y_c[n]$ solves the homogeneous equation — the LCCDE with the input forced to zero:

Homogeneous equation $$\sum_{k=0}^{N} a_k\, y[n-k] = 0$$

Procedure. Assume an exponential trial solution $y[n] = \lambda^{\,n}$. Substituting and dividing out $\lambda^{\,n-N}$ yields the characteristic polynomial(特徵多項式):

Characteristic equation $$\lambda^{N} + a_1 \lambda^{N-1} + a_2 \lambda^{N-2} + \cdots + a_N = 0$$
「代入後約掉 $\lambda^{\,n-N}$」到底在做什麼?(點擊展開)

1. 代入試解。齊次式為 $\sum_{k=0}^{N} a_k\,y[n-k]=0$。把 $y[n]=\lambda^{\,n}$ 代進去,於是 $y[n-k]=\lambda^{\,n-k}$:

$$\sum_{k=0}^{N} a_k\,\lambda^{\,n-k} \;=\; a_0\lambda^{\,n} + a_1\lambda^{\,n-1} + \cdots + a_N\lambda^{\,n-N} \;=\; 0$$

2. 提出最低次幂。每一項都含 $\lambda^{\,n-N}$(最小的指數),把它提出來:

$$\lambda^{\,n-N}\underbrace{\left(a_0\lambda^{N} + a_1\lambda^{N-1} + \cdots + a_N\right)}_{\text{特徵多項式}} \;=\; 0$$

3. 約掉 $\lambda^{\,n-N}$。$\lambda=0$ 是平凡解(對應 $y[n]\equiv0$,沒意義),所以找非零解時 $\lambda^{\,n-N}\neq 0$,可以整條除掉 —— 指數項 $n$ 就此消失,只剩一個純代數方程:

$$a_0\lambda^{N} + a_1\lambda^{N-1} + \cdots + a_N = 0$$

為什麼可以約掉 $\lambda^{\,n-N}$?因為它是「跟 $n$ 有關、但恆不為零」的因子,兩邊同除非零數是合法的。三層理由:

(i) 前提就排除 $\lambda=0$。$\lambda=0$ 給出 $y[n]=0^{\,n}\equiv0$,是沒資訊的平凡解;任何有意義的自然模態都對應 $\lambda\neq0$。

(ii) $\lambda\neq0 \Rightarrow \lambda^{\,n-N}\neq0$(對每個 $n$)。於是第 2 步的式子是「非零 × 某常數 $=0$」:

$$\lambda^{\,n-N}\cdot\underbrace{\big(a_0\lambda^{N}+\cdots+a_N\big)}_{=\,C\ \text{(不含 }n\text{ 的常數)}}=0 \;\Longrightarrow\; C=0$$

(iii) 那個多項式因子完全不含 $n$。$n$ 只出現在被提出來的 $\lambda^{\,n-N}$ 裡;括號那項對所有 $n$ 是同一個常數。既然前面的因子恆不為零,要式子對所有 $n$ 成立,就只能令這個常數 $=0$ —— 這正是「約掉 $\lambda^{\,n-N}$」的真正意思:非零因子不背鍋,責任全丟給那個決定 $\lambda$ 的多項式。

關鍵:這一除,把「對每個 $n$ 都要成立」的差分方程,縮成「只需解出 $\lambda$」的 $N$ 次多項式。再把首項係數正規化($a_0=1$)就得到上面的特徵方程。它的 $N$ 個根 $\lambda_k$ 就是系統的自然模態/極點;每個根貢獻一個 $\lambda_k^{\,n}$ 分量。

With $N$ distinct roots $\lambda_1, \dots, \lambda_N$ (the natural modes / poles of the system):

Complementary solution — distinct roots $$y_c[n] = C_1 \lambda_1^{\,n} + C_2 \lambda_2^{\,n} + \cdots + C_N \lambda_N^{\,n}$$
與 Jordan form 的關係:那些 $n^{m-1}$ 因子從哪來(點擊展開)

把 LCCDE 寫成狀態遞迴 $\mathbf{s}[n+1] = A\,\mathbf{s}[n]$($A$ 為伴隨矩陣 companion matrix),則 $A$ 的特徵值恰好就是特徵根 $\lambda_k$,而 $y[n]$ 完全由 $A^n$ 決定。上面各種模態的形狀,其實就是 $A^n$ 的樣子。

相異根 → 可對角化。$N$ 個相異根時 $A$ 可對角化,$A = P\Lambda P^{-1}$,於是

$$A^n = P\,\Lambda^n P^{-1}, \qquad \Lambda^n = \operatorname{diag}(\lambda_k^{\,n}).$$

得到純粹的模態 $\lambda_k^{\,n}$,沒有任何 $n$ 的多項式前綴——對應上表「distinct roots」那列。

重根 → 缺陷矩陣 defective → Jordan block。某根重複 $m$ 次時,伴隨矩陣少了特徵向量(幾何重數 < 代數重數),無法對角化,只能化為 Jordan block $J = \lambda I + N$($N$ 為冪零矩陣)。此時

$$J^n = \sum_{k=0}^{m-1}\binom{n}{k}\lambda^{\,n-k} N^{k},$$

其中二項式係數 $\binom{n}{k}$ 是 $n$ 的多項式(次數最高 $m-1$)。這正是

$$\lambda^{\,n},\; n\lambda^{\,n},\; n^2\lambda^{\,n},\;\dots,\; n^{m-1}\lambda^{\,n}$$

這一整組模態的來源——你手動補上的 $n^{m-1}$ 因子,本質上就是 Jordan block 的 $\binom{n}{k}$。

共振陷阱其實是隱藏的 Jordan block。把輸入 $\alpha^n$ 看成由一個自己的外生狀態(特徵值 $\alpha$)產生,再與系統疊成一個更大的自治矩陣 $\tilde A$。當 $\alpha = \lambda_k$ 時,這個特徵值的代數重數比特徵向量多一個 → $\tilde A$ 變成缺陷矩陣,冒出一個 $2\times2$ Jordan block,其 $J^n$ 就產生 $n\,\alpha^{\,n}$ 項。所以「試解乘上 $n$」不是憑空規則,而是補上 Jordan 結構所要求的廣義特徵向量 generalized eigenvector 模態。

連續時間完全對應:Jordan block 的重根給出 $t^k e^{\lambda t}$,對應離散的 $n^k \lambda^n$。

2026-06-12T22:19:59.790366 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0.0 2.5 5.0 7.5 10.0 12.5 15.0 n 0.0 0.2 0.4 0.6 0.8 1.0 λⁿ λ = 0.5 (fast decay, stable) 0.0 2.5 5.0 7.5 10.0 12.5 15.0 n 0.0 0.2 0.4 0.6 0.8 1.0 λⁿ λ = 0.9 (slow decay, stable) 0.0 2.5 5.0 7.5 10.0 12.5 15.0 n −0.5 0.0 0.5 1.0 λⁿ λ = −0.8 (alternating, stable) 0.0 2.5 5.0 7.5 10.0 12.5 15.0 n 0 1 2 3 4 λⁿ λ = 1.1 (growing, unstable)
Fig. 3-2 — Natural modes $\lambda^n$ for four characteristic-root values. $|\lambda| < 1$ decays (system memory fades), $\lambda < 0$ alternates sign every sample, and $|\lambda| > 1$ grows without bound — the signature of an unstable system (see §3.5).(特徵根大小決定自然響應:$|\lambda|<1$ 衰減、負根交替變號、$|\lambda|>1$ 發散。)

3.2.2 Particular solution

The particular solution(特解) $y_p[n]$ is any one solution of the full equation with the input present, valid for $n \ge 0$. Assume a form that mimics the input:

Input $x[n]$ (for $n \ge 0$)Assumed particular solution $y_p[n]$
$A$ (constant, e.g. step)$K$
$A\,\alpha^{\,n}$$K\,\alpha^{\,n}$
$A\,n^{p}$$K_0 + K_1 n + \cdots + K_p n^{p}$
$A\cos\omega_0 n$ or $A\sin\omega_0 n$$K_1\cos\omega_0 n + K_2 \sin\omega_0 n$
$A\,\alpha^{\,n}$ where $\alpha$ is a characteristic root$K\,n\,\alpha^{\,n}$ (multiply by $n$)

Substitute the assumed form into the LCCDE and solve for $K$ by matching coefficients.

Resonance trap
若輸入恰好與其中一個自然模態相符($\alpha = \lambda_k$),則單純的猜測 $K\alpha^n$ 會失效——它本身已滿足齊次方程,代入後得到 $0 = \text{某值}$。此時將試解乘上 $n$(若為雙重重合則再乘 $n^2$),做法與微分方程中完全相同。
共振陷阱範例:為什麼要乘 $n$(點擊展開)

考慮一階系統,輸入的底數 $\alpha = 3$ 剛好等於特徵根 $\lambda = 3$:

$$y[n] - 3\,y[n-1] = 3^{\,n}, \qquad n \ge 0.$$

先看錯誤的猜測 $y_p[n] = K\,3^{\,n}$。代入左式:

$$K\,3^{\,n} - 3\!\cdot\! K\,3^{\,n-1} = K\,3^{\,n} - K\,3^{\,n} = 0 .$$

但右式是 $3^{\,n}\neq 0$,於是得到矛盾 $0 = 3^{\,n}$——這就是「$0 = \text{某值}$」。原因是 $3^{\,n}$ 本身就是自然模態,已滿足齊次方程 $y[n]-3y[n-1]=0$,永遠打不出非零的右式。

正確做法:乘上 $n$,試 $y_p[n] = K\,n\,3^{\,n}$。代入:

$$K\,n\,3^{\,n} - 3\!\cdot\! K\,(n\!-\!1)\,3^{\,n-1} = K\,3^{\,n}\big[\,n-(n\!-\!1)\,\big] = K\,3^{\,n}.$$

令其等於右式 $3^{\,n}$,得 $K = 1$,故特解為

$$\boxed{\,y_p[n] = n\,3^{\,n}\,}.$$

多出來的因子 $n$ 讓試解「跳出」齊次解的空間,代入後才會殘留非零項來對應輸入。若特徵根為雙重根($\lambda$ 重複兩次)且輸入又是同一個模態,則要乘 $n^2$;一般而言重合 $m$ 重就乘 $n^m$。這與微分方程中遇到重根/共振時乘 $t$、$t^2$ 的規則完全對應。

3.2.3 Total solution recipe

LCCDE solving summary(解題流程)
  1. Write the characteristic equation; find roots $\lambda_1,\dots,\lambda_N$ → form $y_c[n]$ with unknown $C_k$.
  2. Assume $y_p[n]$ from the input-form table; substitute into the LCCDE to fix its constants.
  3. Write $y[n] = y_c[n] + y_p[n]$, valid for $n \ge 0$.
  4. Generate $y[0], y[1], \dots, y[N-1]$ by iterating the recursion itself from the given $y[-1],\dots,y[-N]$.
  5. Match these values against step 3 to solve for $C_1,\dots,C_N$.
直觀解釋(點擊展開)
把 LCCDE 想成一個有「個性」的系統:齊次解 $y_c[n]$ 是系統的本性(自然響應),完全由特徵根決定,跟輸入無關;特解 $y_p[n]$ 是系統被輸入強迫出來的反應(強迫響應),形狀跟著輸入走。常數 $C_k$ 最後才用初始條件決定,是因為初始條件作用在「總和」上,不是只作用在齊次解上——這是最常見的計算錯誤。求 $y[0], y[1]$ 時直接用遞迴式往前算最保險。

3.2.4 Worked example

Example 3.1 — Second-order LCCDE with a step input

Solve, for $n \ge 0$:

$$y[n] + y[n-1] - 12\,y[n-2] = x[n], \qquad x[n] = 10\,u[n], \qquad y[-1] = -1,\;\; y[-2] = -\tfrac12 .$$
Step 1 — characteristic roots. $\lambda^2 + \lambda - 12 = 0 \Rightarrow (\lambda+4)(\lambda-3)=0 \Rightarrow \lambda_1 = -4,\ \lambda_2 = 3$. So $y_c[n] = C_1(-4)^n + C_2\, 3^n$.
Step 2 — particular solution. The input is a constant $10$ for $n\ge 0$, so try $y_p[n] = K$: $$K + K - 12K = 10 \;\Rightarrow\; -10K = 10 \;\Rightarrow\; K = -1 .$$
Step 3 — total form. $y[n] = C_1(-4)^n + C_2\,3^n - 1$ for $n \ge 0$.
Step 4 — iterate the recursion for $y[0], y[1]$. Using $y[n] = x[n] - y[n-1] + 12y[n-2]$: $$\begin{aligned} y[0] &= 10 - y[-1] + 12\,y[-2] = 10 + 1 - 6 = 5\\ y[1] &= 10 - y[0] + 12\,y[-1] = 10 - 5 - 12 = -7 \end{aligned}$$
Step 5 — match constants. $$\begin{aligned} n=0:&\quad C_1 + C_2 - 1 = 5 &&\Rightarrow\; C_1 + C_2 = 6\\ n=1:&\quad -4C_1 + 3C_2 - 1 = -7 &&\Rightarrow\; -4C_1 + 3C_2 = -6 \end{aligned}$$ Solving: $C_1 = \tfrac{24}{7}$, $C_2 = \tfrac{18}{7}$.
Result. $$\boxed{\,y[n] = \tfrac{24}{7}(-4)^n + \tfrac{18}{7}\,3^n - 1, \qquad n \ge 0\,}$$ Check by recursion: $y[2] = 10 - (-7) + 12(5) = 77$, and the formula gives $\tfrac{24}{7}(16) + \tfrac{18}{7}(9) - 1 = \tfrac{546}{7} - 1 = 77$. ✓
MATLAB check
This exact system is what filter/filtic simulate: a = [1 1 -12]; b = 1; zi = filtic(b,a,[-1 -0.5]); y = filter(b,a,10*ones(1,5),zi) returns 5  -7  77  -151  1085 — matching the closed form. Exercise 3 repeats this workflow on the homework system.

3.3 Zero-Input and Zero-State Response

The same total response can be split a different way, by cause instead of by mathematical form:

Zero-input / zero-state decomposition $$y[n] \;=\; \underbrace{y_{zi}[n]}_{\substack{\text{zero-input response}\\ \text{ICs act, } x[n]=0}} \;+\; \underbrace{y_{zs}[n]}_{\substack{\text{zero-state response}\\ \text{ICs}=0,\ x[n] \text{ acts}}}$$

考試常考:給了非零初始條件的系統不是 LTI(線性性與時不變性會被初始狀態破壞),但它的零狀態部分 $y_{zs}[n]$ 才是 LTI——唯有在初始條件全為零(系統靜止)時,系統才滿足 $y_{zs}[n] = x[n]*h[n]$ 這個卷積關係。

yzi ≠ yc in general
Zero-input vs zero-state is not the same split as complementary vs particular. Both $y_{zi}$ and $y_{zs}$ contain natural-mode terms $\lambda_k^n$; only their constants differ. The identities are: $y_c = y_{zi} + (\text{mode part of } y_{zs})$ and $y_p = (\text{forced part of } y_{zs})$.
Example 3.2 — Decomposing Example 3.1
Zero-input part — solve $y[n]+y[n-1]-12y[n-2]=0$ with $y[-1]=-1$, $y[-2]=-\tfrac12$. Write $y_{zi}[n] = C_1(-4)^n + C_2 3^n$ and impose the conditions at $n=-1,-2$: $$-\tfrac{C_1}{4} + \tfrac{C_2}{3} = -1, \qquad \tfrac{C_1}{16} + \tfrac{C_2}{9} = -\tfrac12 \;\;\Rightarrow\;\; C_1 = -\tfrac{8}{7},\;\; C_2 = -\tfrac{27}{7}$$ $$y_{zi}[n] = -\tfrac{8}{7}(-4)^n - \tfrac{27}{7}\,3^n$$
Zero-state part — same input $10u[n]$ but rest conditions $y[-1]=y[-2]=0$. Then $y_{zs}[0] = 10$, $y_{zs}[1] = 10 - 10 = 0$, and with $y_{zs}[n] = D_1(-4)^n + D_2 3^n - 1$: $$D_1 + D_2 = 11, \qquad -4D_1 + 3D_2 = 1 \;\;\Rightarrow\;\; D_1 = \tfrac{32}{7},\;\; D_2 = \tfrac{45}{7}$$ $$y_{zs}[n] = \tfrac{32}{7}(-4)^n + \tfrac{45}{7}\,3^n - 1$$
Check. $y_{zi} + y_{zs} = \left(-\tfrac{8}{7}+\tfrac{32}{7}\right)(-4)^n + \left(-\tfrac{27}{7}+\tfrac{45}{7}\right)3^n - 1 = \tfrac{24}{7}(-4)^n + \tfrac{18}{7}3^n - 1$ — exactly Example 3.1. ✓
直觀解釋(點擊展開)
零輸入/零狀態是按「能量來源」分:$y_{zi}$ 是系統裡原本存的能量(初始條件)自己放出來的反應;$y_{zs}$ 是外部輸入打進來造成的反應。因為系統是線性的,兩個原因可以分開算再相加(疊加原理)。注意只有 $y_{zs}$ 才等於 $x[n]*h[n]$ ——卷積描述的是「初始鬆弛」系統。考試常考:給初始條件的系統不是 LTI,但它的零狀態部分是。

3.4 Impulse Response of LCCDEs (線性常係數差分方程的脈衝響應)

3.4.1 Impulse response from a difference equation

The impulse response is the zero-state response to $x[n] = \delta[n]$. For a recursive LCCDE, the simplest route is to iterate the recursion with rest initial conditions; for low orders the closed form follows from the natural modes, since for $n > M$ the input terms vanish and $h[n]$ must be a pure combination of modes:

Impulse response of a causal LCCDE (distinct roots, n > M) $$h[n] = \sum_{k=1}^{N} C_k\, \lambda_k^{\,n}$$
Example 3.3 — First-order recursive system

$y[n] = a\,y[n-1] + x[n]$, initially at rest, $x[n]=\delta[n]$.

Iterate: $h[0] = a\cdot 0 + 1 = 1$,   $h[1] = a\cdot 1 = a$,   $h[2] = a^2$, …
Result: $\;\boxed{h[n] = a^{\,n} u[n]}\;$ — one natural mode $\lambda = a$, infinitely long: this single feedback tap creates an IIR system.
2026-06-12T22:19:59.229919 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 5 10 15 20 n 0.0 0.2 0.4 0.6 0.8 1.0 h[n] Impulse response h[n] = (0.8)ⁿ u[n] 0 5 10 15 20 n 0 1 2 3 4 5 s[n] Step response → steady state 1/(1−0.8) = 5
Fig. 3-3 — Impulse response $h[n]=(0.8)^n u[n]$ and step response of $y[n] = 0.8\,y[n-1] + x[n]$, computed with scipy.signal.lfilter. The step response is the running sum of $h[n]$ and settles to $\sum_n h[n] = \frac{1}{1-0.8} = 5$.(一階遞迴系統:脈衝響應呈幾何衰減,步階響應收斂到直流增益 5。)

3.4.2 FIR vs IIR

The structure of the LCCDE determines the impulse-response length:

FIR — Finite Impulse Response(有限脈衝響應)IIR — Infinite Impulse Response(無限脈衝響應)
LCCDE$N = 0$ (non-recursive)$N \ge 1$ (recursive)
Impulse response$h[n] = b_n$ for $0 \le n \le M$, else $0$ — length $M+1$combination of modes $\lambda_k^n$, lasts forever
Stabilityalways BIBO stablestable iff all $|\lambda_k| < 1$
Implementationconvolution = the LCCDE itselfmust use recursion (convolution would never end)
Memory of the pastexactly $M$ samplesfading but unlimited
Read h[n] directly off a non-recursive LCCDE
For $y[n] = \sum_{k=0}^{M} b_k\,x[n-k]$, substituting $x = \delta$ gives $h[n] = \sum_k b_k \delta[n-k]$, i.e. the coefficients are the impulse response: $h = \{b_0, b_1, \dots, b_M\}$. Example: the 5-point moving average has $h[n] = \tfrac15$ for $0 \le n \le 4$.
Recursive ≠ IIR in every case
Recursive implementation and infinite impulse response usually go together, but not always: $y[n] = y[n-1] + \tfrac{1}{L}\big(x[n] - x[n-L]\big)$ is a recursive way to compute the FIR moving average. The honest statement: $N\ge 1$ generally gives IIR, unless pole-zero cancellation occurs.

3.5 Stability

A system is BIBO stable(有界輸入有界輸出穩定) if every bounded input produces a bounded output: $|x[n]| \le B_x < \infty$ for all $n$ implies $|y[n]| \le B_y < \infty$ for all $n$.

For an LTI system, $|y[n]| = \big|\sum_k h[k]x[n-k]\big| \le B_x \sum_k |h[k]|$, which yields the complete characterization:

BIBO stability ⇔ absolutely summable impulse response $$S \;=\; \sum_{k=-\infty}^{\infty} \big|h[k]\big| \;<\; \infty$$

The condition is also necessary: if $S = \infty$, the bounded "worst-case" input $x[n] = \operatorname{sgn}\!\big(h[-n]\big)$ makes $y[0] = \sum_k |h[k]|$ blow up.

Example 3.4 — Stability of h[n] = aⁿu[n]
$\displaystyle S = \sum_{n=0}^{\infty} |a|^n = \frac{1}{1-|a|}$ when $|a| < 1$ (finite → stable); the geometric series diverges when $|a| \ge 1$ (unstable — note $|a|=1$ is also unstable: a step input into the accumulator $y[n]=y[n-1]+x[n]$ grows like $n$).
Stability of causal LCCDE systems(特徵根判穩)
Because $h[n]$ is built from the natural modes $\lambda_k^{\,n}$, a causal LCCDE system is BIBO stable iff every characteristic root lies strictly inside the unit circle: $$|\lambda_k| < 1 \quad \text{for all } k=1,\dots,N.$$ Compare Fig. 3-2: the $\lambda = 1.1$ mode grows without bound — one bad root ruins the whole system. (In Chapter 5's z-transform language, the $\lambda_k$ are the poles.)
Quick second-order check
For $\lambda^2 + a_1\lambda + a_2 = 0$, both roots are inside the unit circle iff $|a_2| < 1$ and $|a_1| < 1 + a_2$ (the stability triangle). Example 3.1 has $a_1 = 1, a_2 = -12$: $|a_2| = 12 \ge 1$ → unstable, consistent with its roots $-4$ and $3$.
跟數位控制(Digital Control)有什麼關係?(點擊展開)

這一整章其實就是數位控制器的數學本體。對應關係:

1. LCCDE = 數位控制器本身。數位控制器 $D(z)$ 落到硬體(MCU / DSP / FPGA)上執行時,就是一條差分方程的遞迴計算式:

$$u[n] = -\sum_{k=1}^{N} a_k\,u[n-k] + \sum_{k=0}^{M} b_k\,e[n-k]$$

每個取樣時刻拿過去的 $u$、$e$ 算出當前輸出 $u[n]$ —— 正是 §3.1 的 recursive computational form。數位 PID(position / velocity form)就是這個。

2. 特徵根 $\lambda_k$ = z 平面的極點。本節「特徵根判穩」的 $\lambda_k$,換到第 5 章 z-transform 語言就寫成極點 $z_k$。連續系統看「極點在左半平面($\operatorname{Re}<0$)」;離散/數位系統看「極點在單位圓內($|\lambda_k|<1$)」 —— 兩者由 $z=e^{sT}$ 對映。這裡的 BIBO 穩定條件,就是數位控制的閉迴路穩定條件。

用 s domain 一起看:模態的取樣就是 $z=e^{sT}$ 的由來。

連續系統的自然模態是 $e^{s_k t}$($s_k$ 是 Laplace/s 平面的極點)。以週期 $T$ 取樣,令 $t=nT$:

$$e^{s_k t}\Big|_{t=nT} = \big(e^{s_k T}\big)^{n} = \lambda_k^{\,n}, \qquad \boxed{\;\lambda_k = e^{s_k T}\;}$$

所以本章的離散模態 $\lambda_k^{\,n}$ 就是連續模態 $e^{s_k t}$ 的取樣版,$s$ 平面極點與 $z$ 平面極點由 $z=e^{sT}$ 一一對映。穩定區域也跟著搬:

s 平面(連續) $z=e^{sT}$ → z 平面(數位) 模態行為
左半平面 $\operatorname{Re}(s)<0$ 單位圓內 $|\lambda|<1$ 衰減 → 穩定
虛軸 $\operatorname{Re}(s)=0$ 單位圓上 $|\lambda|=1$ 臨界 / 等幅振盪
右半平面 $\operatorname{Re}(s)>0$ 單位圓外 $|\lambda|>1$ 發散 → 不穩定

因此「s 平面看左半平面、z 平面看單位圓內」講的是同一件事 —— $e^{sT}$ 把「$\operatorname{Re}(s)<0$」這個左半平面直接彎成單位圓的內部。附帶一提:$s$ 的虛部(頻率 $\omega$)對映成 $\lambda$ 的輻角 $\omega T$,而 $\omega$ 每增加 $2\pi/T$ 就繞單位圓一圈回到原點 —— 這個「多對一」正是取樣的頻疊(aliasing),也是 z domain 只需看主圓、不需看整條 s 軸的原因。

3. 齊次解/特解 = 暫態/穩態。$y_c[n]$(自然模態 $\lambda_k^{\,n}$)= transient response,$y_p[n]$= steady-state。控制器設計的極點配置(pole placement)本質就是「選 $\lambda_k$ 擺哪裡」,決定衰減快慢、有無振盪。

4. 閉迴路。受控體經 ZOH+取樣得到 $G(z)$,配上控制器 $D(z)$,閉迴路特徵方程 $1+D(z)G(z)=0$ 的根=閉迴路極點,決定整個系統響應。

一句話:這章教你「解一條差分方程 + 判極點穩定」;數位控制課就是拿這套去「設計那條差分方程,把極點擺進單位圓」。

3.6 Block Diagram Realizations

An LCCDE maps directly to hardware/software using three primitive elements(三種基本元件):

Writing the second-order LCCDE in computational form,

Second-order direct form $$y[n] = b_0\,x[n] + b_1\,x[n-1] + b_2\,x[n-2] \;-\; a_1\,y[n-1] - a_2\,y[n-2]$$

and drawing one branch per term gives the Direct Form I(直接 I 型) realization — a feed-forward tapped delay line on the input plus a feedback tapped delay line on the output:

x[n] b₀ z⁻¹ x[n−1] b₁ z⁻¹ x[n−2] b₂ + + + y[n] z⁻¹ y[n−1] −a₁ z⁻¹ y[n−2] −a₂ feed-forward (zeros, bₖ) feedback (poles, −aₖ)
Fig. 3-4 — Direct Form I realization of $y[n] = b_0 x[n] + b_1 x[n-1] + b_2 x[n-2] - a_1 y[n-1] - a_2 y[n-2]$. Left delay line stores past inputs (feed-forward taps $b_k$); right delay line stores past outputs (feedback taps $-a_k$). Total: $N+M = 4$ delays.(直接 I 型:左邊延遲線存過去輸入、右邊存過去輸出,共 4 個延遲器。)
Direct Form II preview
Because LTI blocks in cascade commute, the feedback half can be moved before the feed-forward half; the two delay lines then carry the identical internal signal $w[n]$ and can be shared, cutting the delays from $N+M$ to $\max(N,M)$ (the canonical Direct Form II). Chapter on filter structures develops this fully — here it is enough to know the trick exists and why it works.
Sign trap when reading coefficients
MATLAB's filter(b, a, x) uses the LCCDE written with all $y$ terms on the left: $\sum a_k y[n-k] = \sum b_k x[n-k]$. The multipliers in the feedback branches of the block diagram are therefore $-a_1, -a_2$ (negated!). Forgetting this sign flip is the single most common block-diagram error.

3.7 Correlation

Correlation(相關) measures the degree of similarity between two sequences as a function of relative time shift. It is the standard tool for detecting a known waveform inside noise (radar, sonar, GPS), estimating time delays, and finding hidden periodicity.

3.7.1 Cross-correlation and its relation to convolution

Cross-correlation(互相關)of energy signals $$r_{xy}[\ell] \;=\; \sum_{n=-\infty}^{\infty} x[n]\, y[n-\ell], \qquad \ell = 0, \pm 1, \pm 2, \dots$$

The integer $\ell$ is the lag(延遲): $r_{xy}[\ell]$ asks "how much does $x$ look like $y$ shifted right by $\ell$?" Reversing the roles only mirrors the lag axis:

Order swap $$r_{xy}[\ell] = r_{yx}[-\ell]$$

Comparing with the convolution sum shows correlation is convolution with one sequence time-reversed — so all convolution machinery applies:

Correlation via convolution $$r_{xy}[\ell] \;=\; x[\ell] * y[-\ell]$$
Convolution vs correlation — the only difference is the flip
Convolution folds (time-reverses) one signal before sliding; correlation slides without folding. For a sequence symmetric about some point (like the windowed cosine in Exercise 4), convolution and correlation give the same shape up to a shift — that is why matched filters can be built as convolvers.

3.7.2 Autocorrelation properties

The autocorrelation(自相關) is the correlation of a signal with itself, $r_{xx}[\ell] = \sum_n x[n]\,x[n-\ell]$. Its key properties:

Autocorrelation properties $$r_{xx}[0] = \sum_{n}x^2[n] = E_x, \qquad r_{xx}[-\ell] = r_{xx}[\ell], \qquad \big|r_{xx}[\ell]\big| \le r_{xx}[0]$$

and for the cross-correlation the Cauchy–Schwarz bound gives $\big|r_{xy}[\ell]\big| \le \sqrt{r_{xx}[0]\,r_{yy}[0]} = \sqrt{E_x E_y}$. Dividing by the bound yields the normalized correlation(正規化相關係數), handy because it is scale-free:

Normalized (auto/cross) correlation $$\rho_{xx}[\ell] = \frac{r_{xx}[\ell]}{r_{xx}[0]}, \qquad \rho_{xy}[\ell] = \frac{r_{xy}[\ell]}{\sqrt{r_{xx}[0]\,r_{yy}[0]}}, \qquad |\rho| \le 1$$
The maximum is always at zero lag
A signal can never match a shifted copy of itself better than it matches itself unshifted: $r_{xx}[\ell]$ peaks at $\ell = 0$, where it equals the signal energy. In delay-estimation problems, the location of the peak of $r_{xy}[\ell]$ is the delay estimate.

3.7.3 Autocorrelation of periodic sequences

Periodic (power) signals have infinite energy, so the sum is replaced by a time average. For $x[n]$ periodic with period $N$:

Autocorrelation of a power / periodic signal $$r_{xx}[\ell] = \lim_{M\to\infty} \frac{1}{2M+1}\sum_{n=-M}^{M} x[n]\,x[n-\ell] \;\;=\;\; \frac{1}{N}\sum_{n=0}^{N-1} x[n]\,x[n-\ell]$$
Periodicity survives correlation — noise does not
If $x[n]$ is periodic with period $N$, then $r_{xx}[\ell]$ is also periodic with period $N$, showing peaks at $\ell = 0, \pm N, \pm 2N, \dots$ Meanwhile white noise $w[n]$ is uncorrelated with itself at any nonzero shift, so its autocorrelation collapses to a spike at $\ell=0$. For a noisy observation $y[n] = x[n] + w[n]$, away from $\ell = 0$ we get $r_{yy}[\ell] \approx r_{xx}[\ell]$ — the periodic structure pops out of the noise.
2026-06-12T22:20:00.561023 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 10 20 30 40 50 60 n −2 0 2 x[n] Noisy periodic signal x[n] = cos(2πn/16) + w[n] (first 64 samples) −40 −20 0 20 40 lag ℓ −0.5 0.0 0.5 1.0 1.5 rₓₓ[ℓ] Autocorrelation rₓₓ[ℓ] — peaks repeat every ℓ = 16 ⇒ period recovered
Fig. 3-5 — Top: a cosine of period 16 buried in heavy noise (the period is barely visible by eye). Bottom: its autocorrelation shows clean repeating peaks at lags $0, \pm16, \pm32, \pm48$ — the hidden period recovered. The extra spike at $\ell=0$ is the noise energy.(自相關把藏在雜訊裡的週期挖出來:峰值間隔 = 週期 16;$\ell=0$ 多出來的尖峰是雜訊能量。)

3.7.4 Correlation in action

The canonical application is radar/sonar delay estimation(雷達延遲估測): transmit $x[n]$, receive an attenuated, delayed, noisy echo

Radar receive model $$y[n] = \alpha\, x[n-D] + w[n]$$

Cross-correlating receive with transmit gives $r_{yx}[\ell] = \alpha\, r_{xx}[\ell - D] + r_{wx}[\ell]$. Since $r_{xx}$ peaks at zero lag and the noise term is small, $r_{yx}[\ell]$ peaks at $\ell = D$ — read off the round-trip delay, hence target range. The same idea underlies GPS code acquisition and pattern matching.

直觀解釋(點擊展開)
相關就是「滑動內積」:把 $y$ 平移 $\ell$ 格後跟 $x$ 逐點相乘再加總。兩個訊號形狀對齊時,正的對正、負的對負,乘積全是正的,加起來最大——所以峰值位置就是「對齊所需的平移量」。雷達就是用這招:回波跟發射波最像的那個延遲 $D$,乘上波速除以 2 就是目標距離。跟卷積的差別只有一個:卷積要先把訊號左右翻轉,相關不翻。

3.8 Chapter Summary

LCCDE
$\sum_{k=0}^{N} a_k y[n-k] = \sum_{k=0}^{M} b_k x[n-k]$. LTI + causal only when initially at rest. $N\ge1$: recursive; $N=0$: non-recursive.
Solution recipe
$y = y_c + y_p$: roots of $\lambda^N + a_1\lambda^{N-1}+\dots+a_N=0$ give $y_c = \sum C_k\lambda_k^n$; guess $y_p$ from input form; fix $C_k$ last using $y[0..N\!-\!1]$ from the recursion.
Zero-input / zero-state
$y = y_{zi} + y_{zs}$: ICs alone vs input alone. Only $y_{zs} = x*h$. Different split from $y_c + y_p$ — both pieces contain natural modes.
FIR vs IIR
Non-recursive ⇒ $h = \{b_0,\dots,b_M\}$, finite, always stable. Recursive ⇒ $h$ built from $\lambda_k^n$, infinite, stable iff all $|\lambda_k|<1$.
Stability
BIBO ⇔ $\sum|h[k]| < \infty$ ⇔ (causal LCCDE) every characteristic root strictly inside the unit circle. $h=a^nu[n]$: stable iff $|a|<1$.
Correlation
$r_{xy}[\ell] = \sum_n x[n]y[n-\ell] = x[\ell]*y[-\ell]$. $r_{xx}$: even, max $= E_x$ at $\ell=0$; periodic signal ⇒ periodic $r_{xx}$. Peak of $r_{yx}$ locates delay $D$.

Exercises

All four problems of ICE503 DSP Homework #3, fully worked.

Exercise 1 — Stability of four systems

Problem: For each of the following systems, determine whether the system is stable.

(a) $y[n] = \cos\big(x[n]\big)$    (b) $y[n] = r^{\,n} x[n],\; r > 1$    (c) $y[n] = n\,x[n]$    (d) $y[n] = \dfrac{1}{n}\,x[n]$

Click to reveal solution

BIBO test: assume $|x[n]| \le B_x < \infty$ for all $n$ and check whether $|y[n]|$ must stay bounded. These are not LTI systems, so we argue directly from the definition (the $\sum|h|$ test does not apply).

(a) $y[n] = \cos(x[n])$ — STABLE. The cosine of any real number lies in $[-1,1]$, so for every input (bounded or not!) $|y[n]| \le 1$. Bounded output guaranteed → stable.

(b) $y[n] = r^n x[n]$, $r>1$ — UNSTABLE. Counterexample: the bounded input $x[n] = u[n]$ ($B_x = 1$) gives $y[n] = r^n$ for $n \ge 0$, and since $r > 1$, $r^n \to \infty$. No finite $B_y$ exists → unstable. (The time-varying gain $r^n$ is itself unbounded.)

(c) $y[n] = n\,x[n]$ — UNSTABLE. Counterexample: $x[n] = u[n]$ gives $y[n] = n \to \infty$. The gain $|n|$ grows without bound, so a constant input is amplified without limit → unstable.

(d) $y[n] = \frac{1}{n} x[n]$ — STABLE. For every $n \ne 0$, $\big|\tfrac{1}{n}\big| \le 1$, hence $$|y[n]| = \frac{|x[n]|}{|n|} \le |x[n]| \le B_x .$$ The output bound $B_y = B_x$ works for all bounded inputs → stable. (At $n = 0$ the rule $1/n$ is undefined; the system is understood as defined for $n \ne 0$, or with $y[0] := 0$ — either way the bound holds. Contrast with (c): here the gain shrinks with $|n|$ instead of growing.)

Pattern
For memoryless time-varying systems $y[n] = g[n]\,x[n]$, BIBO stability ⇔ the gain sequence $g[n]$ is bounded: (a) gain effect $\le 1$ ✓, (b) $r^n$ unbounded ✗, (c) $n$ unbounded ✗, (d) $1/n$ bounded by 1 ✓.
Exercise 2 — Solve the LCCDE with initial conditions

Problem: An LTI system is described by $$y[n] + 2y[n-1] - 8y[n-2] = 80\,x[n]$$ with initial conditions $y[-1] = -8$, $y[-2] = -9$. If the input is $x[n] = u[n]$, determine $y[n]$ for $n \ge 0$.

Click to reveal solution

Step 1 — complementary solution. Characteristic equation from $y[n]+2y[n-1]-8y[n-2]=0$ with trial $y=\lambda^n$:

$$\lambda^2 + 2\lambda - 8 = 0 \;\Rightarrow\; (\lambda + 4)(\lambda - 2) = 0 \;\Rightarrow\; \lambda_1 = -4,\;\; \lambda_2 = 2$$

so $y_c[n] = C_1(-4)^n + C_2\,2^n$.

Step 2 — particular solution. For $n \ge 0$ the input is the constant $x[n] = 1$, so try $y_p[n] = K$:

$$K + 2K - 8K = 80 \;\Rightarrow\; -5K = 80 \;\Rightarrow\; K = -16$$

Step 3 — total solution form.

$$y[n] = C_1(-4)^n + C_2\,2^n - 16, \qquad n \ge 0$$

Step 4 — get $y[0], y[1]$ from the recursion $y[n] = 80\,x[n] - 2y[n-1] + 8y[n-2]$:

$$\begin{aligned} y[0] &= 80(1) - 2y[-1] + 8y[-2] = 80 + 16 - 72 = 24\\ y[1] &= 80(1) - 2y[0] + 8y[-1] = 80 - 48 - 64 = -32 \end{aligned}$$

Step 5 — solve for the constants.

$$\begin{aligned} n=0:&\quad C_1 + C_2 - 16 = 24 &&\Rightarrow\; C_1 + C_2 = 40\\ n=1:&\quad -4C_1 + 2C_2 - 16 = -32 &&\Rightarrow\; -2C_1 + C_2 = -8 \end{aligned}$$

Subtracting: $3C_1 = 48 \Rightarrow C_1 = 16$, then $C_2 = 24$.

Answer $$\boxed{\;y[n] = 16(-4)^n + 24\,(2)^n - 16, \qquad n \ge 0\;}$$

Verification by recursion: the formula gives $y[2] = 16(16)+24(4)-16 = 336$ and the recursion gives $y[2] = 80 - 2(-32) + 8(24) = 80+64+192 = 336$. ✓ Similarly $y[3] = -848$, $y[4] = 4464$ both ways.

Remark: the roots $-4$ and $2$ lie outside the unit circle, so this system is unstable — the response grows without bound even for the bounded step input, exactly as the numbers show.

Exercise 3 — MATLAB: implement the LCCDE three ways

Problem: MATLAB simulation of the system in Exercise 2, $y[n] + 2y[n-1] - 8y[n-2] = 80x[n]$, $x[n]=u[n]$, $y[-1]=-8$, $y[-2]=-9$:

(a) Implement the LCCDE (closed form) and determine $y[n]$ for $0 \le n \le 4$.
(b) Use a for loop to implement the recursion and determine $y[n]$ for $0 \le n \le 4$.
(c) Use filtic and filter to determine $y[n]$ for $0 \le n \le 4$. All three results must agree.

Click to reveal solution

All three methods must reproduce $y[n] = 16(-4)^n + 24\,(2)^n - 16$ from Exercise 2, i.e.

$$y[0..4] = \{\,24,\; -32,\; 336,\; -848,\; 4464\,\}.$$
clc; clear;

% LCCDE: y[n] + 2y[n-1] - 8y[n-2] = 80 x[n]
a = [1, 2, -8];          % output-side coefficients [a0 a1 a2]
b = 80;                  % input-side coefficient
x = ones(1, 5);          % x[n] = u[n] for 0 <= n <= 4
y_m1 = -8;               % y[-1]
y_m2 = -9;               % y[-2]

% (a) closed-form solution from Exercise 2
n = 0:4;
y_closed = 16*(-4).^n + 24*2.^n - 16;
disp('(a) closed form:');  disp(y_closed);

% (b) direct recursion with a for loop
y = zeros(1, 5);
for k = 1:5
    if k == 1          % n = 0: use y[-1], y[-2]
        y(k) = b*x(k) - a(2)*y_m1   - a(3)*y_m2;
    elseif k == 2      % n = 1: use y[0], y[-1]
        y(k) = b*x(k) - a(2)*y(k-1) - a(3)*y_m1;
    else               % n >= 2
        y(k) = b*x(k) - a(2)*y(k-1) - a(3)*y(k-2);
    end
end
disp('(b) for loop:');  disp(y);

% (c) filtic + filter
zi = filtic(b, a, [-8, -9]);     % past outputs [y(-1), y(-2)]
y_filt = filter(b, a, x, zi);
disp('(c) filtic + filter:');  disp(y_filt);

Output (identical for all three):

(a) closed form:    24   -32   336   -848   4464
(b) for loop:       24   -32   336   -848   4464
(c) filtic + filter: 24   -32   336   -848   4464

How each method works:

  • (a) evaluates the analytic solution — no recursion, valid for any $n$ directly.
  • (b) marches the recursion $y[n] = 80x[n] - 2y[n-1] + 8y[n-2]$ forward sample by sample; the first two iterations reach back into the initial conditions.
  • (c) filtic(b, a, [y(-1) y(-2)]) converts the past outputs into the equivalent internal delay-line state zi of the Direct-Form filter, and filter(b, a, x, zi) then runs the same recursion in optimized form. With no zi, filter assumes a system at rest — it would compute only the zero-state response.

Result regenerated numerically (Python scipy.signal.lfilter + lfiltic, the exact analogues of filter/filtic):

2026-06-12T22:20:00.743164 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 1 2 3 4 n −2000 −1000 0 1000 2000 3000 4000 5000 y[n] 24 -32 336 -848 4464 y[n] for 0 ≤ n ≤ 4 (for-loop, filter/filtic and closed form all agree)
Fig. 3-E1 — $y[n]$ for $0\le n \le 4$: the for-loop recursion, filter/filtic, and the closed form $16(-4)^n + 24\cdot 2^n - 16$ coincide exactly. The alternating, exploding values betray the unstable roots $-4$ and $2$.(三種算法完全一致;數值正負交替且快速放大,反映不穩定的特徵根。)
Exercise 4 — MATLAB: autocorrelation of a windowed sinusoid

Problem: MATLAB simulation:

(a) Generate the sinusoidal signal $$x[n] = \begin{cases} \cos\!\big(\tfrac{1}{5}\pi n\big), & -5 \le n \le 5\\[2pt] 0, & -10 \le n < -5 \;\text{ and }\; 5 < n \le 10 \end{cases}$$ (b) Use the stem function to plot the autocorrelation of $x[n]$.

Click to reveal solution

The autocorrelation of the finite-energy sequence is $r_{xx}[\ell] = \sum_n x[n]\,x[n-\ell]$, computed for lags $-20 \le \ell \le 20$ (a length-21 sequence has $2\cdot 21 - 1 = 41$ correlation lags).

clc; clear;

% (a) generate the windowed cosine on -10 <= n <= 10
n = -10:10;
x = zeros(1, length(n));
for i = 1:length(n)
    if abs(n(i)) <= 5
        x(i) = cos((1/5)*pi*n(i));
    end                          % else: stays 0
end

% (b) autocorrelation r_xx[l] = sum_n x[n] x[n-l]
lags = -(length(n)-1) : (length(n)-1);
r = zeros(1, length(lags));
for k = 1:length(lags)
    s = 0;
    for i = 1:length(x)
        j = i + lags(k);                 % index of x[n - l] (shifted copy)
        if j >= 1 && j <= length(x)      % keep index inside the array
            s = s + x(i) * x(j);
        end
    end
    r(k) = s;
end
% one-line check: r = xcorr(x);  gives the same 41 values

figure;
subplot(2,1,1);
stem(n, x, 'filled'); grid on;
title('x[n] = cos(\pi n/5),  |n| \leq 5'); xlabel('n'); ylabel('x[n]');
subplot(2,1,2);
stem(lags, r, 'filled'); grid on;
title('Autocorrelation r_{xx}[l]'); xlabel('lag l'); ylabel('r_{xx}[l]');

Result regenerated numerically (Python numpy.correlate(x, x, 'full')):

2026-06-12T22:20:00.973020 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ −10.0 −7.5 −5.0 −2.5 0.0 2.5 5.0 7.5 10.0 n −1.0 −0.5 0.0 0.5 1.0 x[n] x[n] = cos(πn/5) for |n| ≤ 5, else 0 −20 −15 −10 −5 0 5 10 15 20 lag ℓ −4 −2 0 2 4 6 rₓₓ[ℓ] Autocorrelation rₓₓ[ℓ] (even, maximum at ℓ = 0)
Fig. 3-E2 — Top: the windowed cosine $x[n]$ (period 10, lasting 11 samples). Bottom: its autocorrelation $r_{xx}[\ell]$, lags $-20$ to $20$.(上:截短餘弦;下:其自相關。)

Checks against the theory of §3.7.2:

  • Maximum at zero lag: $r_{xx}[0] = \sum_n x^2[n] = E_x = 6$ — and indeed $\sum_{n=-5}^{5}\cos^2(\pi n/5) = 6$ ✓ (no other lag reaches 6).
  • Even symmetry: $r_{xx}[-\ell] = r_{xx}[\ell]$, visible in the plot ✓.
  • Oscillation with the signal's period: sidelobes alternate with period $\approx 10$ lags (e.g. $r_{xx}[\pm 5] \approx -4.0$, the strongest negative dip: shifting a cosine by half a period anti-aligns it), but they decay as $|\ell|$ grows because the finite windows overlap less — at $|\ell| \ge 11$ the copies no longer overlap at all and $r_{xx}[\ell] = 0$.
  • Finite support: a length-$L$ sequence has autocorrelation confined to $|\ell| \le L-1 = 20$ ✓.