In: Electrical Engineering
3. For the following analog signal:
xa(t) = 3sin(40πt) + 3cos(50πt)
which is sampled at a rate of 100 samples/second.
a. Design an IIR digital filter that will pass the first
component 3sin(40πt) with attenuation of
less than 1 dB and suppress the second component 3cos(50πt) at
least 50 dB. The filter should be
monotonic in the passband and have ripple in the stopband.
b. Generate 500 samples of the sampled signal xa(t)
at the given sampling rate and use the
filter you designed to process the sampled signal using MATLAB’s
"filter" command.
c. Plot the original signal and the output signal in one window
using MATLAB’s subplot
command ( in either a 1 X 2 arrangement or a 2 X 1 arrangement.
Remember to title all plots and
label all axes.
Please include Matlab code. EVEN JUST PART A HELPS
Question (a)
Since the sampling frequency is
So the digital signal is
We need to pass the low frequency and stop . So we will take the pass band frequency as rad/sample and stop band frequency as rad/sample
Since we need monotonic pass band and ripples in passband we will use Chebyshev Type – II filter.
MATLAB Code
clc;
clear all;
close all;
fs = 100;
Wp = 0.45;
Ws = 0.48;
Rp = 1;
Rs = 50;
[N, Ws] = cheb2ord(Wp, Ws, Rp, Rs);
[b, a] = cheby2(N, Rs, Ws);
w = 0:pi/1000:pi;
H = freqz(b, a, w);
magH = abs(H);
magH_dB = 20*log10(magH);
pha_H = angle(H)*180/pi;
subplot(2,1,1);
plot(w/pi, magH_dB, 'linewidth', 2);
grid
xlabel('Normalized Frequency, \omega (\times \pi
rad/sample)');
ylabel('Magnitude in dB');
title('Magnitude Response of the Filter');
subplot(2,1,2);
plot(w/pi, pha_H, 'linewidth', 2);
grid
xlabel('Normalized Frequency, \omega (\times \pi
rad/sample)');
ylabel('Phase in degree');
title('Phase Response of the Filter');
The frequency response of the designed filter is shown below. After executing the above code, we will get
Question b and c
clc;
clear all;
close all;
fs = 100;
Wp = 0.45;
Ws = 0.48;
Rp = 1;
Rs = 50;
[N, Ws] = cheb2ord(Wp, Ws, Rp, Rs);
[b, a] = cheby2(N, Rs, Ws);
w = 0:pi/1000:pi;
H = freqz(b, a, w);
magH = abs(H);
magH_dB = 20*log10(magH);
pha_H = angle(H)*180/pi;
subplot(2,1,1);
plot(w/pi, magH_dB, 'linewidth', 2);
grid
xlabel('Normalized Frequency, \omega (\times \pi
rad/sample)');
ylabel('Magnitude in dB');
title('Magnitude Response of the Filter');
subplot(2,1,2);
plot(w/pi, pha_H, 'linewidth', 2);
grid
xlabel('Normalized Frequency, \omega (\times \pi
rad/sample)');
ylabel('Phase in degree');
title('Phase Response of the Filter');
%% Generate the discrete signal
n = 0:499;
x = 3*sin(0.4*pi*n) + 3*cos(0.5*pi*n);
y = filter(b,a,x);
%% Ploting the signals
figure
subplot(2,1,1)
stem(n,x,'linewidth', 2);
grid
xlabel('Time Index, n');
ylabel('Amplitude');
title('Input Sequence x[n]');
subplot(2,1,2)
stem(n,y,'linewidth', 2);
grid
xlabel('Time Index, n');
ylabel('Amplitude');
title('Output Sequence y[n]');
The final plot obtained
An add on if you would like
Suppose I am plotting the magnitude spectrum of the input and the output, then we can see that the high frequency component is removed.
The full code is given below
clc;
clear all;
close all;
fs = 100;
Wp = 0.45;
Ws = 0.48;
Rp = 1;
Rs = 50;
[N, Ws] = cheb2ord(Wp, Ws, Rp, Rs);
[b, a] = cheby2(N, Rs, Ws);
w = 0:pi/1000:pi;
H = freqz(b, a, w);
magH = abs(H);
magH_dB = 20*log10(magH);
pha_H = angle(H)*180/pi;
subplot(2,1,1);
plot(w/pi, magH_dB, 'linewidth', 2);
grid
xlabel('Normalized Frequency, \omega (\times \pi
rad/sample)');
ylabel('Magnitude in dB');
title('Magnitude Response of the Filter');
subplot(2,1,2);
plot(w/pi, pha_H, 'linewidth', 2);
grid
xlabel('Normalized Frequency, \omega (\times \pi
rad/sample)');
ylabel('Phase in degree');
title('Phase Response of the Filter');
%% Generate the discrete signal
n = 0:499;
x = 3*sin(0.4*pi*n) + 3*cos(0.5*pi*n);
y = filter(b,a,x);
%% Ploting the signals
figure
subplot(2,1,1)
stem(n,x,'linewidth', 2);
grid
xlabel('Time Index, n');
ylabel('Amplitude');
title('Input Sequence x[n]');
subplot(2,1,2)
stem(n,y,'linewidth', 2);
grid
xlabel('Time Index, n');
ylabel('Amplitude');
title('Output Sequence y[n]');
%% To find the DTFTs of the input and the output
X = x*exp(-j*n'*w);
Y = y*exp(-j*n'*w);
figure
subplot(2,1,1);
plot(w/pi, abs(X), 'linewidth', 2);
grid
xlabel('Normalized Frequency, \omega (\times \pi
rad/sample)');
ylabel('|X(e^{j\omega})|');
title('Magnitude Spectrum of the Input');
subplot(2,1,2);
plot(w/pi, abs(Y), 'linewidth', 2);
grid
xlabel('Normalized Frequency, \omega (\times \pi
rad/sample)');
ylabel('|Y(e^{j\omega})|');
title('Magnitude Spectrum of the Output');
When you run this code, the last figure will be as follows
Here we can see that the frequency .is not present and is eliminated in the output
We can see that only rad/sample frequency is present.