Download as pdf or txt
Download as pdf or txt
You are on page 1of 154

Applied Digital Signal Processing 1st

Edition Manolakis Solutions Manual


Go to download the full and correct content document:
https://testbankfan.com/product/applied-digital-signal-processing-1st-edition-manolaki
s-solutions-manual/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Introduction to Digital Signal Processing 1st Edition


Blandford Solutions Manual

https://testbankfan.com/product/introduction-to-digital-signal-
processing-1st-edition-blandford-solutions-manual/

Digital Signal Processing using MATLAB 3rd Edition


Schilling Solutions Manual

https://testbankfan.com/product/digital-signal-processing-using-
matlab-3rd-edition-schilling-solutions-manual/

Digital Signal Processing Using MATLAB A Problem


Solving Companion 4th Edition Ingle Solutions Manual

https://testbankfan.com/product/digital-signal-processing-using-
matlab-a-problem-solving-companion-4th-edition-ingle-solutions-
manual/

Discrete Time Signal Processing 3rd Edition Oppenheim


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/

Image Processing and Analysis 1st Edition Birchfield


Solutions Manual

https://testbankfan.com/product/image-processing-and-
analysis-1st-edition-birchfield-solutions-manual/

Digital Business Networks 1st Edition Dooley Solutions


Manual

https://testbankfan.com/product/digital-business-networks-1st-
edition-dooley-solutions-manual/

Introduction To Digital Communications 1st Edition


Pursley Solutions Manual

https://testbankfan.com/product/introduction-to-digital-
communications-1st-edition-pursley-solutions-manual/

Introduction to Digital Communications 1st Edition


Grami Solutions Manual

https://testbankfan.com/product/introduction-to-digital-
communications-1st-edition-grami-solutions-manual/
CHAPTER 10

Design of FIR Filters

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:

h[n] = 2he [n]u[n] − he [0]δ[n] (10.14)


Z π  
jω 1 jθ ω−θ
HI (e ) = − HR (e ) cot dθ (10.16)
2π −π 2
First, we have

1 x 1 X 1 1
cot( ) = + −
2 2 x x + 2nπ 2nπ
n=1


1 X
DTFT(u[n]) = U (e jω ) = + πδ(ω − 2πk)
1 − e− jω
k=−∞

Hence,
π
1
Z

H(e ) = 2 × HR (e jθ )U (e j(ω−θ) )dθ − h[0]
2π −π

where


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

Hence, we proved that


π  
1 ω−θ
Z
jω jθ
HI (e ) = − HR (e ) cot dθ
2π −π 2
CHAPTER 10. Design of FIR Filters 630

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

 ω 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ω)

Hence, the magnitude response is:

|H e jω | = (1 + cos ω + cos 2ω + cos 3ω)2 + (sin ω + sin 2ω + sin 3ω)2


 p

(b) Solution:
2

 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

Magnitude Response Amplitude Response


4

3
3
2
2
1

1 0

0 −1
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π

FIGURE 10.1: Plots of magnitude and amplitude responses.

Phase Response Angle Response


4 5

0 0

−2

−4 −5
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π

FIGURE 10.2: Plots of phase and angle responses.


CHAPTER 10. Design of FIR Filters 633

5. Proof:
Part I: Prove expression for A e jω for M = 6 type-III linear-phase FIR


filter.
We have

h[n] = −h[M − n], 0 ≤ n ≤ M, M = 6, h[3] = 0

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

Part II: Prove expression for A e jω for M = 5 type-IV linear-phase FIR




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

6. (a) See plot below.

Amplitude Response
30

20

10

−10
0 0.2 0.4 0.6 0.8 1
ω/π

FIGURE 10.3: Plot of amplitude response from h1 [n].

(b) See plot below.


(c) See plot below.
(d) See plot below.
CHAPTER 10. Design of FIR Filters 635

Amplitude Response
20

15

10

0
0 0.2 0.4 0.6 0.8 1
ω/π

FIGURE 10.4: Plot of amplitude response from h2 [n].

Amplitude Response
0

−5

−10

−15

−20
0 0.2 0.4 0.6 0.8 1
ω/π

FIGURE 10.5: Plot of amplitude response from h3 [n].

Amplitude Response
30

20

10

−10
0 0.2 0.4 0.6 0.8 1
ω/π

FIGURE 10.6: Plot of amplitude response from h4 [n].


CHAPTER 10. Design of FIR Filters 636

7. (a) See plot below.


Impulse Response Amplitude Response
15

4
10

A(e )
2


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

FIGURE 10.7: Plots of impulse response, amplitude response, magnitude response


and pole-zero distribution in part (a).

(b) See plot below.


(c) See plot below.
(d) See plot below.
(e) tba.
M ATLAB script:

% P1007: Reproduce Figures 10.4 and 10.5


close all; clc
%% Part a: Type-I
% hn = [1 2 3 -2 5 -2 3 2 1];
% w = linspace(-1,1,1000)*pi;

%% 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

Impulse Response Amplitude Response


3 10

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

FIGURE 10.8: Plots of impulse response, amplitude response, magnitude response


and pole-zero distribution in part (b).

% 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

Impulse Response Amplitude Response


3 10

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

FIGURE 10.9: Plots of impulse response, amplitude response, magnitude response


and pole-zero distribution in part (c).

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

Impulse Response Amplitude Response


3 10

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

FIGURE 10.10: Plots of impulse response, amplitude response, magnitude re-


sponse and pole-zero distribution in part (d).

8. (a) See plot below.

0db
L = 21
0

−10
20log10|W(e )|

−20

−30

−40

−50
−1 −0.5 0 0.5 1
ω/π

FIGURE 10.11: Plot of the log-magnitude response in dB over −π ≤ ω ≤ π when


L = 21.

(b) See plot below.


(c) See plot below.
M ATLAB script:

% P1008: Stude fixed window magnitude response


% its peak of first side-lobe and transition bandwidth
CHAPTER 10. Design of FIR Filters 640

0db
L = 21
0

−10

20log10|W(e )|

−20

−30

−40

−50
−1 −0.5 0 0.5 1
ω/π

FIGURE 10.12: Plot of the accumulated amplitude response in dB over −π ≤ ω ≤


π when L = 21.

0db
L = 41
0

−10
20log10|W(e )|

−20

−30

−40

−50
−1 −0.5 0 0.5 1
ω/π

FIGURE 10.13: Plot of the log-magnitude response in dB over −π ≤ ω ≤ π when


L = 41.

% 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));

%% Find Peak Values:


[peakH peakHind] = findpeak(Hmagdb);
CHAPTER 10. Design of FIR Filters 641

0db
L = 41
0

−10

20log10|W(e )|

−20

−30

−40

−50
−1 −0.5 0 0.5 1
ω/π

FIGURE 10.14: Plot of the accumulated amplitude response in dB over −π ≤ ω ≤


π when L = 41.

[peakHac peakHacind] = findpeak(Hacdb);


Lh = floor(length(peakH)/2);
sidlobeH = max(peakH(1:Lh));
sidlobeHac = max(peakHac(1:Lh));
bandwid = w(peakHacind(Lh+1)) - w(peakHacind(Lh));
bandwid/pi*L

%% 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 )|


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 )|


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:

% P1009: Design multiband filter using rectangular window


% change window length for performance comparison
close all; clc
% M = 10;
% M = 20;
% M = 40;
M = 60;
h1 = 0.5*fir1(M,0.2,’high’,rectwin(M+1));
h2 = 0.5*fir1(M,[0.4 0.6 0.8],’DC-0’,rectwin(M+1));
h = h1 + h2;
w = linspace(-1,1,1000)*pi;
H = freqz(h,1,w);
%% Plot:
hfa = figconfg(’P1008a’,’small’);
plot(w/pi,abs(H));
ylim([0 1.5])
xlabel(’\omega/\pi’,’fontsize’,LFS)
CHAPTER 10. Design of FIR Filters 643

ylabel(’|H(e^{j\omega})|’,’fontsize’,LFS)
title(’Magnitude Response’,’fontsize’,TFS)
legend([’M = ’,num2str(M)],’location’,’northeast’)

10. (a) See plot below.


Impulse Response Magnitude Response (dB)
0
0.6
−20
0.4

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
ω/π

FIGURE 10.16: Impulse response, magnitude response, approximation error and


zoom of magnitude response of the highpass FIR filter using fixed window design.

(b) See plot below.


M ATLAB script:

% P1010: Design highpass filter using appropriate window


close all; clc
ws = 0.3*pi; wp = 0.5*pi;
As = 50; Ap = 0.001;
[deltap, deltas] = spec_convert(Ap,As,’rel’,’abs’);
delta = min([deltap,deltas]);
A = -20*log10(delta);
[M,wn,beta,ftype] = kaiserord([0.3 0.5],[0 1],[deltas,deltap]);
%% Part (a)
wc = (ws+wp)/2;
% h = ideallp(pi,M) - ideallp(wc,M);
CHAPTER 10. Design of FIR Filters 644

Impulse Response Magnitude Response (dB)


0
0.6
−20
0.4

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
ω/π

FIGURE 10.17: Impulse response, magnitude response, approximation error and


zoom of magnitude response of the highpass FIR filter using fixed window design
by fir1 function.

% 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)

11. (a) See plot below.


(b) See plot below.
(c) See plot below.
M ATLAB script:

% P1011: Study Frequency Sampling Technique of


% different number of samples
close all; clc
% L = 20; % Part a
L = 400; % Part b & c
CHAPTER 10. Design of FIR Filters 646

Magnitude Response
1.2
1
0.8

Magnitude
0.6
0.4
0.2
0
0 0.5 1 1.5 2
ω/π

FIGURE 10.18: Magnitude response when L = 20 in part (a).

Magnitude Response
1.2

1
0.8
Magnitude

0.6

0.4

0.2
0
0 0.5 1 1.5 2
ω/π

FIGURE 10.19: Magnitude response when L = 400 in part (b).

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
ω/π

FIGURE 10.20: Magnitude response when L = 400 in part (c).

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)

12. (a) See plot below.


Magnitude Response
0

−10
Magnitude

−20

−30

−40

−50

−60
0 0.5 1 1.5 2
ω/π

FIGURE 10.21: Magnitude response when L = 20 in part (a).

(b) See plot below.


(c) See plot below.
M ATLAB script:

% P1012: Lowpass filter design by frequency sampling


close all; clc
% L = 20; % Part a
L = 40; % Part b & c
CHAPTER 10. Design of FIR Filters 648

Magnitude Response
0

−10

Magnitude
−20

−30

−40

−50

−60
0 0.5 1 1.5 2
ω/π

FIGURE 10.22: Magnitude response when L = 40 in part (b).

Magnitude Response
0

−10
Magnitude

−20

−30

−40

−50

−60
0 0.5 1 1.5 2
ω/π

FIGURE 10.23: Magnitude response when L = 40 in part (c).

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)

13. (a) Proof:

cos[(n + 1)ω] = cos nω cos ω − sin nω sin ω


cos[(n − 1)ω] = cos nω cos ω + sin nω sin ω
which implies that

cos[(n + 1)ω] + cos[(n − 1)ω] = 2 cos nω cos ω

that is

cos[(n + 1)ω] = 2 cos(ω) cos(nω) − cos[(n − 1)ω]

(b) Proof:
Define θ = cos−1 x, we have

Tn+1 (x) = cos[(n + 1)ω] = 2 cos θ cos nθ − cos[(n − 1)θ]


= 2x · cos(nθ) − cos(n − 1)θ
= 2xTn (x) − Tn−1 (x)
CHAPTER 10. Design of FIR Filters 650

(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

14. (a) See plot below.


Iter = 1
1.1 0.1
e(x)
δ
1 −δ 0.05
f(x)
P2(x)
0.9 0

0.8 −0.05

0.7 −0.1
0 0.2454 0.7546 1

FIGURE 10.24: Graph of f (x), the resulting P2 (x), and e(x).

(b) See plot below.


Iter = 3
1.1 0.1
e(x)
δ
1 −δ 0.05
f(x)
0.9 P2(x)
0

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

% P1014: Illustration of realization of alternation theorem


function [coeff] = main_1014
close all; clc
fx = @(x) 1-2*x+4*x.^2-2*x.^3;
x_init = [0 1/3 2/3 1];
x_loc = x_init;
ii = 0;
thresh_x = 1;
thresh_ex = 1;
while thresh_x > 1e-10 && thresh_ex > 1e-5
ii = ii + 1;
coeff = coeff_solver(x_loc);
N = 10000;
xp = linspace(0,1,N);
a0 = coeff(1); a1 = coeff(2); a2 = coeff(3); delta = coeff(4);
Px = @(x) a0+a1*x+a2*x.^2;
ex = fx(xp)-Px(xp);

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’)

[extrema extrema_loc] = find_extrema(ex,xp);


set(Ax(1),’Xtick’,extrema_loc,’Xgrid’,’on’)
set(Ax(2),’Xtick’,[],’Xgrid’,’on’)
title([’Iter = ’,num2str(ii)],’fontsize’,14)

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

function [extrema extrema_loc] = find_extrema(fx,x)


% Find the locations of extrema of fx
% Inputs:
% x: independent variable, value between 0 and 1
% fx: dependent values
% Output:
% extrema: values of x where fx is an extrema
fx = fx(:)’;
a1 = [0,diff(fx)];
a2 = fliplr([0,diff(fliplr(fx))]);
a = abs(sign(a1) + sign(a2));
ind = find(a>0);
extrema_loc = x(ind);
extrema = fx(ind);
end

15. tba

16.
M ATLAB script:

% P1016: Design highpass FIR filter using Parks-McClellan


close all; clc
CHAPTER 10. Design of FIR Filters 653

Impulse Response Magnitude Response (dB)


0.4 0

−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
ω/π

FIGURE 10.26: Graph of impulse response, magnitude response, approximation


error and zoom magnitude response.

%% 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
ω/π

FIGURE 10.27: Graph of impulse response, magnitude response, approximation


error and zoom magnitude response.

M ATLAB script:

% P1017: Design multiband FIR filter using Parks-McClellan


close all; clc
%% Specification:
ws = 0.3*pi; wp1 = 0.4*pi; wp2 = 0.7*pi; wp3 = 0.75*pi;
deltas = 0.001; deltap1 = 0.005; deltap2 = 0.01;
%% Estimated Filter order using FIRPMORD function:
[M,fo,ao,W] = ...
firpmord([ws,wp1,wp2,wp3]/pi,[0,0.5,1],[deltas,deltap1,deltap2]);
M = M + 2
%% Filter Design using FIRPM function:
[h,delta] = firpm(M,fo,ao,W);
delta,
deltap1,

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

[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])

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:

% P1018: Design a wideband type-III differentiator


% using frequency sampling approach
close all; clc
M = 32;
L = M + 1;
Dw = 2*pi/L;
om = (0:L-1)*Dw;
ind = om >= pi;
om(ind) = om(ind) - 2*pi;
alpha = M/2;
H = j*om.*exp(-j*om*alpha);
hd = real(ifft(H));
h = hd.*hamming(L)’;

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:

% P1019: Design Hilbert transformer using Parks-McClellan


close all; clc
L = 51; M = L-1;
w1 = 0.05*pi; w2 = 0.95*pi;
CHAPTER 10. Design of FIR Filters 659

[h,delta] = firpm(M,[w1 w2]/pi,[1 1],’hilbert’);

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:

function [A,B] = spec_convert(C,D,typein,typeout)


% typein: ’abs’ or ’rel’ or ’ana’
% typeout: ’abs’ or ’rel’ or ’ana’
% C, D: input specifications
% A, B: output specifications
if strcmpi(typein,’abs’)
A = 20*log10((1+C)/(1-C));
B = 20*log10((1+C)/D);
elseif strcmpi(typein,’ana’)
A = 20*log10(sqrt(1+C^2));
B = 20*log10(D);
elseif strcmpi(typein,’rel’)
A = C;
B = D;
end

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

22. (a) Proof:


 
M/2
X

c[k] sin ωk je− jωM/2 , jA e jω e−jωM/2
 
H e =
k=1
(10.34)
c[k] = 2h[M/2 − k], k = 1, 2, . . . , M/2 (10.35)
Since h[M/2] = 0, we have

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

23. (a) Solution:


The impulse response is:
Z π Z π
1 − jnd ω jωn 1
hlp [n] = e · e dω = e− jω(n−nd ) dω
2π −π 2π −π
 
1 1 π sin π(n − nd )
= e− jω(n−nd ) =
2π − j(n − nd ) −π π(n − nd )
= sinc(n − nd )

(b) Proof:
DTFT
x[n] −→ X e jω


Y e jω = X e jω · Hlp e jω = X e jω · e− jnd ω
   

Applying time-shifting property, we have

y[n] = x[n − nd ]

24. tba

25. (a) Solution:


 
1 1 1  j 2πn − j 2πn
w[n] = − × e M −e M wR [n]
2 2 2
1 1 2πn 1 2πn
= wR [n] − wR [n] · e j M + wR [n] · e− j M
2 4 4
Hence, we have
 1  1 2π  1 2π 
W e jω = WR e jω − WR e j(ω− M ) + WR e j(ω+ M )
2 4 4
(b) Comments:
The second and third terms widen the mainlobe of Hann window and
the sidelobes are lowed by the scaling factor.
CHAPTER 10. Design of FIR Filters 663

26. (a) See plot below.


(b) See plot below.
L = 21 L = 21
0 0

−20 −25.9db −20


20log10|W(e )|

20log10|W(e )|


−40 −40

−60 −60

−80 −80

−100 −100
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π

FIGURE 10.30: Log-magnitude response in dB and accumulated amplitude re-


sponse in dB when window length is L = 21.

(c) See plot below.


L = 41 L = 41
0 0

−20 −26.4db −20


20log10|W(e )|

20log10|W(e )|

−40 −40

−60 −60

−80 −80

−100 −100
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π

FIGURE 10.31: Log-magnitude response in dB and accumulated amplitude re-


sponse in dB when window length is L = 41.

M ATLAB script:

% P1026: Stude fixed window magnitude response


% its peak of first side-lobe and transition bandwidth
% Bartlett Window
close all; clc
% L = 21; % Part a
L = 41; % Part b
hw = bartlett(L)’;
Nw = 10000;
w = linspace(-1,1,Nw)*pi;
H = freqz(hw,1,w);
CHAPTER 10. Design of FIR Filters 664

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));

%% Find Peak Values:


[peakH peakHind] = findpeak(Hmagdb);
[valleyH valleyHind] = findvalley(Hmagdb);
[tempL indL] = find(w(valleyHind)<=-1e-3);
[tempR indR] = find(w(valleyHind)>=1e-3);
bandwid = w(valleyHind(indR(1))) - w(valleyHind(indL(end)));
[peakHac peakHacind] = findpeak(Hacdb);
Lshind = w(peakHind) < -1e-3;
sidlobeH = max(peakH(Lshind));

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

27. (a) See plot below.


(b) See plot below.
L = 21 L = 21
0 0

−20 −20
20log10|W(e )|

20log10|W(e )|


−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
ω/π ω/π

FIGURE 10.32: Log-magnitude response in dB and accumulated amplitude re-


sponse in dB when window length is L = 21.

(c) See plot below.


L = 41 L = 41
0 0

−20 −20
20log10|W(e )|

20log10|W(e )|

−40 −42.1db −40


−53.8db
−60 −60

−80 −80

−100 −100
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π

FIGURE 10.33: Log-magnitude response in dB and accumulated amplitude re-


sponse in dB when window length is L = 41.

M ATLAB script:

% P1027: Stude fixed window magnitude response


% its peak of first side-lobe and transition bandwidth
% Hamming Window
close all; clc
% L = 21; % Part a
L = 41; % Part b
hw = hamming(L)’;
% Nw = 1000;
Nw = 10000;
w = linspace(-1,1,Nw)*pi;
CHAPTER 10. Design of FIR Filters 666

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));

