Outline
2.1 Discrete-Time Systems
2.2 Classes of DT Systems
2.3 LTI Systems & Impulse Response
2.4 The Convolution Sum
2.5 LTI Properties via h[n]
2.6 Summary
Exercises
DSP Study Guide · Chapter 2

Discrete-Time Systems (I)

System properties (linearity, time invariance, causality, stability), LTI systems, the impulse response, the convolution sum, and system interconnections

2.1 Discrete-Time Systems

2.1.1 The system operator

A discrete-time system(離散時間系統) is a transformation $T\{\cdot\}$ that maps an input sequence $x[n]$ into an output sequence $y[n]$:

DT System $$y[n] = T\{x[n]\}$$

The operator $T$ may act on the entire input sequence: in general, the output sample $y[n]$ at one time index can depend on input samples $x[k]$ at all indices $k$ — past, present, and future. Everything in this chapter is about classifying systems by which samples they use and how they combine them.

運算子 $T$ 可以作用在整條輸入序列上:一般而言,某一時刻的輸出樣本 $y[n]$ 可以同時取決於所有索引 $k$ 的輸入樣本 $x[k]$——過去、現在與未來都算。 本章自始至終都在做一件事:依照系統「用了哪些樣本」以及「如何把它們組合起來」來分類系統。

Why classify systems?
Most of DSP theory (frequency response, $z$-transform analysis, filter design) applies only to the special class of linear time-invariant(線性非時變) systems. The first job when you meet a new system is to test its properties — that decides which analysis tools you may use.

2.1.2 Example: moving average (MA)

The moving average(移動平均) system computes, for each $n$, the average of the input over a sliding window. The general (possibly non-causal) form averages $M_1$ future and $M_2$ past samples:

Moving Average $$y[n] = \frac{1}{M_1+M_2+1}\sum_{k=-M_1}^{M_2} x[n-k]$$

The common causal $M$-point moving average uses only the present and past $M-1$ samples:

Causal M-point MA $$y[n] = \frac{1}{M}\sum_{k=0}^{M-1} x[n-k]$$

The MA is the simplest smoother(平滑器): averaging adjacent samples cancels rapid, zero-mean fluctuations (noise) while approximately preserving slow trends. Fig. 2-1 shows a noisy sequence and the output of a 5-point MA.

移動平均到底在做什麼?(為何能去雜訊、代價是什麼)(點擊展開)
它取的是「現在這一筆 + 前面 $M-1$ 筆」共 $M$ 筆的平均,當作時刻 $n$ 的輸出: $$y[n]=\tfrac1M\big(x[n]+x[n-1]+\cdots+x[n-M+1]\big).$$ 注意 $k=0$ 就是現在 $x[n]$,不是只有過去;因為完全沒用到 $x[n+1]$ 等未來 ⇒ 因果。 例($M=3$):$y[n]=\tfrac13\big(x[n]+x[n-1]+x[n-2]\big)$。

為什麼平均能去雜訊:把訊號看成「真實值 + 零均值雜訊」。相鄰幾筆的真實值差不多, 平均後幾乎不變;雜訊有正有負,平均後彼此抵消。理論上 $M$ 筆獨立、變異數 $\sigma^2$ 的雜訊,平均後變異數降為 $\sigma^2/M$(雜訊強度約降 $\sqrt{M}$ 倍)。所以它是最簡單的低通/平滑濾波器。

代價有兩個:
  • 延遲:窗口只朝過去看,輸出重心落在 $n-\tfrac{M-1}{2}$,結果比真實訊號慢約 $\tfrac{M-1}{2}$ 拍(Fig. 2-1 可見)。
  • 變鈍:$M$ 越大越平滑、雜訊壓得越乾淨,但邊緣、尖峰等快速變化也被抹平。要在「去雜訊」與「保留細節」之間取捨。
想消除延遲?改用置中平均(同時取前後幾筆,如 $\tfrac13(x[n-1]+x[n]+x[n+1])$), 重心對齊 $n$、無延遲——但用到未來樣本 ⇒ 非因果,只能離線處理(見 §2.2.4 因果性)。
2026-06-12T22:22:27.316490 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 2 4 6 x[n] Noisy input x[n] = s[n] + noise underlying trend s[n] 0 10 20 30 40 50 60 n 0 1 2 3 4 5 y[n] 5-point moving-average output (noise reduced, slight delay)
Fig. 2-1 — A noisy sequence (top) and the output of a causal 5-point moving average (bottom). The averaging suppresses the zero-mean noise while tracking the slow trend, at the cost of a small delay(移動平均抑制雜訊,但引入少量延遲).
Tip — MA is an FIR filter
The $M$-point moving average is a finite impulse response (FIR) filter with impulse response $h[n] = 1/M$ for $0 \le n \le M-1$ (see §2.3.2). In MATLAB: y = conv(x, ones(1,M)/M). Larger $M$ means stronger smoothing but more delay and more blurring of fast features.

2.1.3 Example: accumulator

The accumulator(累加器) sums all input samples up to the present time — the discrete-time analogue of an integrator:

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

Splitting off the newest term gives the equivalent recursive(遞迴) form, which is how you would actually implement it:

Recursive Form $$y[n] = y[n-1] + x[n]$$

For example, with input $x[n]=n\,u[n]$ the output is $y[n] = \sum_{k=0}^{n} k = \frac{n(n+1)}{2}\,u[n]$ — the running sum grows like $n^2$. The accumulator will reappear twice in this chapter: as a system that is linear, time-invariant, causal but unstable (§2.2.5), and as the classic example of an invertible system (§2.5.4).

2.2 Classes of Discrete-Time Systems

Five properties are tested over and over in this course. For each one you should know the formal definition, a standard example, and a standard counterexample.

2.2.1 Memoryless systems

A system is memoryless(無記憶) if $y[n]$ depends only on $x[n]$ at the same index $n$. Example: $y[n]=\left(x[n]\right)^2$. Counterexample: the MA and the accumulator both use past samples, so they have memory.

2.2.2 Linearity

A system $T$ is linear(線性) if it satisfies superposition: for all signals $x_1, x_2$ and all constants $a, b$,

Linearity (Superposition) $$T\{a\,x_1[n] + b\,x_2[n]\} = a\,T\{x_1[n]\} + b\,T\{x_2[n]\}$$

Superposition combines two requirements: additivity(可加性) $T\{x_1+x_2\}=T\{x_1\}+T\{x_2\}$ and homogeneity / scaling(齊次性) $T\{a\,x\}=a\,T\{x\}$. Three slide examples:

Example 2.1 — Three linearity tests
(1) Accumulator $y[n]=\sum_{k\le n}x[k]$ — linear. $\sum_{k\le n}\bigl(a x_1[k]+b x_2[k]\bigr) = a\sum_{k\le n}x_1[k] + b\sum_{k\le n}x_2[k]$. Sums distribute over scaled inputs, so superposition holds exactly.
(2) Squarer $y[n]=\left(x[n]\right)^2$ — nonlinear. Scaling test: input $a\,x[n]$ produces $a^2 x^2[n] \ne a\,x^2[n]$ for general $a$. One failed test is enough.
(3) Affine system $y[n]=c\,x[n]+d$ ($d\neq0$) — nonlinear. Zero input gives $y[n]=d\neq 0$. A linear system must map the zero signal to the zero signal (set $a=b=0$ in the definition). A line that misses the origin is affine, not linear.
仿射系統 $y[n]=c\,x[n]+d$($d\neq0$)——非線性。零輸入會得到 $y[n]=d\neq 0$; 線性系統必須把零訊號映射到零訊號(在定義中令 $a=b=0$ 即可看出)。 一條不通過原點的直線是仿射(affine),而非線性。
「再加一維」能把非線性變線性嗎?(齊次座標 vs 核技巧;3D 影像為何這樣做)(點擊展開)
要分兩種「非線性」來看。

1. 仿射(只差一個常數偏移 $+d$)——加一維「精確」變線性。 這就是電腦圖學的齊次座標(homogeneous coordinates)。$y=cx+d$ 對 $x$ 因為有 $+d$ 不是線性, 但把輸入墊高一維、補一個常數 1: $$\tilde{x}=\begin{bmatrix}x\\ 1\end{bmatrix},\qquad y=\begin{bmatrix}c & d\end{bmatrix}\begin{bmatrix}x\\ 1\end{bmatrix}=cx+d.$$ 現在 $y$ 對「擴增向量 $\tilde x$」是純線性(矩陣乘法、過原點),偏移 $d$ 被藏進矩陣裡。

3D 影像/圖學的確標準這樣做:
  • 3D 點 $(x,y,z)$ 寫成 4 維齊次座標 $(x,y,z,1)$。
  • 旋轉、縮放(本來就線性)+平移(本來是仿射)合併成單一 $4\times4$ 矩陣,整串變換變成矩陣連乘,GPU 一次算完。
  • 透視投影也靠最後那一維($w$ 分量)的除法來實現。

2. 真正的非線性($y=x^2$、$\sin$、乘法 $x_1x_2$)——補一個常數維度救不了。 但「升維」的精神仍有用,只是要升到特徵空間: $$x\ \longmapsto\ \phi(x)=\big(x,\;x^2\big)\quad\Rightarrow\quad y=x^2\text{ 對 }\phi(x)\text{ 的第二維是線性的}.$$ 這就是機器學習的核技巧(kernel trick)/特徵映射:把資料映到更高(甚至無限)維,讓非線性問題在高維變線性可分;代價是維度可能爆炸。

一句話:仿射(差常數偏移)⇒ 補 1 維齊次座標就精確變線性(3D 圖學標準手法); 真非線性($x^2$ 等)⇒ 要升到特徵/核空間,不是補一維就好。本章這個仿射反例,正是「為什麼要用齊次座標」的起點。
Warning — the zero-input shortcut
If $x[n]=0$ for all $n$ does not produce $y[n]=0$ for all $n$, the system is not linear — no further work needed. But the converse fails: zero-in/zero-out does NOT prove linearity (e.g. $y[n]=x^2[n]$ passes the zero test yet is nonlinear). To prove linearity you must verify superposition for arbitrary $a, b, x_1, x_2$.

2.2.3 Time (shift) invariance

A system is time-invariant(非時變), also called shift-invariant, if delaying the input only delays the output by the same amount — the system's behaviour does not change with time:

Time Invariance $$\text{if } y[n] = T\{x[n]\},\ \text{then}\quad T\{x[n-n_0]\} = y[n-n_0] \quad \text{for every integer } n_0$$

How to test: (i) shift the input first, push it through the system to get $w[n]=T\{x[n-n_0]\}$; (ii) shift the original output to get $y[n-n_0]$; (iii) compare. They must agree for every $x$ and every $n_0$.

Example 2.2 — Two shift-invariance counterexamples
(1) Compressor (down-sampler) $y[n]=x[Mn]$, $M\ge 2$ — time-varying. Shifted input: $w[n] = x[Mn-n_0]$. Shifted output: $y[n-n_0] = x[M(n-n_0)] = x[Mn - Mn_0]$. Since $Mn_0 \neq n_0$ for $M \ge 2$, $w[n] \neq y[n-n_0]$ in general. Intuition: the compressor re-labels the time axis, so "when a sample happens" matters.
(2) Time-weighted gain $y[n]=n\,x[n]$ — time-varying. Shifted input: $w[n]=n\,x[n-n_0]$. Shifted output: $y[n-n_0]=(n-n_0)\,x[n-n_0]$. These differ by $n_0\,x[n-n_0]$. The gain applied to a sample depends on the clock, not just the sample.
直觀解釋(點擊展開)
線性:把輸入「加倍」,輸出也恰好加倍;兩個輸入疊加,輸出就是各自輸出的疊加。 判斷時最快的第一步是代入全零輸入——若輸出不是零,必為非線性(例如 $y[n]=cx[n]+d$,$d\neq0$)。 非時變:系統像一台「不會變心」的機器——今天丟進去與明天丟進去同樣的訊號, 得到的回應形狀完全相同,只是時間平移。測試口訣:「先移再過系統」與「先過系統再移」結果必須一樣。 凡是規則裡明確出現 $n$(如 $y[n]=n\,x[n]$)或改變時間軸刻度(如 $x[2n]$、$x[an-b]$ 中 $a\neq1$)的系統, 幾乎都會破壞非時變性。

2.2.4 Causality

A system is causal(因果) if $y[n_0]$ depends only on input samples $x[n]$ with $n \le n_0$ — present and past, never the future. Causality is mandatory for real-time processing; offline (stored-data) processing can afford non-causal systems.

Example 2.3 — Forward vs. backward difference
Forward difference $y[n] = x[n+1]-x[n]$: needs the future sample $x[n+1]$ → non-causal.
Backward difference $y[n] = x[n]-x[n-1]$: uses only present and past → causal.
Likewise the centered MA ($M_1>0$ in §2.1.2) is non-causal, while the $M$-point causal MA is causal. A non-causal FIR system can always be made causal by adding enough delay.
系統的輸出可以包含「未來」輸入項嗎?(點擊展開)
數學上可以。系統定義 $y[n]=T\{x[n]\}$ 並沒有限制只能用過去的輸入。像 $y[n]=x[n+1]$、$y[n]=\tfrac12\big(x[n-1]+x[n+1]\big)$ 都用到未來樣本 $x[n+1]$, 這類系統稱為非因果(non-causal)

因果系統則規定 $y[n_0]$ 只能依賴 $x[n],\,n\le n_0$(現在與過去)。 判別法:若兩輸入在 $n\le n_0$ 完全相同 ⇒ 輸出 $y[n_0]$ 必相同;只要找得到一個用到 $n>n_0$ 的反例,就是非因果。

能不能「實作」用未來項,要看場景:
  • 即時/串流(麥克風、通訊):未來樣本還沒發生,只能因果
  • 離線/批次(整段音檔、影像已存好):整條序列都在記憶體裡,$x[n+1]$ 隨手可取,非因果照樣能跑
所以「未來」是相對於目前處理的索引 $n$;資料若已錄好,非因果濾波器並非不可實現。

