Вы находитесь на странице: 1из 30

CMPE426- Digital Signal Processing Prof.Dr.

Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 1
CH6: FINITE IMPULSE RESPONSE (FIR) FILTER
DESIGN

6.1 Linear Phase Response
Linear phase is important in digital filter design
because it results in a pure time delay with no
amplitude distortion.

The FIR filter is characterized by the following
transfer function

=
1
0
) ( ) (
M
k
k
z k h z H


An FIR filter has linear phase response if its
phase response satisfies one of the following
relationships
= ) (
and
= ) (

Where

and

are constants. The 1st


condition can be satisfied if the filter has a
positive symmetry:

=
=
=
Even M M n
Odd M M n
n M h n h
1 ) 2 / ( , . . , 1 , 0
2 / ) 1 ( , . . , 1 , 0
), 1 ( ) (
2 / ) 1 ( = M

CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 2
When the 2nd condition is satisfied, the filter
will have a negative symmetry:
) 1 ( ) ( n M h n h =
with
2 / ) 1 ( = M
,
2 / =


Therefore, we can say that an FIR filter has
linear phase if its unit sample (or impulse)
response is symmetrical

) 1 ( ) ( n M h n h =


Example: An FIR digital filter has impulse
response, h(n), defined over the interval
1 0 M n
.
a) Show that if M=7 and h(n) satisfies the
symmetry condition
) 1 ( ) ( n M h n h =
and
the filter has a linear phase characteristic.
b) Repeat part (a) if M=8.

Solution:
a) Using the odd symmetry condition, we find
that for M=7:
h(0)=h(6) , h(1)=h(5), h(2)=h(4)
The frequency response, H(w), for the filter is
obtained by making the substitution
T j
e z

=

into the transfer function H(z):
CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 3
) ( ) (
T j
e H H

=

=
6
0
) (
k
T jk
e k h


T j T j T j T j T j T j
e h e h e h e h e h e h h
6 5 4 3 2
) 6 ( ) 5 ( ) 4 ( ) 3 ( ) 2 ( ) 1 ( ) 0 (

+ + + + + + =

[ ]
T j T j T j T j T j T j T j
e h e h e h h e h e h e h e
3 2 2 3 3
) 6 ( ) 5 ( ) 4 ( ) 3 ( ) 2 ( ) 1 ( ) 0 (

+ + + + + + =

( ) ( ) ( ) [ ] ) 3 ( ) 2 ( ) 1 ( ) 0 (
2 2 3 3 3
h e e h e e h e e h e
T j T j T j T j T j T j T j
+ + + + + + =


Using the property
2
cos
jx jx
e e
x

+
=
, we obtain
[ ] ) 3 ( ) cos( ) 2 ( 2 ) 2 cos( ) 1 ( 2 ) 3 cos( ) 0 ( 2 ) (
3
h T h T h T h e H
T j
+ + + =



Now, let a(0)=h(3) and a(k)=2h(3-k) for k=1,2,3.
Then H(w) can be written in compact form as

= =
3
0
) ( 3
) ( ) cos( ) ( ) (
k
j T j
e H e T n k a H



where
=
=
3
0
) cos( ) ( ) (
k
T n k a H
and
T 3 ) ( =

Clearly, the phase response is linear.

b) Using the even symmetry condition, we
find that for M=8:
h(0)=h(7) , h(1)=h(6), h(2)=h(5), h(3)=h(4)

