
Digital Signal Processing
By the end of this session, you should be able to:
A length-\((K+1)\) FIR filter is defined by the input-output relation
\[ \begin{aligned} y(n) &= \sum_{i=0}^{K} b_i\, x(n-i) \\ &= b_0 x(n) + b_1 x(n-1) + \cdots + b_K x(n-K). \end{aligned} \]
ECE view:
Apply the \(z\)-transform to the difference equation:
\[ Y(z) = \sum_{i=0}^{K} b_i z^{-i} X(z). \]
Factor out \(X(z)\) and divide:
\[ H(z) = \frac{Y(z)}{X(z)} = b_0 + b_1 z^{-1} + \cdots + b_K z^{-K}. \]
Key structural properties:
Given
\[ y(n) = 0.1 x(n) + 0.25 x(n-1) + 0.2 x(n-2), \]
determine:
Solution:
Z-transform:
\[ Y(z) = 0.1 X(z) + 0.25 z^{-1} X(z) + 0.2 z^{-2} X(z). \]
Transfer function:
\[ H(z) = \frac{Y(z)}{X(z)} = 0.1 + 0.25 z^{-1} + 0.2 z^{-2}. \]
Filter length:
Coefficients:
Impulse response (inverse \(z\)-transform):
\[ h(n) = 0.1 \delta(n) + 0.25 \delta(n-1) + 0.2 \delta(n-2). \]
From Example 7.1 and the general form, we can say:
Real-world ECE uses:
Tip
For many audio and communication applications, FIR is preferred even when it’s more expensive computationally, because of predictable phase and unconditional stability.

We begin with an ideal lowpass filter with normalized cutoff frequency \(\Omega_c\). Its ideal frequency response is:
\[ H(e^{j\Omega}) = \begin{cases} 1, & 0 \le |\Omega| \le \Omega_c, \\ 0, & \Omega_c \le |\Omega| \le \pi. \end{cases} \]

Because \(H(e^{j\Omega})\) is \(2\pi\)-periodic, we can extend it beyond \(-\pi\) to \(\pi\):

Idea:
Write the periodic spectrum as a complex Fourier series in \(\Omega\):
\[ H(e^{j\Omega}) = \sum_{n=-\infty}^{\infty} c_n e^{-j \omega_0 n \Omega}. \]
Fourier series coefficients:
\[ c_n = \frac{1}{2\pi} \int_{-\pi}^{\pi} H(e^{j\Omega}) e^{j \omega_0 n \Omega} \, d\Omega. \]
For our case, the period is \(2\pi\), so:
\[ \omega_0 = \frac{2\pi}{2\pi} = 1. \]
So the series simplifies to:
\[ H(e^{j\Omega}) = \sum_{n=-\infty}^{\infty} c_n e^{-j n \Omega}. \]
Define \(h(n) = c_n\) ⇒
\[ H(e^{j\Omega}) = \sum_{n=-\infty}^{\infty} h(n) e^{-j n \Omega}. \]
and the corresponding “inverse” formula:
\[ h(n) = \frac{1}{2\pi} \int_{-\pi}^{\pi} H(e^{j\Omega}) e^{j n \Omega} \, d\Omega. \]
Note
This is just the DTFT pair: - \(H(e^{j\Omega}) \leftrightarrow h(n)\). - Except here, we are thinking of using it as a design formula to derive the ideal impulse response from the desired magnitude response.
Apply the formula
\[ h(n) = \frac{1}{2\pi} \int_{-\pi}^{\pi} H(e^{j\Omega}) e^{j n \Omega} \, d\Omega \]
with \(H(e^{j\Omega}) = 1\) for \(|\Omega|\le \Omega_c\) and 0 otherwise.
For \(n = 0\):
\[ \begin{aligned} h(0) &= \frac{1}{2\pi} \int_{-\pi}^{\pi} H(e^{j\Omega})\, d\Omega \\ &= \frac{1}{2\pi} \int_{-\Omega_c}^{\Omega_c} 1 \, d\Omega \\ &= \frac{\Omega_c}{\pi}. \end{aligned} \]
For \(n \ne 0\):
\[ \begin{aligned} h(n) &= \frac{1}{2\pi} \int_{-\Omega_c}^{\Omega_c} e^{j n \Omega} \, d\Omega \\ &= \frac{1}{2\pi} \left[ \frac{e^{j n \Omega}}{j n} \right]_{-\Omega_c}^{\Omega_c} \\ &= \frac{1}{\pi n} \cdot \frac{e^{j n \Omega_c} - e^{-j n \Omega_c}}{2j} \\ &= \frac{\sin(\Omega_c n)}{\pi n}. \end{aligned} \]
So the ideal lowpass impulse response is:
\[ h(n) = \begin{cases} \dfrac{\Omega_c}{\pi}, & n = 0, \\ \dfrac{\sin(\Omega_c n)}{\pi n}, & n \neq 0. \end{cases} \]

