## Vinay K. Ingle, John G. Proakis

## Chapter 7

## FIR FILTER DESIGN - all with Video Answers

## Educators

Chapter Questions

The absolute and relative ( dB$)$ specifications for a lowpass filter are related by (7.1) and (7.2). In this problem we will develop a simple MATLAB function to convert one set of specifications into another.

1. Write a MATLAB function to convert absolute specifications $\delta_1$ and $\delta_2$ into the relative specifications $R_p$ and $A_s$ in dB . The format of the function should be

```

function [Rp,As] = delta2db(delta1,delta2)

% Converts absolute specs delta1 and delta2 into dB specs Rp and As

% [Rp,As] = delta2db(delta1,delta2)

```

Verify your function using the specifications given in Example 7.2.

2. Write a MATLAB function to convert relative $(\mathrm{dB})$ specifications $R_p$ and $A_s$ into the absolute specifications $\delta_1$ and $\delta_2$. The format of the function should be

```

function [delta1,delta2] = db2delta(Rp,As)

% Converts dB specs Rp and As into absolute specs delta1 and delta2

% [delta1,delta2] = db2delta(Rp,As)

```

Verify your function using the specifications given in Example 7.1.

Check back soon!

The Type-1 linear-phase FIR filter is characterized by

$$

h(n)=h(M-1-n)), \quad 0 \leq n \leq M-1, \quad M \text { odd }

$$

Show that its amplitude response $H_r(\omega)$ is given by

$$

H_r(\omega)=\sum_{n=0}^L a(n) \cos (\omega n), \quad L=\frac{M-1}{2}

$$

where coefficients $\{a(n)\}$ are obtained as defined in (7.6).

Check back soon!

The Type-2 linear-phase FIR filter is characterized by

$$

h(n)=h(M-1-n), \quad 0 \leq n \leq M-1, \quad M \text { even }

$$

1. Show that its amplitude response $H_r(\omega)$ is given by

$$

H_r(\omega)=\sum_{n=1}^{M / 2} b(n) \cos \left\{\omega\left(n-\frac{1}{2}\right)\right\}

$$

where coefficients $\{b(n)\}$ are obtained as defined in (7.10).

2. Show that $H_r(\omega)$ can be further expressed as

$$

H_r(\omega)=\cos \left(\frac{\omega}{2}\right) \sum_{n=0}^L \bar{b}(n) \cos (\omega n), \quad L=\frac{M}{2}-1

$$

where coefficients $\bar{b}(n)$ are given by

$$

\begin{aligned}

b(1) & =\bar{b}(0)+\frac{1}{2} \bar{b}(1), \\

b(n) & =\frac{1}{2}[\bar{b}(n-1)+\bar{b}(n)], \quad 2 \leq n \leq \frac{M}{2}-1, \\

b\left(\frac{M}{2}\right) & =\frac{1}{2} \bar{b}\left(\frac{M}{2}-1\right) .

\end{aligned}

$$

Check back soon!

The Type-3 linear-phase FIR filter is characterized by

$$

h(n)=-h(M-1-n), \quad 0 \leq n \leq M-1, \quad M \text { odd }

$$

1. Show that its amplitude response $H_r(\omega)$ is given by

$$

H_r(\omega)=\sum_{n=1}^{(M-1) / 2} c(n) \sin (\omega n)

$$

where coefficients $\{c(n)\}$ are obtained as defined in (7.13).

2. Show that $H_r(\omega)$ can be further expressed as

$$

H_r(\omega)=\sin (\omega) \sum_{n=0}^L \bar{c}(n) \cos (\omega n), \quad L=\frac{M-3}{2}

$$

where coefficients $\bar{c}(n)$ are given by

$$

\begin{aligned}

c(1) & =\bar{c}(0)-\frac{1}{2} \bar{c}(1), \\

c(n) & =\frac{1}{2}[\bar{c}(n-1)-\bar{c}(n)], \quad 2 \leq n \leq \frac{M-3}{2}, \\

c\left(\frac{M-1}{2}\right) & =\frac{1}{2} \bar{c}\left(\frac{M-3}{2}\right) .

\end{aligned}

$$

Check back soon!

The Type-4 linear-phase FIR filter is characterized by

$$

h(n)=-h(M-1-n), \quad 0 \leq n \leq M-1, \quad M \text { even }

$$

1. Show that its amplitude response $H_r(\omega)$ is given by

$$