Following the same approach, we have
CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 4
( ) ( ) ( )
( )
(
(

+ +
+ + + + +
=

2 / 2 /
2 / 3 2 / 3 2 / 5 2 / 5 2 / 7 2 / 7
2 / 7
) 3 (
) 2 ( ) 1 ( ) 0 (
) (
T j T j
T j T j T j T j T j T j
T j
e e h
e e h e e h e e h
e H

) ( 2 / 7
) (
) 2 / cos( ) 3 ( 2 ) 2 / 3 cos( ) 2 ( 2
) 2 / 5 cos( ) 1 ( 2 ) 2 / 7 cos( ) 0 ( 2



j T j
e H
T h T h
T h T h
e =
(

+
+ +
=

where
[ ] ) 2 / 1 ( cos ) ( ) (
4
1
=

=
k k b H
k

,
2 / 7 ) ( T =

and
) 2 / ( 2 ) ( k M h k b =
for k=1, 2,...M/2.

6.2 Types of Linear Phase FIR Filters
There are 4 types of linear phase FIR filters,
depending on whether M is even or odd and
whether h(n) has positive or negative
symmetry. The following table summarizes their
key features.

Impulse
response
symmetry

M
Frequency response
) ( H

Type
Positive
symmetry
Odd

=

=
2 / ) 1 (
0
2 / ) 1 (
) cos( ) ( ) (
M
n
M j
n n a e H


1
Positive
symmetry
Even

=

(

=
2 /
1
2 / ) 1 (
)
2
1
( cos ) ( ) (
M
n
M j
n n b e H


2
Negative
symmetry
Odd
[ ]

=

=
2 / ) 1 (
1
2 / 2 / ) 1 (
) sin( ) ( ) (
M
n
M j
n n a e H


3
Negative
symmetry
Even
[ ]

=

(

=
2 /
1
2 / 2 / ) 1 (
)
2
1
( sin ) ( ) (
M
n
M j
n n b e H


4
CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 5
Where
[ ] 2 / ) 1 ( ) 0 ( = M h a
,
[ ] n M h n a = 2 / ) 1 ( 2 ) (
,
) 2 / ( 2 ) ( n M h n b =



CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 6
Example: Let
{ } 4 , 1 , 1 , 2 , 5 , 6 , 5 , 2 , 1 , 1 , 4 ) ( = n h
.
Determine the amplitude response
) ( H
.

Solution: Since M=11 (odd), and since h(n) is
symmetric about
5 2 / ) 1 ( = = M
, this is a Type-
1 linear phase FIR filter.
6 ) 5 ( ) 0 ( = = h a
,
10 ) 1 5 ( 2 ) 1 ( = = h a
,
4 ) 2 5 ( 2 ) 2 ( = = h a
,
2 ) 3 5 ( 2 ) 3 ( = = h a
,
2 ) 4 5 ( 2 ) 4 ( = = h a
,
8 ) 5 5 ( 2 ) 5 ( = = h a


5 cos ) 5 ( 4 cos ) 4 ( 3 cos ) 3 ( 2 cos ) 2 ( cos ) 1 ( ) 0 ( ) ( a a a a a a H + + + + + =
5 cos 8 4 cos 2 3 cos 2 2 cos 4 cos 10 6 ) ( + + = H


Example: Let
{ } 4 , 1 , 1 , 2 , 5 , 6 , 6 , 5 , 2 , 1 , 1 , 4 ) ( = n h
.
Determine the amplitude response
) ( H
.

Solution: Since M=12 (even), and since h(n) is
symmetric about
5 . 5 2 / ) 1 ( = = M
, this is a
Type-2 linear phase FIR filter.
12 ) 1
2
12
( 2 ) 1 ( = = h b
,
10 ) 2
2
12
( 2 ) 2 ( = = h b
,
4 ) 3
2
12
( 2 ) 3 ( = = h b
,
2 ) 4
2
12
( 2 ) 4 ( = = h b
,
2 ) 5
2
12
( 2 ) 5 ( = = h b
,
8 ) 6
2
12
( 2 ) 6 ( = = h b

CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 7

(

+
(

+
(

+
(

+
(

+
(

=
)
2
1
6 ( cos ) 6 ( )
2
1
5 ( cos ) 5 ( )
2
1
4 ( cos ) 4 (
)
2
1
3 ( cos ) 3 ( )
2
1
2 ( cos ) 2 ( )
2
1
1 ( cos ) 1 ( ) (


b b b
b b b H


)
2
11
cos( 8 )
2
9
cos( 2
)
2
7
cos( 2 )
2
5
cos( 4 )
2
3
cos( 10 )
2
cos( 12 ) (

+
+ = H



Example: Let
{ } 4 , 1 , 1 , 2 , 5 , 0 , 5 , 2 , 1 , 1 , 4 ) ( = n h
.
Determine the amplitude response
) ( H
.

Solution: Since M=11 (odd), and since h(n) is
antisymmetric about
5 2 / ) 1 ( = = M
, this is a
Type-3 linear phase FIR filter.
0 ) 5 ( ) 0 ( = = h a
,
10 ) 1 5 ( 2 ) 1 ( = = h a
,
4 ) 2 5 ( 2 ) 2 ( = = h a
,
2 ) 3 5 ( 2 ) 3 ( = = h a
,
2 ) 4 5 ( 2 ) 4 ( = = h a
,
8 ) 5 5 ( 2 ) 5 ( = = h a


5 sin ) 5 ( 4 sin ) 4 ( 3 sin ) 3 ( 2 sin ) 2 ( sin ) 1 ( ) 0 ( ) ( a a a a a a H + + + + + =

5 sin 8 4 sin 2 3 sin 2 2 sin 4 sin 10 0 ) ( + + = H


CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 8
Example: Let
{ } 4 , 1 , 1 , 2 , 5 , 6 , 6 , 5 , 2 , 1 , 1 , 4 ) ( = n h
.
Determine the amplitude response
) ( H
.

Solution: Since M=12 (even), and since h(n) is
antisymmetric about
5 . 5 2 / ) 1 ( = = M
, this is a
Type-4 linear phase FIR filter.
12 ) 1
2
12
( 2 ) 1 ( = = h b
,
10 ) 2
2
12
( 2 ) 2 ( = = h b
,
4 ) 3
2
12
( 2 ) 3 ( = = h b
,
2 ) 4
2
12
( 2 ) 4 ( = = h b
,
2 ) 5
2
12
( 2 ) 5 ( = = h b
,
8 ) 6
2
12
( 2 ) 6 ( = = h b


(

+
(

+
(

+
(

+
(

+
(

=
)
2
1
6 ( sin ) 6 ( )
2
1
5 ( sin ) 5 ( )
2
1
4 ( sin ) 4 (
)
2
1
3 ( sin ) 3 ( )
2
1
2 ( sin ) 2 ( )
2
1
1 ( sin ) 1 ( ) (


b b b
b b b H


)
2
11
sin( 8 )
2
9
sin( 2
)
2
7
sin( 2 )
2
5
sin( 4 )
2
3
sin( 10 )
2
sin( 12 ) (

+
+ = H





CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 9
6.3 Window Method
Let
) (
D
H
represent the desired frequency
response function. Since
) (
D
H
is a periodic
function of

with period
2
, it can be
expressed as a Fourier series,

=
n
n j
D D
e n h H

) ( ) (

where the Fourier coefficients,
) (n h
D
, are
precisely the corresponding impulse response
samples and are given by

d e H n h
n j
D D
) (
2
1
) (

If we know
) (
D
H
, we can obtain
) (n h
D
by
evaluating the above equation.

For example, we can start with the ideal
lowpass response shown below where c

is the
cutoff frequency and the frequency scale is
normalized: T=1.

CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 10
Hence, the impulse response is given by


= =
c
c
d e d e n h
n j n j
D

2
1
1
2
1
) (

=
0 , 2
0 ,
) sin( 2
) (
n f
n
n
n f
n h
c
c
c c
D



The impulse responses for the ideal highpass,
bandpass and bandstop filters are obtained
from the above equation. These impulse
responses are summarized in the following
Table.

Table 6.1



CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 11
The impulse response for the lowpass filter
(LPF) is shown below.


It is clear that
) (n h
D
is symmetrical about
0 = n

(that is
) ( ) ( n h n h
D D
=
), so that the filter will have
a linear phase response.
However, there are several practical problems
with this method. Since,
) (n h
D
decreases as we
move away from
0 = n
and it carries on to
= n
. Therefore, the resulting filter is not an
FIR.

An obvious solution is to truncate the ideal
impulse response by setting
0 ) ( = n h
D
for
n

greater than M. However, this introduces
undesirable ripples and overshoots as shown
below.
CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 12


Clearly, the more coefficients that are retained,
the closer the filter spectrum is to the ideal
response.

Direct truncation of
) (n h
D
is equivalent to
multiplying the ideal response by a rectangular
window of the form
CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 13

=
=
elsewhere
M n
n w
, 0
2 / ) 1 ( ,..., 1 , 0 , 1
) (

The resulting impulse response decays
smoothly towards zero as shown below.


6.4 Some Common Window Functions
a) Hamming Window
One of the most widely used window
functions is the Hamming window which is
defined as
CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 14



+
=
elsewhere
even M M n M
odd M M n M
M n
n w
0
) . ( 2 / 2 /
) . ( 2 / ) 1 ( 2 / ) 2 (
) / 2 cos( 46 . 0 54 . 0
) (


b) Hanning Window
The Hanning window is defined as



+
=
elsewhere
even M M n M
odd M M n M
M n
n w
0
) . ( 2 / 2 /
) . ( 2 / ) 1 ( 2 / ) 2 (
) / 2 cos( 5 . 0 5 . 0
) (


c) Blackman Window
The Blackman window is defined as
The most relevant features of some of the
most popular window functions are
summurized in Table 6.2.

\
|

+
|

\
|

+
=
elsewhere
even M M n M
odd M M n M
M
n
M
n
n w
0
) . ( 2 / 2 /
) . ( 2 / ) 1 ( 2 / ) 2 (
1
4
cos 08 . 0
1
2
cos 5 . 0 42 . 0
) (


CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 15
6.5 Summary of the Window Method of
Calculating FIR Filter Coefficients
Step 1: Specify the ideal or desired frequency
response
) (
D
H
.

Step 2: Using the table provided before, select
the impulse response,
) (n h
D
, of the desired
filter.

Step 3: Select a window function that satisfies
the passband or attenuation specifications and
then determine the number of filter
coefficients.

Step 4: Obtain values of
) (n w
for the chosen
window function and the values of the actual
FIR coefficients,
) (n h
, by multiplying
) (n h
D
by
) (n w
:

) ( ) ( ) ( n w n h n h
D
=


Example: Determine the coefficients of an FIR
lowpass filter to meet the specifications given
below using the window method.

CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 16
Passband edge frequency=1.5kHz
Transition width=0.5kHz
Stopband attenuation>50dB
Sampling frequency, F
s
=8kHz

Solution: Using Table 6.1, we select
) (n h
D
for
LPF which is given by

=
0 , 2
0 ,
) sin( 2
) (
n f
n
n
n f
n h
c
c
c c
D


From Table, it can be seen that the Hamming,
Blackman and Kaiser windows satisfy the
stopband attenuation requirements. Let us
select the Hamming window for simplicity.

Now, transition width,
kHz F 5 . 0 =

Normalized transition width,
0625 . 0
8
5 . 0
= =

=
s
F
F
f


Using Table 6.2, we obtain that the transition
width for Hamming window is
M f / 3 . 3 =
from
which we obtain the filter length as

8 . 52
0625 . 0
3 . 3 3 . 3
= =

=
f
M

53 = M

CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 17
Then the filter coefficients can be calculated
from
) ( ) ( ) ( n w n h n h
D
=
for
26 26 n
.

However, the cutoff frequency of the resulting
filter is different from the one given in the
specifications (the smearing effect of the
window)
kHz
F
f f
c c
75 . 1
2
5 . 0
5 . 1
2
= + =

+ =

(Unnormalized)
Normalizing this gives 1.75/8=0.21875.


n=0
4375 . 0 21875 . 0 2 2 ) 0 ( = =

=
c D
f h


1 ) 0 cos( 46 . 0 54 . 0 ) 0 ( = + = w


4375 . 0 ) 0 ( ) 0 ( ) 0 ( = = w h h
D


n=1
31219 . 0 ) 21875 . 0 2 sin(
21875 . 0 2
21875 . 0 2
) 1 ( =

D
h


99677 . 0 )
53
2
cos( 46 . 0 54 . 0 ) 1 ( = + =

w


31118 . 0 ) 1 ( ) 1 ( ) 1 ( ) 1 ( = = = w h h h
D


n=2
06013 . 0 ) 21875 . 0 2 2 sin(
21875 . 0 2 2
21875 . 0 2
) 2 ( =

D
h

CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 18

98713 . 0 )
53
2 2
cos( 46 . 0 54 . 0 ) 2 ( =

+ =

w


06012 . 0 ) 2 ( ) 2 ( ) 2 ( ) 2 ( = = = w h h h
D

. . .
. . .
. . .
n=26
01131 . 0 ) 21875 . 0 2 26 sin(
21875 . 0 2 26
21875 . 0 2
) 26 ( =

D
h


08081 . 0 )
53
2 26
cos( 46 . 0 54 . 0 ) 2 ( =

+ =

w


000914 . 0 ) 26 ( ) 26 ( ) 26 ( ) 26 ( = = = w h h h
D


Note that the indices of the filter coefficients
run from -26 to 26. To make the filter causal
(necessary for implementation) we add 26 to
eac index so that the indices start at zero.

For instance, after this adjustment, we obtain
h(0+26)=h(26)=0.4375
h(1+26)=h(27)=0.31118
h(2+26)=h(28)=0.06012
. . .
. . .
h(26+26)=h(52)=-0.000914
CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 19
The filter coefficients, with indices adjusted, are
listed in the following Table.



Example: A requirement exists for an FIR filter
to meet the following specifications:
Passband =150-250Hz
Transition width=50Hz
CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 20
Passband ripple= 0.1dB
Stopband attenuation=60dB
Sampling frequency=1kHz

Obtain the filter coefficients and spectrum using
the window method.

Solution: From the specification, the passband
and stopband ripples are
Passband ripple:

dB
p
1 . 0 ) 1 log( 20 = +

005 . 0
20
1 . 0
) 1 log( = = +
p


01157 . 1 10 1
005 . 0
= = +
p


01157 . 0 =
p


Stopband ripple:

dB
s
60 ) log( 20 =


3
20
60
) log( = =
s



001 . 0 10
3
= =

s


We use the smaller of the ripples,
CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 21

001 . 0 ) , min( = =
s p


It is clear from Table 6.2 that the attenuation
requirements can be met by the Kaiser or the
Blackman window.

For the Kaiser window, the number of
coefficients is computed by

49 . 72
) 1000 / 50 ( 36 . 14
95 . 7 60
36 . 14
95 . 7
=

F
A
M

where
60 ) ( log 20
10
= = A
. The Kaiser
window function is (see Table 6.2)
) (
1
2
1
) (
2 / 1
2

o
o
I
M
n
I
n w

(
(

\
|

=

Where
) (x I
o is the zero-order modified Bessel
function of the first kind. The ripple parameter,

, is given by
0 =
if
dB A 21

) 21 ( 007886 . 0 ) 21 ( 5842 . 0
4 . 0
+ = A A

if
dB A dB 50 21 < <

CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 22
) 7 . 8 ( 1102 . 0 = A
if
dB A 50


Clearly, the coefficient computation using
Kaiser window requires tedious computations
by hand. Therefore, we will discuss its
computation method by a MATLAB program
later!

For the Blackman window, an estimate of the
number of filter coefficients is obtained as
(from Table 6.2)
110
) 1000 / 50 (
5 . 5 5 . 5
=

=
f
M


To account for the smearing effects of the
window function, we compute the cutoff
frequencies as follows
Hz
f
f f
c c
125 1000
2
) 1000 / 50 (
150
2
1 1
= =


Hz
f
f f
c c
275 1000
2
) 1000 / 50 (
250
2
2 2
= + =

+ =



CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 23
Finally, using the Blackman window function
given in Table 6.2, we can compute the filter
coefficients. (EXERCISE)

6.6 FIR Filter Design With MATLAB
The MATLAB Signal Processing Toolbox contains
an excellent set of programs and functions for
the design and analysis of different types of FIR
filters.

For standard, frequency selective linear phase
window based FIR filterd design (lowpass,
highpass, bandpass and bandstop), the key
high-level command in the Toolbox is the fir1
command. The syntax for the fir1 command
is
b=fir1(M-1,Fc)

This command computes and returns N-point
impulse response coefficients of an FIR filter
with a cutoff frequency F
c
. The coefficients are
stored in the vector b which are arranged as
negative powers of z:
) 1 ( 2 1
) 1 ( ... ) 2 ( ) 1 ( ) 0 ( ) (

+ + + + =
M
z M b z b z b b z b

CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 24
The parameter , M, specifies the order of the
filter. The cutoff frequency, F
c
, is normalized
with respect to the Nyquist rate (i.e, half the
sampling frequency) and lies between 0 and 1
(where 1 corresponds to the Nyquist
frequency).

By default, the basic fir1 command applies a
Hamming window and assumes a lowpass filter
(or a bandpass filter if F
c
specifies more than
one cutoff frequency).

However, the basic fir1 command can be
extended by specifying the type of filter and/or
the window function. The syntax in these case
is:
b=fir1(M-1,Fc,filter-type)
b=fir1(M-1,Fc,window)
b=fir1(M-1,Fc,filter-type,window)

For a highpass filter, the word high specifies
the filter type, and for bandstop the word stop
is used. For both bandpass and bandstop filters,
the variable F
c
is a vector that specifies the
CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 25
cutoff frequencies. For highpass and bandstop
filters, the filter length must be an odd integer
(even integer results in zero magnitude
response).

MATLAB supports the use of a variety of
window functions including Hamming, Hanning,
boxcar (rectangular), Kaiser, and Chebyshev
windows. The syntax for generating window
coefficients is:
w=boxcar(M)
w=blackman(M)
w=hamming(M)
w=hanning(M)
w=kaiser(M, beta)

Usually, the window command is embedded
into the fir1 command.

Example: Determine the coefficients of a linear
phase FIR lowpass filter with a passband and
stopband edge frequency of 1kHz and 4.3kHz,
respectively.

CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 26
Solution: From Table 6.2, the approximate
relationship between the transition width and
filter length for a Hamming window-based filter
is

10
10 / ) 1 3 . 4 (
3 . 3 3 . 3
=

f
M

The actual cutoff frequency (allowing for the
smearing effect) is

kHz
F
f f
c c
65 . 2
2
3 . 3
1
2
= + =

+ =


In MATLAB, the cutoff frequency should be
normalized to half the samling frequency. Thus,
53 . 0
5
65 . 2
= =
c
f


MATLAB m-file:
FS=10000; %Sampling Fre.
fc=0.53; %Cutoff frequency
M=10; %Filter length
hd=fir1(M-1,fc,boxcar(M)); %Ideal
wn=hamming(M); %Calculate coefficients
hn=fir1(M-1,fc,wn); %Obtain win. coeff.
[H,f]=freqz(hn,1,512,FS);%Fre. Res.
mag=20*log10(abs(H));
CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 27
plot(f,mag), grid on
xlabel (Frequency (Hz))
ylabel (MagnitudeResponse(dB))


0 500 1000 1500 2000 2500 3000 3500 4000 4500 5000
-90
-80
-70
-60
-50
-40
-30
-20
-10
0
Frequency(Hz)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e

(
d
B
)


Example: Determine the coefficients and plot
the magnitude-frequency response of a
bandpass FIR filter, using the Kaiser window and
MATLAB, that meets the following
specifications:
Passband=150-250Hz
CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 28
Transition width=50Hz
Passband ripple=0.1dB
Stopband attenuation=60dB
Sampling frequency=1kHz

Solution: This problem is identical to Example
on page 18, which gives the filter length, M=73,
and the ripple parameter,
65 . 5 =
.

MATLAB m-file:
FS=1000;
FN=FS/2;
M=73;
beta=5.65;
fc1=125/FN;
fc2=275/FN;
FC=[fc1 fc2];
hn=fir1(M-1,FC,kaiser(M,beta));
[H,f]=freqz(hn,1,512,FS);
mag=20*log10(abs(H));
plot(f,mag), grid on
xlabel (Frequency (Hz))
ylabel (MagnitudeResponse(dB))


CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 29
0 50 100 150 200 250 300 350 400 450 500
-120
-100
-80
-60
-40
-20
0
20
Frequency(Hz)
M
a
g
n
i
t
u
d
e

R
e
s
p
o
n
s
e

(
d
B
)













Log(1)=0dB
f=250Hz
f=150Hz
CMPE426- Digital Signal Processing Prof.Dr. Hasan Kmrcgil
CHAPTER 6: Finite Impulse Response (FIR) Filter Design 30

Вам также может понравиться