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

Untitled document (4)

Uploaded by

moushmithondepu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Untitled document (4)

Uploaded by

moushmithondepu
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 21

Experiment No.

6: IIR Filter design

1. Write MATLAB codes for obtaining the


(i) parallel form realisation and
(ii) cascade form realisation for the following transfer functions:

a. 𝐻(𝑧) = 0.4(1−𝑧 −2 ) / 1+1.2𝑧−1+0.32𝑧−2

Code:

num = [0.4, 0, -0.4];


den = [1, 1.2, 0.3];
[r, p, k] = residuez(num, den);
disp('Parallel form expression:');
disp('H(z) = ');
j=1;
for i = 1:length(r)
if i>1&&p(i-1)==p(i)
j=j+1;
fprintf(' (%f / (1 + %f*z^-1)^%f)', r(i), -p(i),j);
else
j=1;
fprintf(' (%f / (1 + %f*z^-1))', r(i), -p(i));
end
if i < length(r)
fprintf(' +');
end
end
for i=1:length(k)
fprintf(' + %f*z^-%f',k(i),(i-1));
end
nr=roots(num);
dr=roots(den);
fprintf('\nCascaded form expression:');
fprintf('\n');
disp('H(z) = ');
for i=1:length(nr)
fprintf('(1+%fz^-1)',nr(i))
end
fprintf('/(')
for i=1:length(dr)
fprintf('(1+%fz^-1)',dr(i))
end
fprintf(')\n')
Output:

b. 𝐻(𝑧) = 𝑧 2−0.16 / 𝑧 2+1.1𝑧1+0.18

Code:

num = [1, 0, -0.16];


den = [1, 1.1, 0.18];
[r, p, k] = residuez(num, den);
disp('Parallel form expression:');
disp('H(z) = ');
j = 1;
for i = 1:length(r)
if i > 1 && p(i-1) == p(i)
j = j + 1;
fprintf(' (%f / (1 + %f*z^-1)^%f)', r(i), -p(i), j);
else
j = 1;
fprintf(' (%f / (1 + %f*z^-1))', r(i), -p(i));
end
if i < length(r)
fprintf(' +');
end
end
for i = 1:length(k)
fprintf(' + %f*z^-%f', k(i), (i-1));
end
nr = roots(num);
dr = roots(den);
fprintf('\nCascaded form expression:');
fprintf('\n');
disp('H(z) = ');
for i = 1:length(nr)
fprintf('(1+%fz^-1)', nr(i));
end
fprintf('/(');
for i = 1:length(dr)
fprintf('(1+%fz^-1)', dr(i));
end
fprintf(')\n');

Output:

DISCUSSION :

Parallel Form Realisation:


The parallel form realisation is obtained by adding the transfer functions of the
given systems in parallel. This means that the output of the system is the sum of
the outputs of each individual transfer function

Cascade Form Realisation:


The cascade form realisation is obtained by multiplying the transfer functions of
the given systems in series. This means that the output of one system serves as
the input to the next system.

Both realisations represent the same overall system but in different structural
arrangements. The choice between parallel and cascade form realisation
depends on the specific application requirements, such as ease of analysis,
implementation, and stability considerations.
2. Given each of the following digital transfer functions

(i) 𝐻(𝑧) = 0.35(1+𝑧 −1 ) / 1−0.3𝑧−1


(ii) 𝐻(𝑧) = 0.1(1−𝑧 −1) / 1+0.8𝑧−1
(iii) 𝐻(𝑧) = 0.7(1−𝑧 −2) / 1−1.26𝑧−1+0.4𝑧−2
(iv) 𝐻(𝑧) = 0.8(1−1.6𝑧 −1+𝑧 −2) / 1−1.28𝑧−1+0.6𝑧−2
(v) 𝐻(𝑧) = 0.5+0.7𝑧 −1+𝑧 −2 / 1+0.7𝑧−1+0.5𝑧−2

a. Plot the magnitude response and phase response for each transfer function.
b. Identify the corresponding filter type, such as lowpass, highpass, bandpass,
bandstop or allpass.

