0% found this document useful (0 votes)
4 views

DSP_Exp_9[1]

The document outlines the design of IIR digital filters using MATLAB, focusing on various filter types including Butterworth, Chebyshev, and Elliptic filters. It details the procedures for implementing bilinear transformation and impulse invariant methods, along with MATLAB commands for filter design and frequency response visualization. Additionally, it includes specific exercises for designing highpass, bandstop, and bandpass filters with given specifications.
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)
4 views

DSP_Exp_9[1]

The document outlines the design of IIR digital filters using MATLAB, focusing on various filter types including Butterworth, Chebyshev, and Elliptic filters. It details the procedures for implementing bilinear transformation and impulse invariant methods, along with MATLAB commands for filter design and frequency response visualization. Additionally, it includes specific exercises for designing highpass, bandstop, and bandpass filters with given specifications.
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/ 13

23102128 A6 Vansh Ahuja

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

Wp = 1050/(fs/2); % Normalized passband edge frequency


Ws = 600/(fs/2); % Normalized stopband edge frequency
Rp = 1; % Passband ripple in dB
Rs = 50; % Stopband attenuation in dB

%% Compute Filter Order & Design Filters


% Butterworth
[N_butt, Wn_butt] = buttord(Wp, Ws, Rp, Rs);
[num_butt, den_butt] = butter(N_butt, Wn_butt, 'high');

% 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');

%% Apply Bilinear Transformation


[num_butt_bl, den_butt_bl] = bilinear(num_butt, den_butt, fs);
[num_cheby1_bl, den_cheby1_bl] = bilinear(num_cheby1, den_cheby1, fs);
[num_cheby2_bl, den_cheby2_bl] = bilinear(num_cheby2, den_cheby2, fs);
[num_ellip_bl, den_ellip_bl] = bilinear(num_ellip, den_ellip, fs);

%% Apply Impulse Invariant Method


[num_butt_ii, den_butt_ii] = impinvar(num_butt, den_butt, fs);
[num_cheby1_ii, den_cheby1_ii] = impinvar(num_cheby1, den_cheby1, fs);
[num_cheby2_ii, den_cheby2_ii] = impinvar(num_cheby2, den_cheby2, fs);
[num_ellip_ii, den_ellip_ii] = impinvar(num_ellip, den_ellip, fs);

%% Plot Frequency Responses Separately


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]');

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

%% Compute Filter Order & Design Filters


% Butterworth
[N_butt, Wn_butt] = buttord(Wp, Ws, Rp, Rs);
[num_butt, den_butt] = butter(N_butt, Wn_butt, 'stop');

% 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');

%% Apply Bilinear Transformation


[num_butt_bl, den_butt_bl] = bilinear(num_butt, den_butt, fs);
[num_cheby1_bl, den_cheby1_bl] = bilinear(num_cheby1, den_cheby1, fs);
[num_cheby2_bl, den_cheby2_bl] = bilinear(num_cheby2, den_cheby2, fs);
[num_ellip_bl, den_ellip_bl] = bilinear(num_ellip, den_ellip, fs);

%% Apply Impulse Invariant Method


[num_butt_ii, den_butt_ii] = impinvar(num_butt, den_butt, fs);
[num_cheby1_ii, den_cheby1_ii] = impinvar(num_cheby1, den_cheby1, fs);
[num_cheby2_ii, den_cheby2_ii] = impinvar(num_cheby2, den_cheby2, fs);
[num_ellip_ii, den_ellip_ii] = impinvar(num_ellip, den_ellip, fs);

%% Plot Frequency Responses Separately

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.

%% Butterworth Filter Design to Remove sin(8t)


% Given Specifications
fs = 16 / (2*pi); % Minimum Sampling Frequency
T = 0.1; % Sampling period
wc_analog = 4; % Analog filter cutoff frequency (rad/sec)
wc_digital = wc_analog / (pi * fs); % Correct normalization

% Ensure wc_digital is within (0,1)


if wc_digital <= 0 || wc_digital >= 1
error('Cutoff frequency must be within (0,1). Check normalization.');
end

%% Design Butterworth Filters (Third & Sixth Order)


% Third-order Butterworth filter
[N3, Wn3] = buttord(wc_digital, wc_digital * 0.8, 3, 20);
[num3, den3] = butter(N3, Wn3, 'low');

% Sixth-order Butterworth filter


[N6, Wn6] = buttord(wc_digital, wc_digital * 0.8, 3, 20);
[num6, den6] = butter(N6, Wn6, 'low');

%% Apply Bilinear Transformation


[num3_bl, den3_bl] = bilinear(num3, den3, fs);
[num6_bl, den6_bl] = bilinear(num6, den6, fs);

%% Generate Signal x(t) and Apply Filters


t = 0:T:1; % Time vector
x = 2 + sin(8*t); % Input signal

% Apply filters
x_filtered_3 = filter(num3_bl, den3_bl, x);
x_filtered_6 = filter(num6_bl, den6_bl, x);

%% Plot Frequency Responses


figure;
freqz(num3_bl, den3_bl, 1024, fs);
title('Third Order Butterworth Filter - Bilinear Transform [23102128]');

figure;
freqz(num6_bl, den6_bl, 1024, fs);
title('Sixth Order Butterworth Filter - Bilinear Transform [23102128]');

%% Plot Original vs. Filtered Signal


figure;
subplot(2,1,1);
plot(t, x, 'b', t, x_filtered_3, 'r');
title('Third Order Butterworth - Filtering x(t) [23102128]');
legend('Original Signal', 'Filtered Signal');

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

% Compute the minimum filter order


[N, Wn] = buttord(Wp, Ws, Ap, As);

% Design the Butterworth bandpass filter


[num, den] = butter(N, Wn, 'bandpass');

% Frequency response visualization


figure;
freqz(num, den, 1024);
title('Butterworth Bandpass Filter Frequency Response [23102128]');
xlabel('Normalized Frequency');
ylabel('Magnitude (dB)');
grid on;

79
23102128 A6 Vansh Ahuja

POST LAB EXERCISE


1.
%% Butterworth Highpass Filter Design

% 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

% Compute the minimum filter order


[N, Wn] = buttord(Wp, Ws, Ap, As);

% Design the Butterworth highpass filter


[num, den] = butter(N, Wn, 'high');

% Frequency response visualization


figure;
freqz(num, den, 1024, fs);
title('Butterworth Highpass Filter Frequency Response [23102128]');
xlabel('Normalized Frequency');
ylabel('Magnitude (dB)');
grid on;

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)

% Compute minimum order for Chebyshev Type I


[N_cheby, Wn_cheby] = cheb1ord(Wp, Ws, Ap, As);
[num_cheby, den_cheby] = cheby1(N_cheby, Ap, Wn_cheby, 'low');

% Compute minimum order for Butterworth


[N_butt, Wn_butt] = buttord(Wp, Ws, Ap, As);
[num_butt, den_butt] = butter(N_butt, Wn_butt, 'low');

%% Plot Frequency Response for Both Filters


figure;
freqz(num_cheby, den_cheby, 1024);
title('Chebyshev Type I Lowpass Filter Frequency Response [23102128]');
xlabel('Normalized Frequency');
ylabel('Magnitude (dB)');
grid on;

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

% Compute minimum order for Chebyshev Type I


[N_cheby, Wn_cheby] = cheb1ord(Wp, Ws, Ap, As);
[num_cheby, den_cheby] = cheby1(N_cheby, Ap, Wn_cheby, 'low');

% Compute minimum order for Butterworth


[N_butt, Wn_butt] = buttord(Wp, Ws, Ap, As);
[num_butt, den_butt] = butter(N_butt, Wn_butt, 'low');

%% Plot Frequency Response for Both Filters


figure;
freqz(num_cheby, den_cheby, 1024);
title('Chebyshev Type I Lowpass Filter Frequency Response [23102128]');
xlabel('Normalized Frequency');
ylabel('Magnitude (dB)');
grid on;

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

% Given coefficients for analog filter


b = [2]; % Numerator coefficients
a = [1, 2, 3]; % Denominator coefficients

% Sampling frequency (assumed)


fs = 1000;s

% Convert the analog filter to a digital filter using Bilinear Transformation


Method
[num_digital, den_digital] = bilinear(b, a, fs);

% Plot frequency response of the digital filter


figure;
freqz(num_digital, den_digital, 1024, fs);
title('Digital Filter Frequency Response - Bilinear Transformation [23102128]');

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

You might also like