H_r(\omega)=\sum_{n=1}^{M / 2} d(n) \sin \left\{\omega\left(n-\frac{1}{2}\right)\right\}

$$

where coefficients $\{d(n)\}$ are obtained as defined in (7.16).

2. Show that the above $H_r(\omega)$ can be further expressed as

$$

H_r(\omega)=\sin \left(\frac{\omega}{2}\right) \sum_{n=0}^L \tilde{d}(n) \cos (\omega n), \quad L=\frac{M}{2}-1

$$

where coefficients $\bar{d}(n)$ are given by

$$

\begin{aligned}

d(1) & =\bar{d}(0)-\frac{1}{2} \bar{d}(1), \\

d(n) & =\frac{1}{2}[\bar{d}(n-1)-\bar{d}(n)], \quad 2 \leq n \leq \frac{M}{2}-1 \\

d\left(\frac{M}{2}\right) & =\frac{1}{2} \bar{d}\left(\frac{M}{2}-1\right) .

\end{aligned}

$$

Check back soon!

Write a MATLAB function to compute the amplitude response $H_r(\omega)$ given a linear phase impulse response $h(n)$. The format of this function should be

```

function [Hr,w,P,L]=Ampl_Res(h);

% Computes Amplitude response Hr(w) and its polynomial P of order L,

% given a linear-phase FIR filter impulse response h.

% The type of filter is determined automatically by the subroutine.

%

% [Hr,w, P,L] = Ampl_Res(h)

% Hr = Amplitude Response

% w = frequencies between [0 pi] over which Hr is computed

% P = Polynomial coefficients

% L = Order of P

% h = Linear Phase filter impulse response

```

The function should first determine the type of the linear-phase FIR filter and then use the appropriate Hr _Type\# function discussed in this chapter. It should also check if the given

$h(n)$ is of a linear-phase type. Verify your function on sequences given here.

$$

\begin{aligned}

h_{\mathrm{I}}(n) & =(0.9)^{|n-5|} \cos [\pi(n-5) / 12][u(n)-u(n-11)] \\

h_{\mathrm{II}}(n) & =(0.9)^{|n-4.5|} \cos [\pi(n-4.5) / 11][u(n)-u(n-10)] \\

h_{\mathrm{II}}(n) & =(0.9)^{|n-5|} \sin [\pi(n-5) / 12][u(n)-u(n-11)] \\

h_{\mathrm{IV}}(n) & =(0.9)^{|n-4.5|} \sin [\pi(n-4.5) / 11][u(n)-u(n-10)] \\

h(n) & =(0.9)^n \cos [\pi(n-5) / 12][u(n)-u(n-11)]

\end{aligned}

$$

Check back soon!

Prove the following properties of linear-phase FIR filters.

1. If $H(z)$ has four zeros at $z_1=r e^{j \theta}, z_2=\frac{1}{r} e^{-j \theta}, z_3=r e^{-j \theta}$, and $z_4=\frac{1}{r} e^{-j \theta}$ then $H(z)$ represents a linear-phase FIR filter.

2. If $H(z)$ has two zeros at $z_1=e^{j \theta}$ and $z_2=e^{-j \theta}$ then $H(z)$ represents a linear-phase FIR filter.

3. If $H(z)$ has two zeros at $z_1=r$ and $z_2=\frac{1}{r}$ then $H(z)$ represents a linear-phase FIR filter.

4. If $H(z)$ has a zero at $z_1=1$ or a zero at $z_1=-1$ then $H(z)$ represents a linear-phase FIR filter.

5. For each of the sequences given in Problem P7.6, plot the locations of zeros. Determine which sequences imply linear-phase FIR filters.

Check back soon!

A notch filter is an LTI system, which is used to eliminate an arbitrary frequency $\omega=\omega_0$. The ideal linear-phase notch filter frequency response is given by

$$

