Faculty of Engineering
ETN3096 Digital Signal Processing
Lab DSP2 - IIR Filter Design
1. Print out this document and work out the solutions.
2. Before attending this lab session, you must have completed Sketch 1.
3. Show Sketch 1 to the lab instructor (YL Foo) any day, any time BEFORE your designated lab session.
4. Bring this document to the lab session.
5. During the lab session, write down all your results in this document.
6. When the session ends, submit this document to the lab instructor.
1. Introduction
This lab experiment provides the opportunity of learning Infinite Impulse Response (IIR) filter design. After completing this experiment, a student is expected to be able to design an IIR filter that fits a given set of requirements.
1.1 Objective
To learn the design procedure of an IIR filter.
2. Design an IIR Lowpass Filter
Design an IIR lowpasss filter with the following specifications:
1. 3-dB attenuation at the passband frequency of 1500 Hz
2. 10-dB stopband attenuation at the frequency of 3000 Hz
3. Sampling frequency at 8000 Hz
2.1 Butterworth Filter
Design a Butterworth filter that fits the aforementioned specifications.
Sample program:
% % % Modified from Example 8.7, pg. 322
% % % Design a digital lowpasss filter with the following specifications:
% % % 1. 3-dB attenuation at the passband frequency of 1500 Hz
% % % 2. 10-dB stopband attenuation at the frequency of 3000 Hz
% % % 3. Sampling frequency at 8000 Hz
fs = 8000; % Sampling rate (Hz)
f_p = 1500; % Passband freq (Hz)
f_s = 3000; % Stopband freq (Hz)
A_s = 10; % Stopband attenuation (dB)
A_p = 3; % Passband attenuation (dB)
% fs/2 corresponds to Wn = 1
% f_p corresponds to ???
Wn_p = f_p/(fs/2);
Wn_s = f_s/(fs/2);
% % % Can you design a Butterworth filter?
% % % To design a Butterworth filter, use the butter() & buttord() provided by MATLAB
Filt_Ord_ceil = buttord(Wn_p, Wn_s, A_p, A_s); % Determine the filter order
[b, a] = butter(Filt_Ord_ceil, Wn_p);
% % % How do I see the magnitude & phase responses of the filter I designed?
% % % Try freqz()
% % % Type "help freqz" at the command prompt
freqz(b, a, numFreq, fs);
Sketch clearly the magnitude response of the filter.
Sketch 1: Magnitude response of an IIR lowpasss Butterworth filter with (i) 3-dB attenuation at the passband frequency of 1500 Hz, (ii) 10-dB stopband attenuation at the frequency of 3000 Hz, and (iii) sampling frequency of 8000 Hz.
Label both the horizontal and vertical axes clearly. Give their respective unit.
2.2 Filter Order
What will happen if you increase the filter order?
Try with filter orders of 3 and 5. Discuss your observation.
Sketch clearly the magnitude responses of the filter with orders 1, 3, and 5.
Sketch 2: Magnitude responses of an IIR lowpasss Butterworth filter with orders 1, 3, and 5
Use a legend to label the two graphs clearly.
Label both the horizontal and vertical axes clearly. Give their respective unit.
Discuss the difference. Which one gives the best performance?
2.3 Chebyshev and Elliptic Filters
Design Chebyshev and Elliptic filters that fit the aforementioned specifications.
Compare their performance with Butterworth filter.
Sample program:
% % % Can you design a different type of filter, e.g. a Chebyshev filter?
% % % To design a Chebyshev filter, use the cheby1() & cheb1ord() provided by MATLAB.
% Filt_Ord_ceil = cheb1ord(Wn_p, Wn_s, A_p, A_s);
[b_cheby, a_cheby] = cheby1(3, A_p, Wn_p); % Filter order = ?
% % % Can you design a Elliptic filter?
% % % To design an Elliptic filter, use the ellip() & ellipord() provided by MATLAB.
% Filt_Ord_ceil = ellipord(Wn_p, Wn_s, A_p, A_s);
[b_ellip, a_ellip] = ellip(3, A_p, A_s, Wn_p); % Filter order = ?
Sketch clearly the magnitude responses of Butterworth, Chebyshev and Elliptic filters of order 3.
Sketch 3: Magnitude responses of Butterworth, Chebyshev and Elliptic filters of order 3
Use a legend to label the two graphs clearly.
Label both the horizontal and vertical axes clearly. Give their respective unit.
Discuss the difference. Which one gives the best performance?
3. Filtering an Audio Signal
If an audio signal is corrupted by noise, how do you remove the noise?
Steps:
- Listen to the corrupted audio file. Sample the corrupted audio signal.
- Listen to its original (uncorrupted) file. Sample the original audio signal.
- Plot the power spectra of both data. Determine which frequency range is corrupted by noise.
- Design a filter that removes data in the affected range.
- Listen to the filtered audio file to confirm if the noise has been removed.
You are given a set of audio files to work with. They are in pairs: {xo.wav, xn.wav}, x = 2, 9, 11, 15, 24, and 25. xo.wav is the original file, whereas xn.wav is the corrupted one.
Sample program:
% % % If an audio signal is corrupted by noise, how do you remove the noise?
% % % First, read the audio signal that has been corrupted by noise, and listen to it
% % % How do you read an audio signal?
% % % Try audioread()
[x_n, audio_fs] = audioread('2n.wav');
% % % x_n stores the sampled data of audio signal that has been corrupted by noise
% % % the audio data is sampled at the rate of audio_fs (Hz)
% % % What is the power spectrum of this audio signal?
fs = length(x_n); % How many sampled data in 1 second?
Plot_Power_Spectrum(x_n, fs);
hold on;
% % % % How do you play this audio file?
% % % % Try audioplayer(), followed by play()
% p_n = audioplayer(x_n, audio_fs);
% play(p_n);
% % % Second, read the original audio signal that has NOT been corrupted by noise, and listen to it
x_o = audioread('2o.wav'); % x_o stores the sampled data of original audio signal
% % % Assume that the audio sampling rate remains the same as audio_fs (Hz)
Plot_Power_Spectrum(x_o, fs); % Assume that x_o & x_n are of the same length
% legend('Noisy', 'Original');
% p_o = audioplayer(x_o, audio_fs);
% play(p_o);
% % % What is the difference?
% % % What can you do to remove the noise?
% % % What kind of filter should you use?
Save the following program into a separate file, Plot_Power_Spectrum.m
% % x is the signal
% % N is the number of samples
% % Return normalized power spectrum of signal x
function [P_x_norm_half, f_half, P_x_norm, f, f_norm] = Plot_Power_Spectrum(x, N)
X = fft(x);
X_sq = X.*conj(X);
P_x = X_sq/N; % power spectrum of x
P_x_norm = P_x/N; % normalized by N
clear X_sq;
f = -(N/2):(N/2)-1; % N must be divisible by 2
f_half = f((N/2)+1:N); % Only the positive half
f_norm = f/N; % Normalized frequency
P_x_norm = fftshift(P_x_norm);
P_x_norm_half = P_x_norm((N/2)+1:N); % Only the positive half
stem(f_half, P_x_norm_half, 'x-', 'MarkerSize',10);
xlabel('Frequency, \itf\rm (Hz)');
ylabel('Normalized Power (W)');
title('(Single-Sided) Power Spectrum');
Sketch clearly the power spectra of both original and corrupted audio signals.
Sketch 4: Power spectra of the original and corrupted audio signals
Use a legend to label the two graphs clearly.
Label both the horizontal and vertical axes clearly. Give their respective unit.
Which frequency range is corrupted by noise?
What kind of filter (lowpass? highpass? bandpass? bandstop?) can remove the corrupted part?
Determine the specifications of this filter:
Passband frequency = _____ Hz
Stopband frequency = _____ Hz
Passband attenuation = _____ dB
Stopband attenuation = _____ dB
3.1 Butterworth Filter
Design a Butterworth filter that can attenuate the corrupted frequency range.
Check the performance of the filter that you design. Use it to filter the noise corrupted signal to see if it can remove the corrupted part.
Sample program:
% % % Design an IIR Lowpass Filter
% % % For 2n.wav & 2o.wav
f_p = ?; % Passband freq (Hz)
f_s = ?; % Stopband freq (Hz)
A_p = ?; % Passband attenuation (dB)
A_s = ?; % Stopband attenuation (dB)
Wn_p = f_p/(fs/2);
Wn_s = f_s/(fs/2);
% % % Design a Butterworth filter
Filt_Ord_butter = buttord(Wn_p, Wn_s, A_p, A_s); % Determine the filter order
[b, a] = butter(Filt_Ord_butter, Wn_p);
% % % Third, clean or filter the corrupted audio signal, and listen to it.
% % % How to filter a signal?
% % % Try filter()
x_c = filter(b, a, x_n); % x_c stores the sampled data of cleaned (filtered) audio signal
Plot_Power_Spectrum(x_c, fs);
legend('Noisy', 'Original', 'Filtered');
% p_c = audioplayer(x_c, audio_fs);
% play(p_c);
% % % What is the difference?
% % % Does the cleaned (filtered) signal resembles the original one?
figure; freqz(b, a, numFreq, fs); % Show the filter response
% % % Can you try with other .wav files?
Sketch clearly the power spectra of corrupted and filtered audio signals.
Sketch 5: Power spectra of the corrupted and filtered audio signals
Use a legend to label the two graphs clearly.
Label both the horizontal and vertical axes clearly. Give their respective unit.
Listen to the filtered audio file. Did your filter work?
Compare the filtered audio file with the original one. Is there any difference? Why?
Can you try with different filter designs?
3.2 Chebyshev and Elliptic Filters
Design a Chebyshev and an Elliptic filter that can attenuate the corrupted frequency range.
Show their respective magnitude responses below.
Check the performance of the filter that you design. Use it to filter the noise corrupted signal to see if it can remove the corrupted part.
Sample program:
% % % % Design a Chebyshev Filter
% Filt_Ord_cheby = cheb1ord(Wn_p, Wn_s, A_p, A_s);
% [b, a] = cheby1(Filt_Ord_cheby, A_p, Wn_p);
% % % % Design a Elliptic Filter
% Filt_Ord_ellip = ellipord(Wn_p, Wn_s, A_p, A_s);
% [b, a] = ellip(Filt_Ord_ellip, A_p, A_s, Wn_p);
Sketch clearly the magnitude response of Chebyshev filter that fits the required specifications.
Sketch 6: Magnitude response of Chebyshev filter that fits the required specifications
Label both the horizontal and vertical axes clearly. Give their respective unit.
Sketch clearly the magnitude response of Elliptic filter that fits the required specifications.
Sketch 7: Magnitude response of Elliptic filter that fits the required specifications
Label both the horizontal and vertical axes clearly. Give their respective unit.
Did the Chebyshev and Elliptic Filters work? Please confirm.
Can you work with the rest of the audio files?
3.3 Other Audio Files
Repeat the same procedures for the rest of the audio files.
Based on your observations, list down the filter specifications required for these audio files.
For 2n.wav & 2o.wav:
Passband frequency = _____ Hz
Stopband frequency = _____ Hz
For 9n.wav & 9o.wav:
Passband frequency = _____ Hz
Stopband frequency = _____ Hz
For 11n.wav & 11o.wav:
Passband frequency = _____ Hz
Stopband frequency = _____ Hz
For 15n.wav & 15o.wav:
Passband frequency = _____ Hz
Stopband frequency = _____ Hz
For 24n.wav & 24o.wav:
Passband frequency = _____ Hz
Stopband frequency = _____ Hz
For 25n.wav & 25o.wav:
Passband frequency = _____ Hz
Stopband frequency = _____ Hz
4. Conclusion
Summarize what you have learnt from this lab experiment.
YL Foo (2018 Jan)Page 13