Professional Documents
Culture Documents
(Download PDF) Applied Digital Signal Processing 1st Edition Manolakis Solutions Manual Full Chapter
(Download PDF) Applied Digital Signal Processing 1st Edition Manolakis Solutions Manual Full Chapter
https://testbankfan.com/product/introduction-to-digital-signal-
processing-1st-edition-blandford-solutions-manual/
https://testbankfan.com/product/digital-signal-processing-using-
matlab-3rd-edition-schilling-solutions-manual/
https://testbankfan.com/product/digital-signal-processing-using-
matlab-a-problem-solving-companion-4th-edition-ingle-solutions-
manual/
https://testbankfan.com/product/discrete-time-signal-
processing-3rd-edition-oppenheim-solutions-manual/
Wavelet Tour of Signal Processing 3rd Edition Mallat
Solutions Manual
https://testbankfan.com/product/wavelet-tour-of-signal-
processing-3rd-edition-mallat-solutions-manual/
https://testbankfan.com/product/image-processing-and-
analysis-1st-edition-birchfield-solutions-manual/
https://testbankfan.com/product/digital-business-networks-1st-
edition-dooley-solutions-manual/
https://testbankfan.com/product/introduction-to-digital-
communications-1st-edition-pursley-solutions-manual/
https://testbankfan.com/product/introduction-to-digital-
communications-1st-edition-grami-solutions-manual/
CHAPTER 10
Tutorial Problems
1. (a) Solution:
The relative specifications are:
1 + δp
Ap = 20 log 10 = 0.1737dB
1 − δp
1 + δp
As = 20 log10 = 60.0864dB
δs
The analog filter specifications are:
p
ǫ = 10(−0.1Ap ) − 1 = 0.2020
A = 10(0.05As ) = 1010
(b) Solution:
The relative specifications are:
p
Ap = 20 log10 ( 1 + ǫ2 ) = 0.2633dB
As = 20 log10 A = 46.0206dB
The absolute specifications are:
1 + δp
Ap = 20 log10 =⇒ δp = 0.0152
1 − δp
1 + δp
As = 20 log10 =⇒ δs = 2.4395 × 10−4
δs
628
CHAPTER 10. Design of FIR Filters 629
2. Proof:
∞
1 X
DTFT(u[n]) = U (e jω ) = + πδ(ω − 2πk)
1 − e− jω
k=−∞
Hence,
π
1
Z
jω
H(e ) = 2 × HR (e jθ )U (e j(ω−θ) )dθ − h[0]
2π −π
where
∞
jω
X 1
U (e ) = πδ(ω − 2πk) +
1 − e jω
k=−∞
∞
X 1 j ω
= πδ(ω − 2πk) + − cot( )
2 2 2
k=−∞
X(e jω ) = XR (e jω ) + jXI (e jω )
Z π Z π
jω 1 jθ 1
= XR (e ) + XR (e )dθ − XR (e jθ )dθ
2π −π 2π −π
Z π
j ω−θ
− XR (e jθ ) cot dθ
2π −π 2
3. (a) Proof:
(M +1)/2
X 1
H e jω = b[k] cos[ω(k − )] · e− jωM/2 , A e jω · e− jωM/2
2
k=1
(10.29)
b[k] = 2h[(M + 1)/2 − k], k = 1, 2, . . . , (M + 1)/2 (10.30)
M −1
M
X X2 M
X
jω − jkω − jkω
h[k]e− jkω
H e = h[k] · e = h[k]e +
k=0 k=0 k= M2+1
M −1
2
X
− jkω M + 1 − j( M +1 +k)ω
= h[k]e + h[k + ]e 2
2
k=0
M −1
2
X
jω( M M + 1 − j( 1 +k)ω
= h[k]e 2
−k)
+ h[k + ]e 2 · e− jωM/2
2
k=0
M −1
2
X
jω( M M −1 1
= h[k]e 2
−k)
+ h[ − k]e− j( 2 +k)ω · e− jωM/2
2
k=0
M −1
2
X M −1
jω( 12 +k) M −1 − j( 21 +k)ω
= h[ − k]e + h[ − k]e · e− jωM/2
2 2
k=0
M −1
2
X M −1 1
= 2h[ − k] cos ω(k + ) · e− jωM/2
2 2
k=0
M +1
2
X M +1 1
= 2h[ − k] cos ω(k − ) · e− jωM/2
2 2
k=1
(b) Proof:
(M −1)/2
ω X
A e jω = cos( )
b̃[k] cos ωk (10.31)
2
k=0
1
2 (b̃[1] + 2b̃[0]), k=1
b[k] = 1
2 (b̃[k] + b̃[k − 1]), 2 ≤ k ≤ (M − 1)/2 (10.32)
1
2 b̃[(M − 1)/2], k = (M + 1)/2
CHAPTER 10. Design of FIR Filters 631
(M −1)/2
jω
ω X
Ae = cos( ) b̃[k] cos ωk
2
k=0
(M −1)/2
1 X 1 1
= b̃[k] cos ω(k + ) + cos ω(k − )
2 2 2
k=0
(M −1)/2
X 1 1 1 1
= b̃[k] cos ω(k + ) + b̃[k] cos ω(k − )
2 2 2 2
k=0
(M −1)/2
1 ω X 1 1
= (b̃[0] + b̃[1]) cos + (b̃[k] + b̃[k − 1]) cos ω(k − )
2 2 2 2
k=2
1 M
+ b̃[(M − 1)/2] cos ω
2 2
4. (a) Solution:
The DTFT of h[n] is:
∞
X 3
X
H e jω = h[n]e− jωn = e− jωn = 1 + e− jω + e−2 jω + e−3 jω
n=−∞ n=0
= (1 + cos ω + cos 2ω + cos 3ω) − j(sin ω + sin 2ω + sin 3ω)
(b) Solution:
2
jω
X 1
Ae = b[k] cos[ω(k − )], b[k] = 2h[2 − k]
2
k=1
1 3 1 3
A e jω = b[1] cos ω + b[2] cos ω = 2 cos ω + 2 cos ω
2 2 2 2
(c) Solution:
sin ω + sin 2ω + sin 3ω
∠H e jω = − tan−1
1 + cos ω + cos 2ω + cos 3ω
(d) Solution:
3
Ψ e jω = −ωM/2 = − ω
2
CHAPTER 10. Design of FIR Filters 632
3
3
2
2
1
1 0
0 −1
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π
0 0
−2
−4 −5
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π
5. Proof:
Part I: Prove expression for A e jω for M = 6 type-III linear-phase FIR
filter.
We have
6 3 6
X X X
H e jω = h[k] · e− jkω = h[k]e− jωk − h[3]e− jω3 + h[k]e− jkω
k=0 k=0 k=3
X3
= h[k]e− jωk + h[k + 3]e− jω(k+3)
k=0
X3
= h[k]e− jω(k−3) + h[k + 3]e− jωk · e− jω3
k=0
X3
= h[3 − k]e jωk − h[6 − k − 3]e− jωk · e− jω3
k=0
X3
= (h[3 − k] · 2 j sin ωk) · e− jω3
k=0
3
X
= (h[3 − k] · 2 sin ωk) · je− jω3 + 2h[3] j sin(0ω)e− j3ω
k=1
3
!
X π
= c[k] · sin ωk · e j( 2 −3ω)
k=1
CHAPTER 10. Design of FIR Filters 634
filter.
We have
h[n] = −h[M − n], M = 5
5 2
X X
A e jω = h[k] · e− jωk = h[k]e− jωk + h[k + 3]e− jω(k+3)
k=0 k=0
2
X 5 1 5
= h[k]e− jω(k− 2 ) + h[k + 3]e− jω(k+ 2 ) · e− jω 2
k=0
3
X 1 1 5
= h[3 − k]e jω(k− 2 ) + h[3 − k]e− jω(k+ 2 ) · e− jω 2
k=1
3
X 1 5
= 2h[3 − k] j sin[ω(k − )] · e− jω 2
2
k=1
3
!
X 1 5
= 2h[3 − k] sin[ω(k − )] · je− jω 2
2
k=1
3
!
X 1 π 5
= d[k] sin[ω(k − )] e j( 2 − 2 ω)
2
k=1
Amplitude Response
30
20
10
−10
0 0.2 0.4 0.6 0.8 1
ω/π
Amplitude Response
20
15
10
0
0 0.2 0.4 0.6 0.8 1
ω/π
Amplitude Response
0
−5
−10
−15
−20
0 0.2 0.4 0.6 0.8 1
ω/π
Amplitude Response
30
20
10
−10
0 0.2 0.4 0.6 0.8 1
ω/π
4
10
A(e )
2
jω
h[n]
0 0
−2 −5
0 2 4 6 8 −1 −0.5 0 0.5 1
Time Index n ω/π
Magnitude Response Pole−Zero Plot
15
1.5
10
1
Imaginary Part
5 0.5
|H(ejω)|
8
0 0
−5 −0.5
−1
−10
−1.5
−15
−1 −0.5 0 0.5 1 −3 −2 −1 0 1 2
ω/π Real Part
%% Part b: Type-II
% hn = [1 2 3 -2 -2 3 2 1];
% w = linspace(-2,2,1000)*pi;
%% Part c: Type-III
% hn = [1 2 3 -2 0 2 -3 -2 -1];
CHAPTER 10. Design of FIR Filters 637
2 5
A(ejω)
h[n]
0
0
−5
−1
−2 −10
0 2 4 6 8 −2 −1 0 1 2
Time Index n ω/π
Magnitude Response Pole−Zero Plot
10
1.5
1
Imaginary Part
5
0.5
|H(ejω)|
7
0 0
−0.5
−5 −1
−1.5
−10
−2 −1 0 1 2 −3 −2 −1 0 1 2
ω/π Real Part
% w = linspace(-1,1,1000)*pi;
%% Part d: Type-IV
hn = [1 2 3 -2 2 -3 -2 -1];
w = linspace(-2,2,1000)*pi;
H = freqz(hn,1,w);
Hmag = abs(H);
Hangle = angle(H);
n = 0:length(hn)-1;
[Hr w P L] = amplresp(hn,w);
% Plot:
hfa = figconfg(’P1007a’,’small’);
stem(n,hn,’filled’);
ylim([min([hn 0])-.1 max(hn)+.1])
xlabel(’Time Index n’,’fontsize’,LFS)
ylabel(’h[n]’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1007b’,’small’);
CHAPTER 10. Design of FIR Filters 638
2
5
1
A(ejω)
h[n]
0 0
−1
−5
−2
−3 −10
0 2 4 6 8 −1 −0.5 0 0.5 1
Time Index n ω/π
Magnitude Response Pole−Zero Plot
10
1.5
1
Imaginary Part
5
0.5
|H(ejω)|
8
0 0
−0.5
−5 −1
−1.5
−10
−1 −0.5 0 0.5 1 −3 −2 −1 0 1 2
ω/π Real Part
zplane(hn,1)
xlabel(’Real Part’,’fontsize’,LFS)
ylabel(’Imaginary Part’,’fontsize’,LFS)
title(’Pole-Zero Plot’,’fontsize’,TFS)
hfc = figconfg(’P1007c’,’small’);
plot(w/pi,Hmag); grid on
yl = ylim;
ylim([-yl(2) yl(2)])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’|H(e^{j\omega})|’,’fontsize’,LFS)
title(’Magnitude Response’,’fontsize’,TFS)
hfd = figconfg(’P1007d’,’small’);
plot(w/pi,Hr); grid on
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’A(e^{j\omega})’,’fontsize’,LFS)
title(’Amplitude Response’,’fontsize’,TFS)
CHAPTER 10. Design of FIR Filters 639
2
5
1
A(ejω)
h[n]
0 0
−1
−5
−2
−3 −10
0 2 4 6 8 −2 −1 0 1 2
Time Index n ω/π
Magnitude Response Pole−Zero Plot
10
1.5
1
Imaginary Part
5
0.5
|H(ejω)|
7
0 0
−0.5
−5
−1
−1.5
−10
−2 −1 0 1 2 −2 −1 0 1 2
ω/π Real Part
0db
L = 21
0
−10
20log10|W(e )|
jω
−20
−30
−40
−50
−1 −0.5 0 0.5 1
ω/π
0db
L = 21
0
−10
20log10|W(e )|
jω
−20
−30
−40
−50
−1 −0.5 0 0.5 1
ω/π
0db
L = 41
0
−10
20log10|W(e )|
jω
−20
−30
−40
−50
−1 −0.5 0 0.5 1
ω/π
% Rectangular Window
close all; clc
% L = 21; % Part a
L = 41; % Part b
hw = rectwin(L)’;
Nw = 10000;
w = linspace(-1,1,Nw)*pi;
H = freqz(hw,1,w);
Hmag = abs(H);
Hmagdb = 20*log10(Hmag/max(Hmag));
[Ha w2 P2 L2] = amplresp(hw,w);
Hac = abs(cumsum(Ha));
Hacdb = 20*log10(Hac/max(Hac));
0db
L = 41
0
−10
20log10|W(e )|
jω
−20
−30
−40
−50
−1 −0.5 0 0.5 1
ω/π
%% Plot:
hfa = figconfg(’P1008a’,’small’);
plot(w/pi,Hmagdb);hold on
plot(w/pi,sidlobeH*ones(1,Nw),’--k’)
text(w(Nw/5)/pi,sidlobeH,[num2str(sidlobeH,3),’db’],...
’fontsize’,LFS-2,’verticalalignment’,’bottom’)
ylim([-50 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’20log_{10}|W(e^{j\omega})|’,’fontsize’,LFS)
title([’L = ’,num2str(L)],’fontsize’,TFS)
hfb = figconfg(’P1008b’,’small’);
plot(w/pi,Hacdb); hold on
plot(w/pi,sidlobeHac*ones(1,Nw),’--k’)
text(w(Nw/5)/pi,sidlobeHac,[num2str(sidlobeHac,3),’db’],...
’fontsize’,LFS-2,’verticalalignment’,’bottom’)
ylim([-50 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’20log_{10}|W(e^{j\omega})|’,’fontsize’,LFS)
title([’L = ’,num2str(L)],’fontsize’,TFS)
CHAPTER 10. Design of FIR Filters 642
9.
Magnitude Response Magnitude Response
1.5 1.5
M = 10 M = 20
1 1
|H(e )|
|H(e )|
jω
jω
0.5 0.5
0 0
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π
Magnitude Response Magnitude Response
1.5 1.5
M = 40 M = 60
1 1
|H(e )|
|H(e )|
jω
jω
0.5 0.5
0 0
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π
FIGURE 10.15: Amplitude plots of linear-phase FIR filter using the rectangular
window of order M = 10, M = 20, M = 40 and M = 60.
M ATLAB script:
ylabel(’|H(e^{j\omega})|’,’fontsize’,LFS)
title(’Magnitude Response’,’fontsize’,TFS)
legend([’M = ’,num2str(M)],’location’,’northeast’)
Decibels
−40
h(n)
0.2
−60
0
−0.2 −80
−0.4 −100
0 10 20 30 40 50 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB) −3
−4
x 10
Approximation Error −50
x 10
0
1
0.5
Passband dB
Stopband dB
−100 −0.5
Amplitude
−150 −1
−0.5
−1
0 0.2 0.4 0.6 0.8 1 −200 −1.5
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
Decibels
−40
h(n)
0.2
−60
0
−0.2 −80
−0.4 −100
0 10 20 30 40 50 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB) −3
−4
x 10
Approximation Error −50
x 10
0
1
0.5
Passband dB
Stopband dB
−100 −0.5
Amplitude
−150 −1
−0.5
−1
0 0.2 0.4 0.6 0.8 1 −200 −1.5
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
% h = h.*kaiser(M+1,beta);
%% Part (b)
h = fir1(M,wn,ftype,kaiser(M+1,beta));
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[Ha w2 P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
magz2 = nan(1,length(w));
ind = w <= ws;
aperr(ind) = Ha(ind);
magz1(ind) = Hdb(ind);
ind = w >= wp;
aperr(ind) = Ha(ind) - 1;
magz2(ind) = Hdb(ind);
CHAPTER 10. Design of FIR Filters 645
%% Plot:
hfa = figconfg(’P1010a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1010b’,’small’);
plot(w/pi,Hdb);
ylim([-100 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1010c’,’small’);
plot(w/pi,aperr);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1010d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(1),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
set(get(AX(2),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
Magnitude Response
1.2
1
0.8
Magnitude
0.6
0.4
0.2
0
0 0.5 1 1.5 2
ω/π
Magnitude Response
1.2
1
0.8
Magnitude
0.6
0.4
0.2
0
0 0.5 1 1.5 2
ω/π
M = L - 1;
wc = pi/2;
Dw = 2*pi/L;
k1 = floor(wc/Dw);
Ad = [ones(1,k1+1),zeros(1,L-2*k1-1),ones(1,k1)];
alpha = M/2; Q = floor(alpha);
psid = -alpha*2*pi/L*[(0:Q),-(L-(Q+1:M))];
Hd = Ad.*exp(j*psid);
hd = real(ifft(Hd));
h = hd(L/2-9:L/2+10); % Part a & b
% h = hd(L/2-9:L/2+10).*hamming(20)’; % Part c
w = linspace(0,2,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
%% Plot:
CHAPTER 10. Design of FIR Filters 647
Magnitude Response
1
0.8
Magnitude
0.6
0.4
0.2
0
0 0.5 1 1.5 2
ω/π
hf = figconfg(’P1011’,’small’);
plot(w/pi,Hmag);hold on
% plot((0:L-1)/L*2,Ad,’.r’)
ylim([min(Hmag)-0.1 max(Hmag)+0.1])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Magnitude’,’fontsize’,LFS)
title(’Magnitude Response’,’fontsize’,TFS)
−10
Magnitude
−20
−30
−40
−50
−60
0 0.5 1 1.5 2
ω/π
Magnitude Response
0
−10
Magnitude
−20
−30
−40
−50
−60
0 0.5 1 1.5 2
ω/π
Magnitude Response
0
−10
Magnitude
−20
−30
−40
−50
−60
0 0.5 1 1.5 2
ω/π
M = L - 1;
wp = 0.2*pi; ws = 0.3*pi; Ap = 0.2; As = 40;
wc = (wp+ws)/2;
Dw = 2*pi/L;
alpha = M/2; Q = floor(alpha);
psid = -alpha*2*pi/L*[(0:Q),-(L-(Q+1:M))];
T1 = 0.37897949;
%% Part a:
% k = floor(wc/Dw);
% Ad = [ones(1,k+1),zeros(1,L-2*k-1),ones(1,k)];
% Hd = Ad.*exp(j*psid);
% hd = real(ifft(Hd));
% h = hd.*rectwin(L)’;
%% Part b:
% k1 = floor(wp/Dw); k2 = ceil(ws/Dw);
% Ad = [ones(1,k1+1),T1,zeros(1,L-2*k2+1),T1,ones(1,k1)];
CHAPTER 10. Design of FIR Filters 649
% Hd = Ad.*exp(j*psid);
% hd = real(ifft(Hd));
% h = hd.*rectwin(L)’;
%% Part c:
h = fir2(M,[0 wp/pi wc/pi ws/pi 1],[1 1 T1 0 0],rectwin(L));
w = linspace(0,2,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag/max(Hmag));
%% Plot:
hf = figconfg(’P1012’,’small’);
plot(w/pi,Hdb);hold on
plot(w/pi,-40*ones(1,length(w)),’--’,’color’,’k’)
ylim([-60 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Magnitude’,’fontsize’,LFS)
title(’Magnitude Response’,’fontsize’,TFS)
that is
(b) Proof:
Define θ = cos−1 x, we have
(c) Proof:
T0 (x) = 1, T1 (x) = 1
n = 2, T2 (x) = 2xT1 (x) − T0 (x) = 2x2 − 1
n = 3, T3 (x) = 2xT2 (x) − T1 (x) = 2x(2x2 − 1) − x = 4x3 − 3x
n = 4, T4 (x) = 2xT3 (x)−T2 (x) = 2x(4x3 −3x)−(2x2 −1) = 8x4 −8x2 +1
n = 5, T5 (x) = 2xT4 (x)−T3 (x) = 2x(8x4 −8x2 +1)−(4x3 −3x) = 16x5 −20x3 +5x
0.8 −0.05
0.7 −0.1
0 0.2454 0.7546 1
0.8 −0.05
0.7 −0.1
0 0.25 0.75 1
FIGURE 10.25: Graph of final f (x), the resulting P2 (x), and e(x).
M ATLAB script:
CHAPTER 10. Design of FIR Filters 651
hf = figconfg(’P1014’,’small’);
% plot:
[Ax hf1 hf2] = plotyy(xp,[fx(xp);Px(xp)],xp,...
[ex;delta*ones(1,N);-delta*ones(1,N)]);
set(hf2(2),’color’,’k’,’Linestyle’,’:’)
set(hf2(3),’color’,’k’,’Linestyle’,’:’)
legend(’e(x)’,’\delta’,’-\delta’,’f(x)’,’P_2(x)’,’location’,’best’)
thresh_x = max(abs(x_loc-extrema_loc));
[X Y] = meshgrid(abs(extrema),abs(extrema));
thresh_ex = max(abs(X(:)-Y(:)));
x_loc = extrema_loc;
thresh_x, thresh_ex
end
end
CHAPTER 10. Design of FIR Filters 652
%% Subfunctions:
function coeff = coeff_solver(x)
% Given guessed nodes, solve for coefficients a_k and delta
% Input:
% x = [zeta_0 zeta_1 zeta_2 zeta_3];
% Output:
% coeff = [a_0;a_1;a_2;delta];
x = x(:);
n = length(x);
A = [ones(n,1),x,x.^2];
B = [A,x.^3];
c = (-1).^(0:n-1);
A = [A,c(:)];
coeff = inv(A)*B*[1;-2;4;-2];
end
15. tba
16.
M ATLAB script:
−20
0.2
Decibels
−40
h(n)
0
−60
−0.2 −80
−100
0 5 10 15 20 25 0 0.6 0.75 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 0
0.04
0.02
Passband dB
Stopband dB
Amplitude
0 −50
−0.02
−0.04
0 0.2 0.4 0.6 0.8 1 −100 −0.5
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
%% Specification:
ws = 0.6*pi; wp = 0.75*pi; As = 50; Ap = 0.5;
%% Passband and Stopband Ripple Calculation:
deltap = (10^(Ap/20)-1)/(10^(Ap/20)+1);
deltas = (1+deltap)/(10^(As/20));
%% Estimated Filter order using FIRPMORD function:
[M,fo,ao,W] = firpmord([ws,wp]/pi,[0,1],[deltas,deltap]);
M = M + 2
%% Filter Design using FIRPM function:
[h,delta] = firpm(M,fo,ao,W);
delta,
deltap,
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[Ha w2 P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
CHAPTER 10. Design of FIR Filters 654
magz2 = nan(1,length(w));
ind = w <= ws;
aperr(ind) = Ha(ind);
magz1(ind) = Hdb(ind);
ind = w >= wp;
aperr(ind) = Ha(ind)-1;
magz2(ind) = Hdb(ind);
%% Plot:
hfa = figconfg(’P1016a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1016b’,’small’);
plot(w/pi,Hdb);hold on
plot(w/pi,-As*ones(1,length(w)),’--’,’color’,’k’)
ylim([-100 0])
set(gca,’XTick’,[0 ws wp pi]/pi,’Xgrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1016c’,’small’);
plot(w/pi,aperr);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1016d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(2),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
set(get(AX(1),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
set(AX(1),’Ytick’,[-100 -50 0],’ylim’,[-100 0])
CHAPTER 10. Design of FIR Filters 655
17.
Impulse Response Magnitude Response (dB)
0
0.4 −20
Decibels
0.2 −40
h(n)
0 −60
−0.2 −80
−100
0 20 40 60 80 0 0.3 0.4 0.70.75 1
n ω/π
Zoom of Magnitude Response (dB)
−3
x 10
Approximation Error 0 0
5
Passband dB
Stopband dB
Amplitude
1
0 −50 −5
−1
−5
0 0.2 0.4 0.6 0.8 1 −100 −10
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
M ATLAB script:
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
CHAPTER 10. Design of FIR Filters 656
Hdb = 20*log10(Hmag./max(Hmag));
[Ha w2 P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
magz2 = nan(1,length(w));
ind = w <= ws;
aperr(ind) = Ha(ind);
magz1(ind) = Hdb(ind);
ind = w >= wp1 & w <= wp2;
aperr(ind) = Ha(ind)-0.5;
magz2(ind) = Hdb(ind);
ind = w >= wp3;
aperr(ind) = Ha(ind)-1;
magz2(ind) = Hdb(ind);
%% Plot:
hfa = figconfg(’P1017a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1017b’,’small’);
plot(w/pi,Hdb);hold on
plot(w/pi,-As*ones(1,length(w)),’--’,’color’,’k’)
ylim([-100 0])
set(gca,’XTick’,[0 ws wp1 wp2 wp3 pi]/pi,’Xgrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1017c’,’small’);
plot(w/pi,aperr);
set(gca,’Ytick’,[-deltap1 -deltas 0 deltas deltap1],’Ygrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1017d’,’small’);
CHAPTER 10. Design of FIR Filters 657
18.
Amplitude Response Impulse Response
4 1
2 0.5
Amplitude
h[n]
0 0
−2 −0.5
−4 −1
0 0.5 1 1.5 2 0 5 10 15 20 25 30
ω/π n
FIGURE 10.28: Graph of amplitude response and impulse response of the designed
differentiator.
M ATLAB script:
w = linspace(0,2,1000)*pi;
[Ha wt P2 L2] = amplresp(h(:)’,w);
%% Plot:
CHAPTER 10. Design of FIR Filters 658
hfa = figconfg(’P1018a’,’small’);
plot(w/pi,Ha);hold on
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Amplitude Response’,’fontsize’,TFS)
hfb = figconfg(’P1018b’,’small’);
stem(0:M,h,’filled’)
xlim([0 M])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h[n]’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
19.
Amplitude Response Impulse Response
0
0.6
0.4
−0.5 0.2
h(n)
−1 −0.2
−0.4
−0.6
−1.5
0 0.2 0.4 0.6 0.8 1 0 10 20 30 40 50
ω/π n
Approximation Error
0.01
0.005
Amplitude
−0.005
−0.01
0 0.2 0.4 0.6 0.8 1
ω/π
FIGURE 10.29: Graph of amplitude response, impulse response and the approxi-
mation error of the designed Hilbert transformer.
M ATLAB script:
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
[Ha wa P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
ind = (w >= w1 & w <= w2);
aperr(ind) = Ha(ind)+1;
%% Plot:
hfa = figconfg(’P1019a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1019b’,’small’);
plot(w/pi,Ha);hold on
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Amplitude Response’,’fontsize’,TFS)
hfc = figconfg(’P1019c’,’small’);
plot(w/pi,aperr);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
20. tba
CHAPTER 10. Design of FIR Filters 660
Basic Problems
21. M ATLAB function:
if strcmpi(typeout,’ana’)
A = sqrt(10^(0.1*A)-1);
B = 10^(0.05*B);
elseif strcmpi(typeout,’abs’)
A = 10^(A/20);
A = (A-1)/(A+1);
B = 10^(B/20);
B = (A+1)/B;
end
CHAPTER 10. Design of FIR Filters 661
M M/2 M
X X X
H e jω = h[k] · e− jkω = h[k]e− jkω + h[k]e− jkω
k=0 k=0 k=M/2
M/2
X
= h[k]e− jkω + h[k + M/2]e− j(k+M/2)ω
k=0
M/2
X M
= h[k]e− j(k−M/2)ω + h[k + M/2]e− jkω · e j 2 ω
k=0
M/2
X M
= h[M/2 − k]e− j(M/2−k−M/2)ω − h[M − k − M/2]e− jkω · e j 2 ω
k=0
M/2
X M
= h[M/2 − k]e jkω − h[M/2 − k]e− jkω · e j 2 ω
k=0
M/2
X M
= (2h[M/2 − k] · j sin kω) · e j 2 ω
k=0
M/2
X M
= 2h[M/2 − k] sin kω · je j 2 ω
k=1
M/2
X π M
= c[k] sin kω · e j( 2 − j 2 ω)
k=1
(b) tba
CHAPTER 10. Design of FIR Filters 662
(b) Proof:
DTFT
x[n] −→ X e jω
Y e jω = X e jω · Hlp e jω = X e jω · e− jnd ω
y[n] = x[n − nd ]
24. tba
20log10|W(e )|
jω
jω
−40 −40
−60 −60
−80 −80
−100 −100
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π
20log10|W(e )|
jω
jω
−40 −40
−60 −60
−80 −80
−100 −100
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π
M ATLAB script:
Hmag = abs(H);
Hmagdb = 20*log10(Hmag/max(Hmag));
[Ha w2 P2 L2] = amplresp(hw,w);
Hac = abs(cumsum(Ha));
Hacdb = 20*log10(Hac/max(Hac));
bandwid/pi*L
%% Plot:
hfa = figconfg(’P1026a’,’small’);
plot(w/pi,Hmagdb);hold on
plot(w/pi,sidlobeH*ones(1,Nw),’--k’)
text(w(Nw/5)/pi,sidlobeH,[num2str(sidlobeH,3),’db’],...
’fontsize’,LFS-2,’verticalalignment’,’bottom’)
ylim([-100 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’20log_{10}|W(e^{j\omega})|’,’fontsize’,LFS)
title([’L = ’,num2str(L)],’fontsize’,TFS)
hfb = figconfg(’P1026b’,’small’);
plot(w/pi,Hacdb); hold on
ylim([-100 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’20log_{10}|W(e^{j\omega})|’,’fontsize’,LFS)
title([’L = ’,num2str(L)],’fontsize’,TFS)
CHAPTER 10. Design of FIR Filters 665
−20 −20
20log10|W(e )|
20log10|W(e )|
jω
jω
−40.6db
−40 −40
−52.6db
−60 −60
−80 −80
−100 −100
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π
−20 −20
20log10|W(e )|
20log10|W(e )|
jω
jω
−80 −80
−100 −100
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π
M ATLAB script:
H = freqz(hw,1,w);
Hmag = abs(H);
Hmagdb = 20*log10(Hmag/max(Hmag));
[Ha w2 P2 L2] = amplresp(hw,w);
Hac = abs(cumsum(Ha));
Hacdb = 20*log10(Hac/max(Hac));
%% Plot:
hfa = figconfg(’P1027a’,’small’);
plot(w/pi,Hmagdb);hold on
plot(w/pi,sidlobeH*ones(1,Nw),’--k’)
text(w(Nw/5)/pi,sidlobeH,[num2str(sidlobeH,3),’db’],...
’fontsize’,LFS-2,’verticalalignment’,’bottom’)
ylim([-100 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’20log_{10}|W(e^{j\omega})|’,’fontsize’,LFS)
title([’L = ’,num2str(L)],’fontsize’,TFS)
hfb = figconfg(’P1027b’,’small’);
plot(w/pi,Hacdb); hold on
plot(w/pi,sidlobeHac*ones(1,Nw),’--k’)
text(w(Nw/5)/pi,sidlobeHac,[num2str(sidlobeHac,3),’db’],...
’fontsize’,LFS-2,’verticalalignment’,’bottom’)
ylim([-100 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’20log_{10}|W(e^{j\omega})|’,’fontsize’,LFS)
title([’L = ’,num2str(L)],’fontsize’,TFS)
CHAPTER 10. Design of FIR Filters 667
Decibels
−40
h(n)
0.2
0.1 −60
0
−80
−0.1
−100
0 5 10 15 20 25 30 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 −40
0.01
Passband dB
Stopband dB
Amplitude
0 −0.04 −80
−0.01
0 0.2 0.4 0.6 0.8 1 −0.08 −120
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
%% Part (a)
wc = (ws+wp)/2;
dw = ws - wp;
L = 6.6*pi/dw;
M = L-1;
if mod(M,2) == 1
M = M+1;
end
CHAPTER 10. Design of FIR Filters 668
Decibels
−40
h(n)
0.2
0.1 −60
0
−80
−0.1
−100
0 5 10 15 20 25 30 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
−3
x 10
Approximation Error 0 −40
6
4 −0.01 −60
Passband dB
Stopband dB
Amplitude
2 −0.02 −80
0 −0.03 −100
−2 −0.04 −120
−4
0 0.2 0.4 0.6 0.8 1 −0.05 −140
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
hd = ideallp(wc,M);
h = hd.*hamming(M+1);
%% Part (b)
% [M,wn,beta,ftype] = kaiserord([0.3 0.5],[1 0],[deltas,deltap]);
% h = fir1(M,wn,ftype,kaiser(M+1,beta));
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[Ha w2 P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
magz2 = nan(1,length(w));
ind = w <= wp;
aperr(ind) = Ha(ind) - 1;
magz1(ind) = Hdb(ind);
ind = w >= ws;
aperr(ind) = Ha(ind);
CHAPTER 10. Design of FIR Filters 669
magz2(ind) = Hdb(ind);
%% Plot:
hfa = figconfg(’P1028a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1028b’,’small’);
plot(w/pi,Hdb);
ylim([-100 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1028c’,’small’);
plot(w/pi,aperr);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1028d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(1),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
set(get(AX(2),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
0.6 −10
−20
Decibels
0.4
h(n)
−30
0.2
−40
0 −50
−60
0 10 20 30 40 50 60 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 −40
0.01
−0.02 −50
0.005
Passband dB
Stopband dB
−0.04 −60
Amplitude
0 −0.06 −70
−0.08 −80
−0.005
−0.1 −90
−0.01
0 0.2 0.4 0.6 0.8 1 −0.12 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
A = -20*log10(delta);
%% Part (a)
wc1 = (ws1+wp1)/2; wc2 = (ws2+wp2)/2;
dw = min([ws1-wp1,wp2-ws2]);
L = 6.2*pi/dw;
M = L-1;
if mod(M,2) == 1
M = M+1;
end
h = ideallp(wc1,M) + ideallp(pi,M) - ideallp(wc2,M);
h = h.*hann(M+1);
%% Part (b)
h = fir1(M,[wc1 wc2]/pi,’stop’,hann(M+1));
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
CHAPTER 10. Design of FIR Filters 671
0.6 −10
−20
Decibels
0.4
h(n)
−30
0.2
−40
0 −50
−60
0 10 20 30 40 50 60 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 −40
0.01
−0.02 −50
0.005
Passband dB
Stopband dB
−0.04 −60
Amplitude
0 −0.06 −70
−0.08 −80
−0.005
−0.1 −90
−0.01
0 0.2 0.4 0.6 0.8 1 −0.12 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1029b’,’small’);
plot(w/pi,Hdb);
ylim([-60 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1029c’,’small’);
plot(w/pi,aperr);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1029d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(1),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
set(get(AX(2),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
%% Part (a)
wc1 = (ws1+wp1)/2; wc2 = (ws2+wp2)/2;
dw = min([wp1-ws1,ws2-wp2]);
CHAPTER 10. Design of FIR Filters 673
0.2 −20
Decibels
−30
h(n)
0 −40
−50
−0.2 −60
−70
0 10 20 30 40 50 60 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
−3
x 10
Approximation Error 0 0
4
−20
2 −0.01
Passband dB
Stopband dB
Amplitude
−40
0 −0.02
−60
−2 −0.03
−80
−4
0 0.2 0.4 0.6 0.8 1 −0.04 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
L = 6.6*pi/dw;
M = L-1;
if mod(M,2) == 1
M = M+1;
end
h = ideallp(wc2,M) - ideallp(wc1,M);
h = h.*hamming(M+1);
%% Part (b)
% [M,wn,beta,ftype] = ...
% kaiserord([ws1 wp1 wp2 ws2]/pi,[0 1 0],[deltas,deltap, deltas]);
% h = fir1(M,wn,ftype,kaiser(M+1,beta));
%% Part (c)
% h = fir1(M,[wc1 wc2]/pi,’DC-0’,hamming(M+1));
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
CHAPTER 10. Design of FIR Filters 674
Decibels
−30
h(n)
0
−40
−0.1
−50
−0.2
−60
−0.3
−70
0 10 20 30 40 50 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
−3
x 10
Approximation Error 0 0
2
1 −20
Passband dB
Stopband dB
Amplitude
0
−40
−1
−60
−2
−3 −80
−4
0 0.2 0.4 0.6 0.8 1 −0.05 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
Decibels
−30
h(n)
0
−40
−0.1
−50
−0.2
−60
−0.3
−70
0 10 20 30 40 50 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 0
0.02
−20
0.01 −0.05
Passband dB
Stopband dB
Amplitude
−40
0 −0.1
−60
−0.01 −0.15
−80
−0.02
0 0.2 0.4 0.6 0.8 1 −0.2 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1030b’,’small’);
plot(w/pi,Hdb);
ylim([-70 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1030c’,’small’);
plot(w/pi,aperr);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1030d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(1),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
CHAPTER 10. Design of FIR Filters 676
set(get(AX(2),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
set(AX(2),’Ylim’,[-100 0],’YTick’,-100:20:0)
31.
Impulse Response Amplitude Response
3
1
2.5
0.5
Amplitude
2
h(n)
0 1.5
−0.5 1
−1 0.5
0
0 10 20 30 40 50 60 0 0.5 1 1.5 2 2.5 3
n ω
M ATLAB script:
w = linspace(0,1,1000)*pi;
[Ha w2 P2 L2] = amplresp(h(:)’,w);
%% Plot:
hfa = figconfg(’P1031a’,’small’);
stem(n,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1031b’,’small’);
plot(w,Ha); xlim([0 pi]);ylim([0 pi])
CHAPTER 10. Design of FIR Filters 677
xlabel(’\omega’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Amplitude Response’,’fontsize’,TFS)
0.2 −20
Decibels
−40
h[n]
−60
−0.2
−80
−0.4
0 5 10 15 20 25 30 0 0.5 1 1.5 2
n ω/π
0.2 −20
Decibels
−40
h[n]
−60
−0.2
−80
−0.4
0 5 10 15 20 25 30 0 0.5 1 1.5 2
n ω/π
M ATLAB script:
om = (0:L-1)*Dw;
alpha = M/2; Q = floor(alpha);
psid = -alpha*Dw*[0:Q,-(L-(Q+1:M))];
%% Part a
k1 = floor(ws/Dw);
k2 = ceil(wp/Dw);
ind = (om>ws & om<wp);
A = (om(ind)-ws)/(wp-ws);
Ad = [zeros(1,k1+1),A,ones(1,L-2*k2+1),fliplr(A),zeros(1,k1)];
Hd = Ad.*exp(j*psid);
hd = real(ifft(Hd));
h = hd.*rectwin(L)’;
%% Part b
ind = om < pi;
h = fir2(M,[om(ind) pi]/pi,[Ad(ind) 1]);
%% Plot
w = linspace(0,2,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag/max(Hmag));
hfa = figconfg(’P1032a’,’small’);
plot(w/pi,Hdb);hold on
plot(w/pi,-As*ones(1,length(w)),’--’,’color’,’k’)
ylim([-As-40 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfb = figconfg(’P1032a’,’small’);
stem(0:M,h,’filled’)
xlim([0 M])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h[n]’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfc = figconfg(’P1032c’,’small’);
CHAPTER 10. Design of FIR Filters 679
plot(w/pi,Hmag);hold on
plot(om/pi,Ad,’.’,’color’,’r’)
ylim([0 max(Hmag)+0.1])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Magnitude’,’fontsize’,LFS)
title(’Magnitude Response’,’fontsize’,TFS)
0.2 −20
Decibels
h[n]
0 −40
−0.2 −60
−0.4 −80
0 5 10 15 20 25 30 35 0 0.5 1 1.5 2
n ω/π
0.2 −20
Decibels
h[n]
0 −40
−0.2 −60
−0.4 −80
0 5 10 15 20 25 30 35 0 0.5 1 1.5 2
n ω/π
M ATLAB script:
%% Part a
k1 = floor(ws1/Dw);
k2 = ceil(wp1/Dw);
k3 = floor(wp2/Dw);
k4 = ceil((ws2-0.05*pi)/Dw);
ind = (om>ws1 & om<wp1);
A = 0.5 - 0.5*cos(pi*(om(ind)-ws1)/(wp1-ws1));
Ad = [zeros(1,k1+1),A,ones(1,k3-k2+1),fliplr(A),zeros(1,L-k4*2+1),...
A,ones(1,k3-k2+1),fliplr(A),zeros(1,k1)];
Hd = Ad.*exp(j*psid);
hd = real(ifft(Hd));
h = hd.*rectwin(L)’;
%% Part b
ind = om < pi;
% h = fir2(M,[om(ind) pi]/pi,[Ad(ind) 0],hann(L));
%% Plot
w = linspace(0,2,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag/max(Hmag));
hfa = figconfg(’P1033a’,’small’);
plot(w/pi,Hdb);hold on
plot(w/pi,-As1*ones(1,length(w)),’--’,’color’,’k’)
ylim([-As1-40 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfb = figconfg(’P1033a’,’small’);
stem(0:M,h,’filled’)
CHAPTER 10. Design of FIR Filters 681
xlim([0 M])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h[n]’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfc = figconfg(’P1033c’,’small’);
plot(w/pi,Hmag);hold on
plot(om/pi,Ad,’.’,’color’,’r’)
ylim([0 max(Hmag)+0.1])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Magnitude’,’fontsize’,LFS)
title(’Magnitude Response’,’fontsize’,TFS)
0.2 As = 29.98
−30
h[n]
0.1 −40
−50
0
−60
−0.1 −70
0 5 10 15 20 25 30 35 0 0.5 1 1.5 2
n ω/π
0.2 −30
h[n]
−50
0
−60
−0.1 −70
0 5 10 15 20 25 30 35 0 0.5 1 1.5 2
n ω/π
0.3
−20
Decibels
0.2
h[n]
−40
0.1
−60 As = 61.21
0
−0.1 −80
0 5 10 15 20 25 30 35 0 0.5 1 1.5 2
n ω/π
%% Part a
k = wc/Dw;
% T = 0.5; % Part a
T = 0.3871; % Part b best one
Ad = [ones(1,k),T,zeros(1,L-k*2-1),T,ones(1,k-1)];
Hd = Ad.*exp(j*psid);
hd = real(ifft(Hd));
h = hd.*rectwin(L)’;
%% Part c
ind = om < pi;
h = fir2(M,[om(ind) pi]/pi,[Ad(ind) 0]); % reference hamming
%% Plot
w = linspace(0,2,1000)*pi;
CHAPTER 10. Design of FIR Filters 683
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag/max(Hmag));
hfa = figconfg(’P1034a’,’small’);
plot(w/pi,Hdb);hold on
plot(w/pi,As*ones(1,length(w)),’--’,’color’,’k’)
text(w(500)/pi,As,[’As = ’,num2str(abs(As),’%.2f’)],...
’horizontalalignment’,’center’,’verticalalignment’,’bottom’,...
’fontsize’,LFS-4)
ylim([-80 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfb = figconfg(’P1034a’,’small’);
stem(0:M,h,’filled’)
xlim([0 M])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h[n]’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfc = figconfg(’P1034c’,’small’);
plot(w/pi,Hmag);hold on
plot(om/pi,Ad,’.’,’color’,’r’)
ylim([0 max(Hmag)+0.1])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Magnitude’,’fontsize’,LFS)
title(’Magnitude Response’,’fontsize’,TFS)
CHAPTER 10. Design of FIR Filters 684
1 3
Amplitude
h[n]
0 2
−1 1
−2 0
0 10 20 30 40 0 0.5 1 1.5 2
n ω/π
5 5
0 0
−5 −5
−10
−10
50 100 150 50 100 150
n n
(c) tba
M ATLAB script:
h = hd;
w = linspace(0,2,1000)*pi;
[Ha wt P2 L2] = amplresp(h(:)’,w);
%% Part b: test
n = 0:150;
xn = 10*cos(0.2*pi*n);
yn = filter(h,1,xn);
%% Plot:
hfa = figconfg(’P1035a’,’small’);
stem(0:M,h,’filled’)
xlim([0 M])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h[n]’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1035b’,’small’);
plot(w/pi,Ha);hold on
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Amplitude Response’,’fontsize’,TFS)
hfc = figconfg(’P1035c’,’long’);
subplot(121)
stem(n(51:end),xn(51:end),’filled’)
ylim([-11 11])
xlabel(’n’,’fontsize’,LFS)
title(’x[n]’,’fontsize’,TFS)
subplot(122)
stem(n(51:end),yn(51:end),’filled’); hold on
ynref = diff(xn);
xlabel(’n’,’fontsize’,LFS)
title(’y[n]’,’fontsize’,TFS)
36.
M ATLAB script:
0.4
−20
Decibels
0.2
h(n)
−40
0
−60
−0.2
−0.4 −80
0 10 20 30 40 0 0.25 0.35 0.7 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 0
0.01
Passband dB
Stopband dB
0.004
Amplitude
0 −50 −0.05
−0.004
−0.01
0 0.2 0.4 0.6 0.8 1 −100 −0.1
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[Ha w2 P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
CHAPTER 10. Design of FIR Filters 687
magz2 = nan(1,length(w));
ind = w <= ws1;
aperr(ind) = Ha(ind);
magz1(ind) = Hdb(ind);
ind = w >= wp1 & w <= wp2;
aperr(ind) = Ha(ind)-1;
magz2(ind) = Hdb(ind);
ind = w >= ws2;
aperr(ind) = Ha(ind);
magz1(ind) = Hdb(ind);
%% Plot:
hfa = figconfg(’P1036a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1036b’,’small’);
plot(w/pi,Hdb);hold on
ylim([-80 0])
set(gca,’XTick’,[0 ws1 wp1 wp2 ws2 pi]/pi,’Xgrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1036c’,’small’);
plot(w/pi,aperr);
set(gca,’Ytick’,[-deltas1 -deltap 0 deltap deltas1],’Ygrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1036d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(2),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
set(get(AX(1),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
CHAPTER 10. Design of FIR Filters 688
37.
Impulse Response Magnitude Response (dB)
0
0.4
−20
0.3
Decibels
−40
0.2
h(n)
0.1 −60
0
−80
−0.1
−100
0 5 10 15 20 0 0.3 0.5 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 0
0.04
0.02 Passband dB
Stopband dB
Amplitude
0 −50
−0.02
−0.04
0 0.2 0.4 0.6 0.8 1 −0.5 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
M ATLAB script:
w = linspace(0,1,1000)*pi;
CHAPTER 10. Design of FIR Filters 689
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[Ha w2 P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
magz2 = nan(1,length(w));
ind = w <= wp;
aperr(ind) = Ha(ind)-1;
magz1(ind) = Hdb(ind);
ind = w >= ws;
aperr(ind) = Ha(ind);
magz2(ind) = Hdb(ind);
%% Plot:
hfa = figconfg(’P1037a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1037b’,’small’);
plot(w/pi,Hdb);hold on
plot(w/pi,-As*ones(1,length(w)),’--’,’color’,’k’)
ylim([-100 0])
set(gca,’XTick’,[0 wp ws pi]/pi,’Xgrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1037c’,’small’);
plot(w/pi,aperr);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1037d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
CHAPTER 10. Design of FIR Filters 690
38.
Impulse Response Magnitude Response (dB)
0.6 0
−5
0.4
−10
Decibels
h(n)
0.2 −15
−20
0
−25
−0.2
−30
0 5 10 15 20 25 0 0.4 0.5 0.7 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 0
0.2
Passband dB
Stopband dB
−0.05 −10
Amplitude
0.05
0.025
0
−0.025
−0.05
−0.1 −20
−0.2
0 0.2 0.4 0.6 0.8 1 −0.15 −30
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
M ATLAB script:
delta,
delta1,
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[Ha ww P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
magz2 = nan(1,length(w));
ind = w <= w1;
aperr(ind) = Ha(ind)-A1;
magz2(ind) = Hdb(ind);
ind = w >= w2 & w <= w3;
aperr(ind) = Ha(ind)-A2;
magz1(ind) = Hdb(ind);
ind = w >= w4;
aperr(ind) = Ha(ind)-A3;
magz2(ind) = Hdb(ind);
%% Plot:
hfa = figconfg(’P1038a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1038b’,’small’);
plot(w/pi,Hdb);hold on
set(gca,’XTick’,[0 w1 w2 w3 w4 pi]/pi,’Xgrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1038c’,’small’);
plot(w/pi,aperr);
delYtick = sort([delta1 delta2 delta3]);
set(gca,’Ytick’,[-delYtick(end:-1:1) 0 delYtick],’Ygrid’,’on’)
CHAPTER 10. Design of FIR Filters 692
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1038d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(2),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
set(get(AX(1),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
0
−0.2 −1
−0.4
−0.6
−1.5
0 5 10 15 20 25 0 0.2 0.4 0.6 0.8 1
n ω/π
FIGURE 10.54: Plots of impulse response and magnitude response of the designed
FIR Hilbert transformer.
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
[Ha wa P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
ind = (w >= w1 & w <= w2);
CHAPTER 10. Design of FIR Filters 693
Input Sequence
1
x[n] 0.5
−0.5
−1
25 30 35 40 45 50 55 60 65 70 75
Time Index n
Output Sequence
1
0.5
y[n]
−0.5
−1
25 30 35 40 45 50 55 60 65 70 75
Time Index n
FIGURE 10.55: Stem subplots of both x[n] and y[n] for 25 ≤ n ≤ 75.
aperr(ind) = Ha(ind)+1;
n = 0:100;
xn = cos(0.3*pi*n);
yn = filter(h,1,xn);
indn = n >= 25 & n <= 75;
%% Plot:
hfa = figconfg(’P1039a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1039b’,’small’);
plot(w/pi,Ha);hold on
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Amplitude Response’,’fontsize’,TFS)
CHAPTER 10. Design of FIR Filters 694
hfc = figconfg(’P1039c’);
subplot(211)
stem(n(indn),xn(indn),’filled’)
xlabel(’Time Index n’,’fontsize’,LFS)
ylabel(’x[n]’,’fontsize’,LFS)
title(’Input Sequence’,’fontsize’,TFS)
subplot(212)
stem(n(indn),yn(indn),’filled’)
xlabel(’Time Index n’,’fontsize’,LFS)
ylabel(’y[n]’,’fontsize’,LFS)
title(’Output Sequence’,’fontsize’,TFS)
isequal(y1,y2)
41.
M ATLAB script:
100
80
Blackman
A (dB)
60
Hamming
s
Hann
40
Bartlett
20 Rectangular
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[peakH peakHind] = findpeak(Hdb);
Lshind = w(peakHind) > wc;
As = max(peakH(Lshind))
bandwid = delw*pi/L
%% Part (b)
beta = 1:9; Nbeta = length(beta);
As_kaiser = zeros(1,Nbeta);
bandwid_kaiser = zeros(1,Nbeta);
for ii = 1:Nbeta
hk = hd.*kaiser(L,beta(ii));
Hk = freqz(hk,1,w);
CHAPTER 10. Design of FIR Filters 696
Hkmag = abs(Hk);
Hkdb = 20*log10(Hkmag./max(Hkmag));
[peakHk peakHkind] = findpeak(Hkdb);
Lshind = w(peakHkind) > wc;
As_kaiser(ii) = abs(max(peakHk(Lshind)));
bandwid_kaiser(ii) = (As_kaiser(ii)-8)/M/2.285;
end
% Plot:
hfc = figconfg(’P1041c’,’small’);
plot(bandwid_kaiser,As_kaiser,’.-b’); hold on
xlabel(’Transition Bandwidth’,’fontsize’,LFS)
ylabel(’A_s (dB)’,’fontsize’,LFS)
% title(’Magnitude Response (dB)’,’fontsize’,TFS);
fw.name = {’Rectangular’,’Bartlett’,’Hann’,’Hamming’,’Blackman’};
fw.As = [21 26 44 53 74];
fw.bw = [1.8 6.1 6.2 6.6 11]*pi/L;
for jj = 1:5
plot(fw.bw(jj),fw.As(jj),’s-k’)
text(fw.bw(jj),fw.As(jj),[’ ’,fw.name{jj}],’fontsize’,LFS-4)
end
ylim([10 100]); xlim([0.1 1.2])
CHAPTER 10. Design of FIR Filters 697
Assessment Problems
42. (a) Proof:
(M +1)/2
jω
X 1
d[k] sin[ω(k − )]· je− jωM/2 , jA e jω e− jωM/2
H e =
2
k=1
(10.38)
d[k] = 2h[(M + 1)/2 − k], k = 1, 2, . . . , (M + 1)/2 (10.39)
M −1
M
X X2 M
X
jω
h[k] · e− jkω = h[k]e− jkω + h[k]e− jkω
H e =
k=0 k=0 k= M2+1
M −1 M −1
2 2
X X M + 1 − j(k+ M +1 )ω
= h[k]e− jkω + h[k + ]e 2
2
k=0 k=0
M −1 M −1
2 2
X X M + 1 − j(k+ 1 )ω − jωM/2
= h[k]e− j(k−M/2)ω + h[k + ]e 2 ·e
2
k=0 k=0
M −1 M −1
2 2
X M − 1 M −1 X M + 1 1
= h[ − k]e− j( 2 −k−M/2)ω − h[M − k − ]e− j(k+ 2 )ω · e− jωM
2 2
k=0 k=0
M −1
2
X M −1
M −1
= h[ − k]e j(k+1/2)ω − h[ − k]e− j(k+1/2)ω · e− jωM/2
2 2
k=0
M −1
2
X M − 1 1
= 2h[ − k] j sin(k + )ω · e− jωM/2
2 2
k=0
M +1
2
X 1
= d[k] sin(k − )ω · e j(π/2−ωM/2)
2
k=1
(b) Proof:
(M −1)/2
jω
ω X
˜ cos kω
Ae = sin( ) d[k] (10.40)
2
k=0
1 ˜ ˜
2 (2d[0] − d[1]), k=1
d[k] = 1 ˜ ˜
2 (d[k − 1] − d[k]), 2 ≤ k ≤ (M − 1)/2 (10.41)
1˜
2 d[(M − 1)/2], k = (M + 1)/2
CHAPTER 10. Design of FIR Filters 698
(M −1)/2
jω
ω X
˜ cos kω
Ae = sin( ) d[k]
2
k=0
(M −1)/2
1 X
˜
= d[k][sin(k + 1/2)ω − sin(k − 1/2)ω]
2
k=0
(M −1)/2
˜ − 1 d[1])
˜ sin ω + ˜ − 1] − d[k])
˜ 1
X
= (d[0] (d[k sin(k − )ω
2 2 2
k=2
1˜ M
+ d[(M − 1)/2] sin( ω)
2 2
4πn
− 0.04wR [n]e− j M
(b) tba.
44. tba
L = 21 L = 21
0 0
−20 −20
20log10|W(e )|
20log10|W(e )|
−31.5db
jω
jω
−40 −40 −44db
−60 −60
−80 −80
−100 −100
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π
L = 41 L = 41
0 0
−20 −20
20log10|W(e )|
−31.5db 20log10|W(e )|
jω
jω
−60 −60
−80 −80
−100 −100
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π
w = linspace(-1,1,Nw)*pi;
H = freqz(hw,1,w);
Hmag = abs(H);
Hmagdb = 20*log10(Hmag/max(Hmag));
[Ha w2 P2 L2] = amplresp(hw,w);
Hac = abs(cumsum(Ha));
Hacdb = 20*log10(Hac/max(Hac));
bandwid/pi*L
%% Plot:
hfa = figconfg(’P1045a’,’small’);
plot(w/pi,Hmagdb);hold on
plot(w/pi,sidlobeH*ones(1,Nw),’--k’)
text(w(Nw/5)/pi,sidlobeH,[num2str(sidlobeH,3),’db’],...
’fontsize’,LFS-2,’verticalalignment’,’bottom’)
ylim([-100 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’20log_{10}|W(e^{j\omega})|’,’fontsize’,LFS)
title([’L = ’,num2str(L)],’fontsize’,TFS)
hfb = figconfg(’P1045b’,’small’);
plot(w/pi,Hacdb); hold on
plot(w/pi,sidlobeHac*ones(1,Nw),’--k’)
text(w(Nw/5)/pi,sidlobeHac,[num2str(sidlobeHac,3),’db’],...
’fontsize’,LFS-2,’verticalalignment’,’bottom’)
ylim([-100 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’20log_{10}|W(e^{j\omega})|’,’fontsize’,LFS)
title([’L = ’,num2str(L)],’fontsize’,TFS)
−20 −20
20log10|W(e )|
20log10|W(e )|
jω
jω
−80 −80
−100 −100
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π
L = 41 L = 41
0 0
−20 −20
20log10|W(e )|
20log10|W(e )|
jω
jω
−40 −40 −44db
−58.1db
−60 −60
−80 −80
−100 −100
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π
%% Plot:
hfa = figconfg(’P1046a’,’small’);
plot(w/pi,Hmagdb);hold on
CHAPTER 10. Design of FIR Filters 702
plot(w/pi,sidlobeH*ones(1,Nw),’--k’)
text(w(Nw/5)/pi,sidlobeH,[num2str(sidlobeH,3),’db’],...
’fontsize’,LFS-2,’verticalalignment’,’bottom’)
ylim([-100 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’20log_{10}|W(e^{j\omega})|’,’fontsize’,LFS)
title([’L = ’,num2str(L)],’fontsize’,TFS)
hfb = figconfg(’P1046b’,’small’);
plot(w/pi,Hacdb); hold on
plot(w/pi,sidlobeHac*ones(1,Nw),’--k’)
text(w(Nw/5)/pi,sidlobeHac,[num2str(sidlobeHac,3),’db’],...
’fontsize’,LFS-2,’verticalalignment’,’bottom’)
ylim([-100 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’20log_{10}|W(e^{j\omega})|’,’fontsize’,LFS)
title([’L = ’,num2str(L)],’fontsize’,TFS)
0.4 −20
Decibels
0.2 −40
h(n)
0 −60
−0.2 −80
−0.4 −100
0 20 40 60 80 100 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB) −3
−4
x 10
Approximation Error 0
x 10
0
2
1
Passband dB
Stopband dB
Amplitude
0 −100 −2
−1
−2
0 0.2 0.4 0.6 0.8 1 −200 −4
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
0.4 −20
Decibels
0.2 −40
h(n)
0 −60
−0.2 −80
−0.4 −100
0 10 20 30 40 50 60 70 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
−3
x 10
Approximation Error 0 0
2
Stopband dB
−50 −0.005
Amplitude
−100 −0.01
−1
−2
0 0.2 0.4 0.6 0.8 1 −150 −0.015
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
M ATLAB script:
%% Part (a)
wc = (ws+wp)/2;
delw = wp-ws;
L = ceil(11*pi/delw); M = L - 1;
if mod(M,2) == 1
M = M + 1;
end
hd = ideallp(pi,M) - ideallp(wc,M);
CHAPTER 10. Design of FIR Filters 704
h = hd.*blackman(M+1);
%% Part (b)
[M,wn,beta,ftype] = kaiserord([0.4 0.5],[0 1],[deltas,deltap]);
h = fir1(M,wn,ftype,kaiser(M+1,beta));
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[Ha w2 P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
magz2 = nan(1,length(w));
ind = w <= ws;
aperr(ind) = Ha(ind);
magz1(ind) = Hdb(ind);
ind = w >= wp;
aperr(ind) = Ha(ind) - 1;
magz2(ind) = Hdb(ind);
%% Plot:
hfa = figconfg(’P1047a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1047b’,’small’);
plot(w/pi,Hdb);
ylim([-100 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1047c’,’small’);
plot(w/pi,aperr);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
CHAPTER 10. Design of FIR Filters 705
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1047d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(1),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
set(get(AX(2),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
−40
0
−0.2 −60
−80
0 10 20 30 40 50 60 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 0
0.01
0.005
Passband dB
Stopband dB
−0.05 −50
Amplitude
−0.1 −100
−0.005
−0.01
0 0.2 0.4 0.6 0.8 1 −0.15 −150
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
Decibels
0.1
h(n)
0 −40
−0.1
−60
−0.2
−0.3
−80
0 10 20 30 40 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 0
0.02
−20
0.01 −0.05
Passband dB
Stopband dB
Amplitude
−40
0 −0.1
−60
−0.01 −0.15
−80
−0.02
0 0.2 0.4 0.6 0.8 1 −0.2 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
delta = min([deltap,deltas]);
A = -20*log10(delta);
%% Part (a)
wc1 = (ws1+wp1)/2; wc2 = (ws2+wp2)/2;
dw = min([wp1-ws1,ws2-wp2]);
L = 6.2*pi/dw;
M = L-1;
if mod(M,2) == 1
M = M+1;
end
hd = ideallp(wc2,M) - ideallp(wc1,M);
h = hd.*hann(M+1);
%% Part (b)
% [M,wn,beta,ftype] = ...
% kaiserord([ws1 wp1 wp2 ws2]/pi,[0 1 0],[deltas,deltap, deltas]);
% h = fir1(M,wn,ftype,kaiser(M+1,beta));
CHAPTER 10. Design of FIR Filters 707
Decibels
h(n)
−40
0
−0.2 −60
−80
0 10 20 30 40 50 60 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 0
0.01
−20
0.005
Passband dB
Stopband dB
−0.05
Amplitude
−40
0
−60
−0.1
−0.005
−80
−0.01
0 0.2 0.4 0.6 0.8 1 −0.15 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
%% Part (c)
% h = fir1(M,[wc1 wc2]/pi,’DC-0’,hann(M+1));
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[Ha w2 P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
magz2 = nan(1,length(w));
ind = w <= ws1;
aperr(ind) = Ha(ind);
magz2(ind) = Hdb(ind);
ind = (w >= wp1 & w <= wp2);
aperr(ind) = Ha(ind) - 1;
magz1(ind) = Hdb(ind);
ind = w >= ws2;
aperr(ind) = Ha(ind);
CHAPTER 10. Design of FIR Filters 708
magz2(ind) = Hdb(ind);
%% Plot:
hfa = figconfg(’P1048a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1048b’,’small’);
plot(w/pi,Hdb);
ylim([-80 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1048c’,’small’);
plot(w/pi,aperr);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1048d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(1),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
set(get(AX(2),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
set(AX(2),’Ylim’,[-100 0],’YTick’,-100:20:0)
Decibels
0.4
h(n)
−30
0.2
−40
0
−50
−0.2 −60
0 10 20 30 40 50 60 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
−3
x 10
Approximation Error 0 −50
2
1 −0.005 −60
Passband dB
Stopband dB
Amplitude
0 −0.01 −70
−1 −0.015 −80
−2 −0.02 −90
−3
0 0.2 0.4 0.6 0.8 1 −0.025 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
%% Part (a)
wc1 = (ws1+wp1)/2; wc2 = (ws2+wp2)/2;
[M,wn,beta,ftype] = ...
kaiserord([wp1 ws1 ws2 wp2]/pi,[1 0 1],[deltap,deltas, deltap]);
hd = ideallp(wc1,M) + ideallp(pi,M) - ideallp(wc2,M);
h = hd.*kaiser(M+1,beta);
%% Part (b)
h = fir1(M,[wc1 wc2]/pi,’stop’,kaiser(M+1,beta));
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[Ha w2 P2 L2] = amplresp(h(:)’,w);
CHAPTER 10. Design of FIR Filters 710
Decibels
0.4
h(n)
−30
0.2
−40
0
−50
−0.2 −60
0 10 20 30 40 50 60 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
−3
x 10
Approximation Error 0 −50
2
1 −0.005 −60
Passband dB
Stopband dB
Amplitude
0 −0.01 −70
−1 −0.015 −80
−2 −0.02 −90
−3
0 0.2 0.4 0.6 0.8 1 −0.025 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
magz2 = nan(1,length(w));
ind = w <= wp1;
aperr(ind) = Ha(ind) - 1;
magz1(ind) = Hdb(ind);
ind = (w >= ws1 & w <= ws2);
aperr(ind) = Ha(ind);
magz2(ind) = Hdb(ind);
ind = w >= wp2;
aperr(ind) = Ha(ind) - 1;
magz1(ind) = Hdb(ind);
%% Plot:
hfa = figconfg(’P1049a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
CHAPTER 10. Design of FIR Filters 711
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1049b’,’small’);
plot(w/pi,Hdb);
ylim([-60 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1049c’,’small’);
plot(w/pi,aperr);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1049d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(1),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
set(get(AX(2),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
50.
Impulse Response Magnitude Response
0.6 1
0.4
0.8
Amplitude
0.2
h(n)
0.6
0
−0.2 0.4
−0.4
0.2
−0.6
0
0 10 20 30 40 0 0.5 1 1.5 2 2.5 3
n ω
FIGURE 10.68: Plots of impulse response and magnitude response of the designed
type-III Hilbert transformer.
M ATLAB script:
M = 40; L = M + 1; n = 0:M;
alpha = M/2; na = (n-alpha);
Dw = 2*pi/L;
w1 = 0*Dw; w2 = L/2*Dw;
hd = (cos(w1*na)-cos(w2*na))./(pi*na); hd(alpha+1) = 0;
h = hd.*hamming(L)’;
%% Part b:
% dd = 1e-6;
% h = fir1(M,[dd 1-dd],’DC-0’,hamming(M+1));
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Ha = abs(H);
%% Plot:
hfa = figconfg(’P1050a’,’small’);
stem(n,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1050b’,’small’);
plot(w,Ha);
xlim([0 pi]);ylim([0 1.1])
xlabel(’\omega’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Magnitude Response’,’fontsize’,TFS)
51.
M ATLAB script:
Decibels
0.2 −40
h(n)
0.1 −60
0
−80
−0.1
−100
0 5 10 15 20 25 30 35 0 0.3 0.5 1
n ω/π
Zoom of Magnitude Response (dB)
−3
x 10
Approximation Error 0 0
3
−0.005 −20
2
Passband dB
Stopband dB
−0.01
Amplitude
1 −40
−0.015
0 −60
−0.02
−1 −80
−0.025
−2
0 0.2 0.4 0.6 0.8 1 −0.03 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
Dw = 2*pi/L;
om = (0:L-1)*Dw;
wc = (wp+ws)/2;
k = floor(wc/Dw);
Ap = [ones(1,k+1),zeros(1,L-2*k-1),ones(1,k)];
h = fir2(M,[0 wc/pi wc/pi 1],[1 1 0 0]);
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[Ha w2 P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
magz2 = nan(1,length(w));
ind = w <= wp;
aperr(ind) = Ha(ind) - 1;
magz1(ind) = Hdb(ind);
ind = w >= ws;
CHAPTER 10. Design of FIR Filters 714
aperr(ind) = Ha(ind);
magz2(ind) = Hdb(ind);
%% Plot:
hfa = figconfg(’P1051a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1051b’,’small’);
plot(w/pi,Hdb);hold on
plot(w/pi,-As*ones(1,length(w)),’--’,’color’,’k’)
ylim([-100 0])
set(gca,’XTick’,[0 wp ws pi]/pi,’Xgrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1051c’,’small’);
plot(w/pi,aperr);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1051d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(1),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
set(get(AX(2),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
set(AX(2),’Ylim’,[-100 0],’YTick’,-100:20:0)
0.4
−20
Decibels
0.2
h[n]
−40
0
−60
−0.2
−0.4 −80
0 5 10 15 20 25 30 0 0.5 1 1.5 2
n ω/π
FIGURE 10.70: Plots of impulse response and magnitude response of the designed
highpass filter using raised-cosine transition.
0.2 −40
h[n]
0 −60
−0.2 −80
−0.4 −100
0 5 10 15 20 25 30 0 0.5 1 1.5 2
n ω/π
FIGURE 10.71: Plots of impulse response and magnitude response of the designed
highpass filter using the fir2 function and the Hamming window.
%% Part a
CHAPTER 10. Design of FIR Filters 716
Hd = Ad.*exp(1j*psid);
hd = real(ifft(Hd));
h = hd.*rectwin(L)’;
%% Part b
ind = om < pi;
h = fir2(M,[om(ind) pi]/pi,[Ad(ind) 1]);
%% Plot
w = linspace(0,2,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag/max(Hmag));
hfa = figconfg(’P1052a’,’small’);
plot(w/pi,Hdb);hold on
plot(w/pi,-As*ones(1,length(w)),’--’,’color’,’k’)
% ylim([-As-30 0])
ylim([-100 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfb = figconfg(’P1052a’,’small’);
stem(0:M,h,’filled’)
xlim([0 M])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h[n]’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfc = figconfg(’P1052c’,’small’);
plot(w/pi,Hmag);hold on
plot(om/pi,Ad,’.’,’color’,’r’)
ylim([0 max(Hmag)+0.1])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Magnitude’,’fontsize’,LFS)
title(’Magnitude Response’,’fontsize’,TFS)
0.2 −20
Decibels
h[n]
0 −40
−0.2 −60
−0.4 −80
0 10 20 30 40 0 0.5 1 1.5 2
n ω/π
FIGURE 10.72: Plots of impulse response and magnitude response of the designed
bandpass filter using linear transition.
0 −40
−0.2 −60
−0.4 −80
0 10 20 30 40 0 0.5 1 1.5 2
n ω/π
FIGURE 10.73: Plots of impulse response and magnitude response of the designed
bandpass filter using the fir2 function and the Hann window.
M ATLAB script:
%% Part a
k1 = floor(ws1/Dw);
k2 = ceil(wp1/Dw);
CHAPTER 10. Design of FIR Filters 718
k3 = floor(wp2/Dw);
k4 = ceil((ws2-0.05*pi)/Dw);
ind = (om>ws1 & om<wp1);
A = (om(ind)-ws1)/(wp1-ws1);
Ad = [zeros(1,k1+1),A,ones(1,k3-k2+1),fliplr(A),zeros(1,L-k4*2+1),...
A,ones(1,k3-k2+1),fliplr(A),zeros(1,k1)];
Hd = Ad.*exp(j*psid);
hd = real(ifft(Hd));
h = hd.*rectwin(L)’;
%% Part b
% ind = om < pi;
% h = fir2(M,[om(ind) pi]/pi,[Ad(ind) 0],hann(L));
%% Plot
w = linspace(0,2,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag/max(Hmag));
hfa = figconfg(’P1053a’,’small’);
plot(w/pi,Hdb);hold on
plot(w/pi,-As1*ones(1,length(w)),’--’,’color’,’k’)
ylim([-80 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfb = figconfg(’P1053a’,’small’);
stem(0:M,h,’filled’)
xlim([0 M])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h[n]’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfc = figconfg(’P1053c’,’small’);
plot(w/pi,Hmag);hold on
plot(om/pi,Ad,’.’,’color’,’r’)
ylim([0 max(Hmag)+0.1])
xlabel(’\omega/\pi’,’fontsize’,LFS)
CHAPTER 10. Design of FIR Filters 719
ylabel(’Magnitude’,’fontsize’,LFS)
title(’Magnitude Response’,’fontsize’,TFS)
54.
Impulse Response Magnitude Response (dB)
0
0.6
−20
0.4
Decibels
−40
h(n)
0.2 −60
0 −80
−0.2 −100
0 10 20 30 40 0 0.3 0.4 0.6 0.7 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 0
0.1
0 −20
−1
Passband dB
Stopband dB
Amplitude
−0.1 −40
−2
−0.2 −60
−0.3 −3
−80
−0.4
0 0.2 0.4 0.6 0.8 1 −4 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
M ATLAB script:
%% Part a
CHAPTER 10. Design of FIR Filters 720
0.6
−20
0.4
Decibels
−40
h(n)
0.2 −60
0 −80
−0.2 −100
0 10 20 30 40 0 0.3 0.4 0.6 0.7 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 0
0.1
0 −1 −20
Passband dB
Stopband dB
Amplitude
−0.1 −2 −40
−0.2 −3 −60
−0.3 −4 −80
−0.4
0 0.2 0.4 0.6 0.8 1 −5 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
%% Part b
% ind = om < pi;
% h = fir2(M,[om(ind) pi]/pi,[Ad(ind) 1],rectwin(L));
CHAPTER 10. Design of FIR Filters 721
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[Ha w2 P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
magz2 = nan(1,length(w));
ind = w <= wp1;
aperr(ind) = Ha(ind) - 1;
magz1(ind) = Hdb(ind);
ind = (w >= ws1 & w <= ws2);
aperr(ind) = Ha(ind);
magz2(ind) = Hdb(ind);
ind = w >= wp2;
aperr(ind) = Ha(ind) - 1;
magz1(ind) = Hdb(ind);
%% Plot:
hfa = figconfg(’P1054a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1054b’,’small’);
plot(w/pi,Hdb);hold on
plot(w/pi,-As*ones(1,length(w)),’--’,’color’,’k’)
ylim([-100 0])
set(gca,’XTick’,[0 wp1 ws1 ws2 wp2 pi]/pi,’Xgrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1054c’,’small’);
plot(w/pi,aperr);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
CHAPTER 10. Design of FIR Filters 722
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1054d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(1),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
set(get(AX(2),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
set(AX(2),’Ylim’,[-100 0],’YTick’,-100:20:0)
hfe = figconfg(’P1054e’,’small’);
plot(w/pi,Hmag);hold on
ind = om < pi;
plot(om(ind)/pi,Ad(ind),’.’,’color’,’r’)
ylim([0 max(Hmag)+0.1])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Magnitude’,’fontsize’,LFS)
title(’Magnitude Response’,’fontsize’,TFS)
0.2 −0.5
h(n)
0
−0.2 −1
−0.4
−0.6
−1.5
0 10 20 30 40 50 0 0.2 0.4 0.6 0.8 1
n ω/π
FIGURE 10.76: Plots of impulse response and amplitude response of the designed
Hilbert transformer.
y(n)
0 0
−0.5 −0.5
−1 −1
50 100 150 50 100 150
n n
M = 50;
n = 0:M; L = M+1; % Impulse response length
alpha = M/2; Q = floor(alpha); % phase delay parameters
k = 0:M; % Frequency sample index
Dw = 2*pi/L; % Width between frequency samples
% Transformer Design using Frequency Sampling (Smooth transition)
Ad = [0,sin(pi/4),ones(1,23),0.5,-0.5,-ones(1,23),-sin(pi/4)];
psid = -alpha*2*pi/L*[(0:Q),-(L-(Q+1:M))]; % Desired Phase
Hd = -1j*Ad.*exp(1j*psid); % Desired Freq Resp Samples
hd = real(ifft(Hd)); % Desired Impulse response
h = hd.*rectwin(L)’; % Actual Impulse response
w = linspace(0,1,1000)*pi;
[Ha wt P2 L2] = amplresp(h(:)’,w);
%% Plot:
hfa = figconfg(’P1055a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1055b’,’small’);
plot(w/pi,Ha);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Amplitude Response’,’fontsize’,TFS)
CHAPTER 10. Design of FIR Filters 724
%% Part b: verification
nn = 0:150;
xn = sin(0.3*pi*nn);
yn = filter(h,1,xn);
ind = nn >= 50;
hfc = figconfg(’P1055c’,’long’);
subplot(121)
stem(nn(ind),xn(ind),’filled’);
ylim([-1.1 1.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’x(n)’,’fontsize’,LFS)
title(’Input Sequence’,’fontsize’,TFS)
subplot(122)
stem(nn(ind),yn(ind),’filled’);
ylim([-1.1 1.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’y(n)’,’fontsize’,LFS)
title(’Output Sequence’,’fontsize’,TFS)
56. tba
57.
M ATLAB script:
w = linspace(0,1,1000)*pi;
CHAPTER 10. Design of FIR Filters 725
0.2 −20
0.1
Decibels
−40
h(n)
0
−60
−0.1
−0.2 −80
−0.3 −100
0 10 20 30 40 0 0.7 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 0
0.05
−0.2
Passband dB
Stopband dB
Amplitude
0 −50 −0.4
−0.6
−0.05
0 0.2 0.4 0.6 0.8 1 −100 −0.8
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[Ha w2 P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
magz2 = nan(1,length(w));
ind = w <= ws;
aperr(ind) = Ha(ind);
magz1(ind) = Hdb(ind);
ind = w >= wp;
aperr(ind) = Ha(ind)-1;
magz2(ind) = Hdb(ind);
%% Plot:
hfa = figconfg(’P1057a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
CHAPTER 10. Design of FIR Filters 726
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1057b’,’small’);
plot(w/pi,Hdb);hold on
plot(w/pi,-As*ones(1,length(w)),’--’,’color’,’k’)
ylim([-100 0])
set(gca,’XTick’,[0 ws wp pi]/pi,’Xgrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1057c’,’small’);
plot(w/pi,aperr);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1057d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(2),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
set(get(AX(1),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
set(AX(1),’Ytick’,[-100 -50 0],’ylim’,[-100 0])
58.
M ATLAB script:
0.6 −20
Decibels
0.4
h(n)
−40
0.2
0 −60
−0.2 −80
0 10 20 30 40 0 0.35 0.45 0.55 0.65 1
n ω/π
Zoom of Magnitude Response (dB)
Approximation Error 0 0
0.01
Passband dB
Stopband dB
0.004 −0.05 −50
Amplitude
−0.01
0 0.2 0.4 0.6 0.8 1 −0.15 −150
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
deltap1,
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[Ha w2 P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
magz2 = nan(1,length(w));
ind = w <= wp1;
aperr(ind) = Ha(ind)-1;
magz1(ind) = Hdb(ind);
ind = w >= ws1 & w <= ws2;
aperr(ind) = Ha(ind);
magz2(ind) = Hdb(ind);
ind = w >= wp2;
aperr(ind) = Ha(ind)-1;
magz1(ind) = Hdb(ind);
%% Plot:
CHAPTER 10. Design of FIR Filters 728
hfa = figconfg(’P1058a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1058b’,’small’);
plot(w/pi,Hdb);hold on
% plot(w/pi,-As*ones(1,length(w)),’--’,’color’,’k’)
ylim([-80 0])
set(gca,’XTick’,[0 wp1 ws1 ws2 wp2 pi]/pi,’Xgrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1058c’,’small’);
plot(w/pi,aperr);
delYtick = sort(unique([deltap1 deltap2 deltas]));
set(gca,’Ytick’,[-delYtick(end:-1:1) 0 delYtick],’Ygrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1058d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(2),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
set(get(AX(1),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
59.
M ATLAB script:
0.4 −20
Decibels
0.2 −40
h(n)
0 −60
−0.2 −80
−100
0 10 20 30 40 50 0 0.3 0.4 0.7 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
−3
x 10
Approximation Error 0 −40
−2 −60
Passband dB
Stopband dB
Amplitude
1
0 −4 −80
−1
−6 −100
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag./max(Hmag));
[Ha ww P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
magz2 = nan(1,length(w));
ind = w <= w1;
aperr(ind) = Ha(ind)-A1;
CHAPTER 10. Design of FIR Filters 730
magz2(ind) = Hdb(ind);
ind = w >= w2 & w <= w3;
aperr(ind) = Ha(ind)-A2;
magz1(ind) = Hdb(ind);
ind = w >= w4;
aperr(ind) = Ha(ind)-A3;
magz1(ind) = Hdb(ind);
%% Plot:
hfa = figconfg(’P1059a’,’small’);
stem(0:M,h,’filled’);
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1059b’,’small’);
plot(w/pi,Hdb);hold on
plot(w/pi,-As*ones(1,length(w)),’--’,’color’,’k’)
ylim([-100 0])
set(gca,’XTick’,[0 w1 w2 w3 w4 pi]/pi,’Xgrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
hfc = figconfg(’P1059c’,’small’);
plot(w/pi,aperr);
delYtick = sort([delta1 delta2 delta3]);
set(gca,’Ytick’,[-delYtick(end:-1:1) 0 delYtick],’Ygrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfd = figconfg(’P1059d’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(2),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
set(get(AX(1),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
CHAPTER 10. Design of FIR Filters 731
0
−0.2 −1
−0.4
−0.6
−1.5
0 10 20 30 40 0 0.2 0.4 0.6 0.8 1
n ω/π
FIGURE 10.81: Plots of impulse response and amplitude response of the designed
FIR differentiator.
w = linspace(0,1,1000)*pi;
H = freqz(h,1,w);
[Ha wa P2 L2] = amplresp(h(:)’,w);
aperr = nan(1,length(w));
ind = (w >= w1 & w <= w2);
aperr(ind) = Ha(ind)+1;
n = 0:150;
xn = 10*cos(0.2*pi*n);
yn = filter(h,1,xn);
indn = n >= 50 & n <= 100;
%% Plot:
hfa = figconfg(’P1039a’,’small’);
stem(0:M,h,’filled’);
CHAPTER 10. Design of FIR Filters 732
Input Sequence
10
5
x[n]
−5
−10
50 55 60 65 70 75 80 85 90 95 100
Time Index n
Output Sequence
10
5
y[n]
−5
−10
50 55 60 65 70 75 80 85 90 95 100
Time Index n
xlim([0 M])
ylim([min(h)-0.1 max(h)+0.1])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1039b’,’small’);
plot(w/pi,Ha);hold on
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Amplitude Response’,’fontsize’,TFS)
hfc = figconfg(’P1039c’);
subplot(211)
stem(n(indn),xn(indn),’filled’)
ylim([-10 10])
xlabel(’Time Index n’,’fontsize’,LFS)
ylabel(’x[n]’,’fontsize’,LFS)
title(’Input Sequence’,’fontsize’,TFS)
CHAPTER 10. Design of FIR Filters 733
subplot(212)
stem(n(indn),yn(indn),’filled’)
ylim([-10 10])
xlabel(’Time Index n’,’fontsize’,LFS)
ylabel(’y[n]’,’fontsize’,LFS)
title(’Output Sequence’,’fontsize’,TFS)
CHAPTER 10. Design of FIR Filters 734
Review Problems
61. (a) See plot below.
Impulse Response Amplitude Response
0.6
1
0.4 0.8
Amplitude
0.6
h(n)
0.2
0.4
0 0.2
0
−0.2
0 10 20 30 40 50 60 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
Magnitude Response (dB) 0 0
0
Hamming, M = 65
−20 Passband dB
Stopband dB
Decibels
−40
−60
−80
0 0.2 0.4 0.6 0.8 1 −0.05
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
0.4 0.8
Amplitude
0.6
h(n)
0.2
0.4
0 0.2
0
−0.2
0 10 20 30 40 50 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
Magnitude Response (dB) 0 0
0
Kaiser, M = 58
−20
Passband dB
Stopband dB
Decibels
−40
−60
−80
0 0.2 0.4 0.6 0.8 1 −0.05
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
%% Part c: Parks-McClellan
[Mpm,fo,ao,W] = firpmord([w1,w2]/pi,[1,0],[deltap,deltas]);
Mpm = Mpm + 2
[hpm,delta] = firpm(Mpm,fo,ao,W);
CHAPTER 10. Design of FIR Filters 736
0.4 0.8
Amplitude
0.6
h(n)
0.2
0.4
0 0.2
0
−0.2
0 5 10 15 20 25 30 35 0 0.2 0.4 0.6 0.8 1
n ω/π
Zoom of Magnitude Response (dB)
Magnitude Response (dB) 0
0
Parks McCllelan, M = 36
−20
Passband dB
Stopband dB
Decibels
−60
−80
0 0.2 0.4 0.6 0.8 1 −1 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π
delta,
deltap,
%% Plot:
% hp = hfw; M = Mfw; Method = ’Hamming’; % Part a
% hp = hkai; M = Mk; Method = ’Kaiser’; % Part b
hp = hpm; M = Mpm; Method = ’Parks McCllelan’;% Part c
w = linspace(0,1,1000)*pi;
H = freqz(hp,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag/max(Hmag));
[Ha wt P2 L2] = amplresp(hp(:)’,w);
aperr = nan(1,length(w));
magz1 = nan(1,length(w));
magz2 = nan(1,length(w));
ind = w <= w1;
aperr(ind) = Ha(ind) - 1;
magz1(ind) = Hdb(ind);
ind = w >= w2;
CHAPTER 10. Design of FIR Filters 737
aperr(ind) = Ha(ind);
magz2(ind) = Hdb(ind);
yn = filter(hp,1,xn);
hfa = figconfg(’P1061a’,’small’);
stem(0:M,hp,’filled’);
xlim([0 M])
xlabel(’n’,’fontsize’,LFS)
ylabel(’h(n)’,’fontsize’,LFS)
title(’Impulse Response’,’fontsize’,TFS)
hfb = figconfg(’P1061b’,’small’);
plot(w/pi,Ha);
ylim([-0.1 1.1])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Amplitude Response’,’fontsize’,TFS)
hfc = figconfg(’P1061c’,’small’);
plot(w/pi,Hdb);
ylim([-80 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Decibels’,’fontsize’,LFS)
title(’Magnitude Response (dB)’,’fontsize’,TFS)
legend([Method,’, M = ’,num2str(M)],’location’,’northeast’)
hfd = figconfg(’P1061d’,’small’);
plot(w/pi,aperr);
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Approximation Error’,’fontsize’,TFS)
hfe = figconfg(’P1061e’,’small’);
[AX hf1 hf2] = plotyy(w/pi,magz1,w/pi,magz2);
set(AX(2),’ylim’,[-100 0])
xlabel(’\omega/\pi’,’fontsize’,LFS)
title(’Zoom of Magnitude Response (dB)’,’fontsize’,TFS)
set(get(AX(1),’Ylabel’),’string’,’Passband dB’,’fontsize’,LFS)
set(get(AX(2),’Ylabel’),’string’,’Stopband dB’,’fontsize’,LFS)
CHAPTER 10. Design of FIR Filters 738
hff = figconfg(’P1061f’,’long’);
plot(n,xn,n,yn)
xlabel(’n’,’fontsize’,LFS)
title(’Time Sequences’,’fontsize’,TFS)
legend(’input’,’output’,’location’,’best’)
CHAPTER 10. Design of FIR Filters 739
Time Sequences
20
input
10 output
−10
−20
0 20 40 60 80 100 120 140 160 180 200
n
(a)
Time Sequences
20
input
10 output
−10
−20
0 20 40 60 80 100 120 140 160 180 200
n
(b)
Time Sequences
20
input
10 output
−10
−20
0 20 40 60 80 100 120 140 160 180 200
n
(c)
FIGURE 10.86: Plot of input and output sequences passing through filters designed
by (a) Hamming window. (b) Kaiser window. (c) Parks-McClellan.
CHAPTER 10. Design of FIR Filters 740
Amplitude Response
0
Hamming, M = 131
−10
−20
Amplitude
−30
−40
−50
−60
Amplitude Response
0
Kaiser, M = 116
−10
−20
Amplitude
−30
−40
−50
−60
n = 0:200;
xn = 10*cos(0.2*pi*n)+sin(0.5*pi*n)+15*cos(0.9*pi*n+pi/3);
indn = n >= 100;
Amplitude Response
0
Frequency Sampling, M = 101
−10
−20
Amplitude
−30
−40
−50
−60
Amplitude Response
0
Parks McCllelan, M = 72
−10
−20
Amplitude
−30
−40
−50
−60
%% Part d: Parks-McClellan
[Mpm,fo,ao,W] = ...
firpmord([ws1,wp1,wp2,ws2]/pi,[0,1,0],[deltas,deltap, deltas]);
Mpm = Mpm + 5
[hpm,delta] = firpm(Mpm,fo,ao,W);
delta,
deltap
%% Plot:
% hp = hfw; M = Mfw; Method = ’Hamming’; % Part a
% hp = hkai; M = Mk; Method = ’Kaiser’; % Part b
% hp = hfs; M = Mfs; Method = ’Frequency Sampling’; % Part c
hp = hpm; M = Mpm; Method = ’Parks McCllelan’;% Part d
w = linspace(0,1,1000)*pi;
CHAPTER 10. Design of FIR Filters 744
hfb = figconfg(’P1062b’,’long’);
plot(n(indn),xn(indn),n(indn),yn(indn))
xlabel(’n’,’fontsize’,LFS)
title(’Time Sequences’,’fontsize’,TFS)
legend(’input’,’output’,’location’,’best’)
hfc = figconfg(’P1062c’);
plot(w/pi,Hdb); hold on
plot(w/pi,-Ap*ones(1,length(w)),’--’,’color’,’k’)
plot(w/pi,-As*ones(1,length(w)),’--’,’color’,’k’)
ylim([-A-20 0])
set(gca,’Xtick’,[0 ws1 wp1 wp2 ws2 pi]/pi,’Xgrid’,’on’)
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Amplitude Response’,’fontsize’,TFS)
legend([Method,’, M = ’,num2str(M)],’location’,’northwest’)
CHAPTER 10. Design of FIR Filters 745
Time Sequences
20
10
−10
−20 input
output
−30
100 110 120 130 140 150 160 170 180 190 200
n
(a)
Time Sequences
20
10
−10
−20 input
output
−30
100 110 120 130 140 150 160 170 180 190 200
n
(b)
Time Sequences
20
10
−10
−20 input
output
−30
100 110 120 130 140 150 160 170 180 190 200
n
(c)
Time Sequences
20
10
−10
−20 input
output
−30
100 110 120 130 140 150 160 170 180 190 200
n
(d)
FIGURE 10.91: Plot of input and output sequences passing through filters designed
by (a) Hamming window. (b) Kaiser window. (c) Frequency-sampling. (d) Parks-
McClellan.
CHAPTER 10. Design of FIR Filters 746
Amplitude Response
4.3
Hann, M = 124
4 ω = 0.746π δ = 0.026
6 p2
Amplitude
δ = 0.012
p1
2.1
1.9 ω2 = 0.245π ω3 = 0.455π
Amplitude Response
4.3
Kaiser, M = 88
4 ω = 0.747π δ = 0.056
6 p2
Amplitude
δ = 0.028
p1
2.1
1.9 ω2 = 0.246π ω3 = 0.454π
δ = 0.022 δ = 0.046
s1 ω = 0.202π ω = 0.498π s2 ω = 0.700π
0.05 1 4 5
−0.05
0 0.2 0.25 0.45 0.5 0.7 0.75 1
ω/π
A = -20*log10(delta);
Amplitude Response
4.3
Frequency Sampling, M = 84
4 ω = 0.750π δ = 0.107
6 p2
Amplitude
δ = 0.101
p1
2.1
1.9 ω2 = 0.248π ω3 = 0.449π
δ = 0.063 δ = 0.145
s1 ω = 0.199π ω = 0.501π s2 ω = 0.700π
0.05 1 4 5
−0.05
0 0.2 0.25 0.45 0.5 0.7 0.75 1
ω/π
[deltas1,deltap1,deltas2/4.5]);
if mod(Mk,2)==1
Mk = Mk + 1;
end
hkai1 = fir1(Mk,[wbp1 wbp2]/pi,’DC-0’,kaiser(Mk+1,beta));
hkai2 = fir1(Mk,whp/pi,’high’,kaiser(Mk+1,beta));
hkai = G2*hkai1 + G4*hkai2;
%% Part d: Parks-McClellan
[Mpm,fo,ao,W] = firpmord([ws1,wp1,wp2,ws2,ws3,wp3]/pi,[G1,G2,G3,G4],...
CHAPTER 10. Design of FIR Filters 749
Amplitude Response
4.3
Parks McCllelan, M = 80
4 ω = 0.747π δ = 0.035
6 p2
Amplitude
δ = 0.048
p1
2.1
1.9 ω2 = 0.244π ω3 = 0.452π
δ = 0.048 δ = 0.048
s1 ω = 0.199π ω = 0.501π s2 ω = 0.700π
0.05 1 4 5
−0.05
0 0.2 0.25 0.45 0.5 0.7 0.75 1
ω/π
[deltas1,deltap1, deltas2,deltap2]);
Mpm = Mpm + 34
[hpm,delta] = firpm(Mpm,fo,ao,W);
delta,
% deltas,
deltas1
%% Plot:
hp = hfw; M = Mfw; Method = ’Hann’; % Part a
% hp = hkai; M = Mk; Method = ’Kaiser’; % Part b
% hp = hfs; M = Mfs; Method = ’Frequency Sampling’; % Part c
% hp = hpm; M = Mpm; Method = ’Parks McCllelan’;% Part d
w = linspace(0,1,1000)*pi;
[Ha wt P2 L2] = amplresp(hp(:)’,w);
% hfa = figconfg(’P1063a’,’small’);
CHAPTER 10. Design of FIR Filters 750
hfa = figconfg(’P1063a’);
plot(w/pi,Ha,’linewidth’,2);
ylim([-0.1 G4+0.2])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Amplitude Response’,’fontsize’,TFS)
set(gca,’XTick’,[0 ws1 wp1 wp2 ws2 ws3 wp3 pi]/pi)
set(gca,’YTick’,[-deltas1 deltas1 G2-deltap1 G2+deltap1...
G4-deltap2 G4+deltap2])
grid on
%% Part e:
legend([Method,’, M = ’,num2str(M)],’location’,’best’)
ind = w <= ws1;
d1 = max(abs(Ha(ind)));
text(w(100)/pi,deltas1,[’\delta_{s1} = ’,num2str(d1,’%.3f’)]...
,’HorizontalAlignment’,’center’,’verticalalignment’,...
’bottom’,’fontsize’,LFS-4)
ind = (w>=wp1 & w <= wp2);
d2 = max(abs(Ha(ind)-G2));
text(w(350)/pi,G2+deltap1,[’\delta_{p1} = ’,num2str(d2,’%.3f’)]...
,’HorizontalAlignment’,’center’,’verticalalignment’,...
’bottom’,’fontsize’,LFS-4)
ind = (w>=ws2 & w <= ws3);
d3 = max(abs(Ha(ind)));
text(w(600)/pi,deltas1,[’\delta_{s2} = ’,num2str(d3,’%.3f’)]...
,’HorizontalAlignment’,’center’,’verticalalignment’,...
’bottom’,’fontsize’,LFS-4)
ind = w >= wp3;
d4 = max(abs(Ha(ind)-G4));
text(w(875)/pi,G4-deltap2,[’\delta_{p2} = ’,num2str(d4,’%.3f’)]...
,’HorizontalAlignment’,’center’,’verticalalignment’,...
’top’,’fontsize’,LFS-4)
ind1 = Ha>deltas1;
ind2 = (w > ws1 & w < wp1);
ind = ind1(:) & ind2(:);
f1 = find(ind==1,1,’first’)-1;
text(w(f1)/pi,deltas1,[’ \omega_1 = ’,...
num2str(w(f1)/pi,’%.3f’),’\pi’],’fontsize’,LFS-4,...
’horizontal’,’left’,’verticalalignment’,’middle’)
CHAPTER 10. Design of FIR Filters 751
ind1 = Ha<G2-deltap1;
ind2 = (w > ws1 & w < wp1);
ind = ind1(:) & ind2(:);
f2 = find(ind==1,1,’last’)+1;
text(w(f2)/pi,G2-deltap1,[’ \omega_2 = ’,...
num2str(w(f2)/pi,’%.3f’),’\pi’],’fontsize’,LFS-4,...
’horizontal’,’left’,’verticalalignment’,’top’)
ind1 = Ha<G2-deltap1;
ind2 = (w > wp2 & w < ws2);
ind = ind1(:) & ind2(:);
f3 = find(ind==1,1,’first’)-1;
text(w(f3)/pi,G2-deltap1,[’ \omega_3 = ’,...
num2str(w(f3)/pi,’%.3f’),’\pi’],’fontsize’,LFS-4,...
’horizontal’,’left’,’verticalalignment’,’top’)
ind1 = Ha>deltas1;
ind2 = (w > wp2 & w < ws2);
ind = ind1(:) & ind2(:);
f4 = find(ind==1,1,’last’)+1;
text(w(f4)/pi,deltas1,[’ \omega_4 = ’,...
num2str(w(f4)/pi,’%.3f’),’\pi’],’fontsize’,LFS-4,...
’horizontal’,’right’,’verticalalignment’,’middle’)
ind1 = Ha>deltas1;
ind2 = (w > ws3 & w < wp3);
ind = ind1(:) & ind2(:);
f5 = find(ind==1,1,’first’)-1;
text(w(f5)/pi,deltas1,[’ \omega_5 = ’,...
num2str(w(f5)/pi,’%.3f’),’\pi’],’fontsize’,LFS-4,...
’horizontal’,’left’,’verticalalignment’,’middle’)
ind1 = Ha<G4-deltap2;
ind2 = (w > ws3 & w < wp3);
ind = ind1(:) & ind2(:);
f6 = find(ind==1,1,’last’)+1;
text(w(f6)/pi,G4-deltap2,[’ \omega_6 = ’,...
num2str(w(f6)/pi,’%.3f’),’\pi’],’fontsize’,LFS-4,...
’horizontal’,’right’,’verticalalignment’,’top’)
CHAPTER 10. Design of FIR Filters 752
Amplitude Response
3.3 Hann, M = 124
δ = 0.014
p2
ω4 = 0.517π ω5 = 0.712π
2.7
2.2 δ = 0.013
p1
Amplitude
ω1 = 0.209π
1.8
ω6 = 0.745π δ = 0.013
p3
1.1
0.9
δ = 0.013
ω2 = 0.247π s1 ω3 = 0.476π
0.05
−0.05
0 0.2 0.25 0.45 0.55 0.7 0.75 1
ω/π
Amplitude Response
3.3 Kaiser, M = 68
δ = 0.090
p2
ω4 = 0.518π ω5 = 0.711π
2.7
2.2 δ = 0.052
p1
Amplitude
ω1 = 0.207π
1.8
ω = 0.748π δ = 0.039
p3
1.1 6
0.9
δs1 = 0.039
ω2 = 0.250π ω3 = 0.473π
0.05
−0.05
0 0.2 0.25 0.45 0.55 0.7 0.75 1
ω/π
A = -20*log10(delta);
Amplitude Response
3.3 Frequency Sampling, M = 60
δ = 0.075
p2
ω4 = 0.541π ω5 = 0.708π
2.7
2.2 δ = 0.107
p1
Amplitude
ω1 = 0.202π
1.8
ω = 0.750π δ = 0.069
p3
1.1 6
0.9
δs1 = 0.064
ω2 = 0.250π ω3 = 0.451π
0.05
−0.05
0 0.2 0.25 0.45 0.55 0.7 0.75 1
ω/π
[Mk,wn,beta,ftype] = ...
kaiserord([ws2 wp2 wp3 wp4]/pi,[0 1 0],...
[deltas,deltap2,deltas/2]);
if mod(Mk,2)==1
Mk = Mk + 1;
end
hkai1 = fir1(Mk,wlp/pi,kaiser(Mk+1,beta));
hkai2 = fir1(Mk,[wbp1 wbp2]/pi,’DC-0’,kaiser(Mk+1,beta));
hkai3 = fir1(Mk,whp/pi,’high’,kaiser(Mk+1,beta));
hkai = G1*hkai1 + G3*hkai2 + G4*hkai3;
Amplitude Response
3.3 Parks McCllelan, M = 50
δ = 0.095
p2
ω4 = 0.523π ω5 = 0.707π
2.7
2.2 δ = 0.096
p1
Amplitude
ω1 = 0.203π
1.8
ω = 0.751π δ = 0.095
p3
1.1 6
0.9
δs1 = 0.048
ω2 = 0.250π ω3 = 0.472π
0.05
−0.05
0 0.2 0.25 0.45 0.55 0.7 0.75 1
ω/π
%% Part d: Parks-McClellan
[Mpm,fo,ao,W] = firpmord([wp1,ws1,ws2,wp2,wp3,wp4]/pi,[G1,G2,G3,G4],...
[deltap1,deltas, deltap2,deltap3]);
Mpm = Mpm + 14
[hpm,delta] = firpm(Mpm,fo,ao,W);
delta,
deltap1,
%% Plot:
hp = hfw; M = Mfw; Method = ’Hann’; % Part a
% hp = hkai; M = Mk; Method = ’Kaiser’; % Part b
% hp = hfs; M = Mfs; Method = ’Frequency Sampling’; % Part c
% hp = hpm; M = Mpm; Method = ’Parks McCllelan’;% Part d
w = linspace(0,1,1000)*pi;
[Ha wt P2 L2] = amplresp(hp(:)’,w);
CHAPTER 10. Design of FIR Filters 756
hf = figconfg(’P1064’);
plot(w/pi,Ha,’linewidth’,2);
ylim([-0.1 G3+0.4])
xlabel(’\omega/\pi’,’fontsize’,LFS)
ylabel(’Amplitude’,’fontsize’,LFS)
title(’Amplitude Response’,’fontsize’,TFS)
set(gca,’XTick’,[0 wp1 ws1 ws2 wp2 wp3 wp4 pi]/pi)
set(gca,’YTick’,[-deltas deltas G4-deltap3 G4+deltap3...
G1-deltap1 G1+deltap1 G3-deltap2 G3+deltap2])
grid on
%% Part e:
legend([Method,’, M = ’,num2str(M)],’location’,’northwest’)
ind = w <= wp1;
d1 = max(abs(Ha(ind)-G1));
text(w(100)/pi,G1+0.15,[’\delta_{p1} = ’,num2str(d1,’%.3f’)]...
,’HorizontalAlignment’,’center’,’verticalalignment’,...
’middle’,’fontsize’,LFS-4)
ind = (w>=ws1 & w <= ws2);
d2 = max(abs(Ha(ind)));
text(w(350)/pi,deltas,[’\delta_{s1} = ’,num2str(d2,’%.3f’)]...
,’HorizontalAlignment’,’center’,’verticalalignment’,...
’bottom’,’fontsize’,LFS-4)
ind = (w>=wp2 & w <= wp3);
d3 = max(abs(Ha(ind)-G3));
text(w(625)/pi,G3+0.15,[’\delta_{p2} = ’,num2str(d3,’%.3f’)]...
,’HorizontalAlignment’,’center’,’verticalalignment’,...
’middle’,’fontsize’,LFS-4)
ind = w >= wp4;
d4 = max(abs(Ha(ind)-G4));
text(w(875)/pi,G4+0.15,[’\delta_{p3} = ’,num2str(d4,’%.3f’)]...
,’HorizontalAlignment’,’center’,’verticalalignment’,...
’middle’,’fontsize’,LFS-4)
ind1 = Ha<G1-deltap1;
ind2 = (w > wp1 & w < ws1);
ind = ind1(:) & ind2(:);
f1 = find(ind==1,1,’first’)-1;
text(w(f1)/pi,G1-deltap1,[’ \omega_1 = ’,...
CHAPTER 10. Design of FIR Filters 757
num2str(w(f1)/pi,’%.3f’),’\pi’],’fontsize’,LFS-4,...
’horizontal’,’left’,’verticalalignment’,’middle’)
ind1 = Ha>deltas;
ind2 = (w > wp1 & w < ws1);
ind = ind1(:) & ind2(:);
f2 = find(ind==1,1,’last’)+1;
text(w(f2)/pi,deltas,[’ \omega_2 = ’,...
num2str(w(f2)/pi,’%.3f’),’\pi’],’fontsize’,LFS-4,...
’horizontal’,’right’,’verticalalignment’,’middle’)
ind1 = Ha>deltas;
ind2 = (w > ws2 & w < wp2);
ind = ind1(:) & ind2(:);
f3 = find(ind==1,1,’first’)-1;
text(w(f3)/pi,deltas,[’ \omega_3 = ’,...
num2str(w(f3)/pi,’%.3f’),’\pi’],’fontsize’,LFS-4,...
’horizontal’,’left’,’verticalalignment’,’middle’)
ind1 = Ha<G3-deltap2;
ind2 = (w > ws2 & w < wp2);
ind = ind1(:) & ind2(:);
f4 = find(ind==1,1,’last’)+1;
text(w(f4)/pi,G3-deltap2,[’ \omega_4 = ’,...
num2str(w(f4)/pi,’%.3f’),’\pi’],’fontsize’,LFS-4,...
’horizontal’,’right’,’verticalalignment’,’middle’)
ind1 = Ha<G3-deltap2;
ind2 = (w > wp3 & w < wp4);
ind = ind1(:) & ind2(:);
f5 = find(ind==1,1,’first’)-1;
text(w(f5)/pi,G3-deltap2,[’ \omega_5 = ’,...
num2str(w(f5)/pi,’%.3f’),’\pi’],’fontsize’,LFS-4,...
’horizontal’,’left’,’verticalalignment’,’middle’)
ind1 = Ha>G4+deltap3;
ind2 = (w > wp3 & w < wp4);
ind = ind1(:) & ind2(:);
f6 = find(ind==1,1,’last’)+1;
text(w(f6)/pi,G4+deltap3,[’ \omega_6 = ’,...
num2str(w(f6)/pi,’%.3f’),’\pi’],’fontsize’,LFS-4,...
’horizontal’,’right’,’verticalalignment’,’middle’)
Another random document with
no related content on Scribd:
Captain Codrington to sir Charles Cotton.
“Off Taragona, June 23, 1811.
“Another regiment arrived from Carthagena yesterday under
convoy of the Cossack, but, as on a former occasion, their arms
were taken from them by colonel Roche, upon their going to embark,
and therefore, as being of no use to the garrison, I have by desire of
the general sent them to Villa Nueva, and as there are already 2000
men in the place without arms, I have sent the Termagant to
Carthagena, to endeavour to procure those which have been thus
inconsiderately taken from the troops belonging to that place.”
(Extract.)
(Translated.)
“I saw myself reduced to my own garrison.” “I considered if my
force was capable of this effort (defending the breach), one of the
most heroic that war furnishes, and to which few men can bring
themselves. I recollected however that I had still eight thousand of
the best and most experienced troops in Spain.” “All conspired
against this poor garrison. Campo Verde in quitting the place
promised to come back quickly to its succour, but he did not,
although he daily renewed his promises. The kingdom of Valencia
sent Miranda with a division which disembarked, and the day
following re-embarked and went to join Campo Verde.
“An English division came on the 26th, colonel Skerrett, who
commanded them, came in the evening to confer with me and to
demand what I wished him to do. I replied that if he would disembark
and enter the place, he should be received with joy and treated as
he merited; that he had only to choose the point that he wished to
defend and I would give it to him, but that all was at his choice, since
I would neither command nor counsel him. The 27th the English
commandants of artillery and engineers came to examine the front
attacked, and being convinced that the place was not in a state to
resist, returned to their vessels, and then all went away from the
place they came to succour.
“This abandonment on the part of those who came to save was
the worst of all; it made such an impression on the soldiers, that they
began to see that they were lost, became low-spirited and only
resisted from my continual exhortations, and because they saw my
coolness and the confidence I had, that if they executed my orders
the French would fail. But this only lasted a few hours, the notion of
being abandoned again seized them and overcame all other ideas.”
Captain Codrington to sir C. Cotton.
“12th July, 1811.
“The vacillating conduct of general Contreras regarding the
defence of Taragona is a principal feature in the loss of that
important fortress.”
(Extract.)
“20th July, 1811.
“The disasters which have befallen the principality will produce
material accusations against the generals who lately commanded in
it, without, I fear, any of them meeting the punishment which is their
due. Some of the enclosed papers may help you to form a just
opinion of their conduct and that of the Spanish marine; and those
respecting the arms for which I sent to Carthagena will show how far
colonel Roche is entitled to the merit which he so largely assumes
on that occasion.”
“To enable you to form a correct opinion of general Contreras I
must refer you to general Doyle, as from his ignorance of our
service, the various requests and proposals which arose from the
vacillations in what he called his determinations, were signified to me
through him. It does not appear to me that he ever visited the works
himself, or it would not have fallen to the lot of captain Adams and
myself to remove two boats, two large stages, sixteen gun-carriages,
and a mortar from the mole, long after the French were advanced
beyond the Francoli battery, and two nights previous to their gaining
the Puerto; an accidental visit to the mole one night, just after placing
the gun-boats and launches, discovered to me this mortar with no
less than twelve guns in readiness for forming a battery; and upon
general Doyle, by my request, representing this to the general of
artillery, he talked of inquiring into it to-morrow.”
“It would be a waste of words to describe further the conduct of the
general of artillery, or I might find sufficient subject in the events of
every passing day from the first investment of the place.”——“I shall
be very ready to come forward personally in aid of that justice which
is due to the numberless brave men who fell a sacrifice to the
criminality of the persons alluded to who have so grossly
misconducted themselves.”
section 2.
(Extract.)
“H.M.S. Undaunted, off Arens, 7th Oct. 1811.
“Having observed, in the Catalonia Gazette of the 24th of
September, the copy of a letter said to be written by colonel Green to
his excellency general Lacy, relative to our operations on the Medas
Islands, from the surrender of the castle to the period of our quitting
them, I beg leave to state to you my surprise and astonishment at
seeing facts so grossly misrepresented, and request you will be
pleased to contradict in the most positive manner the assertions
there made use of. To prove how inconsistent this letter is with real
facts, it may be necessary for me only to say that colonel Green, in
the presence and hearing of all the English officers, on my asking
him a question relative to the practicability of keeping the island, did
declare that he had nothing to do with the expedition; that my
instructions pointed him out as a volunteer only. But immediately
after, in the hearing of all, did declare it to be his opinion that the
island was not tenable.
“As I understood it was intended to form an establishment on the
larger island, I judged it proper to retire from it for a short time and
destroy the remains of the castle, which might induce the enemy to
withdraw from the works he had thrown up, and thereby afford our
ally an opportunity whenever he chose to occupy them again, to
fortify himself without molestation; and this supposition it has
appeared was well grounded. But while the ruins of the castle stood,
it was an object of jealousy to the French; nor would they in my
opinion have quitted the ground they occupied, nor the Spaniards
have been enabled to settle themselves, had this measure not been
adopted. I therefore gave orders for embarking the guns and stores.
“If necessary, I could say much more on the subject of this most
extraordinary letter; the few remarks I have made will, I think, be
sufficient. As an act of courtesy to colonel Green, on landing the
marines I directed the marine officers to receive their orders from
him; but military aid was not necessary, for you may recollect before
the expedition sailed, on your informing me that general Lacy had
offered some Spanish troops, and asking how many I thought would
be necessary, my answer was ‘about forty;’ and I have no hesitation
in declaring that without the assistance of even a single soldier the
castle would have fallen into our hands as speedily as it did on this
occasion.
section 3.
Ditto to ditto.
“18th July, 1811.
“I cannot describe to you the difficulties which I have been put to
by the misconduct of all the Spanish ships and vessels of war which
I have had to communicate with upon the coast, with exception of
the Astrea frigate and the Paloma corvette. In the others I have seen
neither courage to oppose the enemy nor humanity to alleviate the
distresses of their countrymen.”——“I have heard also that the
Algesiras, which lately arrived at Arens, has landed the stores and
ammunition, with which she was charged, at the risk of their falling
into the hands of the enemy, and has quitted the station!”
section 4.
section 5.
section 1.
GENERALS.
Ditto to ditto.
“Madrid, 13 Août, 1810.
“Parmi les lettres que m’a porté le courrier d’Andalousie arrivé
hier, j’en remarque une de monsieur Aranza écrite dans un stile
étudié et que je soupçonne redigée d’accord avec le duc de
Dalmatie. C’est un panégyrique à la louange de ce maréchal dans
lequel monsieur d’Aranza porte aux nues l’intelligence et la zêle du
duc de Dalmatie dans la partie administrative; la considération qu’il
donne aux autorités espagnoles; son extrême adresse à manier les
esprits, et l’habilité de ses dispositions militaires, dans un pays
couvert d’insurgés. M. d’Aranza termine en formant le vœu que le
maréchal ne soit aucunement troublé dans l’exécution de ses plans,
et que le sort de l’Andalousie soit mis entièrement a sa discretion.”
Ditto to ditto.
“Madrid, le 23 Août, 1810.
“Par ma correspondance avec l’Andalousie j’ai appris; de
Cordone: que M. Angulo à reçu les lettres qui l’appellent à Madrid, et
qu’il se dispose à suivre le grand convoi sorti de Seville le 11 du
courant. De Seville: qu’un corsaire Française s’étant emparé d’un
paquebot qui allait de Cadiz à Alicante, on y avait trouvé entr’autres
depêches une lettre de Campmany, grand partisan des Anglais, et
un des Coryphées de la revolution. Il avouait à son ami, don
Anselmo Rodriguez de Ribas, intendant de l’armée du centre, qui
s’était plaint à lui des excès que commettaient certaines juntes, que
Cadiz n’offrait pas un spectacle moins digne de pitié: que les Anglais
qu’il avait appris à connaître s’arrogaient peu à peu toute l’autorité:
que le commerce libre accordé aux ports d’Amerique excitait à Cadiz
un mécontentement général, et que Venegas allait au Méxique en
qualité de viceroi: il parle en outre de l’arrestation de plusieurs
personnes connues, et de la de considération dans laquelle est
tombée la régence.”
Ditto to ditto.
“Madrid, 27 Septembre, 1810.
“Le maréchal Victor permet le passage à beaucoup de femmes qui
veulent se réunir a leurs maris, les femmes en contant les choses
telles qu’elles sont, détruisent bien des erreurs dans lesquelles on a
généralement été entrainé par le gouvernement actuel. L’ennemi
permit ces jours derniers l’entrée dans l’île à plusieurs femmes qui
voulaient passer par Chiclanes pour se réunir à leurs parents, mais
dernièrement elles furent contenus à coups de canon, et un boulet
emporta la tête de celui qui les accompagnait. Le gouvernement
Anglais preside à toutes les opérations, et crainte cette espèce des
communications.”
Ditto to ditto.
“Madrid, le 13 Novembre, 1810.
“Monsieur Pereyra a reçu du maréchal Soult une réponse
extrêmement aigre. Ce commissaire royal persiste dans son opinion
que les mesures indiquées par le duc de Dalmatie pour
l’approvisionnement de l’armée ne rempliront pas le but qu’il se
propose; mais le maréchal veut être obéi. D’un autre côté le général
Sebastiani l’a contraint à lui donner onze cent mille réaux. Placé
entre ces deux écueils, Monsieur Pereyra a perdu courage et
demande à votre majesté de le rappeller à Madrid. Le général
Dufour a pris le commandement de Grenade.
“Mariano Luis de Orquijo.”
Ditto to ditto.
“Madrid, 19 de Decembre, 1810.
“Monsieur le comte de Montarco était le 11 courant a Manzanares,
il m’écrit que les habitans de la Manche se plaignent de ce que les
troupes qui retrouvent dans la province ne les protégent pas autant
que leur nombre le leur permet, que les brigands viennent leur
enlever leurs grains pour les transporter dans les royaumes de
Valence et de Murcie, ou dans l’Estremadoure. Ils craignent une
disette et désirent ardemmement qu’il se forme de grands dépôts de
grains dans des places à l’abri des incursions des partis d’insurgés.
Les commandants des troupes Françaises sont d’une exigence et
d’une hauteur insupportables, et les rapports faits au comte de
Montarco par toutes les autorités légales du pays confirment
complettement ceux que l’intendant de la Manche ne cesse de faire
aux divers ministères depuis plusieurs mois.”
section 2.