H_d\left(e^{j \omega}\right)=\left\{\begin{array}{ll}

0, & |\omega|=\omega_0 ; \\

1 \cdot e^{-j a \omega}, & \text { otherwise. }

\end{array} \quad \text { ( } \alpha\right. \text { is a delay in samples) }

$$

1. Determine the ideal impulse response, $h_d(n)$, of the ideal notch filter.

2. Using $h_d(n)$, design a linear-phase FIR notch filter using a length 51 rectangular window to eliminate the frequency $\omega_0=\pi / 2 \mathrm{rad} / \mathrm{sample}$. Plot amplitude the response of the resulting filter.

3. Repeat part 2 using a length 51 Hamming window. Compare your results.

Check back soon!

Design a linear-phase bandpass filter using the Hann window design technique. The specifications are

$$

\begin{aligned}

& \text { lower stopband edge: } 0.2 \pi \\

& \text { upper stopband edge: } 0.75 \pi \\

& A_s=40 \mathrm{~dB} \\

& \text { lower passband edge: } 0.35 \pi \\

& \text { upper passband edge: } 0.55 \pi \\

& R_p=0.25 \mathrm{~dB} \\

&

\end{aligned}

$$

Plot the impulse response and the magnitude response (in dB ) of the designed filter. Do not use the fir1 function.

Check back soon!

Design a bandstop filter using the Hamming window design technique. The specifications are

$$

\begin{aligned}

& \text { lower stopband edge: } 0.4 \pi \\

& \text { upper stopband edge: } 0.6 \pi \\

& A_s=50 \mathrm{~dB} \\

& \text { lower passband edge: } 0.3 \pi \\

& \text { upper passband edge: } 0.7 \pi \quad R_p=0.2 \mathrm{~dB} \\

&

\end{aligned}

$$

Plot the impulse response and the magnitude response (in dB ) of the designed filter. Do not use the fir1 function.

Check back soon!

Design a bandpass filter using the Hamming window design technique. The specifications are

$$

\begin{aligned}

& \text { lower stopband edge: } 0.3 \pi \quad A_s=50 \mathrm{~dB} \\

& \text { upper stopband edge: } 0.6 \pi \\

& \text { lower passband edge: } 0.4 \pi \\

& \text { upper passband edge: } 0.5 \pi \quad R_p=0.5 \mathrm{~dB}

\end{aligned}

$$

Plot the impulse response and the magnitude response (in dB ) of the designed filter. Do not use the fir1 function.

Check back soon!

Design a highpass filter using one of the fixed window functions. The specifications are

stopband edge: $0.4 \pi, A_s=50 \mathrm{~dB}$

passband edge: $0.6 \pi, R_p=0.004 \mathrm{~dB}$

Plot the zoomed magnitude response (in dB ) of the designed filter in the passband to verify the passband ripple $R_p$. Do not use the fir1 function.

Check back soon!

Using the Kaiser window method, design a linear-phase FIR digital filter that meets the following specifications

$$

\begin{aligned}

0.975 & \leq\left|H\left(e^{j \omega}\right)\right| \leq 1.025, \quad 0 \leq \omega \leq 0.25 \pi \\

0 & \leq\left|H\left(e^{j \omega}\right)\right| \leq 0.005,0.35 \pi \leq \omega \leq 0.65 \pi \\

0.975 & \leq\left|H\left(e^{j \omega}\right)\right| \leq 1.025,0.75 \pi \leq \omega \leq \pi

\end{aligned}

$$

Determine the minimum length impulse response $h(n)$ of such a filter. Provide a plot containing subplots of the amplitude response and the magnitude response in dB . Do not use the fir1 function.

Check back soon!

We wish to use the Kaiser window method to design a linear-phase FIR digital filter that meets the following specifications:

$$

\begin{aligned}

0 & \leq\left|H\left(e^{j \omega}\right)\right| \leq 0.01, \quad 0 \leq \omega \leq 0.25 \pi \\

0.95 & \leq\left|H\left(e^{j \omega}\right)\right| \leq 1.05,0.35 \pi \leq \omega \leq 0.65 \pi \\

0 & \leq\left|H\left(e^{j \omega}\right)\right| \leq 0.01,0.75 \pi \leq \omega \leq \pi

\end{aligned}

$$

Determine the minimum length impulse response $h(n)$ of such a filter. Provide a plot containing subplots of the amplitude response and the magnitude response in dB . Do not use the fir1 function.

Check back soon!

Design the staircase filter of Example 7.26 using the Kaiser window approach. The specifications are

$$

\begin{aligned}

& \text { Band-1: } \quad 0 \leq \omega \leq 0.3 \pi \text {, Ideal gain }=1, \quad \delta_1=0.01 \\

& \text { Band-2: } 0.4 \pi \leq \omega \leq 0.7 \pi \text {, Ideal gain }=0.5, \delta_2=0.005 \\

& \text { Band-3: } 0.8 \pi \leq \omega \leq \pi, \quad \text { Ideal gain }=0, \quad \delta_3=0.001 \\

&

\end{aligned}

$$

Compare the filter length of this design with that of Example 7.26. Provide a plot of the magnitude response in dB . Do not use the fir1 function.

Check back soon!

Design a bandpass filter using a fixed window design technique that has the minimum length and that satisfies the following specifications:

$$

\left.\begin{array}{r}

\left.\begin{array}{r}

\text { lower stopband edge }=0.3 \pi \\

\text { upper stopband edge }=0.6 \pi

\end{array}\right\} A_s=40 \mathrm{~dB} \\

\text { lower passband edge }=0.4 \pi \\

\text { upper passband edge }=0.5 \pi

\end{array}\right\} R_p=0.5 \mathrm{~dB} .

$$

Provide a plot of the log-magnitude response in dB and stem plot of the impulse response.

Check back soon!

Repeat Problem P7.9 using the fir1 function.

Check back soon!

Repeat Problem P7.10 using the fir1 function.

Check back soon!

Repeat Problem P7.11 using the fir1 function.

Check back soon!

Repeat Problem P7.12 using the fir1 function.

Check back soon!

Repeat Problem P7.13 using the fir1 function.

Check back soon!

Repeat Problem P7.14 using the fir1 function.

Check back soon!

Consider an ideal lowpass filter with the cutoff frequency $\omega_c=0.3 \pi$. We want to approximate this filter using a frequency sampling design in which we choose 40 samples.

1. Choose the sample at $\omega_c$ equal to 0.5 , and use the naive design method to compute $h(n)$. Determine the minimum stopband attenuation.

2. Now vary the sample at $\omega_c$, and determine the optimum value to obtain the largest minimum stopband attenuation.

3. Plot the magnitude responses in dB of the preceding two designs in one plot, and comment on the results.

Check back soon!

Design the bandstop filter of Problem P7.10 using the frequency sampling method. Choose the order of the filter appropriately so that there are two samples in the transition band. Use optimum values for these samples. Compare your results with those obtained using the fir2 function.

Check back soon!

Design the bandpass filter of Problem P7.11 using the frequency sampling method. Choose the order of the filter appropriately so that there are two samples in the transition band. Use optimum values for these samples. Compare your results with those obtained using the fir2 function.

Check back soon!

Design the highpass filter of Problem P7.12 using the frequency sampling method. Choose the order of the filter appropriately so that there are two samples in the transition band. Use optimum values. Compare your results with those obtained using the fir2 function.

Check back soon!

Consider the filter specifications given in Figure P7.1. Use the fir2 function and a Hamming window to design a linear-phase FIR filter via the frequency sampling method. Experiment with the filter length to achieve the required design. Plot the amplitude response of the resulting filter.

Check back soon!

Design a bandpass filter using the frequency sampling method. Choose the order of the filter appropriately so that there is one sample in the transition band. Use optimum value for this sample. The specifications are as follows:

$$

\left.\begin{array}{r}

\text { lower stopband edge }=0.3 \pi \\

\text { upper stopband edge }=0.7 \pi

\end{array}\right\} A_s=40 \mathrm{~dB}

$$

$$

\left.\begin{array}{r}

\text { lower passband edge }=0.4 \pi \\

\text { upper passband edge }=0.6 \pi

\end{array}\right\} R_p=0.5 \mathrm{~dB} \text {. }

$$

Provide a plot of the log-magnitude response in dB and stem plot of the impulse response.

Check back soon!

The frequency response of an ideal bandpass filter is given by

$$

