0% found this document useful (0 votes)
9 views12 pages

DSP Exp5 2001ee24

The document outlines a series of experiments for designing various types of digital filters, including Butterworth and Chebyshev-I filters, using techniques such as impulse invariance and bilinear transformation. Each experiment specifies parameters like passband and stopband cutoffs, ripple, and provides MATLAB code for implementation. The document emphasizes the importance of ensuring valid parameter combinations and includes error handling for invalid inputs.

Uploaded by

ashokkushwaha142
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)
9 views12 pages

DSP Exp5 2001ee24

The document outlines a series of experiments for designing various types of digital filters, including Butterworth and Chebyshev-I filters, using techniques such as impulse invariance and bilinear transformation. Each experiment specifies parameters like passband and stopband cutoffs, ripple, and provides MATLAB code for implementation. The document emphasizes the importance of ensuring valid parameter combinations and includes error handling for invalid inputs.

Uploaded by

ashokkushwaha142
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/ 12

EE321

DSP LAB
EXPERIMENT 05

Aim: IIR Filter Design –Analog filter

Name: Kanishk Giri

Roll No: 2001EE24


Aim 1:
Design a lowpass Butterworth filter to satisfy

passband cutoff: Ωp = 0.2π; Passband ripple: Rp = 7 dB


Stopband cutoff: Ωs = 0.3π; Stopband ripple: As = 16 dB

Solution: This filter is characterized by the property that its magnitude is flat in both
passband and stopband.
The magnitude-squared response of an Nth-order lowpass filter is given by :

The analog lowpass filter is specified by the parameters Ωp, Rp, Ωs and As.

clc
clear
close all

% Defining parameters Ωp, Rp, Ωs and As from the given data

Wp = 0.2*pi;
Rp = 7;
Ws = 0.3*pi;
As = 16;

% Writing the filter design


if((Wp>0)&&(Wp<Ws)&&(Rp>0)&&(As>0))
N_order = (log10((10^(Rp/10)-1)/(10^(As/10)-1)))/(2*log10(Wp/Ws));
N_order = ceil(N_order); % rounds each element of
% X to the nearest integer greater
% than or equal to that element.

Wc1 = Wp/((10^(Rp/10)-1)^(0.5/N_order));
Wc2 = Ws/((10^(As/10)-1)^(0.5/N_order));
Wc = (Wc1+Wc2)/2;
[zeros,poles, gain_k] = buttap(N_order); % returns the poles and
% gain of an order n

1
% Butterworth analog lowpass filter prototype.

poles = poles*Wc;
gain_k = gain_k*(Wc^N_order);
B = real(poly(zeros)); % returns the real part of each element
b0_gain = gain_k;
b = gain_k*B;
a = real(poly(poles));
else
% Writing errors
if(Rp <= 0)
error('Rp should be a positive value');
end
if(Wp <= 0)
error('Wp should be a positive value');
end
if(Wp>=Ws)
error('Invalid combination of Wp and Ws');
end
if(As <= 0)
error('As should be a positive value');
end
end
sys = tf(b0_gain,a) % creates a continuous-time
H = bodeplot(sys);

2
Aim 2:
Design a lowpass Chebyshev-I filter to satisfy

passband cutoff: Ωp = 0.2π;Passband ripple: Rp = 1 dB


Stopband cutoff: Ωs = 0.3π;Stopband ripple: As = 16 dB

Solution: The magnitude-squared response of a Chebyshev-I fifilter is

where N is the order of the filter, is the passband ripple factor, which is related to Rp,
and TN (x) is the Nth-order Chebyshev polynomial.
Given Ωp, Ωs, Rp and As, three parameters are required to determine a Chebyshev-I
filter: , Ωc and N.

clc
clear
close all
% Defining parameters Ωp, Rp, Ωs and As from the given data
Rp = 1;
As = 16;
Wp = 0.2*pi;
Ws = 0.3*pi;

% Writing the filter design


E = ((10^(Rp/10)-1)^0.5);
A = 10^(As/20);
Wc = Wp;
Wr = Ws/Wp;
g = ((A*A-1)/(E*E))^(0.5);
N_order = (log10(g+(g*g-1)^0.5))/(log10(Wr+(Wr*Wr-1)^0.5));
N_order = ceil(N_order); % rounds each element of X to the
% nearest integer greater than
% or equal to that element.

% Writing errors
if(A < 1)
error('Invalid value of As');
elseif(Wp <= 0 || Wp >=Ws)
error('Invalid value of Wp');
elseif(Rp <= 0)
error('Invalid value of Rp');

3
elseif(A*A <= (E*E+1))
error('Invalid combination of Rp and As');
else
[zeros,poles,k_gain] = cheb1ap(N_order, Rp);
a = real(poly(poles));
aNn = a(N_order+1);
poles = poles*Wc;
a = real(poly(poles)); % returns the real part of each element
aNu = a(N_order+1);
k_gain = k_gain*aNu/aNn;
B = real(poly(zeros));
b = k_gain*B;
end

sys = tf(k_gain,a) % creates a continuous-time transfer function model


H = bodeplot(sys); % plot the Bode magnitude and phase of the dynamic system model
sys

Aim 3:
Design a lowpass digital filter (Butterworth) using impulse invariance
technique to satisfy

clc
clear
close all
% Defining parameters wp, Rp, ws and As from the given data

4
Rp = 1;
As = 15;
wp = 0.2*pi;
ws = 0.3*pi;
T = 1;
wp = wp/T;
ws = ws/T;
% Writing the filter design
if((wp>0)&&(wp<ws)&&(Rp>0)&&(As>0))
N_order = (log10((10^(0.1*Rp)-1)/(10^(0.1*As)-1)))/(2*log10(wp/ws));
N_order = ceil(N_order); % rounds each element of X to the
% nearest integer greater than or equal to that element.
wc1 = wp/((10^(0.1*Rp)-1)^(0.5/N_order));
wc2 = ws/((10^(0.1*As)-1)^(0.5/N_order));
wc_1 = (wc1+wc2)/2;
[zeros,poles,k] = buttap(N_order);
poles = poles*wc_1;
k = k*(wc_1^N_order);
B = real(poly(zeros));
b = k*B;
a = real(poly(poles));
else
% Writing errors
if(Rp <= 0)
error('Rp should be a positive value');
end
if(wp <= 0)
error('wp should be a positive value');
end
if(wp>=ws)
error('Invalid combination of wp and ws');
end
if(As <= 0)
error('As should be a positive value');
end
end
[residues,pole,k_constant] = residue(b,a); % finds the residues, poles, and
% direct term of a Partial Fraction Expansion
for i = 1:N_order
pole(i) = exp(pole(i)); % returns the exponential e^x for each element in array X
end
[B,A] = residuez(residues,pole,k_constant); % finds the residues, poles, and
% direct terms of a partial fraction expansion
% of the ratio of numerator and denominator polynomials
B = real(B); % returns the real part of each element
A = real(A);
sys = tf(B,A,T); % creates a continuous-time transfer function model

5
subplot(2,1,1)
impulse(sys) % impulse calculates the unit impulse response of a dynamic system
model
subplot(2,1,2)
freqz(B,A); % gives frequency response of digital filter

Aim 4
Design a lowpass digital filter (Chebyshev-I) using impulse invariance
technique to satisfy

clc
clear
close all
% Defining parameters wp, Rp, ws and As from the given data
Rp = 1;
As = 15;
wp = 0.2*pi;
ws = 0.3*pi;
T = 1;
% Writing the filter design
wp = wp/T;
ws = ws/T;
E = ((10^(Rp/10)-1)^0.5);
A = 10^(As/20);
wc = wp;
wr = ws/wp;
g = (((A^2)-1)/(E^2))^(0.5); % gives order
N_order = (log10(g+((g^2)-1)^0.5))/(log10(wr+((wr^2)-1)^0.5));

6
N_order = ceil(N_order); % rounds each element of X to
% the nearest integer greater than or equal to that element.
% Writing errors
if(A < 1)
error('Invalid value of As');
elseif(wp <= 0 || wp >=ws)
error('Invalid value of wp');
elseif(Rp <= 0)
error('Invalid value of Rp');
elseif((A^2) <= ((E^2)+1))
error('Invalid combination of Rp and As');
else
[zeros,poles,k] = cheb1ap(N_order,Rp); % returns the poles and gain of an
% order n Chebyshev Type I analog
% lowpass filter prototype with Rp dB of ripple in the passband
a = real(poly(poles)); % returns the real part of each element
aNn = a(N_order+1);
poles = poles*wc;
a = real(poly(poles));
aNu = a(N_order+1);
k = k*aNu/aNn;
B = real(poly(zeros));
b = k*B;
end
[residues,pole,direct_term] = residue(b,a); % finds the residues, poles, and direct
term
% of a Partial Fraction Expansion of the ratio of two polynomials
for x = 1:N_order
pole(x) = exp(pole(x)); % returns the exponential ex for each element in array X
end
[B,A] = residuez(residues,pole,direct_term); % finds the residues, poles, and
direct terms
% of a partial fraction expansion of the ratio
% of numerator and denominator polynomials
B = real(B); % returns the real part of each element
A = real(A);
sys = tf(B,A,T); % creates a continuous-time transfer function model
[h,g] = impinvar(b,a,1/T); % creates a digital filter with numerator
% and denominator coefficients
tf(h,g,T)
impulse(sys); % impulse calculates the unit
% impulse response of a dynamic system model
freqz(B,A); % gives frequency response of digital filter