%% Find Peak Values:


[peakH peakHind] = findpeak(Hmagdb);
[peakHac peakHacind] = findpeak(Hacdb);
Lshind = w(peakHind) < -1e-3;
sidlobeH = max(peakH(Lshind));
Lshind = w(peakHacind) < 0;
[sidlobeHac slind] = max(peakHac(Lshind));
bandwid = w(peakHacind(slind+1)) - w(peakHacind(slind));
bandwid/pi*L

%% 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

28. (a) See plot below.


Impulse Response Magnitude Response (dB)
0
0.4
−20
0.3

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

0.005 −0.02 −60

Passband dB

Stopband dB
Amplitude

0 −0.04 −80

−0.005 −0.06 −100

−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
ω/π

FIGURE 10.34: Plots of impulse response, magnitude response, approximation


error and zoom magnitude plot using fixed window design technique.

(b) See plot below.


M ATLAB script:

% P1028: Design lowpass filter using appropriate window


close all; clc
ws = 0.5*pi; wp = 0.3*pi;
As = 50; Ap = 0.5;
[deltap, deltas] = spec_convert(Ap,As,’rel’,’abs’);
delta = min([deltap,deltas]);
A = -20*log10(delta);

%% 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

Impulse Response Magnitude Response (dB)


0.5 0
0.4
−20
0.3

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
ω/π

FIGURE 10.35: Plots of impulse response, magnitude response, approximation


error and zoom magnitude plot using Kaiser window design technique.

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)

29. (a) See plot below.


(b) See plot below.
M ATLAB script:

% P1029: Design bandstop filter using hann window


close all; clc
wp1 = 0.2*pi; ws1 = 0.3*pi; ws2 = 0.5*pi; wp2 = 0.65*pi;
deltas = 0.01; deltap = 0.056;
delta = min([deltap,deltas]);
CHAPTER 10. Design of FIR Filters 670

Impulse Response Magnitude Response (dB)


0

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
ω/π

FIGURE 10.36: Plots of impulse response, magnitude response, approximation


error and zoom magnitude plot using Hann window design technique.

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

Impulse Response Magnitude Response (dB)


0

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
ω/π

FIGURE 10.37: Plots of impulse response, magnitude response, approximation


error and zoom magnitude plot using fir1 function.

[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(’P1029a’,’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 672

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)

30. (a) See plot below.


(b) See plot below.
(c) See plot below.
M ATLAB script:

% P1030: Design bandpass filter using window


close all; clc
ws1 = 0.2*pi; wp1 = 0.3*pi; wp2 = 0.5*pi; ws2 = 0.65*pi;
As1 = 45; Ap = 0.75; As2 = 50;
As = max([As1,As2]);
[deltap, deltas] = spec_convert(Ap,As,’rel’,’abs’);
delta = min([deltap,deltas]);
A = -20*log10(delta);

%% Part (a)
wc1 = (ws1+wp1)/2; wc2 = (ws2+wp2)/2;
dw = min([wp1-ws1,ws2-wp2]);
CHAPTER 10. Design of FIR Filters 673

Impulse Response Magnitude Response (dB)


0.4 0
−10

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
ω/π

FIGURE 10.38: Plots of impulse response, magnitude response, approximation


error and zoom magnitude plot using fixed window design technique.

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

Impulse Response Magnitude Response (dB)


0
0.3
−10
0.2
−20
0.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)
−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
ω/π

FIGURE 10.39: Plots of impulse response, magnitude response, approximation


error and zoom magnitude plot using Kaiser window design technique.

[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);
magz2(ind) = Hdb(ind);
%% Plot:
hfa = figconfg(’P1030a’,’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 675

Impulse Response Magnitude Response (dB)


0
0.3
−10
0.2
−20
0.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
ω/π

FIGURE 10.40: Plots of impulse response, magnitude response, approximation


error and zoom magnitude plot using fir1 function.

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 ω

FIGURE 10.41: Plots of impulse response and amplitude response of designed


type-IV differentiator using the Blackman window.

M ATLAB script:

% P1031: Design a type-IV differentiator of order 61


% using blackman window
close all; clc
M = 61; L = M + 1; n = 0:M;
alpha = M/2; na = (n-alpha);
hd = cos(pi*na)./na - sin(pi*na)./(pi*na.^2);
h = hd.*blackman(L)’;

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)

32. (a) See plot below.


Impulse Response Magnitude Response (dB)
0.4 0

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 ω/π

FIGURE 10.42: Plots of impulse response and log-magnitude response of designed


highpass filter using linear transition.

(b) See plot below.


Impulse Response Magnitude Response (dB)
0.4 0

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 ω/π

FIGURE 10.43: Plots of impulse response and log-magnitude response of designed


highpass filter using the fir2 function and the Hamming window.

M ATLAB script:

% P1032: Design a highpass filter using frequency sampling approach


close all; clc
M = 34;
L = M + 1;
ws = 0.6*pi; wp = 0.8*pi;
As = 50; Ap = 1;
Dw = 2*pi/L;
CHAPTER 10. Design of FIR Filters 678

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)

33. (a) See plot below.


Impulse Response Magnitude Response (dB)
0.4 0

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 ω/π

FIGURE 10.44: Plots of impulse response and log-magnitude response of designed


bandpass filter using a raised-cosine transition.

(b) See plot below.


Impulse Response Magnitude Response (dB)
0.4 0

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 ω/π

FIGURE 10.45: Plots of impulse response and log-magnitude response of designed


bandpass filter using the fir2 function and the Hann window.

M ATLAB script:

% P1033: Design a bandpass filter using frequency sampling approach


close all; clc
L = 40;
M = L - 1;
CHAPTER 10. Design of FIR Filters 680

ws1 = 0.2*pi; wp1 = 0.3*pi; wp2 = 0.5*pi; ws2 = 0.65*pi;


As1 = 40; Ap = 0.2; As2 = 40;
Dw = 2*pi/L;
om = (0:L-1)*Dw;
alpha = M/2; Q = floor(alpha);
psid = -alpha*Dw*[0:Q,-(L-(Q+1:M))];

%% 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)

34. (a) See plot below.


Impulse Response Magnitude Response (dB)
0.4 0
−10
0.3
−20
Decibels

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 ω/π

FIGURE 10.46: Plots of impulse response and log-magnitude response of designed


lowpass filter when the sample at ωc be equal to 0.5.

(b) See plot below.


Impulse Response Magnitude Response (dB)
0.4 0
−10
0.3
−20
Decibels

0.2 −30
h[n]

0.1 −40 As = 43.31

−50
0
−60
−0.1 −70
0 5 10 15 20 25 30 35 0 0.5 1 1.5 2
n ω/π

FIGURE 10.47: Plots of impulse response and log-magnitude response of designed


lowpass filter when the sample at ωc be chosen as optimal one.
CHAPTER 10. Design of FIR Filters 682

Impulse Response Magnitude Response (dB)


0.4 0

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 ω/π

FIGURE 10.48: Plots of impulse response and log-magnitude response of designed


lowpass filter using the fir2 function.

(c) See plot above.


M ATLAB script:

% P1034: Design a lowpass filter using frequency sampling approach


close all; clc
L = 40;
M = L - 1;
wc = 0.4*pi;
Dw = 2*pi/L;
om = (0:L-1)*Dw;
alpha = M/2; Q = floor(alpha);
psid = -alpha*Dw*[0:Q,-(L-(Q+1:M))];

%% 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));

% Find minimum stopband attenuation:


[Hdbpeak Hdbpeakind] = findpeak(Hdb);
ind = (w(Hdbpeakind) > wc & w(Hdbpeakind) < 2*pi-wc);
[As Asind] = max(Hdbpeak(ind));
Asloc = w(Asind);

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

35. (a) See plot below.


Impulse Response Amplitude Response
2 4

1 3

Amplitude
h[n]

0 2

−1 1

−2 0
0 10 20 30 40 0 0.5 1 1.5 2
n ω/π

FIGURE 10.49: Plots of impulse response and amplitude response of designed


differentiator.

(b) See plot below.


x[n] y[n]
10
10

5 5

0 0

−5 −5

−10
−10
50 100 150 50 100 150
n n

FIGURE 10.50: Subplots of x[n] and y[n] for 50 ≤ n ≤ 100.

(c) tba
M ATLAB script:

% P1035: Design a FIR differentiator using frequency sampling approach


close all; clc
%% Part a: filter design
L = 50; M = L - 1;
Dw = 2*pi/L;
om = (0:L-1)*Dw;
ind = om >= pi;
om(ind) = om(ind) - 2*pi;
alpha = M/2;
H = j*om.*exp(-j*om*alpha);
hd = real(ifft(H));
CHAPTER 10. Design of FIR Filters 685

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:

% P1036: Design bandpass FIR filter using Parks-McClellan


CHAPTER 10. Design of FIR Filters 686

Impulse Response Magnitude Response (dB)


0

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
ω/π

FIGURE 10.51: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed bandpass digital filter.

close all; clc


%% Specification:
ws1 = 0.25*pi; wp1 = 0.35*pi; wp2 = 0.7*pi; ws2 = 0.8*pi;
deltas1 = 0.01; deltap = 0.004; deltas2 = 0.01;
%% Estimated Filter order using FIRPMORD function:
[M,fo,ao,W] = ...
firpmord([ws1,wp1,wp2,ws2]/pi,[0,1,0],[deltas1,deltap,deltas2]);
M = M + 2
%% Filter Design using FIRPM function:
[h,delta] = firpm(M,fo,ao,W);
delta,
deltas1,

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

set(AX(1),’Ytick’,[-100 -50 0],’ylim’,[-100 0])

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
ω/π

FIGURE 10.52: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed lowpass FIR filter.

M ATLAB script:

% P1037: Design lowpass FIR filter using Parks-McClellan