工程折衷——用延遲換因果:想要非因果的理想響應(例如零相位濾波器)時, 可先暫存幾筆樣本、晚一點再輸出,把「等待」換成「看到未來」。 例如 $y[n]=x[n+1]-x[n]$(非因)整體延遲 1 拍後變成 $y'[n]=y[n-1]=x[n]-x[n-1]$,就成了因果的後向差分。 這也是「A non-causal FIR system can always be made causal by adding enough delay」那句話的意思。

通則(延遲 $L$ 公式):任何 FIR 系統都能寫成有限加權和 $$y[n]=\sum_{k=-L}^{K} b_k\,x[n-k],$$ 其中 $k<0$ 的項就是未來樣本($x[n+1],\dots,x[n+L]$),最遠的未來樣本是 $x[n+L]$(即 $k=-L$)。 把整條輸出延遲這個最大未來步數 $L$: $$y'[n]=y[n-L]=\sum_{k=-L}^{K} b_k\,x[n-L-k] \;\overset{\,m=k+L\,}{=}\;\sum_{m=0}^{K+L} b_{m-L}\,x[n-m].$$ 換完變數後求和只剩 $m\ge0$,即只用到 $x[n],x[n-1],\dots$(現在與過去)⇒ 因果。 最遠的未來項 $x[n+L]$ 正好被推到 $x[n]$(現在)。

數值例(置中 3 點平均,$L=1$): $$y[n]=\tfrac13\big(x[n-1]+x[n]+x[n+1]\big)\quad(\text{非因,最遠用到 }x[n+1])$$ $$\xrightarrow{\text{延遲 }1}\quad y'[n]=y[n-1]=\tfrac13\big(x[n-2]+x[n-1]+x[n]\big)\quad(\text{因果}).$$ 脈衝響應的形狀完全沒變,只是整條輸出晚 $L$ 拍出來——用「等待」換「看到未來」。
前提是 FIR($L$ 有限);若 IIR 用到無上限的未來項($x[n+1],x[n+2],\dots$),找不到有限的 $L$,就無法靠延遲補救。

2.2.5 BIBO stability

A system is BIBO stable(有界輸入有界輸出穩定) if every bounded input produces a bounded output:

BIBO Stability $$|x[n]| \le B_x < \infty \ \ \forall n \quad \Longrightarrow \quad |y[n]| \le B_y < \infty \ \ \forall n$$

To prove instability you only need one bounded input whose output blows up. The classic victim is the accumulator: feed it the bounded step $x[n]=u[n]$ and the output is the unbounded ramp $y[n]=(n+1)u[n]$ — see Fig. 2-4.

2026-06-12T22:22:27.878405 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0.0 0.5 1.0 x[n] = u[n] Bounded input: unit step −5.0 −2.5 0.0 2.5 5.0 7.5 10.0 12.5 n 0 5 10 y[n] = (n+1)u[n] Accumulator output grows without bound → not BIBO stable
Fig. 2-4 — The accumulator driven by the bounded unit step produces the unbounded ramp y[n]=(n+1)u[n]: one bounded input with an unbounded output proves the accumulator is not BIBO stable(累加器不穩定:有界輸入產生無界輸出).
★ Important — System properties at a glance(重要:系統性質總表)
SystemMemorylessLinearTime-inv.CausalStable
Ideal delay $y[n]=x[n-n_d]$, $n_d>0$NoYesYesYesYes
Causal $M$-point MANoYesYesYesYes
Centered MA ($M_1>0$)NoYesYesNoYes
AccumulatorNoYesYesYesNo
Compressor $y[n]=x[Mn]$NoYesNoNoYes
$y[n]=n\,x[n]$YesYesNoYesNo
Squarer $y[n]=x^2[n]$YesNoYesYesYes

2.3 LTI Systems and the Impulse Response

2.3.1 From the sifting property to convolution

A system that is both linear and time-invariant is called LTI(線性非時變) — the slides also use the equivalent name LSI (linear shift-invariant). For LTI systems one single signal characterizes the system completely: the impulse response(脈衝響應)

Impulse Response $$h[n] \;=\; T\{\delta[n]\}$$

The derivation is the most important three lines of the course. Start from the sifting decomposition of Chapter 1 — any sequence is a weighted sum of shifted impulses:

Sifting Property $$x[n] = \sum_{k=-\infty}^{\infty} x[k]\,\delta[n-k]$$

Apply $T$ and use linearity (the $x[k]$ are just constants) and then time invariance ($\delta[n-k] \mapsto h[n-k]$):

Convolution Sum Derivation $$y[n] = T\Bigl\{\sum_{k=-\infty}^{\infty} x[k]\,\delta[n-k]\Bigr\} \;\overset{\text{lin.}}{=}\; \sum_{k=-\infty}^{\infty} x[k]\,T\{\delta[n-k]\} \;\overset{\text{T.I.}}{=}\; \sum_{k=-\infty}^{\infty} x[k]\,h[n-k]$$
Key — h[n] tells you everything
For an LTI system, knowing $h[n]$ means knowing the output for every input: $y[n] = x[n] * h[n]$. All later analysis (frequency response, transfer function) is just different ways of looking at $h[n]$. This is exactly why we care so much about the LTI class.

2.3.2 Impulse response examples

Feed $\delta[n]$ into the systems of §2.1 (Fig. 2-2):

$y[n]=a\,y[n-1]+x[n]$ 的 $h[n]=a^n u[n]$ 怎麼推出來?(點擊展開)
把 $x[n]=\delta[n]$ 餵進去,並假設初始靜止(initial rest:$n<0$ 時 $y[n]=0$)——因果系統的標準假設——然後逐拍遞推 $h[n]=a\,h[n-1]+\delta[n]$:
$n$$a\,h[n-1]$$+\,\delta[n]$$h[n]$
$<0$$0$$0$(初始靜止)
$0$$a\cdot 0=0$$1$$1=a^0$
$1$$a\cdot 1=a$$0$$a=a^1$
$2$$a\cdot a=a^2$$0$$a^2$
$3$$a\cdot a^2=a^3$$0$$a^3$
$\delta[n]$ 只在 $n=0$ 「踢」一下,把 $h[0]$ 設成 1;之後沒有輸入,系統純靠遞迴(回授) $a\cdot(\text{上一拍})$ 自我延續,每拍乘一個 $a$: $$\boxed{h[n]=a^n\,u[n]}\qquad(u[n]\text{:只在 }n\ge0\text{ 存在}).$$ 驗證(代回原式):$n\ge1$ 時 $a\,h[n-1]+\delta[n]=a\cdot a^{n-1}+0=a^n=h[n]$ ✓; $n=0$ 時 $a\,h[-1]+1=0+1=1=a^0$ ✓。

直觀:這是「一個脈衝激發、之後自由衰減」的系統。$|a|<1$ 時 $a^n$ 越來越小 ⇒ 無限長但衰減(穩定的 IIR);$a=1$ 就退化成累加器 $h[n]=u[n]$。

「遞迴」還是「回授」?兩個是同一件事,只是視角不同:
  • 遞迴(recursive,數學/演算法視角):輸出由它自己的過去輸出定義——式子裡有 $y[n-1]$,「用自己算自己」。
  • 回授(feedback,結構/方塊圖視角):同一條 $y[n-1]$ 項,畫成方塊圖時就是把輸出繞回去乘 $a$ 再加進輸入,這條繞回路徑叫回授。
