0% found this document useful (0 votes)
107 views4 pages

FIR Filters Design

This document provides instructions for programming exercise 11 on designing finite impulse response (FIR) filters using the frequency sampling method. It describes how to design a 20th order lowpass FIR filter with a cutoff frequency of 0.3π by taking samples of the desired frequency response and using the inverse discrete Fourier transform. It also discusses how to improve the filter approximation by defining samples in the transition band and using different roll-off approaches. The effects of varying the filter order and using a Hamming window are analyzed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
107 views4 pages

FIR Filters Design

This document provides instructions for programming exercise 11 on designing finite impulse response (FIR) filters using the frequency sampling method. It describes how to design a 20th order lowpass FIR filter with a cutoff frequency of 0.3π by taking samples of the desired frequency response and using the inverse discrete Fourier transform. It also discusses how to improve the filter approximation by defining samples in the transition band and using different roll-off approaches. The effects of varying the filter order and using a Hamming window are analyzed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

CoE 121: Introduction to Digital Signal Processing

Electrical and Electronics Engineering Institute


University of the Philippines, Diliman

Programming Exercise 11: Design of FIR Filters by Frequency Sampling

INSTRUCTIONS
• This is an individual programming exercise. Any clarifications or questions must be
directed to the instructor or student assistant.
• Save your main code in an M-file with the file name CoE121_PE11_<LastName>.m.
Submit your code together with the following files.
o Documentation containing all the answers for each question. Save it as a pdf
file named CoE121_PE11_<LastName>_docu.pdf”.
o The required functions and images.
o Note: A missing file will incur a deduction of 10.
• The deadline of this exercise is on April 15, 11:55 PM. A 10-point deduction per day
will be incurred for late submissions.

FREQUENCY SAMPLING DESIGN TECHNIQUE


In this exercise, we will design finite-duration, impulse response (FIR) filters based from
the samples of the desired frequency response.

Suppose we have L samples Hd[k] of the desired frequency response. Here, k represents
a digital frequency 0 ≤ ωk < 2ϖ where a sample of the frequency response was taken.
The impulse response h[n] of the FIR filter is determined by using the Inverse Discrete
Fourier Transform (IDFT) equation:
𝐿−1
1 2𝜋
ℎ[𝑛] = ∑ 𝐻𝑑 [𝑘]𝑒 𝑗 𝐿 𝑘𝑛 , 𝑛 = 0,1, … , 𝐿 − 1
𝐿
𝑘=0

The samples Hd[k] are generally complex numbers, containing information about the
desired amplitude and angle response. For an FIR filter with a linear phase response, the
desired frequency response samples are described by the equations below.
𝐻𝑑 [𝑘] = 𝐴𝑑 [𝑘]𝑒 𝑗Ψd [𝑘]

