DSP_Exp_9[1]
DSP_Exp_9[1]
Experiment No. 8
Aim: Infer the IIR digital filter technique for a given specification using bilinear
transformation and impulse invariant method using MATLAB program.
Theory:
IIR Filter Types
1) Butterworth filter
Provides the best Taylor series approximation to the ideal lowpass filter response at analog
frequencies Ω = 0 and Ω = ∞; for any order n, the magnitude squared response has 2n − 1
zero derivatives (that is, it is maximally flat) at these locations. Response is monotonic
overall, decreasing smoothly from Ω = 0 to Ω = ∞.
2) Chebyshev Type I filter
It minimizes the absolute difference between the ideal and the actual frequency response over
the entire passband by using an equal ripple in the passband. Stopband response is maximally
flat. The transition from passband to stopband is more rapid than for the Butterworth filter.
3) Chebyshev Type II filter
It minimizes the absolute difference between the ideal and the actual frequency response over
the entire stopband by using an equal ripple in the stopband. Passband response is maximally
flat. The stopband does not approach zero as quickly as the type I filter. The absence of ripple
in the passband, however, is often an important advantage.
4) Elliptic filter
Equiripple in both the passband and stopband. Generally meets filter requirements with the
lowest order of any supported filter type. Given a filter order n, passband ripple, and stopband
ripple, elliptic filters minimize transition width.
For designing Butterworth filter, the commands are
[num, den] = butter(N, Wn)
For designing a Type 1 Chebyshev digital filter, the commands are
[num, den] = cheby1(N, Rp, Wn)
For designing a Type 2 Chebyshev digital filter, the commands are
[num,den] = cheby2(N,Rs,Wn)
For designing Butterworth filter, the commands are
[num, den] = ellip(N, Rp, Rs, Wn)
Each function delivers a lowpass filter by default. To design a bandpass, Wn must be defined
as a vector of 2 elements. The elements hold the corner frequencies of the bandpass filter.
71
23102128 A6 Vansh Ahuja
The filter order N and the scaling factor for the frequency bounds Wn can be determined as
follows:
[N, Wn] = buttord(Wp, Ws, Rp, Rs)
[N, Wn] = cheb1ord(Wp, Ws, Rp, Rs)
[N, Wn] = ellipord(Wp, Ws, Rp, Rs)
Where, the input parameters are the normalized passband edge frequency Wp, the normalized
stopband edge frequency Ws, the passband ripple Rp in dB, and the minimum stopband
attenuation Rs in dB. Both Wp and Ws must be a number between 0 and 1 with the sampling
frequency assumed to be 2 Hz. The output data are the lowest order N meeting the
specifications and the normalized cutoff frequency Wn. If Rp = 3 dB, then Wn = Wp. Buttord
can also be used to estimate the order of a highpass, a bandpass, and a bandstop Butterworth
filter. For a highpass filter design,Wp > Ws. For bandpass and bandstop filter designs, Wp
and Ws are two-element vectors specifying both edge frequencies, with the lower edge
frequency being the first element of the vector. In the latter cases, Wn is also a two-element
vector.
Digital IIR Filter design
The design of an IIR filter is rather straightforward when using the bilinear transformation
technique. An analog filter is converted to a digital one via the bilinear transformation we
obtain the relation
As the bilinear transformation preserves the type of filter (LP, BP etc.) we only need to make
sure that the cut-off frequencies gets mapped to the correct place.
The design technique is summarized here:
1. Start by identifying the discrete time frequencies describing the cut-off frequencies. Use
normalized frequencies in radians where, ω=π represents half the sampling frequency
(ω = 2πf / fs).
2. Calculate the corresponding analog frequencies using Ω = 2 tan(ω / 2).
3. Design an analog filter Ha(s) based on the specifications.
4. Use the bilinear transformation to obtain the final digital (Z-domain) filter.
IN LAB EXERCISE
1.
%% Digital IIR Highpass Filter Design for All Four Types
% Specifications
fs = 3500; % Sampling frequency
72
23102128 A6 Vansh Ahuja
% Chebyshev Type I
[N_cheby1, Wn_cheby1] = cheb1ord(Wp, Ws, Rp, Rs);
[num_cheby1, den_cheby1] = cheby1(N_cheby1, Rp, Wn_cheby1, 'high');
% Chebyshev Type II
[N_cheby2, Wn_cheby2] = cheb2ord(Wp, Ws, Rp, Rs);
[num_cheby2, den_cheby2] = cheby2(N_cheby2, Rs, Wn_cheby2, 'high');
% Elliptic Filter
[N_ellip, Wn_ellip] = ellipord(Wp, Ws, Rp, Rs);
[num_ellip, den_ellip] = ellip(N_ellip, Rp, Rs, Wn_ellip, 'high');
figure;
freqz(num_cheby1_bl, den_cheby1_bl, 1024, fs);
title('Chebyshev I - Bilinear Transform [23102128]');
figure;
freqz(num_cheby2_bl, den_cheby2_bl, 1024, fs);
title('Chebyshev II - Bilinear Transform [23102128]');
figure;
freqz(num_ellip_bl, den_ellip_bl, 1024, fs);
title('Elliptic - Bilinear Transform [23102128]');
figure;
freqz(num_butt_ii, den_butt_ii, 1024, fs);
title('Butterworth - Impulse Invariant [23102128]');
figure;
freqz(num_cheby1_ii, den_cheby1_ii, 1024, fs);
title('Chebyshev I - Impulse Invariant [23102128]');
73
23102128 A6 Vansh Ahuja
figure;
freqz(num_cheby2_ii, den_cheby2_ii, 1024, fs);
title('Chebyshev II - Impulse Invariant [23102128]');
figure;
freqz(num_ellip_ii, den_ellip_ii, 1024, fs);
title('Elliptic - Impulse Invariant [23102128]');
74
23102128 A6 Vansh Ahuja
2.
%% Digital IIR Bandstop Filter Design for All Four Types
% Specifications
fs = 12000; % Sampling frequency
Wp = [2.1, 4.5] / (fs/2); % Normalized passband edge frequencies
Ws = [2.7, 3.9] / (fs/2); % Normalized stopband edge frequencies
Rp = 0.6; % Passband ripple in dB
Rs = 45; % Stopband attenuation in dB
% Chebyshev Type I
[N_cheby1, Wn_cheby1] = cheb1ord(Wp, Ws, Rp, Rs);
[num_cheby1, den_cheby1] = cheby1(N_cheby1, Rp, Wn_cheby1, 'stop');
% Chebyshev Type II
[N_cheby2, Wn_cheby2] = cheb2ord(Wp, Ws, Rp, Rs);
[num_cheby2, den_cheby2] = cheby2(N_cheby2, Rs, Wn_cheby2, 'stop');
% Elliptic Filter
[N_ellip, Wn_ellip] = ellipord(Wp, Ws, Rp, Rs);
[num_ellip, den_ellip] = ellip(N_ellip, Rp, Rs, Wn_ellip, 'stop');
75
23102128 A6 Vansh Ahuja
figure;
freqz(num_butt_bl, den_butt_bl, 1024, fs);
title('Butterworth - Bilinear Transform [23102128]');
figure;
freqz(num_cheby1_bl, den_cheby1_bl, 1024, fs);
title('Chebyshev I - Bilinear Transform [23102128]');
figure;
freqz(num_cheby2_bl, den_cheby2_bl, 1024, fs);
title('Chebyshev II - Bilinear Transform [23102128]');
figure;
freqz(num_ellip_bl, den_ellip_bl, 1024, fs);
title('Elliptic - Bilinear Transform [23102128]');
figure;
freqz(num_butt_ii, den_butt_ii, 1024, fs);
title('Butterworth - Impulse Invariant [23102128]');
figure;
freqz(num_cheby1_ii, den_cheby1_ii, 1024, fs);
title('Chebyshev I - Impulse Invariant [23102128]');
figure;
freqz(num_cheby2_ii, den_cheby2_ii, 1024, fs);
title('Chebyshev II - Impulse Invariant [23102128]');
figure;
freqz(num_ellip_ii, den_ellip_ii, 1024, fs);
title('Elliptic - Impulse Invariant [23102128]');
76
23102128 A6 Vansh Ahuja
77
23102128 A6 Vansh Ahuja
3.
% Apply filters
x_filtered_3 = filter(num3_bl, den3_bl, x);
x_filtered_6 = filter(num6_bl, den6_bl, x);
figure;
freqz(num6_bl, den6_bl, 1024, fs);
title('Sixth Order Butterworth Filter - Bilinear Transform [23102128]');
subplot(2,1,2);
plot(t, x, 'b', t, x_filtered_6, 'r');
title('Sixth Order Butterworth - Filtering x(t) [23102128]');
legend('Original Signal', 'Filtered Signal');
78
23102128 A6 Vansh Ahuja
4.
%% Butterworth Bandpass Filter Design
% Given specifications
Ap = 2; % Passband ripple (dB)
As = 20; % Stopband attenuation (dB)
Wp = [0.27, 0.47]; % Normalized passband edge frequencies
Ws = [0.17, 0.5]; % Normalized stopband edge frequencies
79
23102128 A6 Vansh Ahuja
% Given specifications
Ap = 0.4; % Passband ripple (dB)
As = 30; % Stopband attenuation (dB)
fs = 2000; % Assumed sampling frequency (to normalize frequencies)
Wp = 800 / (fs/2); % Normalized passband edge frequency
Ws = 400 / (fs/2); % Normalized stopband edge frequency
80
23102128 A6 Vansh Ahuja
2.
%% Chebyshev Type I Lowpass Filter Design and Butterworth Comparison
% Given specifications
Ap = 1; % Passband ripple (dB)
As = 15; % Stopband attenuation (dB)
Wp = 0.2; % Normalized passband edge frequency (relative to Nyquist)
Ws = 0.3; % Normalized stopband edge frequency (relative to Nyquist)
figure;
freqz(num_butt, den_butt, 1024);
title('Butterworth Lowpass Filter Frequency Response [23102128]');
xlabel('Normalized Frequency');
ylabel('Magnitude (dB)');
grid on;
3.
a)
%% Chebyshev Type I Lowpass Filter Design and Butterworth Comparison
% Given specifications
Ap = 1; % Passband ripple (dB)
As = 15; % Stopband attenuation (dB)
Wp = 0.2; % Normalized passband edge frequency (relative to Nyquist)
Ws = 0.3; % Normalized stopband edge frequency (relative to Nyquist)
81
23102128 A6 Vansh Ahuja
figure;
freqz(num_butt, den_butt, 1024);
title('Butterworth Lowpass Filter Frequency Response [23102128]');
xlabel('Normalized Frequency');
ylabel('Magnitude (dB)');
grid on;
b)
%% Bilinear Transformation for Analog-to-Digital Filter Conversion
82
23102128 A6 Vansh Ahuja
xlabel('Normalized Frequency');
ylabel('Magnitude (dB)');
grid on;
Learning Outcomes
1. Understand IIR digital filter design using bilinear transformation and impulse
invariant methods.
2. Learn to implement Butterworth, Chebyshev Type I & II, and Elliptic filters in
MATLAB.
3. Explore the frequency response of different IIR filters and their performance in signal
processing.
4. Gain practical skills in filter order determination and MATLAB-based IIR filter
analysis.
83