0% found this document useful (0 votes)
28 views6 pages

Lab 1

The document describes the design and analysis of a Chebyshev Type I filter using Matlab code to specify filter parameters, design the filter, analyze the frequency response, and plot the magnitude response, group delay, and pole-zero locations. Filter specifications are provided for the passband and stopband corner frequencies, maximum passband ripple, and minimum stopband attenuation. Code is included to design the filter, calculate its poles and zeros, and plot the magnitude response, group delay, and pole-zero locations.

Uploaded by

IAMMARKS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views6 pages

Lab 1

The document describes the design and analysis of a Chebyshev Type I filter using Matlab code to specify filter parameters, design the filter, analyze the frequency response, and plot the magnitude response, group delay, and pole-zero locations. Filter specifications are provided for the passband and stopband corner frequencies, maximum passband ripple, and minimum stopband attenuation. Code is included to design the filter, calculate its poles and zeros, and plot the magnitude response, group delay, and pole-zero locations.

Uploaded by

IAMMARKS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

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

% Calculate the filter order


N = cheb1ord(Wc, Ws, Amax, Amin, 's');

% Design the Chebyshev Type I filter


[b, a] = cheby1(N, Amax, Wc, 's');

% Calculate poles and zeros of the filter


[Z, P, K] = tf2zp(b, a);

% Calculate Q-factor of the poles


Q = -abs(P)./(2*real(P));

% Frequency response analysis


omega = linspace(0, 1e5, 1000);
H = freqs(b, a, omega);

% Convert magnitude response to attenuation in dB


Att = 20*log10(abs(H));

% Calculate group delay of the filter


Tg = grpdelay(b, a, omega);

% Plot the magnitude response and group delay


lw = 2;
fs = 16;
fn = 'times';
figure;
plot(omega, Att);
grid on;
xlabel('Frequency (rad/s)');
ylabel('Attenuation (dB)');
title('Chebyshev Type I Filter Magnitude Response');
ylim([-Amin-10, Amax+5]);
set(gca, 'FontName', fn, 'FontSize', fs);
xticks([0:10000:100000]);

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]);

% Plot the pole-zero locations


figure;
zplane(Z, P);
title('Pole-Zero Plot');
set(gca, 'FontName', fn, 'FontSize', fs);

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

% Filter design and frequency response analysis


[n_butter, Wn_butter] = buttord(Wp, Ws, Amax, Amin, 's');
[n_cheby1, Wp_cheby1] = cheb1ord(Wp, Ws, Amax, Amin, 's');
[n_cheby2, Wp_cheby2] = cheb2ord(Wp, Ws, Amax, Amin, 's');
[n_ellip, Wp_ellip] = ellipord(Wp, Ws, Amax, Amin, 's');

[b_butter, a_butter] = butter(n_butter, Wn_butter, 's');


[b_cheby1, a_cheby1] = cheby1(n_cheby1, Amax, Wp_cheby1, 's');
[b_cheby2, a_cheby2] = cheby2(n_cheby2, Amin, Wp_cheby2, 's');
[b_ellip, a_ellip] = ellip(n_ellip, Amax, Amin, Wp_ellip, 's');

omega = logspace(-1, 2, 1000);


[mag_butter, phase_butter] = freqs(b_butter, a_butter, omega);
[mag_cheby1, phase_cheby1] = freqs(b_cheby1, a_cheby1, omega);
[mag_cheby2, phase_cheby2] = freqs(b_cheby2, a_cheby2, omega);
[mag_ellip, phase_ellip] = freqs(b_ellip, a_ellip, omega);

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);

% Plot pole-zero locations for each filter type

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)

% Convert dB to linear scale for Amax and Amin


Ap = 10^(Amax/20);
As = 10^(Amin/20);

% Calculate the frequency ratios


Wpass1 = 2 * pi * Fpass1;
Wstop1 = 2 * pi * Fstop1;
Wstop2 = 2 * pi * Fstop2;
Wpass2 = 2 * pi * Fpass2;

% Estimate the filter order and cutoff frequencies using the buttord function
[n, Wn] = buttord([Wpass1, Wpass2], [Wstop1, Wstop2], Amax, Amin, 's');

% Design the Cauer (elliptic) filter


[b, a] = ellip(n, Ap, As, Wn, 's');

% Frequency response plot in the s-domain


frequencies = logspace(log10(Fpass1), log10(Fpass2), 1000);
s = 1j * frequencies;
H_s = freqs(b, a, s);

% Convert complex response to magnitude (dB)


magnitude_response_db = 20 * log10(abs(H_s));

% Plot the magnitude response in the s-domain


figure;
semilogx(frequencies, magnitude_response_db);
grid on;
title('Cauer (Elliptic) Filter Magnitude Response');
xlabel('Frequency (Hz)');
ylabel('Magnitude (dB)');
xlim([Fpass1, Fpass2]);
ylim([-Amin - 10, Amax + 10]);

% Compute poles and zeros


[z, p, k] = tf2zp(b, a);

% Plot the poles and zeros in the s-plane


figure;
plot(real(p), imag(p), 'rx', 'MarkerSize', 10);
hold on;
plot(real(z), imag(z), 'bo', 'MarkerSize', 8);
grid on;
title('Poles and Zeros of the Cauer (Elliptic) Filter');
xlabel('Real Axis');
ylabel('Imaginary Axis');
legend('Poles', 'Zeros');
% Adjust the figure positions and titles
pos1 = [100, 100, 800, 400];
pos2 = [100, 100, 800, 400];

set(gcf, 'Position', pos1);


set(gca, 'Position', [0.1 0.2 0.85 0.7]);

set(gcf, 'Position', pos2);


set(gca, 'Position', [0.1 0.2 0.85 0.7]);

sgtitle('Cauer (Elliptic) Filter Design Verification', 'FontSize', 16);

output:

You might also like