𝐴𝑑 (𝑒 𝑗0 ) 𝑘=0
𝐴𝑑 [𝑘] = { 𝑗2𝜋(𝐿−𝑘)
𝐴𝑑 (𝑒 𝐿 ) 𝑘 = 1,2, … , 𝐿 − 1

𝜋 𝐿 − 1 2𝜋
± 𝑞− 𝑘 𝑘 = 0, 1, … , 𝑄
Ψ𝑑 [𝑘] = { 2 2 𝐿
𝜋 𝐿 − 1 2𝜋
∓ 𝑞+ (𝐿 − 𝑘) 𝑘 = 𝑄 + 1, … , 𝐿 − 1
2 2 𝐿

Here Ad[k] and Ψd[k] represent the samples of the desired amplitude and angle
response, respectively. The parameter q is 0 for Type I and II FIR filters, and 1 for type
III and IV FIR filters. The parameter Q is floor((L-1)/2).

DESIGN OF LOWPASS FILTERS


We start with the simple case of designing lowpass filters to easily demonstrate the
process of designing filters using the frequency sampling technique.

1. Let’s design a 20-th order, FIR Type I, lowpass filter with a cut-off frequency at ωc =
0.3ϖ. First, we generate the frequency vector where we will define the samples of the
desired frequency response. Note that since the filter order is M = 20, our FIR filter
will have L = M + 1 = 21 samples. This is executed by the line of code below. Type it
in your main M-file for this exercise.

CoE 121 Programming Exercise 11: Design of FIR Filters by Frequency Sampling
2nd Semester 2018-2019
CoE 121: Introduction to Digital Signal Processing
Electrical and Electronics Engineering Institute
University of the Philippines, Diliman
>> M = 20;
>> L = M + 1;
>> wkvec = (0:(L-1))*2*pi/L; % frequency vector

2. We will now define the samples of the desired amplitude and angle response. Since
we want a lowpass filter, the amplitude response must be equal to 1 at 0 ≤ ωk ≤ ωc,
and 0 at ωc < ωk ≤ ϖ. For ϖ < ωk ≤ 2ϖ, the set of samples are just a mirror image of
the set in 0 ≤ ωk ≤ ϖ. The samples of the angle response just obtained using the
equation above. These are accomplished by the lines of code below. Append them to
your existing M-file code.

>> wc = 0.3*pi;
>> Ad = zeros(size(wkvec));
>> Ad(wkvec < wc) = 1; Ad(wkvec > (2*pi-wc)) = 1;
>> alpha = (L-1)/2; Q = floor(alpha)
>> Psid = -alpha*(2*pi/L)*[(0:Q),-(L-(Q+1:M))];

3. Calculate the impulse response samples of your FIR filter using the IDFT. In
MATLAB/Octave, this is done by using the ifft() function. The use of this function is
demonstrated in the following lines of code. Add them to your existing M-file code.

>> Hd = Ad.*exp(1i*Psid);
>> hn = real(ifft(Hd));

4. Verify that your filter will work. Plot the frequency response of your FIR filter from
(3) and superimpose the samples of the desired frequency response from (2). You
should get the plot shown in the figure below.

Observe that for frequency values where we defined the desired response, there is
no difference between the desired and the FIR’s magnitude response values. The
error occurs on frequency values where the amplitude response was not defined.

CoE 121 Programming Exercise 11: Design of FIR Filters by Frequency Sampling
2nd Semester 2018-2019
CoE 121: Introduction to Digital Signal Processing
Electrical and Electronics Engineering Institute
University of the Philippines, Diliman
5. Try to vary the filter order M and observe its effect on the magnitude response.
Generate and superimpose the plots of the log-magnitude response of the filter for M
= 20, 60 and 100. What is the effect of the filter order on the

A. Passband ripple
B. Stopband attenuation
C. Transition band

Write your answers in your documentation file.

IMPROVING THE APPROXIMATION OF THE DESIRED FREQUENCY RESPONSE


The frequency response of the FIR filter can be improved to better approximate the
desired frequency response (which in this case is the ideal lowpass filter).

One way of doing this is instead of defining samples with reference only to the cut-off
frequency ωc, we will now define samples with reference to the passband and stopband
edge frequencies (ωp and ωs respectively), which define the transition band of the FIR
filter. The amplitude response samples falling within this band can be computed using
either a straight-line roll-off approach (first equation below) or a raised-cosine roll-off
approach (second equation below).
𝜔𝑠 − 𝜔
𝐴𝑑 (𝑒 𝑗𝜔 ) = , 𝜔𝑝 < 𝜔 < 𝜔𝑠
𝜔𝑠 − 𝜔𝑝

𝜔𝑠 − 𝜔
𝐴𝑑 (𝑒 𝑗𝜔 ) = 0.5 + 0.5 cos [𝜋 ], 𝜔𝑝 < 𝜔 < 𝜔𝑠
𝜔𝑠 − 𝜔𝑝

6. Redefine the samples of the amplitude response in (2) to allocate samples in the
transition band. Use the straight-line roll-off approach. This can be accomplished by
replacing the lines of code in (2) with the following lines of code.

>> wp = 0.25*pi; ws = 0.35*pi; Dw = 2*pi/L;


>> k1 = floor(wp/Dw); k2 = ceil(ws/Dw);
>> wtrans = ((k2-1):-1:(k1-1))*Dw;
>> A = (ws-wtrans)/(ws-wp); B = fliplr(A);
>> Ad = [ones(1,k1+1),B,zeros(1,L-2*k2+1),…
A,ones(1,k1)];
>> alpha = (L-1)/2; Q = floor(alpha);
>> Psid = -alpha*(2*pi/L)*[(0:Q),-(L-(Q+1:M))];

7. Calculate the impulse response samples of your new FIR filter. Plot the frequency
response of your FIR filter and superimpose the samples of the desired frequency
response from (6). You should get the plot shown in the figure below.

8. Try to vary the filter order M and observe its effect on the magnitude response.
Generate and superimpose the plots of the log-magnitude response of the filter for M
= 20, 60 and 100. What is the effect of the filter order on the

A. Passband ripple
B. Stopband attenuation
C. Transition band

9. Repeat (6) to (8) but this time, using the raised-cosine approach.

CoE 121 Programming Exercise 11: Design of FIR Filters by Frequency Sampling
2nd Semester 2018-2019
CoE 121: Introduction to Digital Signal Processing
Electrical and Electronics Engineering Institute
University of the Philippines, Diliman

Just like in the design of FIR filters via windowing, nonrectangular windows can also be
used to change the characteristics of the filter. Once the impulse response is generated
via IDFT, just multiply it with the window of the same length.

10. Use a Hamming window to change the characteristics of the 20-th order filter
generated in (6). Generate and superimpose the plots of the log-magnitude response
of the filter that used and did not use the Hamming window. What is the effect of
using the nonrectangular window on the

A. Passband ripple
B. Stopband attenuation
C. Transition band
D. Error with respect to the desired magnitude response

CoE 121 Programming Exercise 11: Design of FIR Filters by Frequency Sampling
2nd Semester 2018-2019

You might also like