Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
For Symmetric FIR filter, filter impulse response should satisfy the following condition,
h (n) = h (M-1-n)
For Asymmetric FIR filter, filter impulse response should satisfy the following condition,
h (n) = - h(M-1-n)
H (~) = Hr(~) e- j~ (M - 1) /2
where
Hr(~) = MagnitudeResponse
^ h
i ~ =- j~ (M - 1) /2 = Linear Phase Response
46
Magnitude Response for both odd length and even length filters
^ h
b M - 1l
^ h M - 3 /2 c bM 1 lm
Hr ~ = h
2 + 2 ! h(n) cos ~ -
2
- n , M odd
n= 0
^^ h h
^ h M/2 - 1 c bM 1 lm
H ~ =2
r ! h(n) cos ~ -
2
- n , M even
n= 0
The phase characteristic of the FIR filter for both ‘M’ odd and ‘M’ even is
Z b l ^ h
]- ~ M - 1 , if Hr ~ >0
^ h ] 2
i ~ =[ b l ^ h
]- ~ M - 1 + r , if Hr ~ <0
\ 2
For ‘M’ odd, the center point of the antisymmetric h(n) is n = (M-1)/2 and also
b l
h M- 1 =0
2
Frequency response is given by
;^ h r E
H (~) = Hr(~) e j - ~ (M - 1) /2 +
2
Magnitude Response for both odd length and even length filters
^ h
^ h M - 3 /2 c bM 1 lm
Hr ~ = 2 ! h(n) sin ~ -
2
- n , M odd
n= 0
^^ h h
^ h M/2 - 1 c bM 1 lm
Hr ~ = 2 ! h(n) sin ~ -
2 -
n , M even
n= 0
47
The phase characteristic of the FIR filter for both ‘M’ odd and ‘M’ even is
Z b l ^ h
]r - ~ M - 1, if Hr ~ >0
^ h ]2 2
i ~ =[ b l ^ h
] 3r - ~ M - 1 , if Hr ~ <0
\ 2 2
Note:
[1]. Asymmetric Even – Its frequency response is zero at ‘ω’ = 0 ,(i.e) H(ω) =0 for
Low Pass Filter design. So it is not suitable for LPF and BPF design.
[2]. Asymmetric Odd - It is not suitable for any type of FIR filter design. The reason is
At ‘ω’ = 0 ,(i.e) H(ω) =0 not suitable for LPF and BPF design,
At ‘ω’ = π , (i.e) H(ω) =0 not suitable for HPF and BSF design.
[3]. Symmetric Even - it is suitable for LPF and BPF filter design. The reason is
At ‘ω’ = π , (i.e) H(ω) =0 not suitable for HPF and BSF design.
[4]. Symmetric Odd – It is suitable for all types of FIR filter design.
48
6.1.3 Design Of FIR Filters Using Windowing Techniques
Procedure:
] g
] g
1. Find the Unit Sample Sequence hd n from the given desired frequency response
Hd e i~
hd (n) = 1r
2
#H (e d
j~
)e
j ~n
d~
- r
where ‘n’ varies from - ∞ to + ∞ and –π ≤ω ≤ π.
] g
2. To design finite length filter multiply the doubly infinte unit sample sequence hd n
with finite length window function w(n).
h(n) = hd (n).w(n), 0 # n # M - 1
3. Find the frequency response of the filter using
Hd (~) = / h (n).e-
j ~n
n= 0
] g
The unit sample response hd n is of infinite duration and must be truncated
at some point n = M-1 to give a FIR filter of length ‘M”. There are different types of
window functions used to obtain FIR filter response from infinite impulse response.
49
6.1.4. Different Types of Windowing Techniques
50
Name
wfir — linear-phase FIR filters
Calling Sequence
[wft,wfm,fr]=wfir(ftype,forder,cfreq,wtype,fpar)
Parameters
ftype
forder
cfreq
wtype
fpar
wft
wfm
fr
Frequency grid
Description
Function which makes linear-phase, FIR low-pass, band-pass, high-pass, and stop-band filters
using the windowing technique. Works interactively if called with no arguments.
51
Note: In order to explain the concept of Implementation of FIR filter using SciLab software
two example problems are solved and the results are verfied by writing programs in
SciLab5.
Problem 1.
A Low pass fitler is to be designed with the following desired frequency response
r #~# r
^ j~h *1, - 4 4
H e =
0, r #~#r
4
Determine the filter coefficients hd(n) if the window function is defined as,
) # G
w(n) = 1,0 n M - 1 [ That is Rectangular Window]
0, otherwise
M = filter length = 5.
Sol:
r
4
hd (n) = 1
2r
#H d (~).ej n d~
~
r
-
4
r
4
1
= 2r #1.e
j ~n
d~
r
-
4
;e E
r
j ~n 4
= 21
r jn -
r
4
52
; jr n - j nE
r
hd (n) = 1r e - e
4 4
2 jn
2j sin rn
= 21r jn
4
sin r n
= rn 4
Z r
]] sin 4 n
hd (n) = [ r n , n ! 0
]] 1, n= 0
\4
n = 0, hd(n ) = (1/4) = 0.25
h(3) = 0.25
53
Problem 2.
A Low pass fitler is to be designed with the following desired frequency response
r #~# r
^ j~h * 0, -
4 4
H e =
1, r # ~ #r
4
Determine the filter coefficients hd(n) if the window function is defined as,
) # G
w(n) = 1,0 n M - 1 [ That is Rectangular Window]
0, otherwise
M = filter length = 5.
Sol:
r
1> H
- r
4
h (n) = r
d
2
#H d (~).e
j ~n
d~ + #H d
j ~n
(~).e d~
- r r
4
1> H
- r
4
= 2r #1.e
j ~n
d~ + #1.e
j ~n
d~
- r r
4
r
1 =; ej~n E- 4 ; ej~n Er G
= 2r + jn r
jn - r
4
1 8 r B
r
= r n sin(n ) - sin(n 4)
* sin(nr ) - sin(nr )
hd (n) = 4, for n ! 0
rn
3/4 , for n = 0
54
n = 0 & hd (0) = 3
4
n = 1 & hd (1) = hd (- 1) =- 1
2r
n = 2 & hd (2) = hd (- 2) =- 1r
2
h(3) = 0.75
55
Program 1: This program used to generate digital FIR filter coefficients for the filter
specifications given in problem 2.
clear;
clc;
[wft,wfm,fr]=wfir('hp',forder,cfreq,'re',0);
wft; // Time domain filter coefficients
wfm; // Frequency domain filter values
fr; // Frequency sample points
plot(fr,wfm)
//RESULT
/High pass filter coefficents
//- 0.1591549 - 0.2250791 0.75 - 0.2250791 - 0.1591549 for cut off frequency 0.125
//which is equivalent to pi/4
56
Figure 1. Corresponding to Program 1 output.
57
Program 2: Some properties in graphics window of Program 1 changed in the coding itself
clear;
clc;
close;
[wft,wfm,fr]=wfir('hp',forder,cfreq,'re',0);
wft; // Time domain filter coefficients
wfm; // Frequency domain filter values
fr; // Frequency sample points
a=gca();
a.thickness = 3;
a.foreground = 1;
plot(a,fr,wfm,'marker','.','markeredg','red','marker size',2)
xtitle('Magnitude Response Vs Normalized Frequency','Normalized Frequency W
------>','Magnitude Response H(w)---->');
xgrid(2);
//RESULT
58
Figure 2: Corresponding to Program 2.
59
Program 3: This program is same as that of program 1 and program 2. But the filter order
is changed to M =31.
clear;
clc;
close;
[wft,wfm,fr]=wfir('hp',forder,cfreq,'re',0);
wft; // Time domain filter coefficients
wfm; // Frequency domain filter values
fr; // Frequency sample points
a=gca();
a.thickness = 3;
a.foreground = 1;
plot(a,fr,wfm,'marker','.','markeredg','red','marker size',2)
xtitle('Magnitude Response Vs Normalized Frequency','Normalized Frequency W
------>','Magnitude Response H(w)---->');
xgrid(2);
60
Figure 3: Corresponding to program 3 output
61
Program 4: To write programs to generate LPF FIR filter coefficients for the given
specifications in Problem 1.
clear;
clc;
close;
[wft,wfm,fr]=wfir('lp',forder,cfreq,'re',0);
wft; // Time domain filter coefficients
wfm; // Frequency domain filter values
fr; // Frequency sample points
a=gca();
a.thickness = 3;
a.foreground = 1;
plot(a,fr,wfm,'marker','.','markeredg','red','marker size',2)
xtitle('Magnitude Response Vs Normalized Frequency','Normalized Frequency W
------>','Magnitude Response H(w)---->');
xgrid(2);
//RESULT
62
Figure 4: Corresponds to program 4 output. Filter Length M = 5
63
Program 5: Same as that of Program 4 specifications with Filter order M = 31.
clear;
clc;
close;
[wft,wfm,fr]=wfir('lp',forder,cfreq,'re',0);
wft; // Time domain filter coefficients
wfm; // Frequency domain filter values
fr; // Frequency sample points
a=gca();
a.thickness = 3;
a.foreground = 1;
plot(a,fr,wfm,'marker','.','markeredg','red','marker size',2)
xtitle('Magnitude Response Vs Normalized Frequency','Normalized Frequency W
------>','Magnitude Response H(w)---->');
xgrid(2);
64
Figure 5: Corresponding to program 4 output
65
Program 6: To design and plot Low Pass Filter frequency response and High Pass Filter
clear;
clc;
close;
a=gca();
a.thickness = 3;
a.foreground = 1;
plot(a,fr_LPF,wfm_LPF,'marker','.','markeredg','red','marker size',2)
plot(a,fr_HPF,wfm_HPF,'marker','*','markeredg','blue','marker size',2)
xtitle('Magnitude Response Vs Normalized Frequency','Normalized Frequency W
------>','Magnitude Response H(w)---->');
xgrid(1);
h1 = legend('Low Pass Filter','High Pass Filter');
66
Figure 6: Plotting LPF frequency response and HPF frequency response on the same
Graphic window
67
Problem 3
A Band Pass filter is to be designed with the following desired frequency response
^ j~h *1, r # ~ # 3r
H e = 4 4
0, otherwise
Determine the filter coefficients hd(n) if the window function is defined as,
) # G
w(n) = 1,0 n M - 1 [ That is Rectangular Window]
0, otherwise
M = filter length = 11.
Sol:
r 3r
> -
4 4
H
hd (n) = 1
2r
#H d (~).e
j ~n
d~ + #H d (~).e
j ~n
d~
3r r
-
4 4
r 3r
> -
4 4
H
= 21
r
#1.e
j ~n
d~ + #1.e
j ~n
d~
3r r
-
4 4
r
1 =; ej~n E- 4 ; ej~n E 3r4 G
= 2r jn - 3r
+ jn r
4 4
1 8 ` 3r j ` rjB
= r n sin 4 n - sin n 4
68
h(0) = hd(0 )*w(0) = 0.5
69
Problem 4
A Band Pass filter is to be designed with the following desired frequency response
) # G
w(n) = 1,0 n M - 1 [ That is Rectangular Window]
0, otherwise
M = filter length = 11.
Sol:
R 2r r V
S- 3 3 W
S j~nd~ + # j~nd~ +W
S # 1.e 1.e W
1 S- r - r W
h (n) = r S 3 W
2 S r
d
W
S # 1.ej~nd~ W
S W
S2r W
T 3 X
1 8 ^ h `r j ` 2r j B
= 2r sin r n + sin n - sin n
3 3
h(0) = hd(0 )*w(0) = 0.667
70
h(5) = hd(5 )*w(5) = 0 = h (-5)
71
Program 7:
clear;
clc;
close;
[wft,wfm,fr]=wfir('bp',forder,cfreq,'re',0);
wft; // Time domain filter coefficients
wfm; // Frequency domain filter values
fr; // Frequency sample points
for i = 1:length(wft)
if(abs(wft(i))< 1D-5)
wft(i) = 0.0;
end
end
a=gca();
a.thickness = 3;
a.foreground = 1;
plot(a,fr,wfm,'marker','.','markeredg','red','marker size',2)
xtitle('Frequency Response of Band Pass Filter with Lower cutoff =0.125 & Upper Cutoff =
0.375','Normalized Frequency W ------>','Magnitude Response H(w)---->');
xgrid(2);
//RESULT
72
Figure 7: Frequency response of Band Pass Filter
73
Program 8: Design of Digital Band Stop Filter
clear;
clc;
close;
[wft,wfm,fr]=wfir('sb',forder,cfreq,'re',0);
wft; // Time domain filter coefficients
wfm; // Frequency domain filter values
fr; // Frequency sample points
for i = 1:length(wft)
if(abs(wft(i))< 1D-5)
wft(i) = 0.0;
end
end
a=gca();
a.thickness = 3;
a.foreground = 1;
plot(a,fr,wfm,'marker','.','markeredg','red','marker size',2)
xtitle('Frequency Response of Band Stop Filter with Lower cutoff =0.1667 & Upper Cutoff =
0.3333','Normalized Frequency W ------>','Magnitude Response H(w)---->');
xgrid(2);
//RESULT
74
Figure 8: Frequency Response of Band Stop FIR Filter
75
6.2 Design of FIR filters using Frequency Sampling Technique:
In the frequency sampling method the desired frequency response is specified at a set of
equally spaced frequencies
~k = 2r (k + a), k = 0,1,... M - 1
M 2
M - >odd
k = 0,1,... M - 1
2
M - >even
a = 0 or 1
2
If a = 0 It is said to be Type 1 design
If a = 1 It is said to be Type 2 design
2
^h ^h m- 1
G d ~ = G ~ = / h(n)e- j~n , where ‘m’ is the length of the filter
n= 0
When ~ = 2r (K + a)
M
` 2r j M- 1
(K + a) = / h(n) e- j M (K + n
c 2r m
a)
H
M n= 0
^ h m- 1
H K + a = / h(n) e-
` j
j 2r (K + a) n
m
n= 0
76
Symmetric Frequency Samples:
` j
j 2r (K +n) on both sides,
Multiply by e m
M- 1 ` 2r j jc 2r (k+n)m M - 1 M - 1
/ H M (k + a) e M = / / h(n)e- j 2rM an
k= 0 n= 0 k= 0
;
M- 1 M- 1
2r an E
= / / h(n) e- j
M
k= 0 n= 0
M- 1 6 @
/ H(k + a)ej 2rMkn = M h(n)e- j 2rMan
k= 0
M- 1
/ H(k + a) e
j 2r kn
M
= M h(n) e
- j
2r an
M
k= 0
M- 1
h(n) = 1 / H(k + a) e M
j 2r (k+a)n
, n = 0,1,...M - 1
M k= 0
Note 1:
Since h(n) is real frequency samples H(k + a) satisfy the symmetric condition given
by,
H(k + a) = H (M - k - a)
*
This symmetric condition along with symmetric conditions for h(n) can be used to
reduce the frequency specifications from ‘M’ points to M +1
2 points for ‘M’ odd and M
2
points for ‘M’ even.
77
Note 2:
Assume,
` r j
G(k + a) = (- 1) Hr 2 (k + a)
k
; br r (k+a)(M - 1) E
H(k + a) = G(k + a)e e
jr k j -
2 M
Type 1 and Type 2 design for both h(n) is symmetric and asymmetric
jr k
H(k) = G(k)e M
` 2r kj
k
G(k) = (- 1) Hr , G(K) =- (M - k)
M
' U ` r ` jj1
h(n) = 1 G(0) = 2/ G(k)cos 2 K n + 1
M k= 1 M 2
* M 2- 1, M odd
where, U=
M - 1, M even
2
78
Case (ii) Type 2 design, h(n) is symmetric:
a = 1, b = 0
2
` 1j ` 1j j r jr (2k+1)
H k+ = G k + e- 2 e 2M
2 2
` 1j ` 2r ` 1j j
G k+ = (- 1) k Hr k+
2 M 2
` 1j ` 1j
G k+ = G M - k-
2 2
U ` j 8 ` j` jB
h(n) = 2 / G k + 1 sin 2r k + 1 n + 1
M k= 0 2 M 2 2
Case (iii) Type 1 design, h(n) is symmetric:
a = 0, b = 1
^h ^ h j r jr k
H k = G k e 2 e M , k = 0,1.... M - 1
^h k ` 2r k j
G k = (- 1) Hr , G(k) = G(M - k)
M
(m- 1)/2^ h 8
2 / 2r k ` 1j B
h(n) =- G k sin n+ , M odd
M M 2
k= 1
" (M/2) - 1 8 2r k `
1 n+ 1 `Mj
/ 1j B
h(n) = (- 1) G - 2 G(k) sin n+ , M even
M 2 M 2
k= 1
79
Case (iv) Type 2 design, h(n) is asymmetric:
a = 1, b = 1
2
` j ` j jr (2k+1)/2M jr /2
H k+ 1 = G k+ 1 e e
2 2
` j 8 r B
G k + 1 = (- 1) Hr 2 (k + 1)
k
2 M 2
` 1 j ` 1 j
G k + =- G M - k - ; G(M/2) = 0, for 'M' odd.
2 2
80
Program 9: Design of LPF FIR filter using Frequency Sampling Technique
clear;
clc;
M = 7;
N = ((M-1)/2)+1
wc = %pi/2;
for k =1:M
w(k) = ((2*%pi)/M)*(k-1);
if (w(k)>=wc)
k-1
break
end
end
w
for i = 1:k-1
Hr(i) = 1;
G(i) = ((-1)^(i-1))*Hr(i);
end
for i = k:N
Hr(i) = 0;
G(i) = ((-1)^(i-1))*Hr(i);
end
G
h = zeros(1,M);
G(1)/M;
for n = 1:M
for k = 2:N
h(n) = G(k)*cos((2*%pi/M)*(k-1)*((n-1)+(1/2)))+h(n);
end
h(n) = (1/M)* (G(1)+2*h(n));
end
hst1=fsfirlin(h,1);
pas=1/prod(size(hst1))*.5;
fg=pas:pas:.5;//normalized frequencies grid
a=gca();
a.thickness = 3;
a.foreground = 1;
81
plot(a,2*fg,hst1,'marker','.','markeredg','red','marker size',2)
xtitle('Frequency Response of LPF with Normalized cutoff =0.5','Normalized Frequency W
------>','Magnitude Response H(w)---->');
xgrid(2);
//plot2d(2*fg,hst1);
//RESULT
// N = 4.
// ans = 2.
// w =
// 0.
// 0.8975979
// 1.7951958
//G =
// 1.
// - 1.
// 0.
// 0.
//ans = 0.1428571
//h = - 0.1145625 0. 0. 0. 0. 0. 0.
Figure.9 Digital LPF FIR Filter Design using Frequency Sampling Technique. With
Cutoff Frequency = 0.5, Filter length = 7
82
Program 10. Design of Digital BPF FIR Filter design using Frequency Sampling Technique
83
//Design of FIR Filter using Frquency Sampling Technique
//Band Pass Filter Design
//Cutoff Frequency Wc = pi/2
//M = Filter Lenth = 31
clear;
clc;
M = 15;
N = ((M-1)/2)+1
wc = %pi/2;
Hr = [1,1,1,1,0.4,0,0,0];
for k =1:length(Hr)
w(k) = ((2*%pi)/M)*(k-1);
end
w
k = length(Hr);
for i = 1:k
//Hr(i) = 1;
G(i) = ((-1)^(i-1))*Hr(i);
end
G
h = zeros(1,M);
for n = 1:M
for k = 2:N
h(n) = G(k)*cos((2*%pi/M)*(k-1)*((n-1)+(1/2)))+h(n);
end
h(n) = (1/M)* (G(1)+2*h(n));
end
h
hst1=fsfirlin(h,1);
pas=1/prod(size(hst1))*.5;
fg=pas:pas:.5;//normalized frequencies grid
a=gca();
a.thickness = 3;
a.foreground = 1;
Maximum_Gain = max(hst1)
gain_3dB = Maximum_Gain/sqrt(2)
plot(a,2*fg,hst1,'marker','.','markeredg','red','marker size',2)
84
xgrid(2);
plot(2*fg,gain_3dB,'Magenta')
plot(2*fg,Maximum_Gain,'cyan')
h1 = legend('Frequency Response of BPF','3dB Gain','Maximum Gain');
//RESULT
// N =
//
// 8.
// w =
//
// 0.
// 0.4188790
// 0.8377580
// 1.2566371
// 1.6755161
// 2.0943951
// 2.5132741
// 2.9321531
// G =
//
// 1.
// - 1.
// 1.
// - 1.
// 0.4
// 0.
// 0.
// 0.
// h =
//
//
// column 1 to 9
//
// - 0.0141289 - 0.0019453 0.04 0.0122345 - 0.0913880 - 0.0180899 0.3133176
0.52 0.3133176
//
// column 10 to 15
//
// - 0.0180899 - 0.0913880 0.0122345 0.04 - 0.0019453 - 0.0141289
// Maximum_Gain =
//
// 0.52
// gain_3dB =
//
// 0.3676955
Figure 10. Digital BPF FIR Filter Design using Frequency Sampling Technique. With Cutoff
Frequencies =[0.4 0.5], Filter length = 15
85
86