Untitled document (4)
Untitled document (4)
Code:
Code:
Output:
DISCUSSION :
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
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:
Output
DISCUSSION :
(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
𝑠 + ω𝑐
(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.
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
𝑠 + ω𝑐
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.
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:
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:
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:
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