Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the input signal x(t) = sin(100t) + sin (2000t) + sin(6000t) We need to

ID: 2084364 • Letter: C

Question

Consider the input signal x(t) = sin(100t) + sin (2000t) + sin(6000t) We need to pass the term sin(2000t) and to attenuate the other terms. a) Design a digital fourth and eighth-order IIR Butterworth filters. Plot the input signal along with the magnitude response of the filter and its output signal for each filter. b) Design a digital fourth and eighth-order IIR Chebyshev type I filters. Plot the input signal along with the magnitude response of the filter and its output signal for each filter. (consider R_p = 1 dB) c) Design a digital fourth and eighth-order IIR Elliptic filters. Plot the input signal along with the magnitude response of the filter and its output signal for each filter. (consider R_p = 1 dB, R_s = 60 dB) d) For parts a), b), and c) plot the discrete Fourier transform of the input signal and the output signal for eighth order filters, you can use FFT command.

Explanation / Answer

Copy the following code to a new script file in MATLAB.

clear all; close all; clc;

Fs = 3000;
t = 0:1/Fs:1;
x = sin(100*t)+sin(2000*t)+ sin(6000*t);

% The frequency of the signal to be attenuated is 2000/(2*pi) = 318.3 Hz
% Assume the stopband edges of the filter to be 300 and 337 Hz.
Wn = 2*[300 337]/Fs;

% Part (a)
% 4th Order Filter
% [b,a] = butter(n,Wn,ftype). While designing bandstop fiter, the resulting
% design is of order 2n. This applies to cheby1 and ellip functions too.
% Required order = 4, Therefore, n=2;
[b,a] = butter(2,Wn,'stop');
[h,w] = freqz(b,a);
y1a = filter(b,a,x);
figure; subplot(3,1,1); plot(t,x);
title('Input signal');
xlabel('time (s)'); ylabel('Amplitude');

subplot(3,1,2); plot(w/pi,20*log10(abs(h))); grid on;
title('Magnitude response (N = 4, Butterworth Filter)')
xlabel('Normalized Frequency ( imespi rad/sample)');
ylabel('Magnitude (dB)');

subplot(3,1,3); plot(t,y1a);
title('Output signal');
xlabel('time (s)'); ylabel('Amplitude');

% 8th Order Filter
[b,a] = butter(4,Wn,'stop');
[h,w] = freqz(b,a);
y2a = filter(b,a,x);
figure; subplot(3,1,1); plot(t,x);
title('Input signal');
xlabel('time (s)'); ylabel('Amplitude');

subplot(3,1,2); plot(w/pi,20*log10(abs(h))); grid on;
title('Magnitude response (N = 8, Butterworth Filter)')
xlabel('Normalized Frequency ( imespi rad/sample)');
ylabel('Magnitude (dB)');

subplot(3,1,3); plot(t,y2a);
title('Output signal');
xlabel('time (s)'); ylabel('Amplitude');

% Part (b)
% 4th Order
[b,a] = cheby1(2,1,Wn,'stop');
[h,w] = freqz(b,a);
y1b = filter(b,a,x);
figure; subplot(3,1,1); plot(t,x);
title('Input signal');
xlabel('time (s)'); ylabel('Amplitude');

subplot(3,1,2); plot(w/pi,20*log10(abs(h))); grid on;
title('Magnitude response (N = 4, Chebyshev type 1 Filter)')
xlabel('Normalized Frequency ( imespi rad/sample)');
ylabel('Magnitude (dB)');

subplot(3,1,3); plot(t,y1b);
title('Output signal');
xlabel('time (s)'); ylabel('Amplitude');

% 8th Order
[b,a] = cheby1(4,1,Wn,'stop');
[h,w] = freqz(b,a);
y2b = filter(b,a,x);
figure; subplot(3,1,1); plot(t,x);
title('Input signal');
xlabel('time (s)'); ylabel('Amplitude');

subplot(3,1,2); plot(w/pi,20*log10(abs(h))); grid on;
title('Magnitude response (N = 8, Chebyshev type 1 Filter)')
xlabel('Normalized Frequency ( imespi rad/sample)');
ylabel('Magnitude (dB)');

subplot(3,1,3); plot(t,y2b);
title('Output signal');
xlabel('time (s)'); ylabel('Amplitude');

% Part (c)
% 4th Order
[b,a] = ellip(2,1,60,Wn,'stop');
[h,w] = freqz(b,a);
y1c = filter(b,a,x);
figure; subplot(3,1,1); plot(t,x);
title('Input signal');
xlabel('time (s)'); ylabel('Amplitude');

subplot(3,1,2); plot(w/pi,20*log10(abs(h))); grid on;
title('Magnitude response (N = 4, Elliptical Filter)')
xlabel('Normalized Frequency ( imespi rad/sample)');
ylabel('Magnitude (dB)');

subplot(3,1,3); plot(t,y1c);
title('Output signal');
xlabel('time (s)'); ylabel('Amplitude');

% 8th Order
[b,a] = ellip(4,1,60,Wn,'stop');
[h,w] = freqz(b,a);
y2c = filter(b,a,x);
figure; subplot(3,1,1); plot(t,x);
title('Input signal');
xlabel('time (s)'); ylabel('Amplitude');

subplot(3,1,2); plot(w/pi,20*log10(abs(h))); grid on;
title('Magnitude response (N = 8, Elliptical Filter)')
xlabel('Normalized Frequency ( imespi rad/sample)');
ylabel('Magnitude (dB)');

subplot(3,1,3); plot(t,y2c);
title('Output signal');
xlabel('time (s)'); ylabel('Amplitude');

% % Part (d)
Xf = fftshift(fft(x));
N = length(Xf);
f = (Fs/N)*(-(N-1)/2:(N-1)/2);

Yaf = fftshift(fft(y2a));

figure; subplot(2,1,1); plot(f,abs(Xf)/N);
title('FFT of Input signal');
xlabel('frequency (Hz)'); ylabel('Magnitude');

subplot(2,1,2); plot(f,abs(Yaf)/N);
title('FFT of Output signal (N=8, Butterworth Filter)');
xlabel('frequency (Hz)'); ylabel('Magnitude');

Ybf = fftshift(fft(y2b));

figure; subplot(2,1,1); plot(f,abs(Xf)/N);
title('FFT of Input signal');
xlabel('frequency (Hz)'); ylabel('Magnitude');

subplot(2,1,2); plot(f,abs(Ybf)/N);
title('FFT of Output signal (N=8, Chebyshev type 1 Filter)');
xlabel('frequency (Hz)'); ylabel('Magnitude');

Ycf = fftshift(fft(y2c));

figure; subplot(2,1,1); plot(f,abs(Xf)/N);
title('FFT of Input signal');
xlabel('frequency (Hz)'); ylabel('Magnitude');

subplot(2,1,2); plot(f,abs(Ycf)/N);
title('FFT of Output signal (N=8, Elliptical Filter)');
xlabel('frequency (Hz)'); ylabel('Magnitude');