所以:有回授路徑 ⇔ 差分方程是遞迴的 ⇔ 一般就是 IIR——三者指向同一個機制,只是名字來自不同領域。
FIR vs IIR:「無限長」是什麼意思?跟穩定有關嗎?(點擊展開)
定義看的是脈衝響應 $h[n]$ 的長度:
  • FIR(Finite Impulse Response,有限脈衝響應):只有有限多項 $h[n]$ 非零。例:$M$ 點 MA,$h[n]=\tfrac1M$ 於 $0\le n\le M-1$,其餘為 0。
  • IIR(Infinite Impulse Response,無限脈衝響應):有無限多項非零(可能衰減,但不真正歸零)。例:累加器 $h[n]=u[n]$;一階遞迴 $h[n]=a^n u[n]$。
累加器為何是 IIR:餵 $\delta[n]$ 進 $y[n]=\sum_{k\le n}x[k]$ 得 $h[n]=\sum_{k\le n}\delta[k]=u[n]=\{\dots,0,\underset{n=0}{1},1,1,\dots\}$,從 $n=0$ 起永遠是 1、不歸零,往右無限延伸。

差別不只長度——關鍵在「回授」: IIR 通常來自遞迴/回授(輸出餵回自己),如 $y[n]=a\,y[n-1]+x[n]$: 一個脈衝進去會沿著 $y[n-1]$ 這條回授路徑不斷自我延續,所以拖到無限長。累加器就是 $a=1$ 的特例。 FIR 沒有回授(輸出只是輸入的有限加權和),脈衝過完那幾項就結束。

注意:「無限長」≠「不穩定」,是兩個不同概念。
  • 一階遞迴 $h[n]=a^n u[n]$,$|a|<1$ 時雖無限長但指數衰減 ⇒ BIBO 穩定(圖中 $a=0.8$)。
  • 累加器 $h[n]=u[n]$ 不衰減,$\sum_n|h[n]|=\infty$ ⇒ 不穩定(對應前面總表 Accumulator 的 Stable = No)。
「無限長」講的是 $h[n]$ 拖多久;「穩不穩定」看 $\sum|h[n]|$ 是否有限(§2.2.5)。
2026-06-12T22:22:27.489441 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 5 10 n 0.0 0.2 0.4 0.6 0.8 1.0 h[n] 5-point MA: h[n]=1/5, 0≤n≤4 0 5 10 n 0.0 0.2 0.4 0.6 0.8 1.0 Accumulator: h[n]=u[n] 0 5 10 n 0.0 0.2 0.4 0.6 0.8 1.0 Exponential: h[n]=(0.8)ⁿ u[n]
Fig. 2-2 — Example impulse responses: 5-point moving average (FIR, length 5), accumulator h[n]=u[n] (IIR, not absolutely summable), and the decaying exponential h[n]=(0.8)nu[n] (IIR but stable)(三種典型脈衝響應).

2.4 The Convolution Sum

2.4.1 Definition and mechanics

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

Two complementary readings of the same formula:

Interpretation 1 — superposition of echoes

Read $y[n] = \sum_k x[k]\,h[n-k]$ as a sum over input samples: every input sample $x[k]$ launches its own copy of the impulse response, scaled by $x[k]$ and delayed to start at time $k$. The output is the superposition of all these scaled, shifted echoes. This is the direct picture of "linearity + time invariance at work".

Interpretation 2 — flip and slide(翻轉平移法)

Read the formula one output sample at a time. To get the single number $y[n]$:

  1. Flip: time-reverse $h[k]$ to get $h[-k]$.
  2. Slide: shift it right by $n$ to get $h[n-k]$ (as a function of $k$).
  3. Multiply & sum: $y[n] = \sum_k x[k]\,h[n-k]$ — the inner product of the input with the flipped, shifted impulse response.
  4. Increment $n$ and repeat.

Fig. 2-3 walks through $x[n]=\{1,2,3,2,1\}$ convolved with $h[n]=\{1,1,1\}$: at $n=3$ the flipped window $h[3-k]$ overlaps $x[k]$ on $k=1,2,3$, giving $y[3]=2+3+2=7$.

2026-06-12T22:22:27.714451 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ −4 −2 0 2 4 6 8 k 0 1 2 3 x[k] = {1, 2, 3, 2, 1} −4 −2 0 2 4 6 8 k 0.0 0.2 0.4 0.6 0.8 1.0 h[k] = {1, 1, 1} −4 −2 0 2 4 6 8 k 0 1 2 3 n = 3: overlap k = 1..3 ⇒ y[3] = 2+3+2 = 7 x[k] h[3−k] (flipped, shifted) −4 −2 0 2 4 6 8 n 0 2 4 6 y[n] = x[n] ∗ h[n] = {1, 3, 6, 7, 6, 3, 1}
Fig. 2-3 — Flip-and-slide evaluation of x[n]∗h[n] with x = {1,2,3,2,1} and h = {1,1,1}. Bottom-left: at n = 3 the flipped, shifted window h[3−k] overlaps x[k] on k = 1…3 (shaded), so y[3] = 2+3+2 = 7. Bottom-right: the complete output, length 5+3−1 = 7(翻轉平移法逐點計算卷積).
直觀解釋(點擊展開)
卷積有兩種等價的看法。看法一(疊加回聲):每一個輸入樣本 $x[k]$ 都會「敲」系統一下, 系統回應一個縮放 $x[k]$ 倍、延遲 $k$ 拍的脈衝響應;把所有回聲疊起來就是輸出。 看法二(翻轉平移):要算某一個輸出值 $y[n]$,先把 $h$ 左右翻轉、再平移 $n$ 格, 與 $x$ 對齊後逐點相乘再相加。手算考題時用看法二:畫出 $x[k]$ 與 $h[n-k]$, 找出重疊區間,逐段寫出 $y[n]$ 的公式。檢查答案的兩個小技巧: (1)輸出長度 $=N+M-1$;(2)$\sum_n y[n] = \bigl(\sum_n x[n]\bigr)\bigl(\sum_n h[n]\bigr)$。

2.4.2 Properties of convolution

Algebraic Properties $$\begin{aligned} &\text{Commutative:} && x*h = h*x\\[2pt] &\text{Associative:} && (x*h_1)*h_2 = x*(h_1*h_2)\\[2pt] &\text{Distributive:} && x*(h_1+h_2) = x*h_1 + x*h_2\\[2pt] &\text{Identity:} && x[n]*\delta[n] = x[n]\\[2pt] &\text{Shift:} && x[n]*\delta[n-n_0] = x[n-n_0] \end{aligned}$$

Commutativity follows from the change of variables $m = n-k$ in the sum; it means "you may flip either signal" — always flip the shorter one. The associative and distributive properties are exactly what make cascade and parallel interconnections work (§2.5.3). Convolution is also linear in each argument and time-invariant: if $y = x*h$ then $x[n-n_0]*h[n] = y[n-n_0]$.

2.4.3 Matrix interpretation