Code:

T1_num = [0.35, 0.35];


T1_den = [1, -0.3];
T2_num = [0.1, -0.1];
T2_den = [1, 0.8];
T3_num = [0.7, 0, -0.7];
T3_den = [1, -1.26, 0.4];
T4_num = [0.8, -1.28, 0.8];
T4_den = [1, -1.28, 0.6];
T5_num = [0.5, 0.7, 1];
T5_den = [1, 0.7, 0.5];
w = linspace(0, pi, 1000);
T1_freq = freqz(T1_num, T1_den, w);
T2_freq = freqz(T2_num, T2_den, w);
T3_freq = freqz(T3_num, T3_den, w);
T4_freq = freqz(T4_num, T4_den, w);
T5_freq = freqz(T5_num, T5_den, w);
T1_mag = abs(T1_freq);
T1_phase = angle(T1_freq);
T2_mag = abs(T2_freq);
T2_phase = angle(T2_freq);
T3_mag = abs(T3_freq);
T3_phase = angle(T3_freq);
T4_mag = abs(T4_freq);
T4_phase = angle(T4_freq);
T5_mag = abs(T5_freq);
T5_phase = angle(T5_freq);
figure;
subplot(5, 2, 1);
plot(w/pi, T1_mag);
title('Magnitude Response (T1)');
xlabel('Normalized Frequency (\times\pi rad/sample)');
ylabel('Magnitude');
grid on;
subplot(5, 2, 3);
plot(w/pi, T2_mag);
title('Magnitude Response (T2)');
xlabel('Normalized Frequency (\times\pi rad/sample)');
ylabel('Magnitude');
grid on;
subplot(5, 2, 5);
plot(w/pi, T3_mag);
title('Magnitude Response (T3)');
xlabel('Normalized Frequency (\times\pi rad/sample)');
ylabel('Magnitude');
grid on;
subplot(5, 2, 7);
plot(w/pi, T4_mag);
title('Magnitude Response (T4)');
xlabel('Normalized Frequency (\times\pi rad/sample)');
ylabel('Magnitude');
grid on;
subplot(5, 2, 9);
plot(w/pi, T5_mag);
title('Magnitude Response (T5)');
xlabel('Normalized Frequency (\times\pi rad/sample)');
ylabel('Magnitude');
grid on;
subplot(5, 2, 2);
plot(w/pi, T1_phase);
title('Phase Response (T1)');
xlabel('Normalized Frequency (\times\pi rad/sample)');
ylabel('Phase (radians)');
grid on;
subplot(5, 2, 4);
plot(w/pi, T2_phase);
title('Phase Response (T2)');
xlabel('Normalized Frequency (\times\pi rad/sample)');
ylabel('Phase (radians)');
grid on;
subplot(5, 2, 6);
plot(w/pi, T3_phase);
title('Phase Response (T3)');
xlabel('Normalized Frequency (\times\pi rad/sample)');
ylabel('Phase (radians)');
grid on;
subplot(5, 2, 8);
plot(w/pi, T4_phase);
title('Phase Response (T4)');
xlabel('Normalized Frequency (\times\pi rad/sample)');
ylabel('Phase (radians)');
grid on;
subplot(5, 2, 10);
plot(w/pi, T5_phase);
title('Phase Response (T5)');
xlabel('Normalized Frequency (\times\pi rad/sample)');
ylabel('Phase (radians)');
grid on;

Output
DISCUSSION :

(i) The response of the filter is Low Pass Filter.


(ii) The response of the filter is High Pass Filter.
(iii) The response of the filter is Band Pass Filter.
(iv) The response of the filter is Band Reject Filter.
(v) The response of the filter is All Pass Filter.
3. Given a lowpass prototype 𝐻𝑃 (𝑠) = 1 / 𝑠+1 , determine each of the following
analog filters and plot their magnitude responses from 0 to 200 radians per
second.

(i) The lowpass filter with a cutoff frequency of 40 radians per second.