close all; clc
%% Specification:
wp = 0.3*pi; ws = 0.5*pi; As = 50; Ap = 0.5;
%% Passband and Stopband Ripple Calculation:
[deltap, deltas] = spec_convert(Ap,As,’rel’,’abs’);
%% Estimated Filter order using FIRPMORD function:
[M,fo,ao,W] = firpmord([wp,ws]/pi,[1,0],[deltap,deltas]);
M = M + 2
%% Filter Design using FIRPM function:
[h,delta] = firpm(M,fo,ao,W);
delta,
deltap,

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

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),’Ytick’,[-100 -50 0],’ylim’,[-100 0])

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
ω/π

FIGURE 10.53: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed multiband filter.

M ATLAB script:

% P1038: Design multiband FIR filter using Parks-McClellan


close all; clc
%% Specification:
w1 = 0.4*pi; w2 = 0.5*pi; w3 = 0.7*pi; w4 = 0.8*pi;
A1 = 0.35; A2 = 0.975; A3 = 0.25;
delta1 = 0.05; delta2 = 0.025; delta3 = 0.2;
%% Estimated Filter order using FIRPMORD function:
[M,fo,ao,W] = ...
firpmord([w1,w2,w3,w4]/pi,[A1,A2,A3],[delta1,delta2,delta3]);
M = M + 8
%% Filter Design using FIRPM function:
[h,delta] = firpm(M,fo,ao,W);
CHAPTER 10. Design of FIR Filters 691

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)

39. (a) See plot below.


Impulse Response Amplitude Response
0
0.6
0.4
0.2 −0.5
h(n)

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.

(b) See plot below.


(c) tba.
M ATLAB script:

% P1039: Design Hilbert transformer using Parks-McClellan


close all; clc
M = 25;
w1 = 0.05*pi; w2 = 0.95*pi;
[h,delta] = firpm(M,[w1 w2]/pi,[1 1],’hilbert’);

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)

40. M ATLAB script:

% P1040: Investigate function ’Izero’ and ’kaiser0’


close all; clc
K = 49;
x = rand*60+20;
y = Izero(x,K);
yref = Izero(x,50);
y1 = y*1e8;
y1 = y1 - mod(y1,1);
y1 = y1/1e8;
y2 = yref*1e8;
y2 = y2 - mod(y2,1);
y2 = y2/1e8;

isequal(y1,y2)

41.
M ATLAB script:

% P1041: Comparison between Kaiser window and fixed windows


% in terms of As and transition bandwidth
close all; clc
wc = pi/2; M = 32; L = M + 1; % lowpass filter
hd = ideallp(wc,M);
%% Part a
% h = h.*rectwin(M+1); delw = 1.8;
% h = h.*bartlett(M+1); delw = 6.1;
CHAPTER 10. Design of FIR Filters 695

100

80
Blackman
A (dB)

60
Hamming
s

Hann
40

Bartlett
20 Rectangular

0.2 0.4 0.6 0.8 1 1.2


Transition Bandwidth
FIGURE 10.56: Plot of As versus transition-widths obtained in part (b) and the
corresponding pairs for the fixed windows obtained in part (a).

% h = h.*hann(M+1); delw = 6.2;


% h = h.*hamming(M+1); delw = 6.6;
h = hd.*blackman(M+1); delw = 11;

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

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

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

 ω 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)

2 d[(M − 1)/2], k = (M + 1)/2

CHAPTER 10. Design of FIR Filters 698

(M −1)/2

 ω 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

43. (a) Solution:


h 2πn 2πn 4πn 4πn
i
w[n] = 0.42 − 0.5 × 0.5(e j M − e− j M ) + 0.08 × 0.5(e j M − e− j M ) wR [n]
2πn 2πn 4πn
= 0.42wR [n] − 0.25wR [n]e j M + 0.25wR [n]e− j M + 0.04wR [n]e j M

4πn
− 0.04wR [n]e− j M

Hence, the DTFT of w[n] is:


2π  2π 
W e jω = 0.42WR e jω − 0.25WR e j(ω− M ) + 0.25WR e j(ω+ M )
 
4π  4π 
+ 0.04WR e j(ω− M ) − 0.04WR e j(ω− M )

(b) tba.

44. tba

45. (a) See plot below.


(b) See plot below.
(c) See plot below.
M ATLAB script:
% P1045: Stude fixed window magnitude response
% its peak of first side-lobe and transition bandwidth
% Hann Window
close all; clc
% L = 21; % Part a
L = 41; % Part b
hw = hann(L)’;
Nw = 10000;
CHAPTER 10. Design of FIR Filters 699

L = 21 L = 21
0 0

−20 −20
20log10|W(e )|

20log10|W(e )|
−31.5db


−40 −40 −44db

−60 −60

−80 −80

−100 −100
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π

FIGURE 10.57: Log-magnitude response in dB and accumulated amplitude re-


sponse in dB when window length is L = 21.

L = 41 L = 41
0 0

−20 −20
20log10|W(e )|

−31.5db 20log10|W(e )|

−40 −40 −44db

−60 −60

−80 −80

−100 −100
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π

FIGURE 10.58: Log-magnitude response in dB and accumulated amplitude re-


sponse in dB when window length is L = 41.

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));

%% Find Peak Values:


[peakH peakHind] = findpeak(Hmagdb);
[peakHac peakHacind] = findpeak(Hacdb);
Lshind = w(peakHind) < -1e-3;
sidlobeH = max(peakH(Lshind));
Lshind = w(peakHacind) < 0;
[sidlobeHac slind] = max(peakHac(Lshind));
bandwid = w(peakHacind(slind+1)) - w(peakHacind(slind));
CHAPTER 10. Design of FIR Filters 700

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)

46. (a) See plot below.


(b) See plot below.
L = 21 L = 21
0 0

−20 −20
20log10|W(e )|

20log10|W(e )|

−40 −40 −44db


−58.3db
−60 −60

−80 −80

−100 −100
−1 −0.5 0 0.5 1 −1 −0.5 0 0.5 1
ω/π ω/π

FIGURE 10.59: Log-magnitude response in dB and accumulated amplitude re-


sponse in dB when window length is L = 21.

(c) See plot below.


M ATLAB script:
CHAPTER 10. Design of FIR Filters 701

L = 41 L = 41
0 0

−20 −20
20log10|W(e )|

20log10|W(e )|


−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
ω/π ω/π

FIGURE 10.60: Log-magnitude response in dB and accumulated amplitude re-


sponse in dB when window length is L = 41.

% P1046: Stude fixed window magnitude response


% its peak of first side-lobe and transition bandwidth
% Blackman Window
close all; clc
L = 21; % Part a
% L = 41; % Part b
hw = blackman(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));

%% Find Peak Values:


[peakH peakHind] = findpeak(Hmagdb);
[peakHac peakHacind] = findpeak(Hacdb);
Lshind = w(peakHind) < -1e-8;
sidlobeH = max(peakH(Lshind));
[temp Lshind] = find(w(peakHacind) < 0);
bandwid = w(peakHacind(Lshind(end)+1)) - w(peakHacind(Lshind(end)));
bandwid/pi*L

%% 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)

47. (a) See plot below.


Impulse Response Magnitude Response (dB)
0
0.6

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
ω/π

FIGURE 10.61: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed highpass FIR filter using fixed
window technique.
CHAPTER 10. Design of FIR Filters 703

(b) See plot below.


Impulse Response Magnitude Response (dB)
0
0.6

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
ω/π

FIGURE 10.62: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed highpass FIR filter using Kaiser
window technique.

M ATLAB script:

% P1047: Design highpass filter using appropriate window


close all; clc
ws = 0.4*pi; wp = 0.5*pi;
As = 60; Ap = 1;
[deltap, deltas] = spec_convert(Ap,As,’rel’,’abs’);
delta = min([deltap,deltas]);
A = -20*log10(delta);

%% 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)

48. (a) See plot below.


Impulse Response Magnitude Response (dB)
0
0.4
−20
0.2 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

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
ω/π

FIGURE 10.63: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed bandpass filter using fixed
window technique.

(b) See plot below.


(c) See plot below.
M ATLAB script:

% P1048: Design bandpass filter using window


close all; clc
ws1 = 0.25*pi; wp1 = 0.35*pi; wp2 = 0.65*pi; ws2 = 0.75*pi;
deltas = 0.05; deltap = 0.01;
CHAPTER 10. Design of FIR Filters 706

Impulse Response Magnitude Response (dB)


0
0.3
0.2 −20

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
ω/π

FIGURE 10.64: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed bandpass filter using Kaiser
window technique.

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

Impulse Response Magnitude Response (dB)


0
0.4
−20
0.2

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
ω/π

FIGURE 10.65: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed bandpass filter using the fir1
function.

%% 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)

49. (a) See plot below.


(b) See plot below.
M ATLAB script:

% P1049: Design bandstop filter using hann window


close all; clc
wp1 = 0.4*pi; ws1 = 0.55*pi; ws2 = 0.65*pi; wp2 = 0.75*pi;
Ap1 = 0.5; As = 55; Ap2 = 1;
CHAPTER 10. Design of FIR Filters 709

Impulse Response Magnitude Response (dB)


0
0.8
−10
0.6
−20

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
ω/π

FIGURE 10.66: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed bandpass filter using Kaiser
technique.

[deltap, deltas] = spec_convert(min([Ap1 Ap2]),As,’rel’,’abs’);


delta = min([deltap,deltas]);
A = -20*log10(delta);

%% 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

Impulse Response Magnitude Response (dB)


0
0.8
−10
0.6
−20

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
ω/π

FIGURE 10.67: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed bandpass filter using the fir1
function.

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:

% P1050: Design a type-III Hilbert Transformer of order 40


% using hamming window
close all; clc
CHAPTER 10. Design of FIR Filters 712

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:

% P1051: Design a lowpass filter using frequency sampling approach


close all; clc
M = 35;
L = M + 1;
wp = 0.3*pi; ws = 0.5*pi;
Ap = 0.5; As = 50;
CHAPTER 10. Design of FIR Filters 713

Impulse Response Magnitude Response (dB)


0
0.4
−20
0.3

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
ω/π

FIGURE 10.69: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed lowpass FIR filter.

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)

52. (a) See plot below.


(b) See plot below.
M ATLAB script:

% P1052: Design a highpass filter using frequency sampling approach


CHAPTER 10. Design of FIR Filters 715

Impulse Response Magnitude Response (dB)


0.6 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.

Impulse Response Magnitude Response (dB)


0.6 0

0.4 Decibels −20

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.

close all; clc


M = 32;
L = M + 1;
ws = 0.5*pi; wp = 0.65*pi;
As = 50; Ap = 1;
alpha = M/2; Q = floor(alpha);
psid = -alpha*Dw*[0:Q,-(L-(Q+1:M))];
Dw = 2*pi/L;
om = (0:M)*Dw;
k1 = floor(ws/Dw);
k2 = ceil(wp/Dw);
ind = (om>ws & om<wp);
A = 0.5 + 0.5*cos(pi*(om(ind)-wp)/(wp-ws));
Ad = [zeros(1,k1+1) A ones(1,L-2*k2+1) fliplr(A) zeros(1,k1)];

%% 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)

53. (a) See plot below.


(b) See plot below.
CHAPTER 10. Design of FIR Filters 717

Impulse Response Magnitude Response (dB)


0.4 0

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.

Impulse Response Magnitude Response (dB)


0.4 0

0.2 Decibels −20


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.73: Plots of impulse response and magnitude response of the designed
bandpass filter using the fir2 function and the Hann window.

M ATLAB script:

% P1053: Design a bandpass filter using frequency sampling approach


close all; clc
% L = 40;
L = 44;
M = L - 1;
ws1 = 0.2*pi; wp1 = 0.3*pi; wp2 = 0.5*pi; ws2 = 0.65*pi;
As1 = 40; Ap = 0.2; As2 = 40;
Dw = 2*pi/L;
om = (0:L-1)*Dw;
alpha = M/2; Q = floor(alpha);
psid = -alpha*Dw*[0:Q,-(L-(Q+1:M))];

%% 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
ω/π

FIGURE 10.74: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed bandstop filter.

M ATLAB script:

% P1054: Design a bandstop filter using frequency sampling approach


close all; clc
L = 45;
M = L - 1;
wp1 = 0.3*pi; ws1 = 0.4*pi; ws2 = 0.6*pi; wp2 = 0.7*pi;
deltap = 0.02; deltas = 0.0032;
delta = min([deltap deltas]);
As = -20*log10(delta);
Dw = 2*pi/L;
om = (0:L-1)*Dw;
alpha = M/2; Q = floor(alpha);
psid = -alpha*Dw*[0:Q,-(L-(Q+1:M))];

%% Part a
CHAPTER 10. Design of FIR Filters 720

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 −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
ω/π

FIGURE 10.75: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed bandstop filter using the fir2
function.

ind = (om > wp1 & om < ws1);


sum(ind)
k1 = floor(wp1/Dw);
k2 = ceil(ws1/Dw);
k3 = floor(ws2/Dw);
k4 = ceil((wp2)/Dw);

T1 = 0.05029373; T2 = 0.49149549; % ref


A = [T2 T1];
Ad = [ones(1,k1+1),A,zeros(1,k3-k2+1),fliplr(A),ones(1,L-k4*2+1),...
A,zeros(1,k3-k2+1),fliplr(A),ones(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],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)

55. (a) See plot below.


Impulse Response Amplitude Response
0
0.6
0.4
Amplitude

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.

(b) See plot below.


(c) tba.
M ATLAB script:

% P1055: Design Hilbert transformer using frequency sampling approach


close all; clc
%% Part a: filter design
CHAPTER 10. Design of FIR Filters 723

Input Sequence Output Sequence


1 1

x(n) 0.5 0.5

y(n)
0 0

−0.5 −0.5

−1 −1
50 100 150 50 100 150
n n

FIGURE 10.77: Stem plots of x[n] and y[n] for 50 ≤ n ≤ 100.

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:

% P1057: Design highpass FIR filter using Parks-McClellan


close all; clc
%% Specification:
ws = 0.7*pi; wp = 0.8*pi; As = 55; Ap = 1;
%% Passband and Stopband Ripple Calculation:
[deltap, deltas] = spec_convert(Ap,As,’rel’,’abs’);
%% 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;
CHAPTER 10. Design of FIR Filters 725

Impulse Response Magnitude Response (dB)


0
0.3

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
ω/π

FIGURE 10.78: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed highpass filter.

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:

% P1058: Design bandstop FIR filter using Parks-McClellan


close all; clc
%% Specification:
wp1 = 0.35*pi; ws1 = 0.45*pi; ws2 = 0.55*pi; wp2 = 0.65*pi;
deltap1 = 0.01; deltas = 0.004; deltap2 = 0.01;
%% Estimated Filter order using FIRPMORD function:
[M,fo,ao,W] = ...
firpmord([wp1,ws1,ws2,wp2]/pi,[1,0,1],[deltap1,deltas,deltap2]);
M = M + 4
%% Filter Design using FIRPM function:
[h,delta] = firpm(M,fo,ao,W);
delta,
CHAPTER 10. Design of FIR Filters 727

Impulse Response Magnitude Response (dB)


0
0.8

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.004 −0.1 −100

−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
ω/π

FIGURE 10.79: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed bandstop filter.

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:

% P1059: Design multiband FIR filter using Parks-McClellan


close all; clc
%% Specification:
w1 = 0.3*pi; w2 = 0.4*pi; w3 = 0.7*pi; w4 = 0.8*pi;
A1 = 0; A2 = 0.5; A3 = 1;
CHAPTER 10. Design of FIR Filters 729

Impulse Response Magnitude Response (dB)


0

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

0 0.2 0.4 0.6 0.8 1 −8 −120


ω/π 0 0.2 0.4 0.6 0.8 1
ω/π

FIGURE 10.80: Plots of impulse response, magnitude response, approximation


error and zoom magnitude response of the designed multiband filter.

delta1 = 0.005; delta2 = 0.001; delta3 = 0.01;


%% Estimated Filter order using FIRPMORD function:
[M,fo,ao,W] = ...
firpmord([w1,w2,w3,w4]/pi,[A1,A2,A3],[delta1,delta2,delta3]);
M = M + 4
%% Filter Design using FIRPM function:
[h,delta] = firpm(M,fo,ao,W);
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;
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

60. (a) See plot below.


Impulse Response Amplitude Response
0
0.6
0.4
0.2 −0.5
h(n)

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.

(b) See plot below.


(c) tba.
M ATLAB script:

% P1060: Design Hilbert transformer using Parks-McClellan


close all; clc
L = 50;
M = L - 1;
w1 = 0.05*pi; w2 = 0.95*pi;
[h,delta] = firpm(M,[w1 w2]/pi,[1 1],’hilbert’);

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

FIGURE 10.82: Stem plots of x[n] and y[n] for 50 ≤ n ≤ 100.

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
ω/π

FIGURE 10.83: Impulse, amplitude, log-magnitude, and error response subplots


of FIR filter designed by Hamming window in part (a).

(b) See plot below.


(c) See plot below
(d) Comments:
See plots for reference.
(e) See plot below.
M ATLAB script:

% P1061: Lowpass filter design; All methods


close all; clc
%% Specification:
Fs = 1e3; T = 1/Fs;
n = 0:200; nT = n*T;
xn = 5*cos(400*pi*nT)+10*sin(500*pi*nT);
w1 = 400*pi/Fs; w2 = 500*pi/Fs;
Ap = 1; As = 50;
CHAPTER 10. Design of FIR Filters 735

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 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
ω/π

FIGURE 10.84: Impulse, amplitude, log-magnitude, and error response subplots


of FIR filter designed by Kaiser window in part (b).

[deltap, deltas] = spec_convert(Ap,As,’rel’,’abs’);


delta = min([deltap,deltas]);
A = -20*log10(delta);
wc = (w1+w2)/2;
delw = w2-w1;

%% Part a: Fixed window


L = 6.6*pi/delw; Mfw = L - 1;
hd = ideallp(wc,Mfw);
hfw = hd.*hamming(Mfw+1);

%% Part b: Kaiser window


[Mk,wn,beta,ftype] = ...
kaiserord([w1 w2]/pi,[1 0],[deltap,deltas]);
hkai = fir1(Mk,wc/pi,kaiser(Mk+1,beta));

%% 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

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 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

−40 −0.5 −50

−60

−80
0 0.2 0.4 0.6 0.8 1 −1 −100
ω/π 0 0.2 0.4 0.6 0.8 1
ω/π

FIGURE 10.85: Impulse, amplitude, log-magnitude, and error response subplots


of FIR filter designed by Parks-McClellan in part (c).

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

62. (a) See plot below.

Amplitude Response
0
Hamming, M = 131

−10

−20
Amplitude

−30

−40

−50

−60

0 0.3 0.35 0.65 0.7 1


ω/π

FIGURE 10.87: Amplitude response of FIR filter designed by Hamming window


in part (a).

(b) See plot below.


(c) See plot below.
(d) See plot below.
(e) See plot below.
M ATLAB script:

% P1062: Bandpass filter design; All methods


close all; clc
%% Specification:
ws1 = 0.3*pi; wp1 = 0.35*pi; wp2 = 0.65*pi; ws2 = 0.7*pi;
As = 50; Ap = 1;
[deltap, deltas] = spec_convert(Ap,As,’rel’,’abs’);
delta = min([deltap,deltas]);
A = -20*log10(delta);
CHAPTER 10. Design of FIR Filters 741

Amplitude Response
0
Kaiser, M = 116

−10

−20
Amplitude

−30

−40

−50

−60

0 0.3 0.35 0.65 0.7 1


ω/π

FIGURE 10.88: Amplitude response of FIR filter designed by Hamming window


in part (b).

wc1 = (ws1+wp1)/2; wc2 = (wp2+ws2)/2;


delw = min([wp1-ws1,ws2-wp2]);

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;

%% Part a: Fixed window


L = 6.6*pi/delw; Mfw = L-1;
hd = ideallp(wc2,Mfw) - ideallp(wc1,Mfw);
hfw = hd.*hamming(Mfw+1);