For finite-length sequences, convolution is a matrix–vector product. With $x[n]$ of length $N$ and $h[n]$ of length $M$, stack $y = H\,x$ where $H$ is the $(N{+}M{-}1)\times N$ convolution (Toeplitz) matrix(卷積矩陣) whose columns are shifted copies of $h$. For $h=\{h_0,h_1,h_2\}$ and $N=5$:

Convolution as Matrix Product $$\begin{bmatrix} y[0]\\ y[1]\\ y[2]\\ y[3]\\ y[4]\\ y[5]\\ y[6] \end{bmatrix} = \begin{bmatrix} h_0 & 0 & 0 & 0 & 0\\ h_1 & h_0 & 0 & 0 & 0\\ h_2 & h_1 & h_0 & 0 & 0\\ 0 & h_2 & h_1 & h_0 & 0\\ 0 & 0 & h_2 & h_1 & h_0\\ 0 & 0 & 0 & h_2 & h_1\\ 0 & 0 & 0 & 0 & h_2 \end{bmatrix} \begin{bmatrix} x[0]\\ x[1]\\ x[2]\\ x[3]\\ x[4] \end{bmatrix}$$

Each column is the echo launched by one input sample (Interpretation 1); each row is the flipped window picking out one output sample (Interpretation 2). The constant-along-diagonals (Toeplitz) structure is time invariance written as a matrix.

2.4.4 Support, length, and MATLAB

Key — output support rules
If $x[n]$ has length $N$ starting at index $n_x$, and $h[n]$ has length $M$ starting at $n_h$, then $y = x*h$ has length $\boxed{N+M-1}$, starting at index $n_x+n_h$ and ending at index $(n_x+N-1)+(n_h+M-1)$. Sanity checks: $y[\text{first}] = x[\text{first}]\,h[\text{first}]$ and $\sum_n y[n] = \left(\sum_n x[n]\right)\left(\sum_n h[n]\right)$.
x[n] N = 3, n_x = 1 h[n] M = 4, n_h = 2 ↓ ∗ ↓ y[n] N+M−1 = 6 1 2 3 4 5 6 7 8 start = n_x+n_h = 1+2 = 3 end = (n_x+N−1)+(n_h+M−1) = 8
Fig. 2-4b — Output support adds up(輸出支撐相加): supports translate so $y$ starts where the two earliest samples align(最早樣本相加 $n_x+n_h$)and ends where the two latest align; the count is $N+M-1$(端點各貢獻一個,重疊處只算一次). Here $3+4-1 = 6$ samples spanning indices $3\!\dots\!8$.
MATLAB — conv
y = conv(x, h) returns the full length-$(N{+}M{-}1)$ result. MATLAB vectors carry no time origin — you must track the starting index: if x starts at $n_x$ and h at $n_h$, build the output axis as ny = (nx+nh) : (nx+nh+N+M-2). Plot discrete sequences with stem, never plot.

2.5 LTI System Properties via h[n]

Because $h[n]$ characterizes an LTI system completely, every system property of §2.2 must be readable directly from $h[n]$.

2.5.1 Causality ⇔ h[n] = 0 for n < 0

LTI Causality Test $$\text{LTI system causal} \iff h[n] = 0 \ \text{ for all } n < 0$$

Why: in $y[n] = \sum_k h[k]\,x[n-k]$, the terms with $k<0$ involve $x[n-k]$ with $n-k > n$ — future inputs. They vanish for every input iff $h[k]=0$ for $k<0$. ($\Leftarrow$) is immediate; ($\Rightarrow$) follows because $h[n]$ is itself the response to $\delta[n]$: a causal system cannot respond before the impulse arrives at $n=0$. A sequence with this property is called a causal sequence.

2.5.2 Stability ⇔ absolute summability

