Você está na página 1de 18

# DA NANG UNIVERSITY OF SCIENCE AND TECHNOLOGY

EE 442
W5-20190214
REPORT
Class: 15ECE-CE

Group: 1

Le Quang Dao

Ho Ba Trung

## Le Duc Minh Tuan

Tran Le Quoc
MATLAB implementation:
EXAMPLE 7.14 Consider the lowpass filter specifications from Example 7.8.
ωp = 0.2π, Rp = 0.25 dB
ωs = 0.3π, As = 50 dB
Design an FIR filter using the frequency sampling approach.
Let us choose M = 20 so that we have a frequency sample at ωp, that is, at k = 2:
2𝜋
ωp = 0.2π = x2
20
and the next sample at ωs, that is, at k = 3:
2𝜋
ωs = 0.3π = x3
20
Thus we have 3 samples in the passband [0 ≤ ω ≤ ωp] and 7 samples in the
stopband [ωs ≤ ω ≤ π]. From (7.36) we have
Hr (k) = [1, 1, 1, 0, . . . , 0, 1, 1]

15 zeros
20−1
Since M = 20, α = = 9.5 and since this is a Type-2 linear-phase filter,
2
from (7.37) we have

Now from (7.35) we assemble H (k) and from (7.39) determine the impulse response h (n).
Matlab script:
M = 20; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
Hrs = [1,1,1,zeros(1,15),1,1]; %Ideal Amp Res sampled
Hdr = [1,1,0,0]; wdl = [0,0.25,0.25,1]; %Ideal Amp Res for
plotting
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH); h = real(ifft(H,M));
[db,mag,pha,grd,w] = freqz_m(h,1); [Hr,ww,a,L] = Hr_Type2(h);
subplot(2,2,1);plot(wl(1:11)/pi,Hrs(1:11),'o',wdl,Hdr);
axis([0,1,-0.1,1.1]); title('Frequency Samples: M=20')
xlabel('frequency in pi units'); ylabel('Hr(k)')
set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1])
set(gca,'YTickMode','manual','YTick',[0,1]); grid

## subplot(2,2,2); stem(l,h); axis([-1,M,-0.1,0.3])

title('Impulse Response'); xlabel('n'); ylabel('h(n)');
subplot(2,2,3); plot(ww/pi,Hr,wl(1:11)/pi,Hrs(1:11),'o');
axis([0,1,-0.2,1.2]); title('Amplitude Response')
xlabel('frequency in pi units'); ylabel('Hr(w)')
set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1])
set(gca,'YTickMode','manual','YTick',[0,1]); grid

## subplot(2,2,4);plot(w/pi,db); axis([0,1,-60,10]); grid

title('Magnitude Response'); xlabel('frequency in pi units');
ylabel('Decibels');
set(gca,'XTickMode','Manual','XTick',[0;0.2;0.3;1]);
set(gca,'YTickMode','Manual','YTick',[-16;0]);
set(gca,'YTickLabelMode','manual','YTickLabels',['16';' 0'])

Result:
Analysis: We can observe that the minimum stopband attenuation is about 16 dB, which is clearly
unacceptable. If we increase M, then there will be samples in the transition band, for which we
do not precisely know the frequency response. Therefore the naive design method shouldn’t be
used in practice.
EXAMPLE 7.15: Using the optimum design method, design a better lowpass filter of Example
7.14.
Solution: Let us choose M = 40 so that we have one sample in the transition band
0.2π < ω < 0.3π. Since ω1 = 2 π/40, the transition
band samples are at k = 5
and at k = 40 − 5 = 35.
Let us denote the value of these samples by T1, 0 < T1 < 1; then the sampled
amplitude response is
Hr (k) = [1, 1, 1, 1, 1, T1, 0, . . . , 0, T1, 1, 1, 1, 1]
29 zeros
40−1
Since α = = 19.5, the samples of the phase response are
2

Now we can vary T1 to get the best minimum stopband attenuation. This will result in the
widening of the transition width.
We first see what happens when T1 = 0.5.
Matlab script:
% T1 = 0.5
M = 40; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
Hrs = [ones(1,5),0.5,zeros(1,29),0.5,ones(1,4)];
Hdr = [1,1,0,0,0,0]; wdl = [0,0.25, 0.25, 0.25,0.25,1];
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH);
h = real(ifft(H,M))
[db,mag,pha,grd,w] = freqz_m(h,1); [Hr,ww,a,L] = Hr_Type2(h);
subplot(2,2,1);plot(wl(1:21)/pi,Hrs(1:21),'o',wdl,Hdr);grid
axis([0,1,-0.1,1.1]); title('Frequency Samples: M=40, T1=0.5')
xlabel('frequency in pi units'); ylabel('Hr(k)')
set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1])
set(gca,'YTickMode','manual','YTick',[0,0.5,1]); grid on

## subplot(2,2,2); stem(l,h); axis([-1,M,-0.1,0.3])

title('Impulse Response'); xlabel('n'); ylabel('h(n)');
subplot(2,2,3); plot(ww/pi,Hr,wl(1:21)/pi,Hrs(1:21),'o');grid
axis([0,1,-0.2,1.2]); title('Amplitude Response')
xlabel('frequency in pi units'); ylabel('Hr(w)')
set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1])
set(gca,'YTickMode','manual','YTick',[0,0.5,1]); grid on

## subplot(2,2,4);plot(w/pi,db); axis([0,1,-100,10]); grid

title('Magnitude Response'); xlabel('frequency in pi units');
ylabel('Decibels');
set(gca,'XTickMode','Manual','XTick',[0;0.2;0.3;1]);
set(gca,'YTickMode','Manual','YTick',[-30;0]);
set(gca,'YTickLabelMode','manual','YTickLabels',['30';' 0'])
Result:

Analysis:
We observe that the minimum stopband attenuation is now 30 dB, which is better
than the naive design attenuation but is still not at the acceptable level of 50 dB.

• We now find the most optimum value of T1 with 3 decimal digits to achieve the highest
minimum stopband attenuation:
Matlab script:
Toptimum = 1;

T = Toptimum;
M = 40; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
Hrs = [ones(1,5),T,zeros(1,29),T,ones(1,4)];
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH);
h = real(ifft(H,M));
[db,mag,pha,grd,w] = freqz_m(h,1); [Hr,ww,a,L] = Hr_Type2(h);
delta_w = 2*pi/1000;ws = 0.3*pi;
As = -round(max(db(ws/delta_w+1:1:501)));
Asmax = As;

while T >= 0
Hrs = [ones(1,5),T,zeros(1,29),T,ones(1,4)];
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH);
h = real(ifft(H,M));
[db,mag,pha,grd,w] = freqz_m(h,1); [Hr,ww,a,L] = Hr_Type2(h);
As = -round(max(db(ws/delta_w+1:1:501)));
if As >= Asmax
Asmax = As;
Toptimum = T;
end
T = T - 0.001;
End

## Result: Asmax = 43; Toptimum = 0.387

• We now use T1 = 0.387
Matlab script:
% T1 = 0.387
M = 40; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
Hrs = [ones(1,5),0.387,zeros(1,29),0.387,ones(1,4)];
Hdr = [1,1,0,0,0,0]; wdl = [0,0.25, 0.25, 0.25,0.25,1];
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH);
h = real(ifft(H,M))
[db,mag,pha,grd,w] = freqz_m(h,1); [Hr,ww,a,L] = Hr_Type2(h);
subplot(2,2,1);plot(wl(1:21)/pi,Hrs(1:21),'o',wdl,Hdr);grid
axis([0,1,-0.1,1.1]); title('Frequency Samples: M=40, T1=0.39')
xlabel('frequency in pi units'); ylabel('Hr(k)')
set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1])
set(gca,'YTickMode','manual','YTick',[0,0.387,1]); grid on

## subplot(2,2,2); stem(l,h); axis([-1,M,-0.1,0.3])

title('Impulse Response'); xlabel('n'); ylabel('h(n)');
subplot(2,2,3); plot(ww/pi,Hr,wl(1:21)/pi,Hrs(1:21),'o');grid
axis([0,1,-0.2,1.2]); title('Amplitude Response')
xlabel('frequency in pi units'); ylabel('Hr(w)')
set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1])
set(gca,'YTickMode','manual','YTick',[0,0.387,1]); grid on

## subplot(2,2,4);plot(w/pi,db); axis([0,1,-100,10]); grid

title('Magnitude Response'); xlabel('frequency in pi units');
ylabel('Decibels');
set(gca,'XTickMode','Manual','XTick',[0;0.2;0.3;1]);
set(gca,'YTickMode','Manual','YTick',[-43;0]);
set(gca,'YTickLabelMode','manual','YTickLabels',['43';' 0'])

Result:

Analysis:
We observe that the minimum stopband attenuation is now 43 dB, which is better
than the T1 = 0.5 design attenuation but is still not at the acceptable level of 50
dB.

samples in the transition band so that we can get a better stopband attenuation.
Let us choose M = 60 so that there are two samples in the transition band. Let the values of these
transition band samples be T1 and T2. Then Hr (ω) is given by
H (ω) = [1, . . . , 1, T1, T2, 0, . . . , 0, T2, T1, 1, . . . , 1]

## 7 ones 43 zeros 6 ones

From tables in [22, Appendix B] T1 = 0.5925 and T2 = 0.1099.
Matlab script:
M = 60; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
Hrs =
[ones(1,7),0.5925,0.1099,zeros(1,43),0.1099,0.5925,ones(1,6)];
Hdr = [1,1,0,0]; wdl = [0,0.2,0.3,1];
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH); h = real(ifft(H,M));
[db,mag,pha,grd,w] = freqz_m(h,1); [Hr,ww,a,L] = Hr_Type2(h);
subplot(2,2,1);plot(wl(1:31)/pi,Hrs(1:31),'o',wdl,Hdr);grid
axis([0,1,-0.1,1.1]); title('Lowpass: M=60,T1=0.59, T2=0.109')
xlabel('frequency in pi units'); ylabel('Hr(k)')
set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1]);
set(gca,'YTickMode','manual','YTick',[0,0.109,0.59,1]); grid on

## subplot(2,2,2); stem(l,h); axis([-1,M,-0.1,0.3])

title('Impulse Response'); xlabel('n'); ylabel('h(n)');
subplot(2,2,3); plot(ww/pi,Hr,wl(1:31)/pi,Hrs(1:31),'o');grid
axis([0,1,-0.2,1.2]); title('Amplitude Response')
xlabel('frequency in pi units'); ylabel('Hr(w)')
set(gca,'XTickMode','manual','XTick',[0,0.2,0.3,1])
set(gca,'YTickMode','manual','YTick',[0,0.109,0.59,1]); grid on

## subplot(2,2,4);plot(w/pi,db); axis([0,1,-100,10]); grid

title('Magnitude Response'); xlabel('frequency in pi units');
ylabel('Decibels');
set(gca,'XTickMode','Manual','XTick',[0;0.2;0.3;1]);
set(gca,'YTickMode','Manual','YTick',[-63;0]);
set(gca,'YTickLabelMode','manual','YTickLabels',['63';' 0'])

Result:

Analysis:

• Comparing To Hamming and Blackman windows with (As_ham = 52, M_ham= 67, As_bla
= 73, M_bla = 111 we have the optimum design method is much better with small filter
length
• Comparing to Kaiser window method with As = 52 ; M = 61; the optimum design has hiher
As with lower M. Therefore, the optimum design is better and should be used for this
design.
EXAMPLE 7.17 Design the bandpass filter of Example 7.10 using the frequency sampling
technique. The design specifications are these:
lower stopband edge: ω1s = 0.2π, As = 60 dB
lower passband edge: ω1p = 0.35π, Rp = 1 dB
upper passband edge: ω2p = 0.65π Rp = 1 dB
upper stopband edge: ω2s = 0.8π As = 60 dB
Let us choose M = 40 so that we have two samples in the transition band.
Let the frequency samples in the lower transition band be T1 and T2. Then the samples of the
amplitude response are
Hr (ω) = [0, . . . , 0, T1, T2, 1, . . . , 1, T2, T1, 0, . . . , 0, T1, T2, 1, . . . , 1, T2, T1, 0, . . . , 0]

5 7 9 7 4
The optimum values of T1 and T2 for M = 40 and seven samples in the passband [23, Appendix
B] are:
T1 = 0.109021, T2 = 0.59417456
Matlab script:
M = 40; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
T1 = 0.109021; T2 = 0.59417456;
Hrs=[zeros(1,5),T1,T2,ones(1,7),T2,T1,zeros(1,9),T1,T2,ones(1,7)
,T2,T1,zeros(1,4)];
Hdr = [0,0,1,1,0,0]; wdl = [0,0.2,0.35,0.65,0.8,1];
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH); h = real(ifft(H,M));
[db,mag,pha,grd,w] = freqz_m(h,1); [Hr,ww,a,L] = Hr_Type2(h);