Code:

clc;
clear;
close all;
HP_num = 1;
HP_den = [1, 1];
wc = 40;
LP_num = 1;
LP_den = [1/wc, 1];
w = logspace(0, log10(200), 1000);
LP_mag = abs(freqs(LP_num, LP_den, w));
LP_mag_dB = 20*log10(LP_mag);
figure;
semilogx(w, LP_mag_dB);
grid on;
xlabel('Frequency (rad/s)');
ylabel('Magnitude (dB)');
title('Magnitude Response of Lowpass Filter with Wc = 40 rad/s');

Output:
(ii) The highpass filter with a cutoff frequency of 40 radians per second.

Code:

clc;
clear;
close all;
HP_num = [1,0];
HP_den = [1, 1];
wc = 40;
HP_num = [1/wc, 0];
HP_den = [1/wc, 1];
w = logspace(0, log10(200), 1000);
HP_mag = abs(freqs(HP_num, HP_den, w));
HP_mag_dB = 20*log10(HP_mag);
figure;
semilogx(w, HP_mag_dB);
grid on;
xlabel('Frequency (rad/s)');
ylabel('Magnitude (dB)');
title('Magnitude Response of Highpass Filter with Wc = 40 rad/s');

Output:
(iii) The bandpass filter with a centre frequency of 100 radians per second and
bandwidth of 20 radians per second.

Code:

clc;
clear;
close all;
wc = 100;
bw = 20;
%Calc according to s = (s^2+wc^2)/(bw*s)
BP_num = [20,0];
BP_den = [1, 20, 10000];
% BP_num = [1/wc, 0];
% BP_den = [1/wc, 1];
w = logspace(0, log10(200), 1000);
BP_mag = abs(freqs(BP_num, BP_den, w));
BP_mag_dB = 20*log10(BP_mag);
figure;
semilogx(w, BP_mag_dB);
grid on;
xlabel('Frequency (rad/s)');
ylabel('Magnitude (dB)');
title('Magnitude Response of Bandpass Filter with Wc = 100 rad/s');

Output:
(iv) The band reject filter with a centre frequency of 100 radians per second and
bandwidth of 20 radians per second.

Code:

clc;
clear;
close all;
wc = 100;
bw = 20;
%Calc according to s = (bw*s)/(s^2+wc^2)
BR_num = [1,0, 10000];
BR_den = [1, 20, 10000];
% BR_num = [1/wc, 0];
% BR_den = [1/wc, 1];
w = logspace(0, log10(200), 1000);
BR_mag = abs(freqs(BR_num, BR_den, w));
BR_mag_dB = 20*log10(BR_mag);
figure;
semilogx(w, BR_mag_dB);
grid on;
xlabel('Frequency (rad/s)');
ylabel('Magnitude (dB)');
title('Magnitude Response of BandReject Filter with Wc = 100 rad/s');

Output:
DISCUSSION :

(i) The prototype function was modified, for the low pass filter, from s to
s/wc,where wc is the cutoff
frequency.Substituting s = jw to magnitude and phase response.

(ii) The prototype function was modified, for the high pass filter, from s to
wc/s,where wc is the cutoff
frequency.Substituting s = jw to magnitude and phase response.

(iii) The prototype function was modified, for the band pass filter, from s to
2 2
𝑠 + ω𝑐
𝑠. (𝐵𝑊)
where wc is the cutoff
frequency and BW is bandwidth.Substituting s = jw to magnitude and phase
response.

(iv) The prototype function was modified, for the band reject filter, from s to
𝑠. (𝐵𝑊)
2 2 where wc is the cutoff
𝑠 + ω𝑐

frequency and BW is bandwidth.Substituting s = jw to magnitude and phase


response.
4 ) Given a lowpass prototype 𝐻𝑃 (𝑠) = 1 / 𝑠+1 with a cutoff frequency of 1
rad/sec, use BLT to design the corresponding digital IIR filters given below. Use
MATLAB to plot the magnitude response and phase response of the designed
filters.