Observations:
This is essentially a discrete-time sinc function:
\[ h(n) \propto \frac{\sin(\Omega_c n)}{n}. \]
The ideal impulse response is noncausal and infinite:
\[ H(z) = \sum_{n=-\infty}^{\infty} h(n) z^{-n} = \cdots + h(-2) z^{2} + h(-1) z^{1} + h(0) + h(1) z^{-1} + \cdots \]
Problems:
Practical FIR design steps:
Truncate \(h(n)\) to a finite index range \(-M \le n \le M\).
Use symmetry \(h(n) = h(-n)\) to form:
\[ H(z) = h(M) z^{M} + \cdots + h(1) z^{1} + h(0) + h(1) z^{-1} + \cdots + h(M) z^{-M}. \]
Shift by \(M\) samples to make it causal:
Define \(b_n = h(n - M)\), for \(n = 0,1,\dots,2M\).
Then
\[ H(z) = b_0 + b_1 z^{-1} + \cdots + b_{2M} z^{-2M}. \]
Important
Truncation + shift = basic FIR design by Fourier method.
But: abrupt truncation ⇒ Gibbs effect (ripples in passband and stopband). The window method is our fix.
Table 7.1 (noncausal ideal coefficients \(h(n)\), \(-M \le n \le M\)):
| Filter Type | Ideal Impulse Response \(h(n)\) |
|---|---|
| Lowpass | \(h(0) = \dfrac{\Omega_c}{\pi}\) and \(h(n) = \dfrac{\sin(\Omega_c n)}{n\pi},\; n\neq 0\) |
| Highpass | \(h(0) = \dfrac{\pi - \Omega_c}{\pi}\) and \(h(n) = -\dfrac{\sin(\Omega_c n)}{n\pi},\; n\neq 0\) |
| Bandpass | \(h(0) = \dfrac{\Omega_H - \Omega_L}{\pi}\) and \(h(n) = \dfrac{\sin(\Omega_H n)}{n\pi} - \dfrac{\sin(\Omega_L n)}{n\pi},\; n\neq 0\) |
| Bandstop | \(h(0) = \dfrac{\pi - \Omega_H + \Omega_L}{\pi}\) and \(h(n) = -\dfrac{\sin(\Omega_H n)}{n\pi} + \dfrac{\sin(\Omega_L n)}{n\pi},\; n\neq 0\) |
Then make it causal by shifting: \(b_n = h(n-M)\).
Goal: Design a 3-tap (\(2M+1=3\) ⇒ \(M=1\)) lowpass FIR with:
(a) Coefficients via Fourier method
Normalized cutoff:
\[ \Omega_c = 2\pi \frac{f_c}{f_s} = 2\pi \frac{800}{8000} = 0.2\pi \; \text{rad}. \]
From the lowpass formula:
\[ h(0) = \frac{\Omega_c}{\pi} = 0.2, \quad h(1) = \frac{\sin(0.2\pi)}{\pi} \approx 0.1871, \quad h(-1) = h(1) = 0.1871. \]
Shift by \(M=1\) to get causal coefficients:
\[ \begin{aligned} b_0 &= h(-1) = 0.1871, \\ b_1 &= h(0) = 0.2, \\ b_2 &= h(1) = 0.1871. \end{aligned} \]
\[ H(z) = 0.1871 + 0.2 z^{-1} + 0.1871 z^{-2}. \]
Difference equation (inverse \(z\)-transform):
\[ y(n) = 0.1871 x(n) + 0.2 x(n-1) + 0.1871 x(n-2). \]
This is a symmetric 3-tap FIR lowpass filter.
\[ H(e^{j\Omega}) = 0.1871 + 0.2 e^{-j\Omega} + 0.1871 e^{-j2\Omega}. \]
Factor \(e^{-j\Omega}\):
\[ \begin{aligned} H(e^{j\Omega}) &= e^{-j\Omega} \left( 0.1871 e^{j\Omega} + 0.2 + 0.1871 e^{-j\Omega} \right) \\ &= e^{-j\Omega} \left( 0.2 + 0.3742 \cos\Omega \right). \end{aligned} \]
Magnitude and phase:
\[ |H(e^{j\Omega})| = \big|0.2 + 0.3742 \cos\Omega\big|, \]
\[ \angle H(e^{j\Omega}) = \begin{cases} -\Omega, & 0.2 + 0.3742 \cos\Omega > 0, \\ -\Omega + \pi, & 0.2 + 0.3742 \cos\Omega < 0. \end{cases} \]
Tip
For an FIR with symmetric coefficients and odd length \(2M+1\):
\[ \angle H(e^{j\Omega}) \approx -M \Omega \quad (\text{plus possible }180^\circ \text{ jumps}). \]
⇒ Constant group delay \(M\) samples for all passband frequencies.

