How an analog signal becomes a sequence — impulse-train sampling, spectrum replication, the Nyquist limit, aliasing, sinc reconstruction, discrete-time processing of analog signals, and amplitude quantization.
6.1 Periodic Sampling
6.1.1 The Ideal Continuous-to-Discrete (C/D) Converter
Digital signal processing of real-world signals begins by converting a continuous-time
(CT) signal(連續時間訊號)into a discrete-time (DT) sequence(離散時間序列).
Periodic sampling(週期取樣)records the value of $x_c(t)$ at uniformly
spaced sampling instants $t = nT$:
Here $T$ is the sampling period(取樣週期, seconds/sample), its
reciprocal $f_s = 1/T$ is the sampling frequency(取樣頻率, samples/second
or Hz), and in radian units
Fig. 6-1 — Periodic sampling: the sequence $x[n]$ keeps only the values of $x_c(t)$ at $t=nT$(紅色曲線為連續訊號,藍色梗圖為每隔 $T$ 秒取出的樣本).
Concept — why sampling is "lossy" in general
Infinitely many different CT signals pass through the same set of samples
(see the aliasing demo of Fig. 6-3). The miracle of the sampling theorem (Section 6.3) is
that if $x_c(t)$ is bandlimited and $T$ is small enough, the samples determine
$x_c(t)$ uniquely — sampling then loses nothing.
6.1.2 Impulse-Train Model of Sampling
To analyze sampling mathematically we use a two-stage model. First multiply $x_c(t)$
by a periodic impulse train(脈衝列)$s(t)$, then convert the impulse
areas to a sequence:
The signal $x_s(t)$ (also written $x_p(t)$ in the slides) is still a CT signal — a
train of impulses whose areas equal the sample values $x_c(nT)$. The DT sequence
$x[n]=x_c(nT)$ carries exactly the same information but lives on the integer axis,
with the time scale $T$ removed(時間軸已正規化,不再帶有 $T$ 的資訊).
The impulse train $s(t)$ is periodic with period $T$, so its CTFT is itself an
impulse train in frequency, with spacing $\Omega_s = 2\pi/T$ and area $2\pi/T$:
CTFT of the impulse train
$$S(j\Omega) = \frac{2\pi}{T}\sum_{k=-\infty}^{\infty} \delta(\Omega - k\Omega_s)$$
Multiplication in time is convolution in frequency (divided by $2\pi$), so the spectrum
of the sampled signal is a sum of shifted and scaled copies(平移且縮放的複本)
of $X_c(j\Omega)$:
Spectrum of the sampled signal (replication formula)
$$X_s(j\Omega) = \frac{1}{2\pi}\,X_c(j\Omega) * S(j\Omega)
= \boxed{\;\frac{1}{T}\sum_{k=-\infty}^{\infty} X_c\!\big(j(\Omega - k\Omega_s)\big)\;}$$
Key result — sampling replicates the spectrum
Sampling at rate $\Omega_s$ makes the analog spectrum periodic: copies of
$X_c(j\Omega)$ appear centered at every multiple of $\Omega_s$
(取樣使頻譜以 $\Omega_s$ 為週期複製), each scaled by $1/T$.
If the copies do not overlap, the original spectrum survives intact in the baseband copy;
if they overlap, the overlapped sum can never be untangled — that overlap is
aliasing.
Fig. 6-2 — Spectrum replication. Top: bandlimited $X_c(j\Omega)$ with highest frequency $\Omega_N$. Middle: $\Omega_s > 2\Omega_N$, the replicas at $k\Omega_s$ stay separated (green dashed lines mark $\pm\Omega_s/2$). Bottom: $\Omega_s < 2\Omega_N$, the replicas overlap and the resulting sum (red) is distorted — aliasing(頻譜複本重疊即為混疊).
6.2.2 CT and DT Spectra — the Mapping ω = ΩT
How does the CTFT of $x_s(t)$ relate to the DTFT of the sequence $x[n]$? Take the CTFT
of the impulse-train expression term by term:
From CTFT to DTFT
$$X_s(j\Omega) = \sum_{n} x_c(nT)\,e^{-j\Omega T n}
\qquad\text{vs}\qquad
X(e^{j\omega}) = \sum_{n} x[n]\,e^{-j\omega n}$$
The two sums are identical when $\omega = \Omega T$. Hence
DT spectrum of a sampled signal
$$X(e^{j\omega}) = X_s(j\Omega)\Big|_{\Omega=\omega/T}
= \frac{1}{T}\sum_{k=-\infty}^{\infty} X_c\!\left(j\Big(\frac{\omega}{T} - \frac{2\pi k}{T}\Big)\right)$$
Key — normalized vs analog frequency
$$\omega = \Omega T = \frac{\Omega}{f_s}\qquad
\text{(rad/sample)} = \text{(rad/s)}\times\text{(s/sample)}$$
The analog frequency $\Omega = \Omega_s$ (one full sampling rate) maps to $\omega = 2\pi$;
the half sampling rate $\Omega_s/2$ maps to $\omega = \pi$, the edge of the DT baseband.
This is why the DTFT is always $2\pi$-periodic — all replicas land on a $2\pi$ grid
(類比頻率 $\Omega$ 乘上 $T$ 就變成數位頻率 $\omega$;$\Omega_s/2$ 對應 $\omega=\pi$).
Quantity
Continuous time
Discrete time
Frequency variable
$\Omega$ (rad/s)
$\omega = \Omega T$ (rad/sample)
Transform
CTFT $X_c(j\Omega)$, aperiodic
DTFT $X(e^{j\omega})$, $2\pi$-periodic
Sampling rate
$\Omega_s = 2\pi/T$
$2\pi$
Nyquist frequency (half rate)
$\Omega_s/2 = \pi/T$
$\pi$
Amplitude scale
$X_c$
$\tfrac{1}{T}X_c$ in baseband copy
6.3 The Nyquist Sampling Theorem and Aliasing
6.3.1 The Sampling Theorem
From Fig. 6-2: if $x_c(t)$ is bandlimited(頻帶受限), i.e.
$X_c(j\Omega) = 0$ for $|\Omega| \ge \Omega_N$, the replicas remain disjoint provided
$\Omega_s - \Omega_N \ge \Omega_N$. This is the Nyquist–Shannon sampling theorem:
$2\Omega_N$ is called the Nyquist rate(奈奎斯特率)— the minimum sampling rate.
$\Omega_s/2$ is called the Nyquist frequency(奈奎斯特頻率)— the highest analog frequency representable at sampling rate $\Omega_s$.
Warning — strict inequality at the band edge
A sinusoid exactly at the Nyquist frequency ($\Omega_0 = \Omega_s/2$) is a boundary
case: $\sin(\Omega_s t/2)$ sampled at $t=nT$ gives $\sin(\pi n) = 0$ for all $n$ — the
samples vanish entirely. For sinusoidal content you need $\Omega_s > 2\Omega_0$
strictly(正弦訊號剛好在 $\Omega_s/2$ 時相位不巧可能全取到零點,必須嚴格大於).
6.3.2 Aliasing 混疊
If $\Omega_s < 2\Omega_N$, the shifted copies in the replication formula overlap. High
frequencies fold down and masquerade as low frequencies — they take on an
alias(化名). Once the copies are summed, the overlap cannot be filtered out and
$x_c(t)$ can no longer be recovered.
For a sinusoid the alias is easy to compute: frequencies $\Omega_0$ and
$\Omega_0 + k\Omega_s$ produce exactly the same samples:
Sinusoid aliasing
$$\cos\big((\Omega_0 + k\Omega_s)nT + \phi\big)
= \cos\big(\Omega_0 nT + \phi + 2\pi k n\big)
= \cos\big(\Omega_0 nT + \phi\big)$$
Fig. 6-3 — Time-domain view of aliasing: a 1 Hz and a 9 Hz sinusoid sampled at $f_s = 8$ Hz pass through exactly the same samples(紅點), since $9 = 1 + 8$. After sampling, the 9 Hz signal is indistinguishable from its 1 Hz alias(9 Hz 訊號取樣後「偽裝」成 1 Hz).
Real signals (audio, sensor noise, RF interference) are never perfectly bandlimited.
Before the C/D converter we therefore insert a CT lowpass filter — the
anti-aliasing filter $H_{aa}(j\Omega)$ — that forcibly bandlimits the input
to below the Nyquist frequency:
The anti-aliasing filter deliberately destroys the out-of-band content. That is the
right trade: mild, known lowpass distortion of frequencies you do not care about is far
better than aliasing distortion, which corrupts the in-band signal irreversibly
(寧可犧牲帶外成分,也不要讓它混疊進帶內). Practical filters are not brick-wall, so
designers either leave a guard band or oversample then decimate digitally.
6.3.4 Sampling Bandpass Signals 帶通取樣
A signal need not sit around $\Omega = 0$. If its spectrum occupies a band
$\Omega_L \le |\Omega| \le \Omega_H$ with bandwidth $\Delta\Omega = \Omega_H - \Omega_L$,
sampling replicates the band at multiples of $\Omega_s$; as long as no replicas overlap,
the signal can still be recovered, even with $\Omega_s$ far below $2\Omega_H$.
The sampling rate is set by the bandwidth, not the highest frequency —
the principle behind undersampling receivers in communications(取樣率由頻寬決定,
不是由最高頻率決定,這是軟體無線電下變頻取樣的原理). Achieving the limit requires the
band edges to align favorably with $\Omega_s$, so practical designs use somewhat higher
rates.
6.4 Reconstruction 訊號重建
6.4.1 Ideal Reconstruction (D/C) Filter
If sampling obeyed the Nyquist condition, the baseband replica ($k=0$ term) of
$X_s(j\Omega)$ is an undistorted copy of $X_c(j\Omega)/T$. To rebuild $x_c(t)$ we pass the
impulse train $x_s(t)$ through an ideal lowpass reconstruction filter with
gain $T$ and cutoff at the Nyquist frequency $\pi/T$:
The gain $T$ cancels the $1/T$ amplitude scaling introduced by sampling; the cutoff
$\pi/T = \Omega_s/2$ keeps only the $k=0$ replica and erases all the images at
$\pm\Omega_s, \pm 2\Omega_s,\dots$(增益 $T$ 抵消取樣的 $1/T$ 縮放,截止頻率
$\pi/T$ 刪掉所有複本,只留基頻帶那一份).
6.4.2 Sinc Interpolation 弦波內插
Convolving the impulse train with $h_r(t)$ hangs one scaled sinc on every sample:
Interpolation: $h_r(0)=1$ and $h_r(kT)=0$ for integer $k\ne 0$ — at every sampling instant only one sinc is nonzero, so $\hat{x}_a(nT) = x[n]$ exactly.
Bandlimitation: each sinc is bandlimited to $\pi/T$, so the reconstruction is automatically the unique bandlimited signal through the samples.
Fig. 6-4 — Sinc interpolation: one scaled sinc (gray) is centered on every sample (blue); their sum (red) is the unique bandlimited reconstruction. At each sample instant all other sincs cross zero(每個樣本掛一個 sinc,在取樣點上其他 sinc 都恰為零,因此重建曲線必通過所有樣本).
Warning — ideal reconstruction is non-causal
$h_r(t)$ extends over all time and decays only like $1/t$, so the ideal D/C is
unrealizable. Real DACs use a zero-order hold(零階保持)followed by a smoothing
(anti-imaging) lowpass filter; the staircase hold introduces a mild
$\mathrm{sinc}$-shaped droop that good designs compensate digitally.
In simulations (Exercise 2) the sinc sum is also truncated to finitely many
samples, which causes small edge errors.
6.5 Discrete-Time Processing of Continuous-Time Signals
6.5.1 The C/D → H(ejω) → D/C Chain
The central architecture of applied DSP: filter an analog signal by sampling
it, processing the samples with a DT LTI system, and converting back:
Fig. 6-5 — Discrete-time processing of a continuous-time signal: sample, filter digitally, reconstruct(類比訊號經取樣、數位濾波、再重建).
Tracking the spectra through the chain (assuming no aliasing at the C/D):
Spectra through the chain
$$X(e^{j\omega}) = \frac{1}{T}X_c\!\left(j\frac{\omega}{T}\right)\;(|\omega|\le\pi)
\;\;\rightarrow\;\;
Y(e^{j\omega}) = H(e^{j\omega})X(e^{j\omega})
\;\;\rightarrow\;\;
Y_r(j\Omega) = T\,Y(e^{j\Omega T})\;\Big(|\Omega|\le\frac{\pi}{T}\Big)$$
6.5.2 Effective Continuous-Time Frequency Response
Composing the three relations, the whole chain behaves like a single CT LTI system:
Effective analog response of a DT filter
$$\boxed{\;H_{\text{eff}}(j\Omega) = \begin{cases} H(e^{j\Omega T}), & |\Omega| < \pi/T \\[2pt] 0, & |\Omega| \ge \pi/T \end{cases}\;}$$
Key — one digital filter, many analog filters
The same DT filter $H(e^{j\omega})$ implements a different analog response for every
sampling rate: an ideal DT lowpass with cutoff $\omega_c$ acts as an analog lowpass with
cutoff $\Omega_c = \omega_c/T$. Changing $T$ rescales the entire effective analog frequency
axis(同一顆數位濾波器,改變取樣率就改變了等效的類比截止頻率 $\Omega_c=\omega_c/T$).
This is the rule you need for Homework Exercise 1: design $H(e^{j\omega})$ so that
$H_{\text{eff}}(j\Omega)$ does the desired analog job, substituting $\omega = \Omega T$.
Worked Example 6-1 — DT lowpass acting on an analog signal
A DT ideal lowpass filter has cutoff $\omega_c = \pi/4$. The C/D and D/C run at
$f_s = 8$ kHz. What analog filter does the chain implement?
Step 1. $T = 1/8000$ s. Frequency mapping: $\omega = \Omega T$, so $\Omega = \omega/T = \omega f_s$.
Step 3. So $H_{\text{eff}}(j\Omega)$ is an ideal analog lowpass with 1 kHz cutoff (and zero response beyond 4 kHz, the Nyquist frequency). Doubling $f_s$ to 16 kHz would move the cutoff to 2 kHz with the same digital filter.
6.6 Quantization 量化
6.6.1 Uniform Amplitude Quantization
Sampling discretizes time; a real A/D converter must also discretize
amplitude. A uniform quantizer(均勻量化器)with $B$ bits maps each
sample to the nearest of $2^B$ levels spaced $\Delta$ apart. For full-scale amplitude
$m_{\max}$:
Two standard conventions differ in where the levels sit:
Midtread(中平型): round to the nearest integer multiple of $\Delta$ — zero is a level. Example with $\Delta=1$, 2 bits: levels $\{-2,-1,0,1\}$, codes via two's complement $\{10,11,00,01\}$.
Midrise(中升型): round with a half-step offset, $Q[x] = \Delta\,(\lfloor x/\Delta\rfloor + \tfrac12)$ — zero is a threshold, levels $\{-\tfrac32,-\tfrac12,\tfrac12,\tfrac32\}\Delta$. This is the "rounding with offset" used in Homework 6.
Fig. 6-6 — 2-bit uniform quantizer characteristics. Midtread (left) has a level at zero; midrise (right) has a threshold at zero and levels offset by $\Delta/2$(中平型在 0 有一階;中升型的階梯跨在 0 上). Dashed line: ideal $Q[x]=x$.
6.6.2 Quantization Noise Model
The quantization error $e[n] = Q[x[n]] - x[n]$ is deterministic, but for signals that
are large and busy compared to one LSB it behaves like additive white noise
(加性白雜訊), uncorrelated with itself and with the signal:
Fig. 6-7 — A sinusoid quantized by a 3-bit midrise quantizer (top) and the resulting error sequence (bottom). The error stays within $\pm\Delta/2$ (green dashed) and looks noise-like; its measured power $\approx 6.3\times10^{-3}$ is close to the uniform-model prediction $\Delta^2/12 \approx 5.2\times10^{-3}$(誤差近似均勻分布的白雜訊).
The slides' PSD demonstration (quantizing a sinusoid with $B = 3, 7, 11, 15$ bits) shows
the noise floor dropping by about 24 dB per 4 added bits and staying flat across frequency —
exactly the white, $\Delta^2/12$ model(功率頻譜近似平坦,每加 4 bit 下降約 24 dB).
6.6.3 Quantization SNR, Bits, and Dynamic Range
With signal power $P_{\text{avg}} = \sigma_x^2$ and noise power $\sigma_e^2 = \Delta^2/12$,
substituting $\Delta = 2\,m_{\max}\,2^{-B}$ gives $\sigma_e^2 = \tfrac{1}{3}\,m_{\max}^2\,2^{-2B}$, so:
Every added bit halves $\Delta$, quarters the noise power, and adds
$20\log_{10}2 \approx 6.02$ dB of SNR(每多 1 bit,SNR 提升約 6 dB).
For a full-scale sinusoid $P_{\text{avg}} = m_{\max}^2/2$, giving the famous
$\mathrm{SNR} = 6.02B + 1.76$ dB. The constants 1.76 and 1.17 quoted in audio
specs come from this family of formulas; they are loose upper bounds for real signals.
Worked Example 6-2 — How many bits for an audio CD?
An audio CD targets SNR around 95–98 dB. How many bits of resolution are needed?
Step 2. $6.02B + 1.76 \ge 95 \Rightarrow B \ge 15.5$, so $B = 16$ bits — exactly the CD format. With $B=16$: $\mathrm{SNR} \le 98.1$ dB, matching the slide's quoted noise floor of $-98.08$ dB for the CD anti-aliasing/quantization chain.
Step 3. Real converters fall short of the bound: the TI TLV320AIC23B codec's ADC achieves 90 dB SNR ($\approx$ 14.6 effective bits) and its DAC 100 dB ($\approx$ 16 bits) — datasheet SNR divided by 6.02 estimates the effective number of bits.
Dynamic range(動態範圍)of a linear system equals this SNR: the ratio in dB
between the largest representable signal and the noise floor. Powers use
$10\log_{10}(\cdot)$, amplitudes $20\log_{10}(\cdot)$, since $P \propto |A|^2$.
A related implementation issue is coefficient quantization(係數量化):
filter coefficients stored with finite precision move the poles/zeros of $H(z)$ slightly,
perturbing the realized frequency response — a preview of finite-wordlength effects.
6.7 Chapter Summary
Sampling
$x[n] = x_c(nT)$; model as impulse-train modulation $x_s(t)=\sum_n x_c(nT)\delta(t-nT)$. Sampling rate $\Omega_s = 2\pi/T$.
Spectrum replication
$X_s(j\Omega) = \frac{1}{T}\sum_k X_c(j(\Omega-k\Omega_s))$ — copies at every multiple of $\Omega_s$, scaled by $1/T$. DT spectrum: $X(e^{j\omega}) = X_s(j\omega/T)$.
Nyquist theorem
Bandlimited to $\Omega_N$ + $\Omega_s \ge 2\Omega_N$ ⇒ perfect recovery. Below it: aliasing — high frequencies fold into the baseband irreversibly. Anti-alias filter before C/D; bandpass signals need only $\Omega_s/2 \ge \Delta\Omega$.
Reconstruction
Ideal LPF: gain $T$, cutoff $\pi/T$; equivalently sinc interpolation $\hat{x}_a(t) = \sum_n x[n]\,\mathrm{sinc}((t-nT)/T)$ — the unique bandlimited signal through the samples.
DT processing of CT signals
C/D → $H(e^{j\omega})$ → D/C $\equiv$ analog filter $H_{\text{eff}}(j\Omega) = H(e^{j\Omega T})$ for $|\Omega| < \pi/T$. Frequency mapping $\omega = \Omega T$.
Quantization
Step $\Delta = 2m_{\max}/2^B$; midtread vs midrise. Error $\approx$ uniform white noise, $\sigma_e^2 = \Delta^2/12$; SNR $= 6.02B + 4.77 + 10\log_{10}(P_{\text{avg}}/m_{\max}^2)$ dB — about 6 dB per bit.
Exercises
All problems of Homework 6 with full worked solutions. Exercise 1 is the
analytical problem; Exercises 2–3 are the MATLAB simulation parts (a)–(d) and (e)–(f).
Exercise 1 — DT Processing of a CT Signal with an Anti-Aliasing Filter
Problem: The system of Fig. 6-5, preceded by a CT anti-aliasing filter,
processes the input $g_c(t) = f_c(t) + e_c(t)$:
$g_c(t) \to H_{aa}(j\Omega) \to \text{C/D} \to H(e^{j\omega}) \to \text{D/C} \to y_c(t)$,
with both converters running at period $T$.
$F_c(j\Omega)$ is a triangle of height $A$, nonzero only for $|\Omega| < 400\pi$.
$E_c(j\Omega)$ (wideband noise) is flat with height $B$, nonzero only for $|\Omega| > 400\pi$ — so $g_c(t)$ is not bandlimited.
Anti-aliasing filter: $|H_{aa}(j\Omega)| = 1$ for $|\Omega| \le 400\pi$, falls linearly from 1 to 0 over $400\pi \le |\Omega| \le 800\pi$, and is 0 for $|\Omega| \ge 800\pi$; phase $\angle H_{aa}(j\Omega) = -\Omega^3$.
(a) If the sampling rate is $2\pi/T = 1600\pi$, find $H(e^{j\omega})$ such that
$y_c(t) = f_c(t)$.
(b) Is $y_c(t) = f_c(t)$ still possible with $2\pi/T < 1600\pi$? If so, find the minimum
$2\pi/T$ and the corresponding $H(e^{j\omega})$.
Click to reveal solution
Setup — what reaches the C/D converter. The filter output is
$x_c(t)$ with spectrum $X_c(j\Omega) = H_{aa}(j\Omega)\,[F_c(j\Omega) + E_c(j\Omega)]$:
For $|\Omega| \le 400\pi$: only $f_c$ lives here and $|H_{aa}|=1$, so
$X_c(j\Omega) = F_c(j\Omega)\,e^{-j\Omega^3}$ — the desired signal, but with a nasty
nonlinear phase distortion $e^{-j\Omega^3}$.
For $400\pi < |\Omega| < 800\pi$: a residue of attenuated noise
$E_c(j\Omega)H_{aa}(j\Omega)$ survives.
For $|\Omega| \ge 800\pi$: nothing — $x_c(t)$ is bandlimited to $800\pi$.
The DT system must therefore do two jobs: (i) reject everything outside
the $f_c$ band, and (ii) equalize the phase $e^{-j\Omega^3}$ inside it.
(a) Sampling at $\Omega_s = 2\pi/T = 1600\pi$ (so $T = 1/800$).
Since $x_c$ is bandlimited to $800\pi = \Omega_s/2$, there is no aliasing. In the
DT domain, with $\omega = \Omega T$:
On the $f_c$ band the baseband spectrum is $X(e^{j\omega}) = \frac{1}{T}
F_c(j\omega/T)\,e^{-j(\omega/T)^3}$. The D/C contributes gain $T$ and cuts at $\pi/T$, so
to get $Y_c(j\Omega) = F_c(j\Omega)$ we need $H$ to cancel the phase and act as an ideal
lowpass with cutoff $\pi/2$:
(The exponent $({\omega/T})^3 = \omega^3/T^3 = 5.12\times 10^8\,\omega^3$.)
(b) Can we sample slower? Yes. The key observation: aliasing of the
noise residue band is harmless as long as the folded copies do not land on top of
the $f_c$ band $|\Omega| \le 400\pi$ — whatever lands in $400\pi < |\Omega|$ can still be
removed by the DT lowpass.
When sampling at $\Omega_s$, the replica centered at $+\Omega_s$ occupies
$[\Omega_s - 800\pi,\; \Omega_s + 800\pi]$. Its lowest frequency must not intrude below
$400\pi$:
So the minimum rate is $2\pi/T = 1200\pi$, i.e. $T = 1/600$ — only $1.5\times$ the
$800\pi$ Nyquist rate of $f_c$ itself, not $2\times$ the $800\pi$ band edge of the filtered
noise. At this rate the folded noise occupies exactly
$400\pi \le |\Omega| \le 600\pi$ in the baseband, touching but not entering the signal band.
In DT frequency the $f_c$ band edge maps to $\omega = 400\pi\,T = 2\pi/3$:
Takeaways: (1) the DT filter compensates an analog phase
distortion via the substitution $\Omega = \omega/T$; (2) out-of-band noise may alias onto
itself without harm — the true constraint is protecting the signal band, which permits a
sub-Nyquist (relative to $800\pi$) sampling rate(雜訊混疊到雜訊帶沒關係,只要不疊進訊號帶,
取樣率就可以低於 $1600\pi$).
Problem:
(a) Generate the "continuous-time" signal $x_c(t) = \sin(4\pi t)$, $0 \le t \le 1$, using
the dense grid t = 0:0.001:1, and plot it.
(b) Sample $x_c(t)$ with sampling periods $T = 0.01$, $0.05$, $0.1$ s and stem-plot the
three sequences $x[n]$.
(c) Reconstruct $y_c(t)$ from each sequence using sinc interpolation and plot the three
reconstructions.
(d) Compute the mean square error (MSE) between $x_c(t)$ and each $y_c(t)$.
Click to reveal solution
Frequency check first: $\sin(4\pi t)$ has $f_0 = 2$ Hz, so the Nyquist
rate is 4 Hz. The three sampling rates are $f_s = 100$, $20$, and $10$ Hz — all comfortably
above Nyquist, so in principle every case reconstructs perfectly; the differences we
measure come from truncating the sinc sum to the finite interval $[0,1]$.
clc; clear; close all;
%% (a) "continuous-time" reference signal
t = 0:0.001:1;
xc = sin(4*pi*t);
figure(1); plot(t, xc, 'r');
title('x_c(t) = sin(4\pi t)'); xlabel('t (s)'); ylabel('x_c(t)');
%% (b)+(c) sample with T = 0.01, 0.05, 0.1 and sinc-reconstruct
Ts = [0.01 0.05 0.1];
mse = zeros(1,3);
figure(2);
for i = 1:3
T = Ts(i);
nT = 0:T:1; % sampling instants
xn = sin(4*pi*nT); % x[n] = xc(nT)
subplot(3,2,2*i-1); % left column: x[n]
stem(nT, xn);
title(sprintf('x[n], T = %.2f', T));
xlabel('n'); ylabel('x[n]');
yc = zeros(size(t)); % sinc interpolation
for k = 1:length(nT)
yc = yc + xn(k) * sinc((t - nT(k)) / T);
end
subplot(3,2,2*i); % right column: yc(t)
plot(t, yc, 'r');
title(sprintf('y_c(t), T = %.2f', T));
xlabel('t (s)'); ylabel('y_c(t)');
mse(i) = mean((xc - yc).^2); % (d) mean square error
fprintf('MSE for T = %.2f : %e\n', Ts(i), mse(i));
end
Fig. E-1 — (a) The reference signal $x_c(t)=\sin(4\pi t)$ on the dense grid(用 0.001 s 的細網格近似連續訊號).
Fig. E-2 — (b)(c) Left: sampled sequences for $T = 0.01, 0.05, 0.1$; right: sinc reconstructions (red) vs the original (gray dashed). All three rates exceed Nyquist, so reconstruction is visually faithful even at $T=0.1$ (only 5 samples/period).
(d) Results (computed with the same algorithm in numpy):
$T$ (s)
$f_s$ (Hz)
samples in $[0,1]$
MSE
0.01
100
101
$2.32\times 10^{-6}$
0.05
20
21
$3.32\times 10^{-4}$
0.10
10
11
$3.24\times 10^{-3}$
Discussion. Since all three rates satisfy Nyquist, the ideal
(infinite-length) sinc sum would give zero error in every case. The nonzero MSE comes from
edge effects: the interpolation formula needs samples for all $n\in\mathbb{Z}$, but we
only have $t\in[0,1]$. Each missing out-of-window sinc tail decays like $1/t$, and with
larger $T$ there are fewer, more widely spaced samples, so the truncation error near the
window edges grows — hence MSE increases by roughly $10\times$ for each step of $T$
(誤差來自 sinc 級數被截斷的邊界效應,而非混疊).
Exercise 3 — MATLAB: Midrise Quantization and MSE vs Bits (HW6 Matlab e–f)
Problem:
(e) For the $T=0.01$ sequence $x[n]$, quantize with 2 bits (4 levels), 3 bits (8 levels),
and 4 bits (16 levels), rounding with offset (midrise). Stem-plot the three
quantized signals $x_q[n]$.
(f) Compute the MSE between $x[n]$ and each $x_q[n]$, and discuss the advantages and
disadvantages of using different numbers of bits.
Click to reveal solution
Midrise rule. With full scale $m_{\max}=1$ the step is
$\Delta = 2/2^B$, and rounding with offset means
$x_q = \Delta\,(\lfloor x/\Delta \rfloor + \tfrac12)$, clipped to the outermost levels
$\pm(1 - \Delta/2)$ — the staircase of Fig. 6-6 (right).
%% (e) midrise quantization of the T = 0.01 sequence, B = 2, 3, 4
T = 0.01;
nT = 0:T:1;
xn = sin(4*pi*nT);
bits = [2 3 4];
figure(3);
for i = 1:3
B = bits(i);
D = 2 / 2^B; % step = full scale / #levels
xq = (floor(xn / D) + 0.5) * D; % round with offset (midrise)
xq = min(max(xq, -1 + D/2), 1 - D/2); % clip to outermost levels
subplot(3,1,i);
stem(nT, xq);
title(sprintf('%d-bit midrise quantization (%d levels)', B, 2^B));
xlabel('n'); ylabel('x_q[n]');
%% (f) mean square quantization error
mseq = mean((xn - xq).^2);
fprintf('B = %d bits : Delta = %.4f, MSE = %e (theory %.3e)\n', ...
B, D, mseq, D^2/12);
end
Fig. E-3 — (e) Midrise quantization of $x[n]$ ($T=0.01$) with 2, 3, 4 bits. The staircase approximation visibly tightens as $B$ grows(位元數越多,階梯越貼近原訊號).
(f) Results:
$B$ (bits)
levels
$\Delta$
MSE measured
$\Delta^2/12$ (theory)
2
4
0.500
$2.71\times 10^{-2}$
$2.08\times 10^{-2}$
3
8
0.250
$6.86\times 10^{-3}$
$5.21\times 10^{-3}$
4
16
0.125
$2.02\times 10^{-3}$
$1.30\times 10^{-3}$
Discussion.
Each added bit cuts the MSE by roughly 4× ($\approx 6$ dB), exactly
the $\sigma_e^2 = \Delta^2/12 \propto 4^{-B}$ law of Section 6.6 — halving $\Delta$
quarters the error power.
The measured MSE sits slightly above $\Delta^2/12$ because a full-scale
sinusoid spends extra time near its peaks $\pm 1$, where midrise clipping to
$\pm(1-\Delta/2)$ adds overload error, and because the error of a smooth deterministic
signal is not perfectly uniform.
Trade-off: more bits ⇒ higher fidelity (better SNR, lower distortion)
but more expensive hardware, more memory/bandwidth per sample, and slower conversion;
fewer bits ⇒ cheap and fast but audible/visible staircase distortion and a high noise
floor(位元多:精度高但成本、儲存與傳輸量增加;位元少:便宜快速但量化雜訊明顯).
The right choice matches the application: 16 bits for CD audio, 8–12 bits for video and
many sensors, 1-bit oversampled converters in sigma-delta designs.