7
Aim 5:
Design a digital filter (Butterworth) using Bilinear transformation technique to satisfy

clc
clear
close all
% Defining parameters wp, Rp, ws and As from the given data
Rp = 1;
As = 15;
wp = 0.2*pi;
ws = 0.3*pi;
T = 1;
wp = (2/T)*tan(wp/2);
ws = (2/T)*tan(ws/2);
% Writing the filter design
if((wp>0)&&(wp<ws)&&(Rp>0)&&(As>0))
N_order = (log10((10^(0.1*Rp)-1)/(10^(0.1*As)-1)))/(2*log10(wp/ws));
N_order = ceil(N_order); % rounds each element of X to the
% nearest integer greater than
% or equal to that element.
wc_1 = wp/((10^(0.1*Rp)-1)^(0.5/N_order));
wc_2 = ws/((10^(0.1*As)-1)^(0.5/N_order));
wc = (wc_1+wc_2)/2;
[zeros,poles,k] = buttap(N_order); % returns the poles and gain of an
% order n Butterworth analog lowpass filter prototype.
poles = poles*wc;
k = k*(wc^N_order);

8
B = real(poly(zeros)); % returns the real part of each element
b = k*B;
a = real(poly(poles));
else
% Writing errors
if(Rp <= 0)
error('Rp should be a positive value');
end
if(wp <= 0)
error('wp should be a positive value');
end
if(wp>=ws)
error('Invalid combination of wp and ws');
end
if(As <= 0)
error('As should be a positive value');
end
end
[residues,pole,direct_term] = residue(b,a); % finds the residues, poles, and
% direct term of a Partial Fraction
% Expansion of the ratio of two polynomials
[Z,P,K] = bilinear(residues,pole,0,1/T); % converts the s-domain transfer function
% in pole-zero form specified by z, p, k
% and sample rate fs to a discrete equivalent.
[B,A] = residuez(Z,P,K); % finds the residues, poles, and direct terms
% of a partial fraction expansion of the
% ratio of numerator and denominator polynomials
B = real(B); % returns the real part of each element
A = real(A);
sys = tf(B,A,T); % creates a continuous-time transfer function model
impulse(sys); % impulse calculates the unit impulse response
% of a dynamic system model
freqz(B,A); % Frequency response of digital filter

9
Aim 6:
Design a digital filter (Chebyshev-I) using Bilinear transformation technique to satisfy

clc
clear
close all
% Defining parameters wp, Rp, ws and As from the given data
Rp = 1;
As = 15;
wp = 0.2*pi;
ws = 0.3*pi;
T = 1;
wp = (2/T)*tan(wp/2);
ws = (2/T)*tan(ws/2);
% Writing the filter design
E = ((10^(0.1*Rp)-1)^0.5);
A = 10^(As/20);
wc = wp;
wr = ws/wp;
g = (((A^2)-1)/(E^2))^(0.5); % gives order
N_order = (log10(g+((g^2)-1)^0.5))/(log10(wr+((wr^2)-1)^0.5));
N_order = ceil(N_order); % rounds each element of X to the
% nearest integer greater than
% or equal to that element.
% Writing errors
if(A < 1)
error('Invalid value of As');
elseif(wp <= 0 || wp >=ws)
error('Invalid value of omega_p');
elseif(Rp <= 0)
error('Invalid value of Rp');
elseif((A^2) <= ((E^2)+1))
error('Invalid combination of Rp and As');
else
[zeros,poles,k] = cheb1ap(N_order,Rp); % returns the poles and gain of an
% order n Chebyshev Type I analog
% lowpass filter prototype with Rp dB of ripple in the passband
a = real(poly(poles)); % returns the real part of each element
aNn = a(N_order+1);
poles = poles*wc;
a = real(poly(poles));
aNu = a(N_order+1);
k = k*aNu/aNn;
B = real(poly(zeros));

10
b = k*B;
end
[residues,pole,direct_term] = residue(b,a); % finds the residues, poles, and
% direct term of a Partial Fraction
% Expansion of the ratio of two polynomials
[Z,P,K] = bilinear(residues,pole,0,1/T); % converts the s-domain transfer function
% in pole-zero form specified by z, p, k
% and sample rate fs to a discrete equivalent.
[B,A] = residuez(Z,P,K); % finds the residues, poles, and
% direct terms of a partial fraction expansion
% of the ratio of numerator and denominator polynomials
B = real(B); % returns the real part of each element
A = real(A);
sys = tf(B,A,T); % creates a continuous-time transfer function model
impulse(sys); % impulse calculates the unit impulse
% response of a dynamic system model
freqz(B,A); % Frequency response of digital filter

11

You might also like