Observations:
Trade-off: more taps ⇒ better frequency selectivity, but:
The passband and stopband ripples in ideal-based FIR design come from:
Analogy:
In our discrete-time design:
We will reduce these ripples by using smoother windows (Hanning, Hamming, Blackman, etc.) instead of the abrupt rectangular window.
Because the FIR coefficients are symmetric, the filter has linear phase:
\[ \angle H(e^{j\Omega}) \approx -M\Omega. \]
If input is a sinusoid \(x(n) = A \sin(\Omega n)\), the steady-state output is:
\[ y(n) = A |H(e^{j\Omega})| \sin\big(\Omega(n - M)\big). \]
For a sum of sinusoids within the passband, all components get same delay ⇒ waveform shape is preserved ⇒ no phase distortion.

Consider input (sum of two sinusoids):
\[ x(n) = \sin(0.05\pi n) u(n) - \frac{1}{3} \sin(0.15\pi n) u(n). \]
Linear phase filter (delay 8 samples):
\[ y_1(n) = \sin\big(0.05\pi(n-8)\big) - \frac{1}{3}\sin\big(0.15\pi(n-8)\big). \]
Nonlinear phase filter with \(90^\circ\) phase shift at both frequencies:
\[ y_2(n) = \sin(0.05\pi n - \pi/2) - \frac{1}{3} \sin(0.15\pi n - \pi/2). \]

In audio: nonlinear phase can make transients smeared or “hollow” sounding ⇒ FIR linear-phase filters are desirable.
Specs:
Normalized edges:
\[ \Omega_L = 2\pi \frac{2000}{8000} = 0.5\pi, \quad \Omega_H = 2\pi \frac{2400}{8000} = 0.6\pi. \]
Ideal bandpass impulse (noncausal):
\[ h(0) = \frac{\Omega_H - \Omega_L}{\pi} = 0.1. \]
\[ h(1) = \frac{\sin(0.6\pi)}{\pi} - \frac{\sin(0.5\pi)}{\pi} \approx -0.01558, \]
\[ h(2) = \frac{\sin(1.2\pi)}{2\pi} - \frac{\sin(\pi)}{2\pi} \approx -0.09355, \]
with symmetry:
\[ h(-1)=h(1),\quad h(-2)=h(2). \]
Shift by \(M=2\):
\[ b_0 = b_4 = -0.09355, \quad b_1 = b_3 = -0.01558, \quad b_2 = 0.1. \]
Transfer function:
\[ H(z) = -0.09355 - 0.01558 z^{-1} + 0.1 z^{-2} - 0.01558 z^{-3} - 0.09355 z^{-4}. \]
MATLAB frequency response (Program 7.1) gives:

Observations:
Fix: Window the impulse response instead of raw truncation.
We know:
Idea:
Mathematically:
\[ h_w(n) = h(n)\, w(n), \]
where \(w(n)\) is a window function, nonzero for \(-M \le n \le M\), symmetric around 0.
Effect in frequency:
\[ w_{\text{rec}}(n) = 1,\quad -M \le n \le M. \]
\[ w_{\text{tri}}(n) = 1 - \frac{|n|}{M},\quad -M \le n \le M. \]
\[ w_{\text{han}}(n) = 0.5 + 0.5\cos\left(\frac{\pi n}{M}\right),\quad -M \le n \le M. \]
\[ w_{\text{ham}}(n) = 0.54 + 0.46\cos\left(\frac{\pi n}{M}\right),\quad -M \le n \le M. \]
\[ w_{\text{black}}(n) = 0.42 + 0.5\cos\left(\frac{\pi n}{M}\right) + 0.08\cos\left(\frac{2\pi n}{M}\right),\quad -M \le n \le M. \]

Given noncausal symmetric coefficients (ideal lowpass):
\[ h(0)=0.25,\; h(\pm1)=0.22508,\; h(\pm2)=0.15915,\; h(\pm3)=0.07503. \]
Use Hamming window with \(M=3\):
Window values:
\[ \begin{aligned} w_{\text{ham}}(0) &= 0.54 + 0.46 \cos(0) = 1.0, \\ w_{\text{ham}}(\pm 1) &= 0.77, \\ w_{\text{ham}}(\pm 2) &= 0.31, \\ w_{\text{ham}}(\pm 3) &= 0.08. \end{aligned} \]
Windowed coefficients:
\[ \begin{aligned} h_w(0) &= 0.25 \times 1 = 0.25, \\ h_w(\pm1) &= 0.22508 \times 0.77 \approx 0.17331, \\ h_w(\pm2) &= 0.15915 \times 0.31 \approx 0.04934, \\ h_w(\pm3) &= 0.07503 \times 0.08 \approx 0.00600. \end{aligned} \]

Observation: coefficients are smoothly tapered toward zero ⇒ reduced Gibbs ripples.
Design ideal truncated impulse response \(h(n)\):
Apply window:
\[ h_w(n) = h(n)\, w(n),\quad -M \le n \le M. \]
Make it causal by shifting \(M\) samples:
\[ b_n = h_w(n - M),\quad n = 0, 1, \dots, 2M. \]
Same spec as Example 7.2:
Ideal coefficients (from Example 7.2):
\[ h(0) = 0.2,\quad h(\pm1) = 0.1871. \]
Hamming window (for \(M=1\)):
\[ w_{\text{ham}}(0) = 1,\quad w_{\text{ham}}(\pm1) = 0.08. \]
Windowed noncausal coefficients:
\[ \begin{aligned} h_w(0) &= 0.2 \times 1 = 0.2, \\ h_w(\pm 1) &= 0.1871 \times 0.08 \approx 0.01497. \end{aligned} \]
Shift by \(M=1\):
\[ b_0 = b_2 = 0.01497,\quad b_1 = 0.2. \]
Transfer function:
\[ H(z) = 0.01497 + 0.2 z^{-1} + 0.01497 z^{-2}. \]
Frequency response:
\[ H(e^{j\Omega}) = e^{-j\Omega}\big(0.2 + 0.02994\cos\Omega\big). \]
Magnitude:
\[ |H(e^{j\Omega})| = \big|0.2 + 0.02994\cos\Omega\big|. \]
Phase:
\[ \angle H(e^{j\Omega})= \begin{cases} -\Omega, & 0.2 + 0.02994\cos\Omega > 0, \\ -\Omega + \pi, & 0.2 + 0.02994\cos\Omega < 0. \end{cases} \]
Sample values (Table 7.4) show slightly reduced peak magnitude and less ripple compared to the unwindowed case.

