Discrete-Time Systems II — Difference Equations & Correlation離散時間系統(二)—— 差分方程與相關離散時間システム(II)—— 差分方程式と相関
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 Equations3.1 線性常係數差分方程3.1 線形定係数差分方程式
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.
LCCDE — general N-th order formLCCDE —— 一般 N 階形式LCCDE —— 一般の N 次形
$$\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)遞迴形式(a₀ 已正規化為 1)再帰形(a₀ を 1 に正規化)
$$y[n] \;=\; -\sum_{k=1}^{N} a_k\, y[n-k] \;+\; \sum_{k=0}^{M} b_k\, x[n-k]$$
$N$ = order of the equation(階數)= number of past outputs that feed back.
Linear: $y$ and $x$ terms appear to the first power only, never multiplied together.
Constant-coefficient: the $a_k, b_k$ do not depend on $n$ — this is what makes the system time-invariant.
$N$ = 方程的階數(order)= 回授進來的過去輸出個數。
線性:$y$ 與 $x$ 的各項都只出現一次方,彼此也不相乘。
常係數:$a_k$、$b_k$ 不隨 $n$ 改變——這正是系統非時變的原因。
$N$ = 方程式の次数 = 帰還してくる過去の出力の個数。
線形:$y$ と $x$ の項は一次のみで現れ、互いに掛け合わされることはない。
定係数:$a_k, b_k$ は $n$ に依存しない——これが系を時不変にしている。
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.與無限長的 $h[n]$ 做卷積,每算一個輸出樣本就要無限多次乘法。而一條差分方程只要每個樣本 $N + M + 1$ 次乘法就能產生相同的輸出。每一個實際使用的 IIR 數位濾波器都是以差分方程實作的,絕不會真的去做卷積。無限に長い $h[n]$ との畳み込みでは、出力 1 標本あたり無限回の乗算が必要になる。差分方程式なら、1 標本あたりわずか $N + M + 1$ 回の乗算で同じ出力が得られる。実用的な IIR ディジタルフィルタはすべて差分方程式として実装されており、畳み込みをそのまま計算することはない。
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).光有一條差分方程並不能定義出唯一的系統——你還必須指定初始條件(initial conditions)$y[-1], \dots, y[-N]$。只有在初始鬆弛(initially relaxed,$y[-1] = \dots = y[-N] = 0$)的情況下,這個系統才既是 LTI 又是因果的。初始條件非零時,系統既非線性也非時不變(它違反齊次性:零輸入不會給出零輸出)。差分方程式だけでは、系は一意に定まらない——初期条件 $y[-1], \dots, y[-N]$ も指定しなければならない。この系が LTI かつ因果的になるのは、初期静止(initially relaxed)のとき、すなわち $y[-1] = \dots = y[-N] = 0$ のときに限る。初期条件が非零であれば、系は線形でも時不変でもない(斉次性を破る:零入力が零出力を与えない)。
But that applies only to the mapping "input → complete output". The total response always splits into the zero-input response (ZIR — produced by the initial conditions alone) plus the zero-state response (ZSR — produced by the input alone, from rest): $y[n] = y_{\text{zi}}[n] + y_{\text{zs}}[n]$. Even when the initial conditions are non-zero and the system as a whole is not LTI, its zero-state part ($x[n]\to y_{\text{zs}}[n]$) still is LTI and causal — which is exactly why $h[n]$ can be defined and why $y_{\text{zs}}[n]=x[n]*h[n]$ holds. The nonlinearity comes only from that fixed ZIR offset term.但這只針對「輸入 → 全部輸出」這個映射。總響應永遠可拆成 零輸入響應(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 偏置項。ただしそれは「入力 → 出力全体」という写像についての話である。全応答はつねに、零入力応答(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 systems3.1.2 遞迴系統與非遞迴系統3.1.2 再帰系と非再帰系
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).
Procedure. Assume an exponential trial solution $y[n] = \lambda^{\,n}$. Substituting and dividing out $\lambda^{\,n-N}$ yields the characteristic polynomial(特徵多項式):
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).
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:
$A\,\alpha^{\,n}$ where $\alpha$ is a characteristic root
$K\,n\,\alpha^{\,n}$ (multiply by $n$)
輸入 $x[n]$($n \ge 0$)
假設的特解 $y_p[n]$
$A$(常數,例如步階)
$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$ 或 $A\sin\omega_0 n$
$K_1\cos\omega_0 n + K_2 \sin\omega_0 n$
$A\,\alpha^{\,n}$,而且 $\alpha$ 剛好是特徵根
$K\,n\,\alpha^{\,n}$(要乘上 $n$)
入力 $x[n]$($n \ge 0$)
仮定する特解 $y_p[n]$
$A$(定数、たとえばステップ)
$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$ または $A\sin\omega_0 n$
$K_1\cos\omega_0 n + K_2 \sin\omega_0 n$
$A\,\alpha^{\,n}$ で $\alpha$ が特性根と一致する場合
$K\,n\,\alpha^{\,n}$($n$ を掛ける)
Substitute the assumed form into the LCCDE and solve for $K$ by matching coefficients.
把假設的形式代回差分方程,比對係數即可解出 $K$。
仮定した形を差分方程式に代入し、係数を比較して $K$ を求める。
Resonance trap
共振陷阱
共振の落とし穴
If the input happens to match one of the natural modes ($\alpha = \lambda_k$), the plain guess $K\alpha^n$ fails — it already satisfies the homogeneous equation, so substituting it yields $0 = \text{something}$. In that case multiply the trial solution by $n$ (and by $n^2$ for a double coincidence), exactly as in differential equations.若輸入恰好與其中一個自然模態相符($\alpha = \lambda_k$),則單純的猜測 $K\alpha^n$ 會失效——它本身已滿足齊次方程,代入後得到 $0 = \text{某值}$。此時將試解乘上 $n$(若為雙重重合則再乘 $n^2$),做法與微分方程中完全相同。入力がたまたま固有モードの一つと一致する場合($\alpha = \lambda_k$)、単純な試行解 $K\alpha^n$ は破綻する——それ自体がすでに斉次方程式を満たしているため、代入すると $0 = \text{something}$ になってしまう。その場合は、微分方程式のときとまったく同じように、試行解に $n$ を掛ける(二重に一致していれば $n^2$ を掛ける)。
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 .$$
Zero-input response(零輸入響應) $y_{zi}[n]$: set $x[n] = 0$; the stored initial conditions alone drive the output. It is purely a combination of natural modes $\lambda_k^n$.
Zero-state response(零狀態響應) $y_{zs}[n]$: set $y[-1]=\dots=y[-N]=0$ (system at rest); the input alone drives the output. This is the part equal to $x[n]*h[n]$, and it contains both natural-mode terms and the particular (forced) term.
A classic exam point: a system given non-zero initial conditions is not LTI (the stored state destroys both linearity and time invariance), but its zero-state part $y_{zs}[n]$ is. Only when all initial conditions are zero (the system is at rest) does the convolution relation $y_{zs}[n] = x[n]*h[n]$ hold.
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})$.零輸入/零狀態的拆法,與齊次解/特解的拆法不是同一回事。$y_{zi}$ 與 $y_{zs}$ 都含有自然模態項 $\lambda_k^n$,差別只在係數。兩者的關係是:$y_c = y_{zi} + (y_{zs}$ 中的模態部分$)$,而 $y_p = (y_{zs}$ 中的受迫部分$)$。零入力/零状態という分け方は、斉次解/特解という分け方と同じではない。$y_{zi}$ と $y_{zs}$ はどちらも固有モード項 $\lambda_k^n$ を含み、違うのは係数だけである。関係式は $y_c = y_{zi} + (\text{mode part of } y_{zs})$ および $y_p = (\text{forced part of } y_{zs})$ となる。
Example 3.2 — Decomposing Example 3.1範例 3.2 —— 把範例 3.1 拆開例題 3.2 —— 例題 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$$
3.4 Impulse Response of LCCDEs3.4 線性常係數差分方程的脈衝響應3.4 線形定係数差分方程式のインパルス応答
3.4.1 Impulse response from a difference equation3.4.1 由差分方程求脈衝響應3.4.1 差分方程式からインパルス応答を求める
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:
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$.
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$.對 $y[n] = \sum_{k=0}^{M} b_k\,x[n-k]$,代入 $x = \delta$ 得 $h[n] = \sum_k b_k \delta[n-k]$,也就是說係數本身就是脈衝響應:$h = \{b_0, b_1, \dots, b_M\}$。例如 5 點移動平均在 $0 \le n \le 4$ 上有 $h[n] = \tfrac15$。$y[n] = \sum_{k=0}^{M} b_k\,x[n-k]$ に $x = \delta$ を代入すると $h[n] = \sum_k b_k \delta[n-k]$ となる。つまり係数そのものがインパルス応答である:$h = \{b_0, b_1, \dots, b_M\}$。例として、5 点移動平均は $0 \le n \le 4$ で $h[n] = \tfrac15$ をもつ。
Recursive ≠ IIR in every case
遞迴不等於一定是 IIR
再帰型が必ず IIR とは限らない
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.遞迴實作與無限脈衝響應通常結伴出現,但並非總是如此:$y[n] = y[n-1] + \tfrac{1}{L}\big(x[n] - x[n-L]\big)$ 就是用遞迴的方式來計算 FIR 移動平均。誠實的說法是:$N\ge 1$ 通常給出 IIR,除非發生極零點對消。再帰的な実装と無限インパルス応答はたいてい同時に現れるが、つねにそうとは限らない。$y[n] = y[n-1] + \tfrac{1}{L}\big(x[n] - x[n-L]\big)$ は、FIR の移動平均を再帰的に計算する方法である。正確に言えば、$N\ge 1$ は一般には IIR を与えるが、極零相殺が起これば話は別である。
3.5 Stability3.5 穩定性3.5 安定性
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$.
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]範例 3.4 —— h[n] = aⁿu[n] 的穩定性例題 3.4 —— 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$).
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.)因為 $h[n]$ 是由自然模態 $\lambda_k^{\,n}$ 組成的,所以一個因果的差分方程系統為 BIBO 穩定的充要條件是每一個特徵根都嚴格落在單位圓內:
$$|\lambda_k| < 1 \quad \text{對所有 } k=1,\dots,N.$$
對照圖 3-2:$\lambda = 1.1$ 那個模態無界成長 —— 一個壞根就毀了整個系統。(用第 5 章 z 轉換的語言來說,這些 $\lambda_k$ 就是極點。)$h[n]$ は固有モード $\lambda_k^{\,n}$ から組み立てられるので、因果的な差分方程式系が BIBO 安定である必要十分条件は、すべての特性根が単位円の内部に厳密に存在することである:
$$|\lambda_k| < 1 \quad \text{for all } k=1,\dots,N.$$
図 3-2 と比べてみよう:$\lambda = 1.1$ のモードは際限なく増大する——根が一つ悪いだけで系全体が台無しになる。(第 5 章の z 変換の言葉でいえば、この $\lambda_k$ が極である。)
Quick second-order check
二階系統的快速檢查法
2 次系の手早い判定法
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$.對 $\lambda^2 + a_1\lambda + a_2 = 0$,兩個根都在單位圓內的充要條件是 $|a_2| < 1$ 且 $|a_1| < 1 + a_2$(穩定三角形)。範例 3.1 中 $a_1 = 1$、$a_2 = -12$:$|a_2| = 12 \ge 1$ → 不穩定,與它的根 $-4$ 和 $3$ 一致。$\lambda^2 + a_1\lambda + a_2 = 0$ については、両根が単位円の内部にある必要十分条件は $|a_2| < 1$ かつ $|a_1| < 1 + a_2$ である(安定三角形)。例題 3.1 では $a_1 = 1, a_2 = -12$ であり、$|a_2| = 12 \ge 1$ → 不安定。根が $-4$ と $3$ であることと整合している。
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:
再對每一項畫出一條分支,就得到直接 I 型(Direct Form I)實現 —— 輸入端一條前饋的抽頭延遲線,加上輸出端一條回授的抽頭延遲線:
各項ごとに枝を 1 本描くと、直接形 I(Direct Form I)による実現が得られる——入力側のフィードフォワード型タップ付き遅延線に、出力側の帰還型タップ付き遅延線を足したものである:
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]$. The left delay line stores past inputs (feed-forward taps $b_k$); the right delay line stores past outputs (feedback taps $-a_k$). Total: $N+M = 4$ delays.
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.因為串聯的 LTI 方塊可以交換順序,回授那一半可以搬到前饋那一半之前;此時兩條延遲線帶的是完全相同的內部訊號 $w[n]$,因此可以共用,把延遲器從 $N+M$ 個減到 $\max(N,M)$ 個(也就是標準的直接 II 型)。濾波器結構那一章會完整展開這件事——在這裡只要知道有這個技巧、以及它為什麼行得通就夠了。縦続接続された LTI ブロックは交換できるので、帰還側の半分をフィードフォワード側の半分より前へ移すことができる。すると二つの遅延線はまったく同じ内部信号 $w[n]$ を運ぶことになり、共用できる。遅延器は $N+M$ 個から $\max(N,M)$ 個へ減る(これが正準な直接形 II である)。フィルタ構造の章でこれを本格的に展開する——ここでは、そういう技法が存在することと、なぜそれが成り立つのかを知っていれば十分である。
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.MATLAB 的 filter(b, a, x) 用的是把所有 $y$ 項移到左邊的差分方程寫法:$\sum a_k y[n-k] = \sum b_k x[n-k]$。因此方塊圖回授分支上的乘法器是 $-a_1, -a_2$(要變號!)。忘掉這個變號,是畫方塊圖時最常犯的一個錯。MATLAB の filter(b, a, x) は、$y$ の項をすべて左辺にまとめた書き方の差分方程式 $\sum a_k y[n-k] = \sum b_k x[n-k]$ を使う。したがってブロック図の帰還枝にある乗算器は $-a_1, -a_2$ となる(符号が反転する!)。この符号反転を忘れることが、ブロック図を描くときに最も多い誤りである。
3.7 Correlation3.7 相關3.7 相関
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.
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:
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.卷積在滑動之前會先把其中一個訊號摺疊(時間反轉);相關則不摺疊就直接滑動。對於關於某點對稱的序列(例如習題 4 的加窗餘弦),卷積與相關給出的形狀只差一個平移——這正是匹配濾波器可以用卷積器來實作的原因。畳み込みはスライドさせる前に一方の信号を折り返す(時間反転する)が、相関は折り返さずにスライドさせる。ある点に関して対称な系列(演習 4 の窓かけ余弦など)では、畳み込みと相関はシフトを除いて同じ形を与える——整合フィルタを畳み込み器として実装できるのはこのためである。
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:
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.一個訊號與自己平移後的複本,永遠不可能比它與未平移的自己更相像:$r_{xx}[\ell]$ 的峰值在 $\ell = 0$,其值等於訊號能量。在延遲估測問題中,$r_{xy}[\ell]$ 峰值的位置就是延遲的估計值。信号が、シフトした自分自身のコピーと、シフトしていない自分自身よりも似ることはありえない:$r_{xx}[\ell]$ は $\ell = 0$ でピークをとり、その値は信号のエネルギーに等しい。遅延推定の問題では、$r_{xy}[\ell]$ のピーク位置が遅延の推定値そのものである。
3.7.3 Autocorrelation of periodic sequences3.7.3 週期序列的自相關3.7.3 周期系列の自己相関
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.若 $x[n]$ 的週期為 $N$,則 $r_{xx}[\ell]$ 也以 $N$ 為週期,在 $\ell = 0, \pm N, \pm 2N, \dots$ 處出現峰值。另一方面,白雜訊 $w[n]$ 在任何非零平移下都與自己不相關,所以它的自相關塌縮成 $\ell=0$ 處的一根尖峰。因此對含雜訊的觀測 $y[n] = x[n] + w[n]$,在離開 $\ell = 0$ 之後就有 $r_{yy}[\ell] \approx r_{xx}[\ell]$ —— 週期結構從雜訊中浮了出來。$x[n]$ が周期 $N$ をもつなら、$r_{xx}[\ell]$ も周期 $N$ をもち、$\ell = 0, \pm N, \pm 2N, \dots$ にピークが現れる。一方、白色雑音 $w[n]$ は零でないシフトでは自分自身と無相関なので、その自己相関は $\ell=0$ の 1 本のスパイクに潰れる。したがって雑音を含む観測 $y[n] = x[n] + w[n]$ では、$\ell = 0$ から離れたところで $r_{yy}[\ell] \approx r_{xx}[\ell]$ となる——周期構造が雑音の中から浮かび上がってくる。
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.
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.
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.
(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.)
Exercise 2 — Solve the LCCDE with initial conditions習題 2 — 在初始條件下解差分方程演習 2 — 初期条件つきで差分方程式を解く
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$.
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.
(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.
(a) 實作差分方程的封閉解,求 $0 \le n \le 4$ 的 $y[n]$。
(b) 用 for 迴圈實作遞迴,求 $0 \le n \le 4$ 的 $y[n]$。
(c) 用 filtic 與 filter 求 $0 \le n \le 4$ 的 $y[n]$。三種結果必須一致。
(a) 差分方程式の閉じた解を実装し、$0 \le n \le 4$ の $y[n]$ を求めよ。
(b) for ループで漸化式を実装し、$0 \le n \le 4$ の $y[n]$ を求めよ。
(c) filtic と filter を使って $0 \le n \le 4$ の $y[n]$ を求めよ。三つの結果は一致しなければならない。
Click to reveal solution點擊展開解答クリックして解答を表示
All three methods must reproduce $y[n] = 16(-4)^n + 24\,(2)^n - 16$ from Exercise 2, i.e.
(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.
(c)filtic(b, a, [y(-1) y(-2)]) は過去の出力を、直接形フィルタの内部遅延線の等価な状態 zi に換算する。続く filter(b, a, x, zi) が同じ漸化式を最適化された形で走らせる。zi を与えなければ filter は系が静止していると仮定する——その場合は零状態応答しか計算されない。
Result regenerated numerically (Python scipy.signal.lfilter + lfiltic, the exact analogues of filter/filtic):
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習題 4 — MATLAB:加窗弦波的自相關演習 4 — MATLAB:窓かけ正弦波の自己相関
Problem: MATLAB simulation:
題目:MATLAB 模擬:
問題:MATLAB によるシミュレーション:
(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]$.
(a) 次の正弦波信号を生成せよ。
$$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) stem 関数を使って $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')):
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$ ✓.