(i) Lowpass filter with a cutoff frequency of 50 Hz, assuming a sampling rate of
300 Hz.

Code:

clc
clear
close all
wc = 2*pi*50;
fs = 300;
pnum = 1;
pden = [1, 1];
[numd,dend] = bilinear(pnum, pden, fs);
disp([numd, dend]);
% LP_num = [50 , 50];
% LP_den = [650 , -550];
w = linspace(0,pi,pi*300);
LP_mag = abs(freqz(numd, dend, w));
LP_mag_dB = 20*log10(LP_mag);
figure;
semilogx(w*300 , LP_mag_dB);
grid on;
xlabel('Frequency (radians/second)');
ylabel('Magnitude (dB)');
title('Magnitude Response of Lowpass Filter with Cutoff Frequency 50 rad/s');

Output:

(ii) High Pass filter with a cutoff frequency of 50 Hz, assuming a sampling rate
of 300 Hz.
Code:

clc
clear
close all
wc = 50;
fs = 300;
pnum = [1/wc,0];
pden = [1/wc, 1];
[numd,dend] = bilinear(pnum, pden, fs);
disp([numd, dend]);
w = linspace(0,pi,pi*300);
HP_mag = abs(freqz(numd, dend, w));
HP_mag_dB = 20*log10(HP_mag);
figure;
semilogx(w*300 , HP_mag_dB);
grid on;
xlabel('Frequency (radians/second)');
ylabel('Magnitude (dB)');
title('Magnitude Response of HighPass Filter');

Output:

(iii) Bandpass filter with a lower cutoff frequency of 60 Hz, an upper cutoff
frequency of 80 Hz, and a sampling rate of 350 Hz.
Code:

clc;
clear;
close all;
wc = 70;
bw = 20;
%Calc according to s = (s^2+wc^2)/(bw*s)
BP_num = [20,0];
BP_den = [1, 20, 4900];
[numd, dend] = bilinear(BP_num, BP_den, 350);
w = logspace(0, log10(200), 1000);
BP_mag = abs(freqs(BP_num, BP_den, w));
BP_mag_dB = 20*log10(BP_mag);
figure;
semilogx(w, BP_mag_dB);
grid on;
xlabel('Frequency (rad/s)');
ylabel('Magnitude (dB)');
title('Magnitude Response of Bandpass Filter');

Output:

(iv) Bandstop filter with a lower cutoff frequency of 60 Hz, an upper cutoff
frequency of 80 Hz, and a sampling rate of 350 Hz.

Code:
clc;
clear;
close all;
wc = 70;
bw = 20;
%Calc according to s = (bw*s)/(s^2+wc^2)
BR_num = [1,0, 4900];
BR_den = [1, 20, 4900];
[numd, dend] = bilinear(BR_num, BR_den, 350);
w = logspace(0, log10(200), 1000);
BR_mag = abs(freqs(BR_num, BR_den, w));
BR_mag_dB = 20*log10(BR_mag);
figure;
semilogx(w, BR_mag_dB);
grid on;
xlabel('Frequency (rad/s)');
ylabel('Magnitude (dB)');
title('Magnitude Response of BandReject Filter');

Output:

DISCUSSION :
For all functions, we substituted s =
2
𝑇 ( 𝑧−1
𝑧+1 ) to get the corresponding digital
𝑗ω
filter. Then we substituted s = 𝑒 and plotted the magnitude and phase
response.

The bilinear transformation method provides a straightforward and accurate way


to convert analog filters into digital filters while preserving stability.

Then:

(i) The prototype function was modified, for the low pass filter, from s to s/wc

(ii) The prototype function was modified, for the high pass filter, from s to wc/s

(iii) The prototype function was modified, for the band pass filter, from s to
2 2
𝑠 + ω𝑐
𝑠. (𝐵𝑊)

(iv) The prototype function was modified, for the band reject filter, from s to
𝑠. (𝐵𝑊)
2 2
𝑠 + ω𝑐

Where wc is the cutoff frequency.