H_d\left(e^{j \omega}\right)=\left\{\begin{array}{l}

0, \quad 0 \leq|\omega| \leq \pi / 3 \\

1, \quad \pi / 3 \leq|\omega| \leq 2 \pi / 3 \\

0,2 \pi / 3 \leq|\omega| \leq \pi

\end{array}\right.

$$

1. Determine the coefficients of a 25-tap filter based on the Parks-McClellan algorithm with stopband attenuation of 50 dB . The designed filter should have the smallest possible transition width.

2. Plot the amplitude response of the filter using the function developed in Problem P7.6.

Check back soon!

Consider the bandstop filter given in Problem P7.10.

1. Design a linear-phase bandstop FIR filter using the Parks-McClellan algorithm. Note that the length of the filter must be odd. Provide a plot of the impulse response and the magnitude response in dB of the designed filter.

2. Plot the amplitude response of the designed filter and count the total number of extrema in stopband and passbands. Verify this number with the theoretical estimate of the total number of extrema.

3. Compare the order of this filter with those of the filters in Problems P7.10 and P7.24.

4. Verify the operation of the designed filter on the following signal

$$

x(n)=5-5 \cos \left(\frac{\pi n}{2}\right) ; \quad 0 \leq n \leq 300

$$

Check back soon!

Using the Parks-McClellan algorithm, design a 25-tap FIR differentiator with slope equal to 1 sample/cycle.

1. Choose the frequency band of interest between $0.1 \pi$ and $0.9 \pi$. Plot the impulse response and the amplitude response.

2. Generate 100 samples of the sinusoid

$$

x(n)=3 \sin (0.25 \pi n), \quad n=0, \ldots, 100

$$

and process through the preceding FIR differentiator. Compare the result with the theoretical "derivative" of $x(n)$. Note: Don't forget to take the 12 -sample delay of the FIR filter into account.

Check back soon!

Design a lowest-order equiripple linear-phase FIR filter to satisfy the specifications given in Figure P7.2. Provide a plot of the amplitude response and a plot of the impulse response.

Check back soon!

A digital signal $x(n)$ contains a sinusoid of frequency $\pi / 2$ and a Gaussian noise $w(n)$ of zero mean and unit variance; i.e.,

$$

x(n)=2 \cos \frac{\pi n}{2}+w(n)

$$

We want to filter out the noise component using a 50th-order causal and linear-phase FIR filter.

1. Using the Parks-McClellan algorithm, design a narrow bandpass filter with passband width of no more than $0.02 \pi$ and stopband attenuation of at least 30 dB . Note that no other parameters are given and that you have to choose the remaining parameters for the firpm function to satisfy the requirements. Provide a plot of the log-magnitude response in dB of the designed filter.

2. Generate 200 samples of the sequence $x(n)$ and processed through the preceding filter to obtain the output $y(n)$. Provide subplots of $x(n)$ and $y(n)$ for $100 \leq n \leq 200$ on one plot and comment on your results.

Check back soon!

Design a minimum order linear-phase FIR filter, using the Parks-McClellan algorithm, to satisfy the requirements given in Figure P7.1.

1. Provide a plot of the amplitude response with grid-lines and axis labeling as shown in Figure P7.1.

2. Generate the following signals

$$

x_1(n)=\cos (0.25 \pi n), \quad x_2(n)=\cos (0.5 \pi n), \quad x_3(n)=\cos (0.75 \pi n) ; \quad 0 \leq n \leq 100 .

$$

Process these signals through this filter to obtain the corresponding output signals $y_1(n), y_2(n)$, and $y_3(n)$. Provide stem plots of all input and output signals in one figure.

Check back soon!

Design a minimum-order linear-phase FIR filter, using the Parks-McClellan algorithm, to satisfy the requirements given in Figure P7.3. Provide a plot of the amplitude response with grid-lines and axis labeling as shown in Figure P7.3.

Check back soon!

The specifications on the amplitude response of an FIR filter are given in Figure P7.4.

1. Using a window design approach and a fixed window function, design a minimum-length linear-phase FIR filter to satisfy the given requirements. Provide a plot of the amplitude response with grid-lines as shown in Figure P7.4.

2. Using a window design approach and the Kaiser window function, design a minimum-length linear-phase FIR filter to satisfy the given requirements. Provide a plot of the amplitude response with grid-lines as shown in Figure P7.4.

3. Using a frequency-sampling design approach and with no more than two samples in the transition bands, design a minimum-length linear-phase FIR filter to satisfy the given requirements. Provide a plot of the amplitude response with grid-lines as shown in Figure P7.4.

4. Using the Parks-McClellan design approach, design a minimum-length linear-phase FIR filter to satisfy the given requirements. Provide a plot of the amplitude response with grid-lines as shown in Figure P7.4.

5. Compare the preceding four design methods in terms of

- the order of the filter

- the exact band-edge frequencies

- the exact tolerances in each band

Check back soon!

Design a minimum-order linear-phase FIR filter, using the Parks-McClellan algorithm, to satisfy the requirements given in Figure P7.5. Provide a plot of the amplitude response with grid-lines as shown in Figure P7.5.

Check back soon!

Design a minimum-length linear-phase bandpass filter of Problem P7.9 using the Parks-McClellan algorithm.

1. Plot the impulse response and the magnitude response in dB of the designed filter in one figure plot.

2. Plot the amplitude response of the designed filter and count the total number of extrema in passband and stopbands. Verify this number with the theoretical estimate of the total number of extrema.

3. Compare the order of this filter with that of the filter in Problem P7.9.

Check back soon!