%% Part b: Kaiser window


[Mk,wn,beta,ftype] = ...
kaiserord([ws1 wp1 wp2 ws2]/pi,[0 1 0],[deltas,deltap, deltas]);
hkai = fir1(Mk,[wc1 wc2]/pi,’DC-0’,kaiser(Mk+1,beta));
CHAPTER 10. Design of FIR Filters 742

Amplitude Response
0
Frequency Sampling, M = 101

−10

−20
Amplitude

−30

−40

−50

−60

0 0.3 0.35 0.65 0.7 1


ω/π

FIGURE 10.89: Amplitude response of FIR filter designed by Hamming window


in part (c).

%% Part c: Frequency sampling


Mfs = 101;
L = Mfs + 1;
Dw = 2*pi/L;
om = (0:Mfs)*Dw;
ind = (om > ws1 & om < wp1);
sum(ind)
k1 = floor(ws1/Dw);
k2 = ceil(wp1/Dw);
k3 = ceil(wp2/Dw);
k4 = k3+2;
% T1 = 0.10288086; T2 = 0.58097354; % ref
T1 = 0.09288086; T2 = 0.61097354;
AT = [T1 T2];
Ad = [zeros(1,k1+1),AT,ones(1,k3-k2),fliplr(AT),zeros(1,L-2*k4+1),...
AT,ones(1,k3-k2),fliplr(AT),zeros(1,k1)];
ind = om < pi;
CHAPTER 10. Design of FIR Filters 743

Amplitude Response
0
Parks McCllelan, M = 72

−10

−20
Amplitude

−30

−40

−50

−60

0 0.3 0.35 0.65 0.7 1


ω/π

FIGURE 10.90: Amplitude response of FIR filter designed by Hamming window


in part (d).

hfs = fir2(Mfs,[om(ind) pi]/pi,[Ad(ind) 0],kaiser(L,1.1));

%% 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

[Ha wt P2 L2] = amplresp(hp(:)’,w);


H = freqz(hp,1,w);
Hmag = abs(H);
Hdb = 20*log10(Hmag/max(Hmag));
yn = filter(hp,1,xn);

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

63. (a) See plot below.

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π

δs1 = 0.013 δs2 = 0.026


ω = 0.202π ω = 0.497π ω = 0.701π
0.05 1 4 5
−0.05
0 0.2 0.25 0.45 0.5 0.7 0.75 1
ω/π

FIGURE 10.92: Amplitude response of FIR filter designed by Hann window in


part (a).

(b) See plot below.


(c) See plot below.
(d) See plot below.
(e) Comment:
See each plot for reference.
M ATLAB script:

% P1063: Multiband filter design; All methods


close all; clc
%% Specification:
ws1 = 0.2*pi; wp1 = 0.25*pi; wp2 = 0.45*pi;
ws2 = 0.5*pi; ws3 = 0.7*pi; wp3 = 0.75*pi;
G1 = 0; G2 = 2; G3 = 0; G4 = 4.15;
deltas1 = 0.05; deltap1 = 0.1; deltas2 = 0.05; deltap2 = 0.15;
delta = min([deltas1 deltap1 deltap2 deltas2]);
CHAPTER 10. Design of FIR Filters 747

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
ω/π

FIGURE 10.93: Amplitude response of FIR filter designed by Kaiser window in


part (b).

A = -20*log10(delta);

wbp1 = (ws1+wp1)/2; wbp2 = (wp2+ws2)/2; whp = (ws3+wp3)/2;


delw = 0.05*pi;

%% Part a: Fixed window


L = ceil(6.2*pi/delw); Mfw = L - 1;
if mod(Mfw,2) == 1
Mfw = Mfw + 1;
end
hfw1 = fir1(Mfw,[wbp1 wbp2]/pi,’DC-0’,hann(Mfw+1));
hfw2 = fir1(Mfw,whp/pi,’high’,hann(Mfw+1));
hfw = G2*hfw1 + G4*hfw2;

%% Part b: Kaiser window


