In: Electrical Engineering
2. Design a digital lowpass filter to meet the following
specifications:
passband edge = 0:45π
stopband edge = 0:5π
Rp = 0.5 dB, As = 60 dB
a. Design a Buttterworth filter, you may use the butteworth and butter commands to implement.
b. Design Chebyshev Type 1 filter ( use the equivalent commands to above )
c. Design an Elliptic filter ( use the equivalent commands to part a ).
d. List the order of each filter and find the actual Rp and As
for each filter. To find the ripple
and attenuation values you should use freqz to output the frequency
response h and frequency w
values to a vector at enough points , say 1000, then use the min or
max commands to find the
min or max in the passband or stopband range in the frequency
response. You may need to use
commands to convert to dB.
e. Plot the magnitude response (in dB) for all three filters on
one plot and plot the phase
response for all three filters on another plot ( title the graph,
label axes, and use a legend to
identity the filter )
Please include Matlab code. EVEN JUST PART A HELPS
Part a
MATLAB Code
clc;
clear all;
close all;
Wp = 0.45;
Ws = 0.5;
Rp = 0.5;
Rs = 60;
[N, Wn] = buttord(Wp, Ws, Rp, Rs);
[b, a] = butter(N, Wn);
fprintf('The order of the Butterworth filter to meet the given specifications is %d \n', N);
w = 0:pi/1000:pi;
H = freqz(b, a, w);
H_dB = 20*log10(abs(H));
H_phase = angle(H)*180/pi;
subplot(2,1,1)
plot(w/pi, H_dB, 'linewidth',2);
grid
xlabel('Normalized Frequency (\times \pi rad/sample)');
ylabel('Magnitude in dB');
title('Magnitude Response of the Butterworth Filter');
subplot(2,1,2)
plot(w/pi, H_phase, 'linewidth',2);
grid
xlabel('Normalized Frequency (\times \pi rad/sample)');
ylabel('Phase in degrees');
title('Phase Response of the Butterworth Filter');
After Execution, we get
In the command window, the order required is displayed
The order of the Butterworth filter to meet the
given specifications is 51
>>
The frequency response plot obtained for the Butterworth Filter is as follows
Part b
MATLAB Code
clc;
clear all;
close all;
Wp = 0.45;
Ws = 0.5;
Rp = 0.5;
Rs = 60;
[N, Wn] = cheb1ord(Wp, Ws, Rp, Rs);
[b, a] = cheby1(N, Rp, Wp);
fprintf('The order of the Chebyshev Type I filter to meet the given specifications is %d \n', N);
w = 0:pi/1000:pi;
H = freqz(b, a, w);
H_dB = 20*log10(abs(H));
H_phase = angle(H)*180/pi;
subplot(2,1,1)
plot(w/pi, H_dB, 'linewidth',2);
grid
xlabel('Normalized Frequency (\times \pi rad/sample)');
ylabel('Magnitude in dB');
title('Magnitude Response of the Chebyshev Type I Filter');
subplot(2,1,2)
plot(w/pi, H_phase, 'linewidth',2);
grid
xlabel('Normalized Frequency (\times \pi rad/sample)');
ylabel('Phase in degrees');
title('Phase Response of the Chebyshev Type I Filter');
After Execution, we get
In the command window, the order required is displayed
The order of the Chebyshev Type I filter to meet the
given specifications is 16
>>
The frequency response plot obtained for the Chebyshev Type I Filter is as follows
Part c
MATLAB Code
clc;
clear all;
close all;
Wp = 0.45;
Ws = 0.5;
Rp = 0.5;
Rs = 60;
[N, Wn] = ellipord(Wp, Ws, Rp, Rs);
[b, a] = ellip(N, Rp, Rs, Wp);
fprintf('The order of the Elliptic filter to meet the given specifications is %d \n', N);
w = 0:pi/1000:pi;
H = freqz(b, a, w);
H_dB = 20*log10(abs(H));
H_phase = angle(H)*180/pi;
subplot(2,1,1)
plot(w/pi, H_dB, 'linewidth',2);
grid
xlabel('Normalized Frequency (\times \pi rad/sample)');
ylabel('Magnitude in dB');
title('Magnitude Response of the Elliptic Filter');
subplot(2,1,2)
plot(w/pi, H_phase, 'linewidth',2);
grid
xlabel('Normalized Frequency (\times \pi rad/sample)');
ylabel('Phase in degrees');
title('Phase Response of the Elliptic Filter');
After Execution, we get
In the command window, the order required is displayed
The order of the Elliptic filter to meet the given
specifications is 8
>>
The frequency response plot obtained for the Elliptic Filter is as follows
Part d
MATLAB Code
clc;
clear all;
close all;
Wp = 0.45;
Ws = 0.5;
Rp = 0.5;
Rs = 60;
w = 0:pi/1000:pi;
[Nb, Wn] = buttord(Wp, Ws, Rp, Rs);
[bb, ab] = butter(Nb, Wn);
Hb = freqz(bb, ab, w);
Nc = cheb1ord(Wp, Ws, Rp, Rs);
[bc, ac] = cheby1(Nc, Rp, Wp);
Hc = freqz(bc, ac, w);
Ne = ellipord(Wp, Ws, Rp, Rs);
[be, ae] = ellip(Ne, Rp, Rs, Wp);
He = freqz(be, ae, w);
wp_range = 0:pi/1000:0.45*pi;
ws_range = 0.5*pi:pi/1000:pi;
L1 = length(wp_range);
L2 = length(ws_range);
Hb_pb = Hb(1:L1);
Hb_pb_min = min(Hb_pb);
Rpb = 20*log10(abs(Hb_pb_min));
Hb_sb = Hb(L2:end);
Hb_sb_max = max(Hb_sb);
Rsb = 20*log10(abs(Hb_sb_max));
Hc_pb = Hc(1:L1);
Hc_pb_min = min(Hc_pb);
Rpc = 20*log10(abs(Hc_pb_min));
Hc_sb = Hc(L2:end);
Hc_sb_max = max(Hc_sb);
Rsc = 20*log10(abs(Hc_sb_max));
He_pb = He(1:L1);
He_pb_min = min(He_pb);
Rpe = 20*log10(abs(He_pb_min));
He_sb = He(L2:end);
He_sb_max = max(He_sb);
Rse = 20*log10(abs(He_sb_max));
fprintf('The order of the Butterworth filter to meet the given
specifications is %d \n', Nb);
fprintf('The order of the Chebyshev Type I filter to meet the given
specifications is %d \n', Nc);
fprintf('The order of the Elliptic filter to meet the given
specifications is %d \n \n \n', Ne);
fprintf('The pass band ripple of the Butterworth filter designed is
%f dB \n', Rpb);
fprintf('The stop band attenuation of the Butterworth filter
designed is %f dB \n', Rsb);
fprintf('The pass band ripple of the Chebyshev Type I filter
designed is %f dB \n', Rpc);
fprintf('The stop band attenuation of the Chebyshev Type I filter
designed is %f dB \n', Rsc);
fprintf('The pass band ripple of the Elliptic filter designed is %f
dB \n', Rpe);
fprintf('The stop band attenuation of the Elliptic filter designed
is %f dB \n', Rse);
After executing, we get
The order of the Butterworth filter to meet the given
specifications is 51
The order of the Chebyshev Type I filter to meet the given
specifications is 16
The order of the Elliptic filter to meet the given specifications
is 8
The pass band ripple of the Butterworth filter designed is
-0.425802 dB
The stop band attenuation of the Butterworth filter designed is
-60.000000 dB
The pass band ripple of the Chebyshev Type I filter designed is
-0.500000 dB
The stop band attenuation of the Chebyshev Type I filter designed
is -64.966806 dB
The pass band ripple of the Elliptic filter designed is -0.500000
dB
The stop band attenuation of the Elliptic filter designed is
-60.000000 dB
>>
Part (e)
clc;
clear all;
close all;
Wp = 0.45;
Ws = 0.5;
Rp = 0.5;
Rs = 60;
w = 0:pi/1000:pi;
[Nb, Wn] = buttord(Wp, Ws, Rp, Rs);
[bb, ab] = butter(Nb, Wn);
Hb = freqz(bb, ab, w);
Hb_dB = 20*log10(abs(Hb));
Hb_phase = angle(Hb)*180/pi;
Nc = cheb1ord(Wp, Ws, Rp, Rs);
[bc, ac] = cheby1(Nc, Rp, Wp);
Hc = freqz(bc, ac, w);
Hc_dB = 20*log10(abs(Hc));
Hc_phase = angle(Hc)*180/pi;
Ne = ellipord(Wp, Ws, Rp, Rs);
[be, ae] = ellip(Ne, Rp, Rs, Wp);
He = freqz(be, ae, w);
He_dB = 20*log10(abs(He));
He_phase = angle(He)*180/pi;
plot(w/pi, Hb_dB, w/pi, Hc_dB, w/pi, He_dB, 'linewidth',2);
grid
xlabel('Normalized Frequency (\times \pi rad/sample)');
ylabel('Magnitude in dB');
title('Magnitude Response of the Filters Designed');
legend('Magnitude Response of Butterworth Filter', 'Magnitude
Response of Chebyshve Type - I Filter', 'Magnitude Response of
Elliptic Filter', 'Location', 'SouthWest');
figure
plot(w/pi, Hb_phase, w/pi, Hc_phase, w/pi, He_phase,
'linewidth',2);
grid
xlabel('Normalized Frequency (\times \pi rad/sample)');
ylabel('Phase in degrees');
title('Phase Response of the Filters Designed');
legend('Phase Response of Butterworth Filter', 'Phase Response of
Chebyshve Type - I Filter', 'Phase Response of Elliptic Filter',
'Location', 'SouthWest');
The plots obtained after execution