Lab 1
Lab 1
LAB 1
QUESTION 1
Matlab code
% Filter specifications
Wc = 40000; % Passband corner frequency in rad/s
Ws = 56000; % Stopband corner frequency in rad/s
Amax = 0.28029; % Maximum passband ripple in dB
Amin = 40; % Minimum stopband attenuation in dB
figure;
plot(omega, Tg);
grid on;
xlabel('Frequency (rad/s)');
ylabel('Group Delay');
title('Chebyshev Type I Filter Group Delay');
set(gca, 'FontName', fn, 'FontSize', fs);
xticks([0:10000:100000]);
output:
Verification:
QUESTION 2 – 6 marks
Code:
% Filter specifications
Amax = 0.01; % Maximum passband ripple in dB
Amin = 40; % Minimum stopband attenuation in dB
Wp = 2; % Passband corner frequency in rad/s
Ws = 3; % Stopband corner frequency in rad/s
mag_butter = 20*log10(abs(mag_butter));
mag_cheby1 = 20*log10(abs(mag_cheby1));
mag_cheby2 = 20*log10(abs(mag_cheby2));
mag_ellip = 20*log10(abs(mag_ellip));
phase_butter = rad2deg(phase_butter);
phase_cheby1 = rad2deg(phase_cheby1);
phase_cheby2 = rad2deg(phase_cheby2);
phase_ellip = rad2deg(phase_ellip);
% Plot magnitude responses on a logarithmic scale
lw = 2;
fs = 16;
fn = 'times';
figure;
semilogx(omega, mag_butter, 'b', 'LineWidth', lw);
hold on;
semilogx(omega, mag_cheby1, 'r', 'LineWidth', lw);
semilogx(omega, mag_cheby2, 'g', 'LineWidth', lw);
semilogx(omega, mag_ellip, 'm', 'LineWidth', lw);
grid on;
xlabel('Frequency (rad/s)');
ylabel('Magnitude (dB)');
title('Comparison of LP Filters: Butterworth, Chebyshev I, Chebyshev II, and Elliptic');
legend('Butterworth', 'Chebyshev I', 'Chebyshev II', 'Elliptic', 'Location', 'southwest');
set(gca, 'FontName', fn, 'FontSize', fs);
Output:
QUESTION 3 – 5 marks
Code:
% Given specifications
Amax = 0.28; % Maximum passband ripple (dB)
Amin = 60; % Minimum stopband attenuation (dB)
Fpass1 = 12; % First passband frequency (Hz)
Fstop1 = 25; % First stopband frequency (Hz)
Fstop2 = 32; % Second stopband frequency (Hz)
Fpass2 = 60; % Second passband frequency (Hz)
% Estimate the filter order and cutoff frequencies using the buttord function
[n, Wn] = buttord([Wpass1, Wpass2], [Wstop1, Wstop2], Amax, Amin, 's');
output: