Maulina Putri Lestari - M0220052 - Tugas 5
Maulina Putri Lestari - M0220052 - Tugas 5
Maulina Putri Lestari - M0220052 - Tugas 5
TUGAS
Disusun Oleh:
Maulina Putri Lestari (M0220052)
Problem 7.1
The absolute and relative (dB) specifications for a lowpass filter are related by (7.1) and (7.2).
In this problem we will develop a simple MATLAB function to convert one set of
specifications into another.
1. Write a MATLAB function to convert absolute specifications δ1 and δ2 into the relative
specifications Rp and As in dB. The format of the function should be
Hasil Running
2. Skrip matlab
function [d1,d2] = db2delta(Rp,As)
% Conversion from Relative dB specs to Absolute delta specs.
% [d1,d2] = db2delta(Rp,As)
% d1 = Passband tolerance
% d2 = Stopband tolerance
% Rp = Passband ripple
% As = Stopband attenuation
Rp = 0.25;
As = 50;
K = 10^(Rp/20);
delta1 = (K-1)/(K+1);
delta2 = (1+delta1)*(10^(-As/20));
disp(delta1);
disp(delta2);
end
Maulina Putri Lestari (M0220052)
Hasil Running:
Problem 7.12
Design a highpass filter using one of the fixed window functions. The specifications are
stopband edge: 0.4π, As = 50 dB
passband edge: 0.6π, Rp = 0.004 dB
Plot the zoomed magnitude response (in dB) of the designed filter in the passband to verify the
passband ripple Rp. Do not use the fir1 function.
Answer
Skrip matlab
clc; close all;
%% Specifications:
ws = 0.4*pi; % stopband edge
wp = 0.6*pi; % passband edge
Rp = 0.004; % passband ripple
As = 50; % stopband attenuation
%
% Select the min(delta1,delta2) since delta1=delta2 in windodow design
[delta1,delta2] = db2delta(Rp,As);
if (delta1 < delta2)
delta2 = delta1; disp('Delta1 is smaller than delta2')
Delta1 is smaller than delta2
[Rp,As] = delta2db(delta1,delta2)
Rp =
Maulina Putri Lestari (M0220052)
0.0040
As =
72.7577
end
%
tr_width = abs(wp-ws);
M = ceil(11*pi/tr_width); M = 2*floor(M/2)+1, % choose odd M
M =
55
n = 0:M-1; w_blk = (blackman(M))’;
wc = (ws+wp)/2;
hd = ideal_lp(pi,M)-ideal_lp(wc,M); h = hd .* w_blk;
[db,mag,pha,grd,w] = freqz_m(h,1); delta_w = pi/500;
Rpd = -min(db(ceil(wp/delta_w)+1:floor(pi/delta_w)+1)), % Actual passband
ripple
Rpd =
0.0039
Asd = floor(-max(db(1:(ws/delta_w)+1))), % Actual Attn
Asd =
71
%
%% Zoomed Filter Response Plot
Hf_1 = figure('Units','inches','position',[1,1,5,3],'color',[0,0,0],...
'paperunits','inches','paperposition',[0,0,5,3]);
set(Hf_1,'NumberTitle','off','Name','P7.12');
plot(w(301:501)/pi,db(301:501),'linewidth’,1); title('Zoomed Magnitude
Response in dB');
axis([0.6,1,-0.005,0.001]); xlabel('\omega/\pi'); ylabel('Decibels')
set(gca,'XTick',[0.6;1])
set(gca,'XTickLabel',['0.6’;’ 1 ’],'fontsize',8)
set(gca,'YTick',[-0.004;0]); set(gca,'YTickLabel',['-0.004’;'0']);grid
Problem 7.20
Repeat Problem P7.12 using the fir1 function.
Answer:
Matlab scipt:
clc; close all;
%% Specifications:
ws = 0.4*pi; % stopband edge
wp = 0.6*pi; % passband edge
Rp = 0.004; % passband ripple
As = 50; % stopband attenuation
%
% Select the min(delta1,delta2) since delta1=delta2 in windodow design
[delta1,delta2] = db2delta(Rp,As);
if (delta1 < delta2)
delta2 = delta1; disp('Delta1 is smaller than delta2')
Delta1 is smaller than delta2
[Rp,As] = delta2db(delta1,delta2)
Rp =
0.0040
As =
72.7577
end
%
tr_width = abs(wp-ws);
M = ceil(11*pi/tr_width); M = 2*floor(M/2)+1, % choose odd M
M =
55
n = 0:M-1; w_blk = (blackman(M))';
wc = (ws+wp)/2; hd = ideal_lp(pi,M)-ideal_lp(wc,M);
h = fir1(M-1,wc/pi,'high',w_blk);
[db,mag,pha,grd,w] = freqz_m(h,1); delta_w = pi/500;
Rpd = -min(db(ceil(wp/delta_w)+1:floor(pi/delta_w)+1)), % Actual passband
ripple
Rpd =
0.0039
Asd = floor(-max(db(1:(ws/delta_w)+1))), % Actual Attn
Asd =
71
%
%% Zoomed Filter Response Plot
Hf_1 = figure('Units','inches','position',[1,1,5,3],'color',[0,0,0],...
'paperunits','inches','paperposition',[0,0,5,3]);
set(Hf_1,'NumberTitle','off','Name','P7.12');
plot(w(301:501)/pi,db(301:501),'linewidth',1);
title('Zoomed Magnitude Response in dB');
axis([0.6,1,-0.005,0.001]); xlabel('\omega/\pi'); ylabel('Decibels')
set(gca,'XTick',[0.6;1])
set(gca,'XTickLabel',['0.6';' 1 '],'fontsize',8)
set(gca,'YTick',[-0.004;0]); set(gca,'YTickLabel',['-0.004';' 0 ']);grid
Maulina Putri Lestari (M0220052)