5. Use impulse-invariant method for designing the digital filters 𝐻(𝑧) from the
corresponding Laplace transfer functions 𝐻(𝑠) given below. Use sampling rate 𝑓𝑠
= 10 Hz. Also, plot the magnitude frequency response and the phase frequency
response with respect to 𝐻(𝑠) and 𝐻(𝑧) for the frequency range from 0 to 𝑓𝑠 2
Hz.

(i) 𝐻(𝑠) = 3 / 𝑠+3

Code:

clc,clearvars,close all
w = 0:0.001*pi:pi ;
fsamp = 10 ; %sampling rate
T = 1/fsamp ;
syms s;
syms z;
H(s) = 3/(s+3) ;
h_t = ilaplace(H(s)) ;
H(z) = ztrans(h_t) ;
subplot(2,1,1)
plot(w,20*(log10(abs(H(exp(1i*w)))))) ;
xlabel('w');
xlim([0 pi]) ;
ylabel('|H(w)|');
title('Magnitude response of IIR filter');
subplot(2,1,2)
plot(w,angle(H(exp(1i*w)))) ;
xlabel('w');
xlim([0 pi]) ;
ylabel('/H(w)');
title('Phase response of IIR filter');

Output:

(ii) 𝐻(𝑠) = 1 / 𝑠2+3𝑠+2


Code:

clc,clearvars,close all
w = 0:0.001*pi:pi ;
fsamp = 10 ; %sampling rate
T = 1/fsamp ;
syms s;
syms z;
H(s) = 1/(s.^2 + 3*s + 2) ;
h_t = ilaplace(H(s)) ;
H(z) = ztrans(h_t) ;
subplot(2,1,1)
plot(w,abs(H(exp(1i*w)))) ;
xlabel('w');
xlim([0 pi]) ;
ylabel('|H(w)|');
title('Magnitude response of IIR filter');
subplot(2,1,2)
plot(w,angle(H(exp(1i*w)))) ;
xlabel('w');
xlim([0 pi]) ;
ylabel('/H(w)');
title('Phase response of IIR filter');

Output:

(iii) 𝐻(𝑠) = 𝑠 / 𝑠2+4𝑠+5


Code:

clc,clearvars,close all
w = 0:0.001*pi:pi ;
fsamp = 10 ; %sampling rate
T = 1/fsamp ;
syms s;
syms z;
H(s) = s/(s.^2 + 4*s + 5) ;
h_t = ilaplace(H(s)) ;
H(z) = ztrans(h_t) ;
subplot(2,1,1)
plot(w,abs(H(exp(1i*w)))) ;
xlabel('w');
xlim([0 pi]) ;
ylabel('|H(w)|');
title('Magnitude response of IIR filter');
subplot(2,1,2)
plot(w,angle(H(exp(1i*w)))) ;
xlabel('w');
xlim([0 pi]) ;
ylabel('/H(w)');
title('Phase response of IIR filter');

Output:

Discussion:
The Impulse Invariant method is a technique used to convert continuous-time
systems to discrete-time systems while preserving their impulse response. Here
are the basic steps involved in the impulse invariant method:

1. Continuous-Time System: Start with a continuous-time system represented by


its transfer function H(s), where s is the Laplace transform variable.

2. Impulse Response: Compute the impulse response (h(t)) of the


continuous-time system. This can be done by taking the inverse Laplace
transform of the transfer function.

3. Sampling: Choose a sampling period (Ts), which determines the discrete-time


intervals at which the continuous-time system will be sampled.

4. Discrete-Time Impulse Response: Obtain the discrete-time impulse response


(hd[n]) by sampling the continuous-time impulse response h(t) at intervals of
(Ts). This is done by evaluating (h(t)) at discrete-time instances (t = nTs), where
n is an integer.

5. Frequency Response: The program then plots the magnitude and phase
responses of the continuous-time transfer function H(s) and the discrete-time
transfer function H[z]

Group D12

T.K.Sreevatsa Murthy (B210656EC)


Thondepu Moushmi (B210745EC)

You might also like