LTI BIBO Test $$\color{#c0392b}{\boldsymbol{\text{LTI system BIBO stable} \iff S \;=\; \sum_{k=-\infty}^{\infty} \bigl|h[k]\bigr| < \infty}}$$
Proof sketch (both directions)
Sufficiency ($S<\infty$ ⇒ stable): if $|x[n]|\le B_x$, $$|y[n]| = \Bigl|\sum_k h[k]\,x[n-k]\Bigr| \le \sum_k |h[k]|\,|x[n-k]| \le B_x \sum_k |h[k]| = B_x S < \infty.$$
Necessity ($S=\infty$ ⇒ unstable): choose the bounded adversarial input(有界對抗性輸入,最壞情況)$x[n] = \operatorname{sgn}\!\bigl(h[-n]\bigr)$ (so $|x[n]|\le1$). Then $$y[0] = \sum_k h[k]\,x[-k] = \sum_k h[k]\operatorname{sgn}(h[k]) = \sum_k |h[k]| = S = \infty,$$ so one output sample already diverges.
Examples: MA: $\sum|h| = M\cdot\frac1M = 1$ → stable. Accumulator: $\sum_n |u[n]| = \infty$ → unstable (consistent with Fig. 2-4). $h[n]=a^n u[n]$: $\sum_{n\ge0}|a|^n = \frac{1}{1-|a|}$ if $|a|<1$ → stable iff $|a|<1$.
什麼是「有界對抗性輸入」?(bounded adversarial input)

對抗性(adversarial)指的是刻意構造、用來「打垮」系統的最壞情況輸入,但它仍必須是有界的($|x[n]|\le1$)——因為 BIBO 的定義就是「任何有界輸入」都要產生有界輸出,所以我們有權挑選最刁鑽的那一個。

要證明系統不穩定,只需找到一個有界輸入使輸出發散即可。因此不隨便取,而是選最「惡意」的: $$x[n] = \operatorname{sgn}\!\bigl(h[-n]\bigr).$$

它的巧妙之處在於 $n=0$ 時,符號剛好對齊每個 $h[k]$: $$y[0] = \sum_k h[k]\,x[-k] = \sum_k h[k]\,\operatorname{sgn}(h[k]) = \sum_k |h[k]| = S.$$ 每一項都變成 $+|h[k]|$,沒有任何抵消、全部同號相加(建設性疊加)——這正是最壞情況。若 $S=\infty$,則單一個輸出樣本 $y[0]$ 就已發散,系統必不穩定。

總結:有界對抗性輸入 = 有界(合法測試輸入)+ 符號對齊(使輸出最大化),是揭露系統不穩定最乾淨俐落的構造。

為什麼用 $h[-n]$ 而不是 $h[n]$?

關鍵在於卷積本身內建的時間反轉(翻摺,flip)。輸出在 $n=0$ 時為 $$y[0] = \sum_k h[k]\,x[0-k] = \sum_k h[k]\,x[-k].$$ 注意輸入的索引是 $-k$ 而不是 $k$。要讓每一項都同號相加,必須讓 $$x[-k] = \operatorname{sgn}(h[k]) \quad\text{對所有 } k.$$

令 $m=-k$(即 $k=-m$)代換,得 $$x[m] = \operatorname{sgn}(h[-m]) \;\Longrightarrow\; x[n] = \operatorname{sgn}(h[-n]).$$ 這個 $h[-n]$ 正好抵消卷積的翻摺——兩次反轉互相抵消,代回後: $$y[0]=\sum_k h[k]\,\underbrace{\operatorname{sgn}(h[k])}_{x[-k]}=\sum_k|h[k]|=S.$$

若改用 $x[n]=\operatorname{sgn}(h[n])$,則 $x[-k]=\operatorname{sgn}(h[-k])$,符號與 $h[k]$ 對不上,各項會部分抵消,無法把總和逼到 $S$。那個負號的存在,完全是為了配合卷積的翻摺。

那「不左右翻摺」就不能取符號嗎?能——取符號(sgn)本身完全不需要翻摺,這兩件事是獨立、目的不同的。翻摺不是為了取得符號,而是為了抵消卷積自己內建的翻摺:

  • 取符號 sgn:丟掉大小、只留 $\pm1$ — 讓輸入有界($|x|\le1$)且各項同號相加。
  • 左右翻摺 $n\to-n$:把訊號鏡射 — 抵消卷積公式裡的 $x[-k]$。

因為輸出 $y[0]=\sum_k h[k]\,x[\boldsymbol{-k}]$ 中的輸入已被卷積翻過一次;我要的是 $x[-k]=\operatorname{sgn}(h[k])$,所以 $x$ 本身必須先反著放,被卷積再翻一次後才正過來——兩次翻摺剛好抵消。簡言之:符號管「有界+同號」,翻摺管「對齊卷積的 $-k$」,兩者缺一不可,但互不替代。

① h[k]:我們要對齊的符號(落在 k ≥ 0) 0 1 2 3 + 翻摺① 我們故意反著放:x[n] = sgn(h[−n]),落在 n ≤ 0 ↓ ② x[n] = sgn(h[−n])(建構出的輸入,落在 n ≤ 0) 0 −1 −2 −3 翻摺② 卷積自動取 x[−k]:再翻回 k ≥ 0 ↓ ③ x[−k]:卷積翻回後,與 ① 同號 ✓ 0 1 2 3 x[−k] 與 h[k] 同號 ⇒ h[k]·x[−k] = |h[k]| 全為正
Fig. 2-5c — 兩次翻摺剛好抵消(two flips cancel):① $h[k]$ 是我們想對齊的符號;② 我們故意把輸入反著放成 $x[n]=\operatorname{sgn}(h[-n])$(落在 $n\le0$);③ 卷積在算 $y[0]=\sum_k h[k]\,x[-k]$ 時自動再翻一次取 $x[-k]$,把它翻回 $k\ge0$ 並與 ① 完全同號,因此每項 $h[k]\,x[-k]=|h[k]|$ 全為正,$y[0]=S$。
① h[n] 原本的脈衝響應 混合正負號 0 1 2 3 翻摺 flip:n → −n(左右鏡射)↓ ② h[−n] 時間反轉 0 −1 −2 −3 取符號 sgn:只留 ±1,丟掉大小 ↓ ③ x[n] = sgn(h[−n]) 對抗輸入 |x[n]| ≤ 1 有界 +1 −1 0 −1 −2 −3
Fig. 2-5b — 對抗輸入的構造(construction of the adversarial input):把 $h[n]$ 左右翻摺成 $h[-n]$,再取符號得 $x[n]=\operatorname{sgn}(h[-n])$。如此一來 $x[-k]=\operatorname{sgn}(h[k])$ 與 $h[k]$ 同號,使 $y[0]=\sum_k|h[k]|=S$(綠色=正、紅色=負)。

那把 ① $h[k]$ 和 ③ $x[-k]$ 真的卷積起來,$y[0]$ 是什麼結果?下面一步一步算(仍用 $h=[0.8,-0.5,0.3,-0.2]$):

步驟① 對齊 h[k] 與 x[−k](k = 0,1,2,3) h[k] x[−k] +0.8 −0.5 +0.3 −0.2 +1 −1 +1 −1 k=0 步驟② 逐項相乘 h[k]·x[−k] (負×負 = 正,全部翻正) 0.8×(+1) (−0.5)×(−1) 0.3×(+1) (−0.2)×(−1) 0.8 0.5 0.3 0.2 = |h[k]| 步驟③ 全部相加 → y[0] = ∑ |h[k]| = S 0.8 0.5 0.3 0.2 0.8 1.3 1.6 1.8 y[0] = 0.8 + 0.5 + 0.3 + 0.2 = 1.8 = ∑|h[k]| = S 沒有任何抵消,全部同號相加 → 這就是輸出能達到的最大值(最壞情況)
Fig. 2-5d — ①$\,*\,$③ 在 $n=0$ 的卷積結果(the convolution at $n=0$):對齊後逐項相乘,因 $x[-k]=\operatorname{sgn}(h[k])$ 使每個乘積都變成 $+|h[k]|$(負乘負為正),全部相加得 $y[0]=\sum_k|h[k]|=S=1.8$。這正是不穩定判據裡「一個有界輸入就能讓輸出衝到 $S$」的算術過程。
把輸入右移 4,結果會變嗎?(時間不變性 time invariance)

不變。由卷積的時間不變性:把輸入延遲 $4$,輸出也只是跟著延遲 $4$,數值完全不變。設 $x'[n]=x[n-4]$,則 $$y'[n]=(h*x')[n]=(h*x)[n-4]=y[n-4]\quad\Longrightarrow\quad y'[4]=y[0]=S=1.8.$$

直接驗算也一致:$y'[4]=\sum_k h[k]\,x'[4-k]=\sum_k h[k]\,x[-k]=y[0].$ 換句話說整張圖只是往右滑 4 格,峰值 $S$ 出現的位置變了,大小沒變。這也說明證明裡為何可以隨意挑 $n=0$ 來算——任何一個「符號全對齊」的樣本都等於 $S$。

原始輸出 y[n] (輸入 x[n] 落在 n = −3 … 0) y[0]=1.8=S −3 −2 −1 0 1 2 3 整段右移 4:y[n] → y[n−4],S 不變 右移後 y′[n]=y[n−4] (輸入 x′[n] 落在 n = 1 … 4) y′[4]=1.8=S 1 2 3 4 5 6 7
Fig. 2-5e — 時間不變性(time invariance):把輸入右移 $4$,整條輸出 $y[n]$ 原封不動往右滑 $4$ 格成 $y'[n]=y[n-4]$。原本在 $n=0$ 的峰值 $S=1.8$ 移到 $n=4$,數值不變、形狀不變——只有位置改變。
只有 $n=0$ 保證「全正相加 = S」,其他索引會抵消

對。對抗輸入是專為 $n=0$ 調好的($x[-k]=\operatorname{sgn}(h[k])$),所以唯有在 $n=0$ 每一項都同號為正: $$y[0]=\sum_k h[k]\,\underbrace{x[-k]}_{=\,\operatorname{sgn}(h[k])}=\sum_k |h[k]|=0.8+0.5+0.3+0.2=1.8=S.$$ 其他索引對不齊,符號混雜、部分抵消,甚至端點只剩單一項(根本不是「和」):

$n$各項$y[n]$
$-3$只有 $h[0]x[-3]=0.8(-1)$(單一項)$-0.8$
$-2$$0.8(+1)+(-0.5)(-1)$$+1.3$
$-1$$0.8(-1)+(-0.5)(+1)+0.3(-1)$(全負)$-1.6$
$0$$0.8+0.5+0.3+0.2$(全正)$+1.8=S$
$1$混合正負$-1.0$
$2$混合正負$+0.5$
$3$只有 $h[3]x[0]=-0.2$(單一項)$-0.2$

比較大小:$|y[n]| = 0.8,\,1.3,\,1.6,\,\mathbf{1.8},\,1.0,\,0.5,\,0.2$——峰值 $1.8$ 只在 $n=0$ 出現,其餘樣本嚴格較小。這就是證明只讀 $y[0]$ 的原因:它是唯一保證 $|y|$ 達到 $S$ 的樣本;若 $S=\infty$,光這一個樣本就發散 ⇒ 系統不穩定。

2.5.3 Connected systems: cascade and parallel

The convolution algebra of §2.4.2 translates directly into block-diagram rules (Fig. 2-5):

x[n] h₁[n] h₂[n] y[n] x[n] h₁[n] ∗ h₂[n] y[n] Cascade: convolve impulse responses x[n] h₁[n] h₂[n] y[n] x[n] h₁[n] + h₂[n] y[n] Parallel: add impulse responses
Fig. 2-5 — Connected LTI systems: a cascade(串聯)is equivalent to a single system with $h_1*h_2$ (order interchangeable); a parallel connection(並聯)is equivalent to $h_1+h_2$.

2.5.4 Inverse systems

A system $h_i[n]$ is the inverse(反系統) of $h[n]$ if their cascade is the identity system:

Inverse System $$h[n] * h_i[n] = \delta[n] \quad\Longrightarrow\quad x[n] \to \boxed{h} \to \boxed{h_i} \to x[n]$$
Example 2.4 — Accumulator and first difference are inverses
Accumulator: $h[n]=u[n]$. Backward first difference: $h_i[n]=\delta[n]-\delta[n-1]$.
Check the cascade using the shift property: $$u[n]*\bigl(\delta[n]-\delta[n-1]\bigr) = u[n]-u[n-1] = \delta[n]. \checkmark$$
Interpretation: differencing undoes accumulation, exactly as differentiation undoes integration. Inverse systems are the foundation of equalization(等化)— undoing the distortion of a channel by cascading it with its inverse.
Warning — inverses are not always nice
The inverse of a perfectly causal, stable system may be non-causal or unstable. Existence and properties of $h_i[n]$ are much easier to discuss with the $z$-transform (poles and zeros swap roles) — a preview of later chapters.

2.6 Chapter Summary

System properties

Linear: superposition $T\{ax_1+bx_2\}=aT\{x_1\}+bT\{x_2\}$ (zero in → zero out is necessary). Time-invariant: $x[n-n_0]\mapsto y[n-n_0]$. Causal: no future samples. BIBO stable: bounded in → bounded out.

LTI ⇒ convolution

$x[n]=\sum_k x[k]\delta[n-k]$, so $y[n]=\sum_k x[k]h[n-k]=x[n]*h[n]$. The impulse response $h[n]=T\{\delta[n]\}$ fully characterizes the system.

Convolution algebra

Commutative, associative, distributive; $x*\delta[n-n_0]=x[n-n_0]$. Length: $N+M-1$; start index $n_x+n_h$. Matrix view: Toeplitz $H$, $y=Hx$.

Properties via h[n]

Causal ⇔ $h[n]=0,\ n<0$. Stable ⇔ $\sum|h[k]|<\infty$. Cascade: $h_1*h_2$. Parallel: $h_1+h_2$. Inverse: $h*h_i=\delta$.

Exercises

All three problems of ICE503 Homework #2, with full worked solutions.

Exercise 1 — System properties

Problem: For each of the following systems, determine whether the system is (1) linear, (2) time-invariant, and (3) causal.

(a) $y[n] = a^2 x[n] - b$,   $a$ and $b$ non-zero constants
(b) $y[n] = x[an-b]$,   $a$ and $b$ non-zero positive constants
(c) $y[n] = \dfrac{1}{M}\Bigl(x[n] + \displaystyle\sum_{k=1}^{(M-1)/2}\bigl(x[n-k]+x[n+k]\bigr)\Bigr)$   ($M$ odd)
(d) $y[n] = \log_2\bigl(\lvert x[n]\rvert\bigr)$

Click to reveal solution

(a) $y[n]=a^2x[n]-b$ — not linear; time-invariant; causal.

Linearity: zero input gives $y[n]=-b\neq0$, so the system fails the zero-in/zero-out necessary condition → nonlinear (it is affine). Explicitly, $T\{x_1+x_2\} = a^2(x_1+x_2)-b$ but $T\{x_1\}+T\{x_2\} = a^2(x_1+x_2)-2b$.

Time invariance: shifted input $x[n-n_0]$ → $a^2x[n-n_0]-b = y[n-n_0]$. The rule has no explicit dependence on $n$ → time-invariant.

Causality: $y[n]$ uses only $x[n]$ (memoryless) → causal.

(b) $y[n]=x[an-b]$ — linear; not time-invariant; not causal (in general).

Linearity: for input $\alpha x_1+\beta x_2$ the output is $\alpha x_1[an-b]+\beta x_2[an-b] = \alpha y_1[n]+\beta y_2[n]$ → linear (any system that merely re-indexes the input is linear).

Time invariance: shift the input: $w[n]=x[n-n_0]$ gives $T\{w\} = w[an-b] = x[an-b-n_0]$, while the shifted output is $y[n-n_0] = x[a(n-n_0)-b] = x[an-b-an_0]$. These agree for all $x$ only if $an_0=n_0$ for every $n_0$, i.e. only if $a=1$. For a general positive constant $a\neq1$ → not time-invariant (time-scaling re-labels the clock).

Causality: $y[n]$ reads the input at time $an-b$. Causality requires $an-b\le n$, i.e. $(a-1)n\le b$, for every $n$ — impossible for $a>1$ when $n$ grows (e.g. $a=2,b=1$: $y[2]=x[3]$, a future sample) → not causal in general. (In the special case $a=1$ the system is the pure delay $x[n-b]$, $b>0$, which is both time-invariant and causal.)

(c) Centered moving average — linear; time-invariant; not causal.

Write $y[n] = \frac{1}{M}\sum_{k=-(M-1)/2}^{(M-1)/2} x[n-k]$, a symmetric window of odd length $M$ centered on $n$.

Linearity: a weighted sum of input samples with constant weights satisfies superposition term by term → linear.

Time invariance: replacing $x[\cdot]\to x[\cdot-n_0]$ shifts every term identically: $T\{x[n-n_0]\} = \frac1M\sum_k x[n-n_0-k] = y[n-n_0]$ → time-invariant.

Causality: the terms $x[n+k]$ for $k=1,\dots,(M-1)/2$ are future samples → not causal.

(d) $y[n]=\log_2(|x[n]|)$ — not linear; time-invariant; causal.

Linearity: scaling test: input $\alpha x[n]$ gives $\log_2(|\alpha|\,|x[n]|) = \log_2|\alpha| + \log_2|x[n]| \neq \alpha\,\log_2|x[n]|$ → nonlinear (the log turns scaling into an additive offset).

Time invariance: the rule is a fixed memoryless nonlinearity, independent of $n$: shifted input → shifted output → time-invariant.

Causality: depends only on $x[n]$ → causal.

SystemLinearTime-invariantCausal
(a) $a^2x[n]-b$NoYesYes
(b) $x[an-b]$YesNo (unless $a{=}1$)No (unless $a{=}1$)
(c) centered MAYesYesNo
(d) $\log_2|x[n]|$NoYesYes
Exercise 2 — Linear or nonlinear?

Problem: The system $T$ is known to be time-invariant. When the inputs are $x_1[n]$, $x_2[n]$, $x_3[n]$, the responses are $y_1[n]$, $y_2[n]$, $y_3[n]$ (Figure 1 of the homework):

$$\begin{aligned} x_1[n] &= \delta[n] + 2\,\delta[n-1] &&\longrightarrow& y_1[n] &= 2\,\delta[n-1] + 3\,\delta[n-2]\\ x_2[n] &= 2\,\delta[n-1] &&\longrightarrow& y_2[n] &= 2\,\delta[n-2] + 4\,\delta[n-3]\\ x_3[n] &= \delta[n-4] &&\longrightarrow& y_3[n] &= 3\,\delta[n+2] + 2\,\delta[n+1] \end{aligned}$$

Determine whether the system $T$ is linear or nonlinear.

Click to reveal solution

Strategy: assume $T$ is linear, combine that assumption with the given fact that $T$ is time-invariant, and look for a contradiction among the three input–output pairs.

Step 1 — relate the inputs. Notice that $$x_1[n] = \delta[n] + 2\,\delta[n-1] = \delta[n] + x_2[n].$$ If $T$ were linear (additivity), the response to $\delta[n]$ would have to be $$h[n] \;=\; T\{\delta[n]\} \;=\; y_1[n] - y_2[n] = 2\delta[n-1] + 3\delta[n-2] - 2\delta[n-2] - 4\delta[n-3] = 2\delta[n-1] + \delta[n-2] - 4\delta[n-3].$$

Step 2 — invoke time invariance. $T$ is time-invariant, so the response to $x_3[n] = \delta[n-4]$ would have to be $h[n-4]$: $$T\{\delta[n-4]\} = 2\,\delta[n-5] + \delta[n-6] - 4\,\delta[n-7],$$ a sequence supported on $n = 5, 6, 7$.

Step 3 — compare with the measured response. The actual response is $$y_3[n] = 3\,\delta[n+2] + 2\,\delta[n+1],$$ supported on $n = -2, -1$. The two disagree completely → contradiction.

$$\boxed{\text{The system } T \text{ is nonlinear.}}$$

Cross-check (independent contradiction). Since $x_2[n] = 2\,\delta[n-1] = 2\,x_3[n+3]$: by time invariance the response to $x_3[n+3]$ is $y_3[n+3] = 3\delta[n+5]+2\delta[n+4]$; if $T$ were also linear (homogeneity) we would need $y_2[n] = 2\,y_3[n+3] = 6\,\delta[n+5] + 4\,\delta[n+4]$. But the measured $y_2[n] = 2\delta[n-2]+4\delta[n-3]$ — again a contradiction, confirming nonlinearity.

Remark: note the logic direction — the data can disprove linearity, but no finite set of input–output pairs could ever prove it.

Exercise 3 — MATLAB: 5-point moving average

Problem: The input signal is $$x[n] = \delta[n] + 3\,\delta[n-1] + 7\,\delta[n-2] + 2\,\delta[n-3] + 4\,\delta[n-4]$$ and the output of a 5-point moving average is $$y[n] = \frac{1}{5}\sum_{k=0}^{4} x[n-k].$$ (a) Use the stem function to plot $x[n]$. (b) Use a for loop to calculate $y[n]$. (c) Use the convolution function to calculate $y[n]$ (results of (b) and (c) must agree). (d) Use stem to plot $y[n]$.

Click to reveal solution

Setup. The input vector is $x = [1\;3\;7\;2\;4]$ on $n=0,\dots,4$ ($N=5$) and the filter is the FIR impulse response $h[n]=\frac15$ for $0\le n\le4$ ($M=5$). The output has length $N+M-1 = 9$, on $n = 0,\dots,8$.

clc; clear; close all;

n = 0:4;                       % time index of the input
x = [1 3 7 2 4];               % x[n] sample values
N = length(x);                 % input length
M = 5;                         % moving-average length

%% (a) plot x[n] with stem
figure(1)
stem(n, x, 'filled');
xlabel('n'); ylabel('x[n]');
title('Input signal x[n]');
grid on;

%% (b) compute y[n] with a for loop
x_padded = [x zeros(1, M-1)];  % zero-pad to handle the boundary
y_loop = zeros(1, N + M - 1);  % preallocate the output

for i = 1:(N + M - 1)          % loop over output samples
    sum_val = 0;
    for k = 0:(M - 1)          % accumulate the M-sample window
        if (i - k) > 0         % keep the index valid (x[n]=0 for n<0)
            sum_val = sum_val + x_padded(i - k);
        end
    end
    y_loop(i) = sum_val / M;   % the average
end

%% (c) compute y[n] with conv
h = (1/M) * ones(1, M);        % MA impulse response h[n] = 1/5, n = 0..4
y_conv = conv(x, h);           % identical to y_loop

%% (d) plot y[n] with stem
n_out = 0:(N + M - 2);         % output time index, length N+M-1

figure(2)
subplot(2,1,1)
stem(n_out, y_loop, 'filled');
xlabel('n'); ylabel('y[n]');
title('Output y[n] (for loop)');
grid on;

subplot(2,1,2)
stem(n_out, y_conv, 'filled');
xlabel('n'); ylabel('y[n]');
title('Output y[n] (conv)');
grid on;

Hand check (and program output). $y[n] = \frac15\,(x*\mathbf{1}_5)[n]$: each output is the sum of the (at most five) input samples in the window $n-4,\dots,n$, divided by 5:

$n$012345678
window sum14111317161364
$y[n]$0.20.82.22.63.43.22.61.20.8

The loop and conv give exactly the same vector, as required — the nested loop literally evaluates the convolution sum $y[n]=\sum_k h[k]\,x[n-k]$ that conv implements. Sanity checks from §2.4.4: length $5+5-1=9$ ✓; first sample $y[0]=x[0]h[0]=0.2$ ✓; $\sum_n y[n] = 17\cdot1 = 17$, and indeed $\sum x = 17$, $\sum h = 1$ ✓.

2026-06-12T22:22:28.006969 image/svg+xml Matplotlib v3.10.8, https://matplotlib.org/ 0 2 4 6 8 0 2 4 6 x[n] Input x[n] 0 2 4 6 8 n 0 1 2 3 y[n] Output y[n] of the 5-point moving average (loop = conv)
Fig. 2-6 — Homework 2, Problem 3 result regenerated: input x[n] = {1,3,7,2,4} (top) and the 5-point moving-average output y[n] (bottom). The for-loop and conv results coincide exactly(for 迴圈與 conv 結果完全相同).