[Mk,wn,beta,ftype] = ...
kaiserord([ws1 wp1 wp2 ws2]/pi,[0 1 0],...
CHAPTER 10. Design of FIR Filters 748

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
ω/π

FIGURE 10.94: Amplitude response of FIR filter designed by frequency-sampling


in part (c).

[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 c: Frequency sampling


% Mfs = 90;
Mfs = 84;
L = Mfs + 1;
hfs = fir2(Mfs,[0 ws1+0.002*pi wp1 wp2 ws2 ws3+0.001*pi wp3 pi]/pi,...
[G1 G1 G2 G2 G3 G3 G4 G4],rectwin(L));

%% 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
ω/π

FIGURE 10.95: Amplitude response of FIR filter designed by Parks-McClellan in


part (d).

[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

64. (a) See plot below.

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
ω/π

FIGURE 10.96: Amplitude response of FIR filter designed by Hann window in


part (a).

(b) See plot below.


(c) See plot below.
(d) See plot below.
(e) Comment:
See each plot for reference.
M ATLAB script:

% P1064: Multiband filter design; All methods


close all; clc
%% Specification:
wp1 = 0.2*pi; ws1 = 0.25*pi; ws2 = 0.45*pi;
wp2 = 0.55*pi; wp3 = 0.7*pi; wp4 = 0.75*pi;
G1 = 2; G2 = 0; G3 = 3; G4 = 1;
deltap1 = 0.2; deltas = 0.05; deltap2 = 0.3; deltap3 = 0.1;
delta = min([deltas deltap1 deltap2 deltap3]);
CHAPTER 10. Design of FIR Filters 753

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
ω/π

FIGURE 10.97: Amplitude response of FIR filter designed by Kaiser window in


part (b).

A = -20*log10(delta);

wlp = (wp1+ws1)/2; wbp1 = (wp2+ws2)/2; wbp2 = (wp3+wp4)/2;


whp = wbp2;
delw = 0.05*pi;

%% Part a: Fixed window


L = ceil(6.2*pi/delw); Mfw = L - 1;
if mod(Mfw,2) == 1
Mfw = Mfw + 1;
end
hfw1 = fir1(Mfw,wlp/pi,hann(Mfw+1));
hfw2 = fir1(Mfw,[wbp1 wbp2]/pi,’DC-0’,hann(Mfw+1));
hfw3 = fir1(Mfw,whp/pi,’high’,hann(Mfw+1));
hfw = G1*hfw1 + G3*hfw2 + G4*hfw3;

%% Part b: Kaiser window


CHAPTER 10. Design of FIR Filters 754

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
ω/π

FIGURE 10.98: Amplitude response of FIR filter designed by frequency-sampling


in part (c).

[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;

%% Part c: Frequency sampling


% Mfs = 70;
Mfs = 60;
L = Mfs + 1;
hfs = fir2(Mfs,[0 wp1 ws1 ws2+0.005*pi wp2 wp3 wp4 pi]/pi,...
[G1 G1 G2 G2 G3 G3 G4 G4],rectwin(L));
CHAPTER 10. Design of FIR Filters 755

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
ω/π

FIGURE 10.99: Amplitude response of FIR filter designed by Parks-McClellan in


part (d).

%% 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.”

Captain Codrington to sir C. Cotton.

(Extract.)

“June 29, 1811.


“The Regulus with five transports including a victualler arrived with
colonel Skerrett and his detachments on the 26th. The surf was so
great on that day that we had no other communication in the
forenoon than by a man swimming on shore with a letter, and upon
colonel Skerrett putting questions to general Doyle and myself upon
the conduct he should pursue according to his orders, we agreed in
our opinion that although the arrival of the troops before the Puerto
(lower town) was taken would probably have saved the garrison, it
was now too late, and that their being landed, if practicable, would
only serve to prolong the fate of the place for a very short time at the
certain sacrifice of the whole eventually. This opinion was grounded
on a number of different circumstances, and was in perfect
coincidence with that of captains Adam and White. In the evening
the surf abated sufficiently for general Doyle, colonel Skerrett, and
some of his officers, as well as the captains of the squadron and
myself, to wait upon general Contreras, who repeated his
determination to cut his way out and join the marquis of Campo
Verde the instant the enemy’s breaching battery should open, and
which he expected would take place the following morning, and who
agreed the English ought not to land with any view of defending the
town, although he wished them to join in his meditated sortie.”

Extracts from general Contreras’ report.

(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.”

Captain Codrington to sir E. Pellew.


“12th July, 1811.
“The marquis blames generals Caro and Miranda, whilst the latter
retort the accusation; and I am inclined to think that in giving full
credit to what each says of the other, neither will suffer ignominy
beyond that to which his conduct has entitled him.”

Ditto to Mr. Wellesley.

(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.

Captain Codrington to sir E. Pellew.


“29th July, 1811.
“Had colonel Green, the military agent appointed to succeed
general Doyle, adopted the plan of his predecessor of continuing at
the head-quarters of the army and in personal communication with
the captain-general instead of retiring to Peniscola with the money
and arms remaining, we should not be left as we are to the
precarious source of mere accidental communications for receiving
intelligence.”

Ditto to Don F. Savartes, vocal of the Junta.


“28th July, 1811.
“————Colonel Green, the British military agent, being at
Peniscola, I have opened the letter from the junta to him.”——“Had I
not in this instance opened the letters to the admiral and the military
agent, the junta would have received no answer to them until it
would have been too late to execute their object.”

Captain Thomas to captain Codrington.

(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.

Captain Codrington’s orders to captain Adam of the


Invincible.
“July 1st, 1811.
“You are hereby directed, in consequence of a representation
made to me by general Doyle, to proceed towards Majorca in search
of the Spanish frigates Prueba, Diana, and Astrea, which the general
reports to be going to that island (contrary to orders) with the
treasure, archives of the province, and the vessels laden with stores
and ammunition destined for the inland fortresses of Catalonia,
together with the officers and soldiers which were saved from
Taragona, and which are required to join the army immediately. Upon
meeting them you are to deliver the accompanying order for them to
return here, and you are, if necessary, to enforce obedience.”

Captain Codrington to sir Charles Cotton.


“Villa Nueva, 3d July, 1811.
“I should feel the more hurt by being driven to adopt such a
measure had not the whole conduct both of the Prueba and Diana
made their captains a disgrace to the situation they hold. These two
frigates remained quiet spectators of the British squadron engaging
the batteries of the enemy on the 22d of last month, and never
attempted to give any assistance to the garrison, except by now and
then sending a gun-boat to join those manned by the English. They
did not assist in the embarkation of the numberless women, children,
and wounded soldiers, until goaded into it by the orders of general
Contreras, after I had already sent above two thousand to this place;
and even when I had no longer any transports for their reception, the
captain of the Prueba refused to receive some wounded officers.”

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.

Captain Codrington to sir E. Pellew.


“12th July, 1811.
“General Milans is collecting a mixture of troops, consisting of
those who have escaped the enemy.”
“He speaks loudly of his indifference to a command, while he
boasts that if he were captain-general he would raise forty thousand
men and clear the country of the enemy! But in the midst of this
disgusting rhodomontade it is not difficult to see that self-interest is
the main spring of all his actions, and that instead of raising an army
he is more likely, by the system he has adopted, to shake the
stability of that which is still left for the defence of the principality.”
Captain Codrington to sir H. Wellesley.
“September 1, 1811.
“The affair of general Milans” (namely, the sending of corn to
Barcelona under his passport) “which I mentioned to you in my last
private letter, is still involved in mystery, which I hope however to
penetrate upon my return to Arens de Mar. The Mataro papers
reported that two soldiers were shot and a serjeant flogged at Arena
for suffering corn to pass their guard at Mongat on its way to
Barcelona. The fact of the punishment is I believe truly stated, but
the cause no less falsely, enterely as I suspect with the view of
terminating my investigation into this nefarious traffic. General Lacy,
instead of answering my letter, refers me by word of mouth to the
junta, and the deputation from the junta, who went to Mataro (as they
assured me) purposely to investigate the business, now tell me that
it is an affair purely military, and refer me to general Milans himself.”

section 5.

Extract from a minute made by captain Codrington.


“Mattaro, July 6, 1811.
“Colonel O’Ronan, aid-du-camp to the marquis of Campo Verde,
arrived, and informed me that he came from the marquis, who was
on his march to this town or Arens, for the purpose of embarking all
the infantry not Catalans, and the whole of the remaining cavalry,
leaving the horses on the beach. Colonel O’Ronan said this
determination was the result of a junta, composed of the marquis,
general St. Juan, general Caro, general Miranda, the general of
artillery, brigadier Santa Cruz, Velasco, and Sarsfield; that after the
thing had been proposed and discussed a long time, Sarsfield was
the first to give his vote, that he rose from his seat and said, ‘any
officer who could give such an opinion must be a traitor to his
country, and that he and his division would stand or fall with the
principality.’ Every other officer was of a contrary opinion, except the
marquis (it afterwards appeared that Santa Cruz also supported
Sarsfield), who thought with Sarsfield, and yet it seems he allowed
himself to be led on by the other generals. In short, it appears he
was resolved to abandon the principality.
“I told him, without hesitation, that to embark the Valencians I felt a
duty to general O’Donnel, to the kingdom of Valencia, and to the
whole nation, but that I felt it equally my duty upon no account to
embark the army of Catalonia, and thus become a party concerned
in the abandonment of a province I had been sent to
protect.”——“The colonel, who could not venture on shore again lest
he should be murdered by the inhabitants of Mattaro, for having
been the bearer of a commission to arrest brigadier Milans about a
month ago, sent to the marquis my answer.”

Extract from a minute of information given by the baron


d’Eroles.
“July 9, 1811.
“The baron d’Eroles was appointed captain-general of Catalonia
by the junta of general officers, of which the marquis of Campo
Verde was president, and by the voice of the people. His reply was,
that so long as the army continued in the principality, and that there
was a senior general officer, he would not admit it, but that the
moment the army passed the frontier (it was then at Agramunt, in full
march to Aragon), he would accept the command, unmindful of the
dreadful situation in which he should place himself, but he would do
so in order to continue the struggle, and to prevent anarchy and
confusion. In this state things were when general Lacy arrived. The
baron instantly sought him, could not find, but met one of his aid-du-
camps, by whom he wrote to him to say what had occurred, but that
he was resolved to support general Lacy in his command, not only
with all his local influence, but by his personal exertions, and that he
would immediately join him to put this resolution in practice.”

Extract from general Doyle’s Letter after seeing the above.


“The Valencian division, that is to say, two thousand four hundred
of the four thousand three hundred soldiers who disembarked in this
province, are now on board to return to Valencia. General Miranda
says the desertion took place in consequence of the marquis’s
determination to proceed to Aragon, which made them believe they
would not be embarked. In short, most disgraceful has been the
conduct of this division, and the marquis, as you will see by this letter
to me, attaches to it no small portion of blame.”

Captain Codrington to the marquis of Campo Verde.


“Blake, July 5, 1811.
“I have to remind you that by ordering the Valencian division out of
Taragona, in breach of the terms by which I bound myself when I
brought them, you yourself broke the pledge given by me, and
dissolved the contract.”

Extracted from captain Codrington’s papers.


“Minute of a conference betwixt generals Caro and Miranda with
general Doyle and myself this day.
“July 9, 1811.
“About eight o’clock generals Caro and Miranda came on board
the Blake. After being seated in the cabin with general Doyle and
myself, general Caro begged general Doyle would explain to me,
that they were come in consequence of my promise, to request I
would embark the division of Valencian troops which I had brought
from Peniscola. I desired to know what promise general Caro
understood me to have made? He answered, that I would take the
above troops back to Valencia. I denied positively that I had made
any promise to re-embark them if they should ever join the marquis
of Campo Verde, although I had deeply pledged myself to restore
them to general O’Donnel if they joined in a sortie from the garrison,
which I was very confident would be decisive of its success. I then
referred general Miranda to a similar explanation, which I gave to
him, through general Doyle, on the day after our quitting Peniscola,
when he had said he was ordered, both by his written instructions
and by verbal explanation from general O’Donnel, not to land within
the garrison. General Miranda instantly repeated that so he was;
upon which general Doyle, to whom he had shewn those instructions
jointly with myself, after leaving Taragona for Villa Nueva, when
under a difficulty as to how he should proceed, referred him to them
again, when it appearing that he was therein positively ordered
‘desembarear en la plaza de Tarragona,’ general Doyle stopped.
“General Miranda. ‘Ah! but read on.’
“General Doyle. ‘No, sir, there is the positive proof of your
receiving such an order.’
“General Miranda. ‘Well, but read on.’
“General Doyle. ‘No, sir. This (pointing to the paper) is the positive
proof of your receiving such an order, which we wanted to establish,
because you positively denied it.’
“Upon this general Caro, shrugging up his shoulders, said, ‘he was
not aware of there being any such order.’ And general Miranda again
requested general Doyle would read on.
“General Doyle. ‘For what purpose?’
“General Miranda. ‘To prove that I was not to shut myself up with
the division in the plaza de Taragona.’
“General Doyle. ‘There is no occasion, sir, for any proof of that, for
it was a part of the very stipulation made by captain Codrington
when he strongly pledged himself to general O’Donnel.’
“General Doyle continued,—‘And now, general Caro, that we have
proved to you that general Miranda had orders to land in Taragona,
and that captain Codrington is bound by no such promise as you had
imagined, I must inform you that he has been eight days upon the
coast with all the ships of war and transports which are wanted for
other services, for the sole purpose of embarking these troops; and
he desires me to add that in consideration of what is due to the
liberal and exemplary assistance afforded by general O’Donnel and
Valencia in aid of Taragona, but not at all on account of any pledge
he has been said to have given, that he will use the same exertion in
re-embarking and restoring the troops which he would have done if
so bound by his word of honour.’”

Mr. Wellesley to lord Wellesley.


“July 28.
“The morning of 30th of June, a few hours after the arrival of the
British squadron and Spanish vessels in the roadstead of Villa
Nueva, five thousand French infantry and five hundred cavalry
surprised the place by a night-march, and seized all the property of
Taragona, which had been sent there before the siege. Twenty-five
thousand dollars for each of the next three months was demanded,
but no violence or plunder allowed. Eroles narrowly escaped. Lacy,
appointed to command in Catalonia, arrived 1st July at Villa Nueva,
the 6th went to Igualada to join Campo Verde.”
“Desertion in the army at Mataro has been carried to a most
alarming extent since the fall of Taragona; the first night fifteen
hundred men disappeared, nearly three hundred cavalry had
likewise set off towards Aragon; and these desertions are to be
attributed to the gross neglect and want of activity on the part of the
officers.”————“The only division that keeps together in any
tolerable order is that of general Sarsfield, of about two thousand
men.”————“He had however disputes with Eroles, and the people
called for the latter to lead them.”
No. III.

section 1.

POLITICAL S TAT E OF KING JOSEPH.

S PA N I S H MINISTER’S COMPLAINTS OF THE FRENCH

GENERALS.

From the councillor of state, Mariano Luis Orquijo, to


king Joseph.
“Madrid, 22 Juillet, 1810.
“Sire,—Le commissaire royal de Cordoue me mande, que le duc
de Dalmatie lui a fait écrire officiellement de ne remettre aucune
somme d’argent à la capitale lors même que le ministre des finances
le demanderait, jusqu’à ce que les dépenses de l’armée des
régimens qu’on lève et des employés de la province, &c., furent
pleinement couverts, et que le duc prendrait les mesures
convenables, dans le cas que cette détermination ne fut pas suivie.”

“Madrid, 3 Agosto de 1810.


“Le général Sebastiani a fait voir au commissaire royale à
Grenade, un ordre du duc de Dalmatie, qui lui enjoint de la manière
la plus expresse, de le mettre en état d’arrestation si pour le 1er
Août lui et le préfet de Malaga ne mettent au pouvoir de Sebastiani
quatre millions de réaux. L’exorbitance de cette somme, pour une
province qui a déjà payé son contingent, et le court terme de huit
jours designé pour le payement, donnent à croire que cette somme
une fois livrée on en demandera une plus forte. Selon toutes les
apparences, et d’après les conversations particulières, il s’agit de
profiter de l’absence du roi pour mettre les Andalousies sur le même
pied que les provinces de Biscaye, Burgos, &c. Il se peut néanmoins
qu’on ait voulu inspirer ces craintes dans des idées tout-à-fait
différentes. Quoiqu’il en soit il serait scandaleux de voir un
commissaire qui représente la personne du roi arrêté dans une de
ses provinces.”

From Mariano Luis Orquijo to king Joseph.


“Madrid, 7 Août, 1810.
“Monsieur d’Aranza m’écrit en dâte du 22 Août dans une lettre
particulière les paroles suivantes, en les soulignant pour mieux fixer
l’attention: ‘Le maréchal Soult est très content, mais il ne fera usage
de son autorité que pour le bien: il aime le roi et la nation: ce pays lui
plait beaucoup.’”

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.”

“Valladolid, le 11 Août, 1810.


“Sire,—Je suis arrivé a Valladolid, où je n’ai pas trouvé le général
Kellermann. Il parait que les Espagnols out cerné un détachement
de Français qui se trouve à la Puebla de Sanabria, et que ce général
y eu allé pour le débloquer. Les guerrilles ont été hier aux portes de
Valladolid, et il y à cinq a six jours que soixante dix Français ont été
détruits à Villalon; la terreur s’est emparée de tous les esprits, et l’on
croit que trois cent hommes ne suffisent pas pour faire paner un
courrier: malgré cela, je parterai demain, escorté par deux cent
hommes avec un convoi de prisonniers de Ciudad Rodrigo, donc le
nombre n’est pas considérable, parcequ’ici on leur accorde la liberté
moyennant une somme qu’on règle avec le général Kellermann pour
les frais de la guerre.
“Toutes les autorités du pays sont venues me visiter, et me
consulter sur la conduite qu’elles doivent tenir depuis les derniers
ordres du général Kellermann pour qu’elles n’obeinent ni ne
correspondent avec d’autre autorité que la sienne. C’est la
chancellerie qui se trouve plus embarrassée que toute autre, parce-
qu’elle ne peut concilier l’administrat de la justice au nom de votre
majesté avec l’impossibilité de correspondre avec son ministre.
“Je n’ai pas reçu le moindre égard du général Dufrene qui est à la
place du général Kellermann. Il ne m’a pas visité, ni même accorde
un factionnaire; tout le monde s’en est apperçu, et cette conduite a
confirmé l’opinion que l’on a conçue que votre majesté ne règne
point dans ce pays. J’ai tâché de detruire une idée qui décourage les
véritables sujets de votre majesté, et soutient les espérances de ses
ennemis. Les généraux ne s’apperçoivent pas du mal qu’ils
produisent en ferant croire que le service de l’empereur, et ses
intérêts peuvent être en contradiction avec ceux de votre majesté.
“Si le général Dufrene s’était borné à ne rien faire pour faciliter
mon voyage, j’aurai moins de motifs de plainte contre lui, mais il a
retenu l’escorte de cavalerie que le général Tilly m’avait donnée. De
toutes les manières, Sire, je ferai tout ce qui sera en mon pouvoir
pour accélérer mon voyage, et répondre à la confiance avec laquelle
votre majesté a daigné me distinguer.
“Le marquis Almenara.”

Orquijo to Joseph, relating his conference with the French


ambassador.
(Extract.)
“Madrid, Août 22, 1810.
“Je lui dis de s’adresser sur ces deux points au ministre des
relations extérieures, il me répondit qu’un désagrément qu’on
éprouvait avec lui était l’obligation de lui donner à tout bout de
champ des notes écrites, qu’à Vittoria il l’avait compromis en
présentant à votre majesté ces notes comme officielles, que le bon
vieux duc (ce sont ses propres expressions) étourdissait dans
l’instant, qu’il n’entendait point, ou ne voulait point entendre ce qu’on
lui disait, et qu’il demandait qu’on lui donnat par écrit ce qui n’était
pas nécessaire d’écrire. Je lui répétais toujours qu’il devait
s’adresser au duc puisque c’était le seul canal par lequel il devait
diriger ses demandes, que je ne me mélais point de ces affaires, et
que je n’en entretiendrais votre majesté à moins que votre majesté
ne m’en parlat la première, mais comme simple particulier je
l’assurai de l’inviolabilité des promesses de votre majesté et de ses
idées liberales. L’ambassadeur ajouta que dans la matinée du jour
de St. Napoleon, et les jours suivants, le général Belliard, Borelli, et
leurs alentours avaient parlé fort mal des expressions de votre
majesté sur ses premiers devoirs, et qu’il ne doutait pas qu’ils n’en
eussent écrit à Paris; qu’il n’avait pas pu se dispenser de transmettre
à sa cour ces paroles; mais qu’il les avait présentés comme une
conséquence du premier discours tenu par votre majesté et une
nuance nécessaire pour adoucir le mauvais effêt qu’avait produit ici
l’article du Moniteur sur les mots de l’empereur au duc de Berg. Je le
lui avais présenté de cette manière en sortant de l’appartement de
votre majesté, et je lui montrai en même temps un rapport venu de la
Navarre dans lequel on dépeignait le facheux étât de ce royaume en
proie aux excès des bandes de brigands et aux dilapidations des
gouvernemens militaires. Si l’ambassadeur a écrit dans ces termes
comme il me l’a dit, autant par honneur que par attachement à votre
majesté, à son pays et au notre, il a bien rempli ses devoirs.
Quoiqu’il en soit, je me lui cru obligé de donner connaissance à votre
majesté de ces faits ainsi que de la surprise que, selon
l’ambassadeur, a causé à l’empereur et au ministère Français le
silence du duc de Santa Fé qui ne s’explique sur rien.
L’ambassadeur se plaint d’avoir été compromis par lui, car à sa
demande et en consequence des conversations fréquentes qu’il eut
avec lui pendant les trois jours qu’il passa à Madrid, il écrivit à sa
cour que le duc de Santa Fé était chargé de négocier sur la situation
de votre majesté et celle de notre pays, que l’ambassadeur lui-
même disait ne pouvoir pas durer. C’est à la lettre ce que c’est dit
entre l’ambassadeur et moi.” &c. &c.

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.”

“Madrid, le 15 Février, 1811.


“Sire,—Le préfet de Santander me remêt, en dâte du 16 Janvier,
copie des offices qu’il a reçus pour la réunion de cette province au
gouvernement militaire de Biscaye. J’ai l’honneur de les mettre sous
les yeux de votre majesté en lui observant que cette mesure a été
prise sur la proposition du général Caffarelli.
“On a demandé au préfet de Santander un état des employés
civils et militaires, des moines, du clergé, et des appointemens dont
ils jouissent. Il croit en conséquence que des attributions ainsi que
celles des employés seront nulles des que la province sera
gouvernée à l’instar de celle de Biscaye. Il ajoute que lui et les chefs
principaux de l’administration sont décidés à ne travailler que sous
les ordres de votre majesté et demandent avec instance que votre
majesté ne les abandonne pas.
“Le sous-préfet de Logrogne me dit en dâte du 22 Janvier que
l’opinion publique s’est améliorée depuis qu’on y a appris les
nouvelles du Portugal, et qu’on y connait le peu de moyens de
defense qu’offre Valence dans le désordre extrême qui y règne. La
Riofa ne renferme plus de bandes complettes d’insurgés, mais on y
trouve encore quelques brigands épars et des voleurs de grands
chemins.
“Mariano Luis de Orquijo.”

section 2.

(Relating to Joseph’s abdication.)

Vindication of the King.


Le ministre secrétaire d’état à monsieur le duc de Santa Fé,
et en son absence à monsieur le marquis d’Almenara.
Palais de Madrid, le 12 Septembre, 1810, Pars.
Excellence,—Le courrier de cabinet, Don Martin Estenoz, qui
partit de Paris le 22 Juillet, a remis les lettres écrites par V. E. le
même jour et les copies de celles que vous envoyâtes le 19 Juin par
le courrier Alvarez, qui furent interceptées. Le roi les a lues avec la
plus grande attention, et après s’être bien pénétré des
communications faites à V. E. au nom de l’empereur, par monsieur le
due de Cadore, et les observations particulières de ce ministre, S.
M. desirant détruire d’un seul trait, les craintes et la défiance que des
personnes, tout au moins mal instruites, se sont efforcées d’inspirer,
m’a ordonné d’entrer en explication sur tous les points dont elles
traitent. Mais je dois avant tout faire connaître à V. E. que le roi s’est
montré satisfait de la juste interprétation donnée à ses idées, et à
ses sentimens dans la réponse que V. E. a faite au duc de Cadore,
relativement à la protection dont S. M. I. désire que le commerce
Français jouisse dans les réglemens des douanes, en offrant
d’assurer une faveur réciproque dans ses états aux productions
d’Espagne. L’empereur ne peut ignorer les vues liberales de son
auguste frère, et si S. M. I. a été exactement informée sur ce point,
elle saura que, dès son avénement au trône, le roi a écarté bien des
obstacles opposés à l’industrie française qu’il s’agit de favoriser
encore par de nouvelles dispositions.
Il est bien douloureux pour le roi d’avoir à se justifier de plusieurs
imputations auxquelles on a dû croire puisqu’on les a
communiquées a V. E. L’une d’elles est que le roi a rendu à leurs
propriétaires, ou disposé à son gré, d’une partie des biens
confisqués par l’empereur. Cela supposerait de la part de S. M. un
oubli de la parole donnée a l’empereur de ne se mêler en aucune
manière de ces confiscations: mais c’est un infame imposture, et son
auteur mérite un chatiment exemplaire. Qu’on cite une propriété un
pouce de terrain confisqué par l’empereur, et dont on ait disposé: on
ne le pourra point si dans une pure question de fait on en impose
ainsi a l’empereur, que sera ce lorsqu’on ne parle que par
conjectures et présomption? Le roi porte à un si haut degré son

You might also like