From Fourier series to the discrete-time Fourier transform: frequency response, DTFT pairs and theorems, Parseval's relation, and group delay.
4.1 The Fourier Domain
Joseph Fourier (1768–1830) claimed that any function of a variable — continuous
or discontinuous — can be expanded in a series of sines of multiples of that variable.
The modern statement is more careful about convergence, but the idea survives intact:
signals can be represented as sums (or integrals) of sinusoids, and this representation
— the Fourier domain(傅立葉域 / 頻域) — is where LTI systems become
simple to analyze.
4.1.1 Fourier series and Fourier coefficients
A periodic signal $x(t)$ with period $T$ (fundamental frequency $\Omega_0 = 2\pi/T$)
can be approximated by a sum of harmonics(諧波) of the fundamental
frequency:
Equivalently, each harmonic pair $a_k\cos + b_k\sin$ can be written as a single
sinusoid with an amplitude and a phase shift(相位移):
$A_k\cos(k\Omega_0 t + \phi_k)$ with $A_k = \sqrt{a_k^2+b_k^2}$,
$\phi_k = -\arctan(b_k/a_k)$. The set $\{c_k\}$ is the signal, viewed in the
Fourier domain.
Fig. 4-1 — Fourier-series partial sums of a square wave.
More harmonics give a better fit, but the overshoot near the jumps (Gibbs phenomenon) never
shrinks below about 9%.(方波的傅立葉級數部分和:諧波越多越接近,但跳變處的 Gibbs 過衝不會消失。)
For aperiodic continuous-time signals, the spacing $\Omega_0=2\pi/T$ between harmonics
goes to zero as $T\to\infty$ and the sum becomes an integral — the
Fourier transform(傅立葉轉換):
and by duality a sinc in time transforms to a rectangle in frequency — which is
exactly why the ideal lowpass filter of §4.3.3 has a sinc impulse response. A pure sine
$\sin(\Omega_0 t)$ transforms to a pair of impulses at $\pm\Omega_0$: a single frequency
occupies a single point in the Fourier domain.
Concept — narrow in time ↔ wide in frequency
The shorter the pulse $T_p$, the wider its sinc mainlobe ($\propto 1/T_p$)(時域越窄,頻域越寬).
This time–frequency tradeoff reappears in windowing, in the uncertainty principle, and in the
STFT of Chapter 9.
4.1.3 Eigenfunctions of LTI systems and frequency response
Why are complex exponentials the right building blocks? Feed
$x[n] = e^{j\omega n}$ (for all $n$) into an LTI system with impulse response $h[n]$:
The output is the same exponential scaled by the complex constant
$H(e^{j\omega})$ — the frequency response(頻率響應) of the system,
which is precisely the DTFT of $h[n]$. So $e^{j\omega n}$ is an
eigenfunction of every LTI system, with eigenvalue $H(e^{j\omega})$.
For a real LTI system and real input $x[n]=A\cos(\omega_0 n + \phi)$, the steady-state output is
$$y[n] = A\,\bigl|H(e^{j\omega_0})\bigr|\cos\!\bigl(\omega_0 n + \phi + \angle H(e^{j\omega_0})\bigr)$$
Magnitude is scaled by $|H|$, phase is shifted by $\angle H$ — the frequency never changes.
(弦波進、同頻率弦波出:只改振幅與相位。)This is used directly in Exercise 2(c).
4.2 The Discrete-Time Fourier Transform (DTFT) 🔖
4.2.1 Definition
For a sequence $x[n]$, the discrete-time Fourier transform(離散時間傅立葉轉換)
is the continuous, complex-valued function of the normalized angular frequency
$\omega$ (rad/sample):
Warning — why the argument is written $e^{j\omega}$
The notation $X(e^{j\omega})$ (not $X(\omega)$) is deliberate: the transform depends on
$\omega$ only through $e^{j\omega}$, which makes the $2\pi$-periodicity explicit and
connects directly to the z-transform of Chapter 5 — the DTFT is the z-transform evaluated
on the unit circle $z=e^{j\omega}$.(寫成 $e^{j\omega}$ 是刻意的:強調週期性,並對應單位圓上的 z 轉換。)
4.2.2 Periodicity of the DTFT
Because $n$ is an integer, $e^{-j(\omega+2\pi)n} = e^{-j\omega n}e^{-j2\pi n} = e^{-j\omega n}$.
The periodicity is implicit in the definition:
Implicit periodicity
$$X\bigl(e^{j(\omega+2\pi k)}\bigr) = X(e^{j\omega})\qquad\text{for any integer } k$$
Key — one period tells all
Every DTFT is periodic in $\omega$ with period $2\pi$. We therefore only ever need one period,
conventionally $-\pi \le \omega < \pi$ or $0 \le \omega < 2\pi$. High frequencies live near
$\omega=\pm\pi$, low frequencies near $\omega = 0$.(DTFT 一定以 $2\pi$ 為週期,看一個週期就夠;
$\omega=0$ 附近是低頻,$\pm\pi$ 附近是最高頻。)In Exercise 3 the spectra are plotted over
$0\le\omega\le 6\pi$ precisely to make this periodicity visible — you will see three identical copies.
4.2.3 Inverse DTFT
The DTFT can be inverted by integrating over any one period. Multiply
$X(e^{j\omega})$ by $e^{j\omega n}$ and integrate:
Substituting the analysis equation into the synthesis integral and swapping sum and
integral, every term dies except $m=n$, returning $x[n]$ exactly. The pair
(analysis, synthesis) says: $x[n]$ is a
superposition of exponentials $e^{j\omega n}$ over a continuum of frequencies, weighted
by $X(e^{j\omega})\,d\omega/2\pi$.
An LTI system is BIBO stable iff $h[n]$ is absolutely summable — which is exactly the
condition for $H(e^{j\omega})$ to exist as an ordinary (uniformly convergent) function.
A stable system always has a well-defined frequency response.(穩定 ⇔ $h[n]$ 絕對可和 ⇔
頻率響應存在且連續。)
Example 4-A — DTFT of the exponential sequence $x[n]=a^n\mu[n]$
Assume $|a|<1$ so the sequence is absolutely summable.
Insert into the definition and recognize a geometric series:
$$X(e^{j\omega}) = \sum_{n=0}^{\infty} a^n e^{-j\omega n}
= \sum_{n=0}^{\infty}\bigl(a\,e^{-j\omega}\bigr)^n = \frac{1}{1-a\,e^{-j\omega}}
\quad{\scriptstyle\textcolor{gray}{|a e^{-j\omega}| = |a| < 1}}$$
Magnitude and phase (rationalize with the conjugate):
$$\bigl|X(e^{j\omega})\bigr| = \frac{1}{\sqrt{1-2a\cos\omega+a^2}},\qquad
\theta(\omega) = -\arctan\frac{a\sin\omega}{1-a\cos\omega}$$
Sanity check(合理性驗証): for $0<a<1$, $|X|$ is largest at $\omega=0$
(value $\tfrac{1}{1-a}$) and smallest at $\omega=\pi$ (value $\tfrac{1}{1+a}$) — a lowpass shape,
consistent with a slowly decaying, smooth time sequence. See Fig. 4-4 for $a=\tfrac12$.
4.3.2 The rectangular pulse and the Dirichlet kernel
Example 4-B — DTFT of a length-$M$ rectangular pulse
Let $x[n]=1$ for $0\le n\le M-1$ and zero elsewhere — a finite geometric sum:
Factor half-angle exponentials from numerator and denominator:
$$X(e^{j\omega})
= \frac{e^{-j\omega M/2}\bigl(e^{j\omega M/2}-e^{-j\omega M/2}\bigr)}
{e^{-j\omega/2}\bigl(e^{j\omega/2}-e^{-j\omega/2}\bigr)}
= \underbrace{\frac{\sin(\omega M/2)}{\sin(\omega/2)}}_{\text{Dirichlet kernel}}\;
e^{-j\omega(M-1)/2}$$
The linear-phase factor $e^{-j\omega(M-1)/2}$ just reflects that the pulse is
centered at $n=(M-1)/2$. Zeros of $|X|$ fall at $\omega = 2\pi k/M$, $k=1,\dots,M-1$; the
mainlobe width is $4\pi/M$ — longer pulse, narrower mainlobe.
Fig. 4-2 — Magnitude of the DTFT of a length-8 rectangular
pulse: the Dirichlet kernel $\left|\sin(\omega M/2)/\sin(\omega/2)\right|$, the discrete-time
analogue of the sinc. Peak value $M$ at $\omega=0$; zeros at $\omega=2\pi k/M$.
(長度 8 矩形脈衝的 DTFT 幅度 — Dirichlet 核,離散版的 sinc。)
4.3.3 The ideal lowpass filter and the sinc sequence
Going the other way — specify a perfect rectangle in frequency and ask what
sequence produces it. With cutoff $\omega_c$:
At $n=0$ the value is $h_{lp}[0]=\omega_c/\pi$ (take the limit). The impulse response is a
sampled sinc.
Fig. 4-3 — Impulse response of the ideal lowpass filter with
$\omega_c=\pi/4$: $h_{lp}[n]=\sin(\omega_c n)/\pi n$, a two-sided, infinitely long sinc sequence
(dashed: continuous sinc envelope).(理想低通的脈衝響應是雙邊無限長的 sinc 序列。)
Warning — the ideal LPF is unrealizable
$h_{lp}[n]$ is noncausal (nonzero for $n<0$) and decays only like $1/n$, so it is
not absolutely summable — the ideal LPF is unstable and cannot be implemented exactly.
Its DTFT converges only in the mean-square sense, with Gibbs ripples appearing whenever the
sinc is truncated. All of filter design (Chapters 13–14) is the art of approximating this
ideal with realizable systems.(理想低通非因果、不絕對可和,只能近似,不能實現。)
4.4 DTFT Theorems and Properties
4.4.1 Property table
Let $x[n]\leftrightarrow X(e^{j\omega})$, $g[n]\leftrightarrow G(e^{j\omega})$.
All transforms below are $2\pi$-periodic, so frequency shifts wrap around.
$|e^{-j\omega n_0}X| = |X|$: delaying a sequence never changes its magnitude spectrum, it only
adds linear phase with slope $-n_0$.(時移不改變幅度頻譜,只加上斜率 $-n_0$ 的線性相位。)
This is the cleanest way to remember what "linear phase = pure delay" means in §4.6.
4.4.2 Symmetry relations and real sequences
Define the conjugate-symmetric / conjugate-antisymmetric parts
(共軛對稱/反對稱部分) of a sequence and of a spectrum:
From the table (time reversal + conjugation, proved in Exercise 1) follow the pairings:
Sequence
DTFT
$x[-n]$
$X(e^{-j\omega})$
$x^*[n]$
$X^*(e^{-j\omega})$
$x^*[-n]$
$X^*(e^{j\omega})$
$\mathrm{Re}\{x[n]\}$
$X_{cs}(e^{j\omega})$
$j\,\mathrm{Im}\{x[n]\}$
$X_{ca}(e^{j\omega})$
$x_{cs}[n]$
$\mathrm{Re}\{X(e^{j\omega})\}$
$x_{ca}[n]$
$j\,\mathrm{Im}\{X(e^{j\omega})\}$
Key — DTFT of a real sequence
If $x[n]$ is real, then $X(e^{j\omega}) = X^*(e^{-j\omega})$ (conjugate symmetry). Hence
$$|X(e^{j\omega})| = |X(e^{-j\omega})| \;{\scriptstyle\textcolor{gray}{\text{(even)}}},\qquad
\arg X(e^{j\omega}) = -\arg X(e^{-j\omega}) \;{\scriptstyle\textcolor{gray}{\text{(odd)}}}$$
Real part and $|X|$ are even functions of $\omega$; imaginary part and phase are odd.
For real signals, the half-band $0\le\omega\le\pi$ carries all the information.
(實數序列的頻譜共軛對稱:幅度偶、相位奇,看 $0$ 到 $\pi$ 就夠。)
Convolution in time becomes multiplication in frequency(時域卷積=頻域相乘). This is
the practical payoff of the whole chapter: instead of sliding and summing, multiply two
spectra pointwise and (if needed) invert. Exercise 3 verifies this numerically in MATLAB —
the convolution result and the IDTFT of $X\cdot H$ agree to machine precision.
Example 4-C — convolution via the DTFT
Let $h[n]=\bigl(\tfrac12\bigr)^n\mu[n]$ and $x[n]=\delta[n]-\tfrac12\delta[n-1]$. Find $y[n]=x[n]\ast h[n]$.
Transform each: $H(e^{j\omega}) = \dfrac{1}{1-\frac12 e^{-j\omega}}$ (Example 4-A),
and $X(e^{j\omega}) = 1-\tfrac12 e^{-j\omega}$ (linearity + shift of $\delta$).
Invert by inspection: $y[n]=\delta[n]$. The FIR sequence $x[n]$ is the
inverse system of the IIR system $h[n]$ — a cancellation that is nearly invisible in the
time domain but trivial in the Fourier domain.(頻域一眼看出兩系統互為反系統。)
4.4.4 Modulation and windowing
The dual of convolution: multiplying two sequences convolves their spectra
(periodic convolution, over one period):
Carrier modulation: $x[n]\cos(\omega_0 n)$ has spectrum
$\tfrac12 X(e^{j(\omega-\omega_0)})+\tfrac12 X(e^{j(\omega+\omega_0)})$ — the baseband
spectrum is shifted to $\pm\omega_0$(把頻譜搬到載波頻率).
Windowing: truncating a sequence to length $M$ multiplies it by a
rectangular window, i.e. convolves its spectrum with the Dirichlet kernel of Fig. 4-2 —
smearing details (mainlobe) and leaking energy (sidelobes). This drives window design in
the FIR-filter and spectral-analysis chapters.
4.5 Parseval's Relation and the Energy Density Spectrum
Energy computed sample-by-sample in time equals energy computed frequency-by-frequency
— the DTFT neither creates nor destroys energy, it only reorganizes it. (This is the
$g=x$ special case of the general inner-product form in the table of §4.4.1.)
4.5.2 Energy density spectrum and autocorrelation
Energy density spectrum(能量密度頻譜)
$$S_{xx}(\omega) = \bigl|X(e^{j\omega})\bigr|^2
\qquad\Longrightarrow\qquad
\mathcal{E}_x = \frac{1}{2\pi}\int_{-\pi}^{\pi} S_{xx}(\omega)\,d\omega$$
$S_{xx}(\omega)$ tells how the signal's energy is distributed over frequency. It connects
back to the time domain through the autocorrelation sequence(自相關序列):
(Apply the convolution theorem with $g[n]=x^*[-n]\leftrightarrow X^*(e^{j\omega})$, using
the symmetry proved in Exercise 1(c).) The EDS is the DTFT of the autocorrelation — phase
information is gone; only energy-vs-frequency remains. Note $r_{xx}[0]=\mathcal{E}_x$,
recovering Parseval.
Concept — through an LTI system
Since $Y(e^{j\omega})=H(e^{j\omega})X(e^{j\omega})$, energy spectra multiply by the magnitude
squared of the frequency response:
$$S_{yy}(\omega) = \bigl|H(e^{j\omega})\bigr|^2\,S_{xx}(\omega)$$
The system reshapes the energy distribution by $|H|^2$ — the phase of $H$ does not affect
where the energy sits, which is why $|H|$ alone decides "lowpass / highpass / bandpass".
(通過 LTI 系統,能量頻譜乘上 $|H|^2$;相位不影響能量分佈。)
4.6 Magnitude, Phase, and Group Delay
4.6.1 Magnitude–phase representation of the frequency response
Writing $H(e^{j\omega}) = |H(e^{j\omega})|\,e^{j\theta(\omega)}$ splits the action of an
LTI system on each frequency into a gain $|H|$(增益)and a
phase shift $\theta(\omega)$(相位移). For the first-order system of
Example 4-A:
Fig. 4-4 — Magnitude (top) and phase (bottom) of
$H(e^{j\omega}) = 1/(1-\tfrac12 e^{-j\omega})$, i.e. $h[n]=(1/2)^n\mu[n]$. Lowpass: gain 2 at DC,
gain 2/3 at $\omega=\pi$; magnitude even, phase odd — as required for a real $h[n]$.
(一階系統的幅度/相位響應:幅度為偶函數、相位為奇函數。)
Warning — phase is only known modulo $2\pi$
Numerical routines (MATLAB angle, NumPy np.angle) return the
principal value $\arg H \in (-\pi,\pi]$, producing artificial $2\pi$ jumps in plots
(visible in the Exercise 3 phase plots). The continuous "unwrapped" phase
(unwrap) is needed before differentiating to get group delay.
(數值相位是主值,會出現 $2\pi$ 跳變;算群延遲前要先 unwrap。)
4.6.2 Group delay
A pure delay $h[n]=\delta[n-n_0]$ has $H(e^{j\omega})=e^{-j\omega n_0}$ — linear phase
with slope $-n_0$. Generalizing, the local slope of the (unwrapped) phase measures how much
each narrowband group of frequencies is delayed:
Group delay(群延遲)
$$\tau_g(\omega) = -\frac{d}{d\omega}\,\theta(\omega)
\qquad{\scriptstyle\textcolor{gray}{\theta(\omega)=\text{unwrapped }\arg H(e^{j\omega})}}$$
Interpretation: a narrowband signal centered at $\omega_0$ (a slowly varying envelope on
a carrier) comes out with its envelope delayed by $\tau_g(\omega_0)$ samples and its
carrier phase shifted by $\theta(\omega_0)$. If $\tau_g$ is constant — linear phase — every
group is delayed equally and the waveform shape is preserved; if $\tau_g$ varies with
$\omega$, different frequency components arrive at different times and the waveform is
dispersed(相位失真/色散).
Fig. 4-5 — Left: phase of the 5-point moving average
$H(e^{j\omega})=\frac{1}{5}\sum_{k=0}^{4}e^{-j\omega k}$ — piecewise linear with slope $-2$
($\pi$ jumps occur where the real Dirichlet factor changes sign). Right: its group delay is
exactly $\tau_g=2$ samples at all frequencies (linear phase), while the first-order IIR system
$1/(1-0.8e^{-j\omega})$ has frequency-dependent group delay — low frequencies are delayed up
to 4 samples, high frequencies barely at all.(線性相位 FIR 群延遲恆定;IIR 群延遲隨頻率變化,
造成波形失真。)
Key — linear phase ⇔ constant group delay
$\theta(\omega) = -\omega n_0 \iff \tau_g(\omega)=n_0$: the system behaves (in phase) like a
pure $n_0$-sample delay. Symmetric FIR filters ($h[n]=h[M-1-n]$, like the moving average)
achieve this exactly with $n_0=(M-1)/2$; causal IIR filters never can. This is the central
selling point of FIR filters in Chapter 14.(線性相位=常數群延遲;對稱 FIR 可精確達成,因果 IIR 不行。)
4.7 Summary
The transform pair
$X(e^{j\omega})=\sum_n x[n]e^{-j\omega n}$;
$x[n]=\frac{1}{2\pi}\int_{-\pi}^{\pi}X(e^{j\omega})e^{j\omega n}d\omega$.
Always $2\pi$-periodic; one period suffices. Exists uniformly iff $\sum|x[n]|<\infty$.
Eigenfunctions & frequency response
$e^{j\omega n}$ in → $H(e^{j\omega})\,e^{j\omega n}$ out. Sinusoid in → same-frequency
sinusoid out, scaled by $|H|$, shifted by $\angle H$. $H(e^{j\omega})$ = DTFT of $h[n]$;
exists for every stable system.
Parseval: $\sum|x[n]|^2=\frac{1}{2\pi}\int_{-\pi}^{\pi}|X|^2 d\omega$. EDS
$S_{xx}=|X|^2$ = DTFT of autocorrelation $r_{xx}[\ell]$; through a system,
$S_{yy}=|H|^2 S_{xx}$.
Phase & group delay
$\tau_g(\omega)=-d\theta/d\omega$ = envelope delay per frequency group. Linear phase ⇔
constant $\tau_g$ ⇔ shape-preserving delay; symmetric FIR achieves it, causal IIR cannot.
Exercises
All three problems of Homework 4 (ICE503 DSP), with full worked solutions.
Exercise 1 — DTFT symmetry proofs
Problem: Let $X(e^{j\omega})$ denote the DTFT of $x[n]$,
$X(e^{j\omega})=\sum_{n=-\infty}^{\infty}x[n]e^{-j\omega n}$. Prove that
the DTFT of $x[-n]$ is $X(e^{-j\omega})$;
the DTFT of $x^*[n]$ is $X^*(e^{-j\omega})$;
the DTFT of $x^*[-n]$ is $X^*(e^{j\omega})$;
the DTFT of $\mathrm{Re}\{x[n]\}$ is $X_{cs}(e^{j\omega})$;
the DTFT of $x_{cs}[n]$ is $\mathrm{Re}\{X(e^{j\omega})\}$.
Click to reveal solution
(a) Substitute and change the summation index $m=-n$
(the sum runs over all integers either way):
(c) Combine (a) and (b): apply (b) to the sequence $x[-n]$, whose DTFT
is $X(e^{-j\omega})$ by (a). Replacing $\omega\to-\omega$ inside the conjugate of (a)'s result:
Parts (d) and (e) are duals: Re in one domain ↔ conjugate-symmetric part in the other.
Setting $x[n]$ real in (b) gives the cornerstone result $X(e^{j\omega})=X^*(e^{-j\omega})$
of §4.4.2.
Exercise 2 — First-order LTI system in the Fourier domain
Problem: An LTI system is described by
$h[n]=\bigl(\tfrac12\bigr)^n\mu[n]$.
Determine the frequency response $H(e^{j\omega})$.
If the input is $x[n]=\delta[n]-4\delta[n-2]$, determine $X(e^{j\omega})$ and the DTFT
$Y(e^{j\omega})$ of the output $y[n]=x[n]\ast h[n]$.
If the input is $x[n]=\cos\bigl(\tfrac{\pi n}{5}\bigr)$, determine $X(e^{j\omega})$ and
$Y(e^{j\omega})$.
Click to reveal solution
(a) Geometric series with ratio $\tfrac12 e^{-j\omega}$
(Example 4-A with $a=\tfrac12$; converges since $|\tfrac12 e^{-j\omega}|=\tfrac12<1$):
Cross-check in the time domain(時域驗算): convolving directly,
$y[n]=\bigl(\tfrac12\bigr)^n\mu[n]-4\bigl(\tfrac12\bigr)^{n-2}\mu[n-2]$; its DTFT is
$\frac{1}{1-\frac12 e^{-j\omega}}-\frac{4e^{-j2\omega}}{1-\frac12 e^{-j\omega}}$ — the same. Note also
$1-4e^{-j2\omega}=(1-2e^{-j\omega})(1+2e^{-j\omega})$, so for $n\ge 2$,
$y[n]=(\tfrac12)^n(1-16)= -15\,(\tfrac12)^n$, with $y[0]=1$, $y[1]=\tfrac12$.
(c) The cosine is a power signal — its DTFT exists in the distribution
sense (§4.2.4). Using $\cos(\omega_0 n)=\tfrac12(e^{j\omega_0 n}+e^{-j\omega_0 n})$ and
$e^{j\omega_0 n}\leftrightarrow 2\pi\delta(\omega-\omega_0)$, with $\omega_0=\pi/5$:
and since $h[n]$ is real, $H(e^{-j\pi/5})=H^*(e^{j\pi/5})$. By the eigenfunction property
(§4.1.3) the time-domain output is the same-frequency sinusoid
Problem: An LTI system is described by
$h[n]=\bigl(\tfrac13\bigr)^n\mu[n]$ and the input sequence is
$x[n]=2\delta[n]-\tfrac23\delta[n-1]$.
Use stem to plot $x[n]$ and $h[n]$ for $0\le n\le 99$
($x$ in subplot(2,1,1), $h$ in subplot(2,1,2), axes labeled).
Use the definition to calculate the DTFTs
$X(e^{j\omega})=\sum_n x[n]e^{-j\omega n}$ and $H(e^{j\omega})=\sum_n h[n]e^{-j\omega n}$
for $\omega = 0:\frac{\pi}{100}:6\pi$.
Calculate $Y(e^{j\omega})=X(e^{j\omega})H(e^{j\omega})$ in the frequency domain; plot
magnitude and angle of $X$, $H$, $Y$ in a $3\times2$ subplot grid over $\omega=0:\frac{\pi}{100}:6\pi$.
Compute $y[n]=x[n]\ast h[n]$ by convolution, then compute the IDTFT
$\hat{y}[n]=\frac{1}{2\pi}\int_{-\pi}^{\pi}Y(e^{j\omega})e^{j\omega n}d\omega$ numerically;
stem-plot $y[n]$ and $\hat{y}[n]$ for $0\le n\le 99$.
Click to reveal solution
Analytical setup(先手算). Closed-form DTFTs (geometric series + shift theorem):
In MATLAB the infinite DTFT sums are simply evaluated by these closed forms.
Cleaned-up script (from DSP_HW4_tony.m):
clc; clear;
n = 0:99;
% sequences
x = 2*(n==0) - (2/3)*(n==1); % x[n] = 2*delta[n] - (2/3)*delta[n-1]
h = (1/3).^n; % h[n] = (1/3)^n * mu[n], n >= 0
%% (a) stem plots of x[n] and h[n]
figure;
subplot(2,1,1); stem(n, x, 'filled');
xlabel('n'); ylabel('x[n]'); title('x[n]');
subplot(2,1,2); stem(n, h, 'filled');
xlabel('n'); ylabel('h[n]'); title('h[n]');
%% (b) DTFTs by definition (closed-form geometric sums)
omega = 0 : pi/100 : 6*pi;
X = 2 - (2/3)*exp(-1j*omega); % finite sum: two terms
H = 1 ./ (1 - (1/3)*exp(-1j*omega)); % geometric series, |1/3| < 1
%% (c) frequency-domain product, magnitude / phase plots
Y = X .* H;
figure;
subplot(3,2,1); plot(omega, abs(X)); xlabel('\omega'); ylabel('|X(e^{j\omega})|');
subplot(3,2,2); plot(omega, angle(X)); xlabel('\omega'); ylabel('arg X(e^{j\omega})');
subplot(3,2,3); plot(omega, abs(H)); xlabel('\omega'); ylabel('|H(e^{j\omega})|');
subplot(3,2,4); plot(omega, angle(H)); xlabel('\omega'); ylabel('arg H(e^{j\omega})');
subplot(3,2,5); plot(omega, abs(Y)); xlabel('\omega'); ylabel('|Y(e^{j\omega})|');
subplot(3,2,6); plot(omega, angle(Y)); xlabel('\omega'); ylabel('arg Y(e^{j\omega})');
%% (d) time-domain convolution vs numerical IDTFT
y = conv(x, h);
y = y(1:100); % keep 0 <= n <= 99
w = -pi : pi/2000 : pi; % IDTFT must integrate ONE period
Yw = (2 - (2/3)*exp(-1j*w)) ./ (1 - (1/3)*exp(-1j*w));
y_hat = zeros(1, length(n));
for k = 1:length(n)
y_hat(k) = real( trapz(w, Yw .* exp(1j*w*n(k))) / (2*pi) );
end
figure;
subplot(2,1,1); stem(n, y, 'filled');
xlabel('n'); ylabel('y[n]'); title('y[n] = conv(x,h)');
subplot(2,1,2); stem(n, y_hat, 'filled');
xlabel('n'); ylabel('y\^[n]'); title('y\^[n] from IDTFT of Y(e^{j\omega})');
max(abs(y - y_hat)) % ~1e-16: identical
Warning — bug fixed from the original script
The original DSP_HW4_tony.m evaluated the IDTFT integral with
trapz(omega, ...) over $0\le\omega\le 6\pi$ — that is three periods, so
dividing by $2\pi$ gives $3\,y[n]$, three times too large (and it also used
$x[n]=\delta[n]-\tfrac12\delta[n-1]$ instead of the assigned input). The IDTFT must integrate over
exactly one period, e.g. $-\pi\le\omega\le\pi$ as in the formula. The script above fixes both.
(原始程式在 $0$–$6\pi$ 上積分 — 共三個週期 — 再除以 $2\pi$,結果是正確值的 3 倍;反轉換只能積一個週期。)
(a) $x[n]$ has only two nonzero samples ($x[0]=2$, $x[1]=-\tfrac23$);
$h[n]$ decays geometrically and is visually zero after $n\approx 10$:
Fig. 4-6 — Exercise 3(a): stem plots of
$x[n]=2\delta[n]-\frac{2}{3}\delta[n-1]$ (top) and $h[n]=(1/3)^n\mu[n]$ (bottom), $0\le n\le 99$.
(b), (c) The spectra over $0\le\omega\le 6\pi$ show three identical periods —
the implicit $2\pi$-periodicity of §4.2.2 made visible. $|H|$ peaks at $\omega=0,2\pi,4\pi,6\pi$
(value $\tfrac{1}{1-1/3}=1.5$): a lowpass response. The phase plots use the principal value, hence
the sawtooth-like behavior:
Fig. 4-7 — Exercise 3(c): magnitude (left column) and phase
(right column) of $X(e^{j\omega})$, $H(e^{j\omega})$, $Y(e^{j\omega})=XH$ over
$\omega = 0:\pi/100:6\pi$. Three identical periods confirm DTFT periodicity.
(三個完全相同的週期,驗證 DTFT 的 $2\pi$ 週期性。)Note $|Y| = 2$ exactly, and $\arg Y$ is pure
numerical noise at the $10^{-17}$ level — see part (d): $Y(e^{j\omega})\equiv 2$.
(d) Convolution in time vs multiplication in frequency followed by the
numerical IDTFT — the two stem plots are indistinguishable
($\max_n|y[n]-\hat{y}[n]|\approx 2.9\times10^{-16}$, machine precision), a numerical proof of the
convolution theorem:
Fig. 4-8 — Exercise 3(d): $y[n]$ by time-domain convolution
(top) and $\hat{y}[n]$ by numerical IDTFT of $Y(e^{j\omega})$ (bottom). Identical to machine
precision(兩者到機器精度完全一致 — 卷積定理的數值驗證).
Analytically: $y[n]=2(\tfrac13)^n\mu[n]-\tfrac23(\tfrac13)^{n-1}\mu[n-1]$, i.e.
$y[0]=2$ and $y[n]=0$ for $n\ge1$... check: for $n\ge 1$,
$y[n]=2(\tfrac13)^n-\tfrac23(\tfrac13)^{n-1}=2(\tfrac13)^n-2(\tfrac13)^n=0$. Indeed
$Y(e^{j\omega})=\frac{2(1-\frac13 e^{-j\omega})}{1-\frac13 e^{-j\omega}}=2$, so $y[n]=2\delta[n]$ —
$x[n]$ is (twice) the inverse system of $h[n]$, exactly the structure of Example 4-C. The stem
plots confirm it: a single spike of height 2 at $n=0$.