subplot(2,2,1);plot(wl(1:21)/pi,Hrs(1:21),'o',wdl,Hdr);grid
axis([0,1,-0.1,1.1]); title('Bandpass: M=40,T1=0.5941,
T2=0.109')
xlabel('frequency in pi units'); ylabel('Hr(k)')
set(gca,'XTickMode','manual','XTick',[0,0.2,0.35,0.65,0.8,1])
set(gca,'YTickMode','manual','YTick',[0,0.109,0.59,1]); grid on

## subplot(2,2,2); stem(l,h); axis([-1,M,-0.4,0.4])

title('Impulse Response'); xlabel('n'); ylabel('h(n)');
subplot(2,2,3); plot(ww/pi,Hr,wl(1:21)/pi,Hrs(1:21),'o');grid
axis([0,1,-0.2,1.2]); title('Amplitude Response')
xlabel('frequency in pi units'); ylabel('Hr(w)')
set(gca,'XTickMode','manual','XTick',[0,0.2,0.35,0.65,0.8,1])
set(gca,'YTickMode','manual','YTick',[0,0.109,0.59,1]); grid on

## subplot(2,2,4);plot(w/pi,db); axis([0,1,-100,10]); grid

title('Magnitude Response'); xlabel('frequency in pi units');
ylabel('Decibels');
set(gca,'XTickMode','Manual','XTick',[0,0.2,0.35,0.65,0.8,1]);
set(gca,'YTickMode','Manual','YTick',[-60;0]);
set(gca,'YTickLabelMode','manual','YTickLabels',['60';' 0'])

Result:

Analysis: We observe from the graph that Asupper = 60.01, Aslower=69.06. These value are both
acceptable for the design. Moreover, the filter length M = 40 – significantly low
comparing to Kaiser window: Asupper ≈ Aslower = 61; M = 51.
EXAMPLE 7.18 Design the following highpass filter:
Stopband edge: ωs = 0.6π As = 50 dB
Passband edge: ωp = 0.8π Rp = 1 dB
Recall that for a highpass filter M must be odd (or Type-1 filter). Hence we will choose M = 33
to get two samples in the transition band. With this choice of M it is not possible to have
frequency samples at ωs and ωp. The samples of the amplitude response are
Hr (k) = [0, . . . , 0, T1, T2, 1, . . . , 1, T2, T1, 0, . . . , 0]
11 8 10
while the phase response samples are:

## The optimum values of transition samples are T1 = 0.1095 and T2 = 0.598.

Matlab script:
M = 33; alpha = (M-1)/2; l = 0:M-1; wl = (2*pi/M)*l;
T1 = 0.1095; T2 = 0.598;
Hrs = [zeros(1,11),T1,T2,ones(1,8),T2,T1,zeros(1,10)];
Hdr = [0,0,1,1]; wdl = [0,0.6,0.8,1];
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
angH = [-alpha*(2*pi)/M*k1, alpha*(2*pi)/M*(M-k2)];
H = Hrs.*exp(j*angH); h = real(ifft(H,M));
[db,mag,pha,grd,w] = freqz_m(h,1); [Hr,ww,a,L] = Hr_Type1(h);
subplot(2,2,1);plot(wl(1:31)/pi,Hrs(1:31),'o',wdl,Hdr);grid
axis([0,1,-0.1,1.1]); title('Highpass: M=33,T1=0.1095,T2=0.598')
xlabel('frequency in pi units'); ylabel('Hr(k)')
set(gca,'XTickMode','manual','XTick',[0;0.6;0.8;1])
set(gca,'YTickMode','manual','YTick',[0,0.109,0.59,1]); grid on

## subplot(2,2,2); stem(l,h); axis([-1,M,-0.4,0.4])

title('Impulse Response'); xlabel('n'); ylabel('h(n)');
subplot(2,2,3); plot(ww/pi,Hr,wl(1:31)/pi,Hrs(1:31),'o');grid
axis([0,1,-0.2,1.2]); title('Amplitude Response')
xlabel('frequency in pi units'); ylabel('Hr(w)')
set(gca,'XTickMode','manual','XTick',[0;0.6;0.8;1])
set(gca,'YTickMode','manual','YTick',[0,0.109,0.59,1]); grid on

## subplot(2,2,4);plot(w/pi,db); axis([0,1,-100,10]); grid

title('Magnitude Response'); xlabel('frequency in pi units');
ylabel('Decibels');
set(gca,'XTickMode','manual','XTick',[0;0.6;0.8;1])
set(gca,'YTickMode','Manual','YTick',[-55;0]);
set(gca,'YTickLabelMode','manual','YTickLabels',['55';' 0'])

Result:

Analysis:
We observe that As = 55 > 50. This method is suitable for this design.
EXAMPLE 7.19 Design a 33-point digital differentiator based on the ideal differentiator of (7.31)
given in Example 7.12.
From (7.31) the samples of the (imaginary-valued) amplitude response are given by
and for linear phase the phase samples are

Therefore

Matlab script:
M = 33; alpha = (M-1)/2; Dw = 2*pi/M;
l = 0:M-1; wl = Dw*l;
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
Hrs = [j*Dw*k1,-j*Dw*(M-k2)];
angH = [-alpha*Dw*k1, alpha*Dw*(M-k2)];
H = Hrs.*exp(j*angH);
h = real(ifft(H,M));
[Hr,ww,a,P]=Hr_Type3(h);

subplot(2,1,1); k = 1:(M+1)/2;
plot(ww/pi,+Hr/pi,wl(k)/pi,abs(Hrs(k))/pi,'o',wl(k)/pi,wl(k)/pi)
;
title('Differentiator, frequency sampling design : M = 33');
xlabel('frequency in pi units'); ylabel('Hr in pi units');

## subplot(2,1,2); stem(l,h); axis([-1,M,-1.1,1.1]);

title('Impulse response'); xlabel('n'); ylabel('h(n)');
set(gca,'XTickMode','manual','XTick',[0;alpha;M-1])

Result:
Analysis:
We observe that the differentiator is not a full-band differentiator. Therefore, we cannot design
a 33-point digital differentiator based on the ideal differentiator as required.
EXAMPLE 7.20 Design a 51-point digital Hilbert transformer based on the ideal Hilbert
transformer of (7.32).
From (7.32) the samples of the (imaginary-valued) amplitude response are given
by

MATLAB script:
M = 51; alpha = (M-1)/2; Dw = 2*pi/M;
l = 0:M-1; wl = Dw*l;
k1 = 0:floor((M-1)/2); k2 = floor((M-1)/2)+1:M-1;
Hrs = [0,-j*ones(1,(M-3)/2),-0.39j,0.39j,j*ones(1,(M-3)/2)];
angH = [-alpha*Dw*k1, alpha*Dw*(M-k2)];
H = Hrs.*exp(j*angH);
h = real(ifft(H,M));
[Hr,ww,a,P]=Hr_Type3(h);

subplot(2,1,1); k = 1:(M+1)/2;
plot(ww/pi,-Hr,wl(k)/pi,abs(H(k)),'o');
title('Hilbert Transformer, frequency sampling design : M = 51')
xlabel('frequency in pi units'); ylabel('Amplitude response')
set(gca,'XTickMode','manual','XTick',[0:0.2:1])
set(gca,'YTickMode','manual','YTick',[0;0.39;1]);grid

## subplot(2,1,2); stem(l,h); axis([-1,M,-1,1]);

title('Impulse response'); xlabel('n'); ylabel('h(n)');
set(gca,'XTickMode','manual','XTick',[0;alpha;M-1])

Result:
Analysis: Comparing to ex 7.13, we can observe that the optimum design method has lower
Ripple than all the window methods. Therefore, this optimum design method should be applied
into this design.