Specs:
Ideal bandstop \(h(n)\) (Table 7.1):
\[ h(0) = \frac{\pi - \Omega_H + \Omega_L}{\pi} = 0.9, \]
\[ h(1) \approx 0.01558, \quad h(2) \approx 0.09355, \quad h(-1)=h(1),\; h(-2)=h(2). \]
Hamming window (\(M=2\)):
\[ w_{\text{ham}}(0) = 1,\quad w_{\text{ham}}(\pm1)=0.54,\quad w_{\text{ham}}(\pm2)=0.08. \]
Windowed coefficients:
\[ \begin{aligned} h_w(0) &= 0.9, \\ h_w(\pm1) &= 0.01558\times0.54\approx0.00841, \\ h_w(\pm2) &= 0.09355\times0.08\approx0.00748. \end{aligned} \]
Shift by \(M=2\):
\[ b_0 = b_4 = 0.00748,\quad b_1 = b_3 = 0.00841,\quad b_2 = 0.9. \]
Transfer function:
\[ H(z) = 0.00748 + 0.00841 z^{-1} + 0.9 z^{-2} + 0.00841 z^{-3} + 0.00748 z^{-4}. \]
firwdFor larger designs, we let MATLAB do the heavy lifting. Custom function:
N: number of taps (must be odd).Ftype:
WnL, WnH: lower and upper cutoff frequencies (in radians).
WnH = 0, use WnL = Ω_c.WnL = 0, use WnH = Ω_c.Wtype:
This function internally:
Specs:
Use firwd twice:
Magnitude responses:

Observations:
Coefficients listed in Table 7.6.
For the same lowpass spec (25 taps, \(f_c=2000\) Hz):

Qualitative summary:
Trade-off:
For normalized transition width
\[ \Delta f = \frac{|f_{\text{stop}} - f_{\text{pass}}|}{f_s}, \]
approximate length for each window:
| Window | \(w(n)\) | Length \(N\) | Passband Ripple (dB) | Stopband Atten (dB) |
|---|---|---|---|---|
| Rectangular | \(1\) | \(N \approx \dfrac{0.9}{\Delta f}\) | 0.7416 | 21 |
| Hanning | \(0.5+0.5\cos(\pi n/M)\) | \(N \approx \dfrac{3.1}{\Delta f}\) | 0.0546 | 44 |
| Hamming | \(0.54+0.46\cos(\pi n/M)\) | \(N \approx \dfrac{3.3}{\Delta f}\) | 0.0194 | 53 |
| Blackman | \(0.42+0.5\cos(\pi n/M)+0.08\cos(2\pi n/M)\) | \(N \approx \dfrac{5.5}{\Delta f}\) | 0.0017 | 74 |
Design cutoff frequency:
\[ f_c = \frac{f_{\text{pass}} + f_{\text{stop}}}{2}. \]
Tip
Design recipe from specs:
firwd) to get coefficients.Specs:
Compute normalized transition width:
\[ \Delta f = \frac{|2150 - 1850|}{8000} = 0.0375. \]
Window choice:
Length estimate:
\[ N = \frac{0.9}{\Delta f} = \frac{0.9}{0.0375} \approx 24. \]
Take odd \(N=25\).
Design cutoff frequency:
\[ f_c = \frac{1850 + 2150}{2} = 2000 \; \text{Hz}. \]
This is exactly the lowpass designed in Example 7.7.
Apply this lowpass FIR to speech sampled at 8 kHz:


Perceptually:
Specs:
Transition width:
\[ \Delta f = \frac{|2500 - 1500|}{8000} = 0.125. \]
From Table 7.7:
Length estimate:
\[ N = \frac{3.1}{0.125} = 24.8 \Rightarrow N=25. \]
Cutoff frequency:
\[ f_c = \frac{1500+2500}{2} = 2000 \; \text{Hz}, \quad \Omega_c = 0.5\pi. \]
Use firwd(25, 2, 0, 0.5*pi, 3) to generate highpass coefficients.
Frequency response:

Apply to speech:


Perceptually:
Specs:
Compute transition widths:
\[ \Delta f_1 = \frac{1600-500}{8000} = 0.1375, \quad \Delta f_2 = \frac{3500-2300}{8000} = 0.15. \]
Using Hamming window (≈53 dB stopband, 0.0194 dB ripple):
\[ N_1 = \frac{3.3}{0.1375} \approx 24,\quad N_2 = \frac{3.3}{0.15} \approx 22. \]
Choose \(N=25\).
Cutoff frequencies for ideal bandpass:
\[ f_L = \frac{1600+500}{2} = 1050\; \text{Hz},\quad f_H = \frac{3500+2300}{2} = 2900\; \text{Hz}. \]
Normalized:
\[ \Omega_L = 0.2625\pi,\quad \Omega_H = 0.725\pi. \]
Use firwd(25, 3, Ω_L, Ω_H, 4) to generate Hamming-windowed bandpass FIR.
Frequency response:

Coefficients in Table 7.9.
Filtering speech:


Specs:
Transition widths:
\[ \Delta f_1 = \frac{1500}{8000} = 0.1875,\quad \Delta f_2 = \frac{1300}{8000} = 0.1625. \]
Need ≈60 dB attenuation ⇒ Blackman window (~74 dB).
Lengths:
\[ N_1 = \frac{5.5}{0.1875} \approx 29.3,\quad N_2 = \frac{5.5}{0.1625} \approx 33.8. \]
Choose odd \(N=35\).
Cutoff frequencies:
\[ \Omega_L = 2\pi\frac{1250}{8000} = 0.3125\pi,\quad \Omega_H = 2\pi\frac{2850}{8000} = 0.7125\pi. \]
Use firwd(35, 4, Ω_L, Ω_H, 5) to get bandstop FIR.
Frequency response:

Coefficients in Table 7.10.
Filtering speech:


Use case: removing a narrowband interference (like a whistle) from speech.
Problem:
Design a 7-tap lowpass FIR filter (\(N=7\), so \(M=3\)) with:
Tasks:
Window method:
Window choices (rough performance):
Filter length from specs:
Real-world ECE:
FIR structure:
\[ y(n) = \sum_{i=0}^{K} b_i x(n-i),\quad H(z) = \sum_{i=0}^{K} b_i z^{-i}. \]
Frequency response (DTFT of impulse response):
\[ H(e^{j\Omega}) = \sum_{n=-\infty}^{\infty} h(n) e^{-jn\Omega}. \]
Inverse DTFT (design equation):
\[ h(n) = \frac{1}{2\pi}\int_{-\pi}^{\pi} H(e^{j\Omega}) e^{jn\Omega} \, d\Omega. \]
Ideal lowpass impulse response:
\[ h(n) = \begin{cases} \frac{\Omega_c}{\pi}, & n=0, \\ \frac{\sin(\Omega_c n)}{\pi n}, & n\neq 0. \end{cases} \]
Other ideal FIRs (noncausal):
Lowpass:
\[ h(n) = \frac{\Omega_c}{\pi} \text{ for } n=0;\quad h(n) = \frac{\sin(\Omega_c n)}{n\pi} \text{ for } n\neq 0. \]
Highpass:
\[ h(0) = \frac{\pi - \Omega_c}{\pi};\quad h(n) = -\frac{\sin(\Omega_c n)}{n\pi},\; n\neq 0. \]
Bandpass:
\[ h(0) = \frac{\Omega_H - \Omega_L}{\pi};\quad h(n) = \frac{\sin(\Omega_H n)}{n\pi} - \frac{\sin(\Omega_L n)}{n\pi},\; n\neq 0. \]
Bandstop:
\[ h(0) = \frac{\pi - \Omega_H + \Omega_L}{\pi};\quad h(n) = -\frac{\sin(\Omega_H n)}{n\pi} + \frac{\sin(\Omega_L n)}{n\pi},\; n\neq 0. \]
Windowing:
\[ h_w(n) = h(n) w(n),\quad -M \le n \le M. \]
Causal coefficients:
\[ b_n = h_w(n-M),\quad n=0,1,\dots,2M. \]
Linear phase (symmetric FIR, odd length):
\[ \angle H(e^{j\Omega}) = -M\Omega \; (+ \text{optional } \pi \text{ jumps}). \]
Transition width and length (example for Hamming):
\[ \Delta f = \frac{|f_{\text{stop}} - f_{\text{pass}}|}{f_s},\quad N \approx \frac{3.3}{\Delta f}. \]
\[ f_c = \frac{f_{\text{pass}} + f_{\text{stop}}}{2}. \]
{pyodide} blocks).{ojs} blocks) to change parameters.Try to:
Task: Change the coefficients and input samples and re-run the code.
Try:
b to [1/3, 1/3, 1/3] → moving average lowpass.x to a step: [0, 0, 1, 1, 1, 1].We know the ideal lowpass impulse response is
\[ h(n) = \begin{cases} \Omega_c / \pi, & n = 0, \\ \sin(\Omega_c n) / (\pi n), & n \neq 0. \end{cases} \]
Use the sliders to see how \(\Omega_c\) and truncation index \(M\) affect \(h(n)\).
We shift the impulse response by \(M\) samples to get a causal FIR:
\[ b_n = h(n - M), \quad n = 0,\dots,2M. \]
Interactively see the effect of the shift.
Now we compute the DTFT of truncated \(h(n)\) and plot \(|H(e^{j\Omega})|\).
Explore:
We now apply a window to \(h(n)\):
\[ h_w(n) = h(n) w(n). \]
Compare rectangular and Hamming windows.
Observe:
Play with different windows and see main-lobe / side-lobe trade-offs.
viewof oc4 = Inputs.range([0.1, 0.9], {step: 0.05, label: "Normalized cutoff Ω_c / π"})
viewof M4 = Inputs.range([10, 80], {step: 2, label: "M (half-length)"} )
viewof wmulti = Inputs.checkbox(
["Rectangular", "Hanning", "Hamming", "Blackman"],
{label: "Windows to plot", value: ["Rectangular", "Hanning", "Hamming", "Blackman"]}
)Try:
Use the rules of thumb to estimate \(N\) from transition width \(\Delta f\).
Experiment:
Let’s approximate a lowpass design with:
viewof fpass = Inputs.range([500, 3500], {step: 100, label: "Passband edge f_pass (Hz)", value: 1800})
viewof fstop = Inputs.range([600, 3900], {step: 100, label: "Stopband edge f_stop (Hz)", value: 2200})
viewof wdesign = Inputs.select(
["Rectangular", "Hanning", "Hamming", "Blackman"],
{label: "Window type", value: "Hamming"}
)Challenge:
Test the linear phase property of a symmetric FIR on a sum of sinusoids.
viewof f1 = Inputs.range([200, 1500], {step: 50, label: "Sinusoid 1 frequency f1 (Hz)", value: 400})
viewof f2 = Inputs.range([500, 3000], {step: 50, label: "Sinusoid 2 frequency f2 (Hz)", value: 1200})
viewof Nd = Inputs.range([5, 41], {step: 2, label: "Filter length N (odd)", value: 17})
viewof ocd = Inputs.range([0.1, 0.9], {step: 0.05, label: "Normalized cutoff Ω_c / π for lowpass", value: 0.4})Explore:
In this interactive deck you:
Suggested follow-ups:
firwin in SciPy, fir1 in MATLAB) and compare with your manual designs.