You are on page 1of 66

Kochar Inderkumar

Asst. Professor
MPSTME, Mumbai
Introduction
FIR Filter Design
Window Based Design
Frequency Sampling Method
IIR Filter Design
Mappings from s-domain to z-domain
Magnitude Approximations


In signal processing, the functions of a filter are:
Removing unwanted parts of the signal, such as random noise
Extracting useful parts of the signal, such as the components
lying within a certain frequency range.
There are two main kinds of filters:
analog and digital
Analog Filters:
An analog filter uses analog electronic circuits made up from
components such as resistors and capacitors to produce the
required filtering effect. Such filter circuits are widely used
in such applications as noise reduction, signal enhancement,
and many other areas.

Advantages:
- simple and consolidated methodologies of plan
- fast and simple realization

Disadvantages:
- little stable and sensitive to temperature variations
- expensive to realize in large amounts.
Digital Filters:
A digital filter uses a digital processor to perform numerical
calculations on sampled values of the signal. The processor
may be a general-purpose computer such as a PC, or a
specialized Digital Signal Processor chip.

Advantages:
- Programmable
- Easily designed, tested and implemented on a computer.
-Extremely stable with respect both to time and temperature.
- Can handle low frequency signals accurately.
1. Unity Gain Filter
2. Constant gain filter
3. Unit delay filter
4. Two - term Difference filter
5. Two-term average filter
6. Three-term average filter
(3-point moving average filter)

Note:
Order of the filter is the number of previous inputs used
to compute the current output.

Understanding Simple Filtering Operations:
( )
( )
[ ] [ ]
[ ] . [ ]
[ ] [ 1]
[ ] [ ] [ 1]
[ ] 0.5 [ ] [ 1]
1
[ ] [ ] [ 1] [ 2]
3
y n x n
y n K x n
y n x n
y n x n x n
y n x n x n
y n x n x n x n
=
=
=
=
= +
= + +
The design of a digital filter is carried out in three steps:
Specifications
Determined by the applications
Approximations
Magnitude and phase approximations
Implementation
Difference equation or
System function H(z), or
An impulse response h(n)
Specifications are required in the frequency-domain in terms
of the desired magnitude and phase response of the filter.
Generally a linear phase response in the passband is desirable.
In the case of FIR filters, It is possible to have exact linear
phase.
In the case of IIR filters, a linear phase in the passband is
not achievable.
Absolute specifications
Provide a set of requirements on the
magnitude response function |H(e
j
)|.
Generally used for FIR filters.

Relative specifications
Provide requirements in decibels (dB), given
by



Used for both FIR and IIR filters.
10
max
| ( ) |
20log 0
| ( ) |
j
j
H e
dB scale
H e
e
e
= >
Band [0,
p
] is called the
passband, and
p
is the tolerance
(or ripple) that we are willing to
accept in the ideal passband
response.
Band [
s
, ] is called the
stopband, and
s
is the
corresponding tolerance (or
ripple)
Band [
p
,
s
] is called the
transition band, and there is no
restriction on the magnitude
response in this band.
1
10
1
2
10
1
1
20log 0
1
20log 0
1
p
s
R for passband
A for stopband
o
o
o
o

= >
+
= >
+
10
max
( )
dB scale 20log
( )
H
H
e
e
=
10
20log (1 )
p p
o o =
10
20log ( )
s s
o o =
A Finite Impulse Response (FIR) digital filter is one whose
impulse response is of finite duration.

The general difference equation for a FIR digital filter is:
where:
y(n) is the filter output at discrete time instance n.
b
k
is the k-th feed-forward tap, or filter coefficient.
x(n-k) is the filter input delayed by k samples.
M is the number of feed-forward taps in the FIR filter.
Note: The FIR filter output depends only on the previous M
inputs. This feature is why the impulse response for a FIR filter
is finite.
0
[ ] [ ]
M
k
k
y n b x n k
=
=

Advantages in using an FIR filter:


Can be designed with exact linear phase.
Filter structure always stable with quantized coefficients.

Disadvantage in using an FIR filter
Order of an FIR filter is considerably higher than that of an
equivalent IIR filter meeting the same specifications; this
leads to higher computational complexity for FIR
Symmetric and Anti-symmetric FIR filters:
Symmetry in filter impulse response will ensure Linear phase







Zeros exist in reciprocal-conjugate pairs
SEQUENCE TYPE FILTER TYPE
TYPE-1 Odd length even symmetry
TYPE-2 Even length even symmetry
TYPE-3 Odd length odd symmetry
TYPE-4 Even length odd symmetry
Fourier series based method

Window based method

Frequency sampling method

Optimal FIR filter design
( ) ( )
( )
1
( ) ( )
2
j j n
d d
n
d
j j n
d d
H e h n e
where h n are Fourier series coefficients
h n H e e d
e e
t
e e
t
e
t

=
=

}
Motivation: Since the desired freq response H
d
(e
j
) is a periodic
function in with period 2, it can be expressed as Fourier
series expansion
This expansion results in non-causal and infinite impulse
response coefficients.
It can be made finite duration by truncation.
Linear phase can be obtained by introducing symmetric
property in the filter impulse response, i.e., h(n) = h(-n)
Can be made causal by introducing sufficient delay.
1. From the desired frequency response using inverse FT
relation obtain h
d
(n)
2. Truncate the infinite length of the impulse response to
finite length with ( assuming M odd)



3. Introduce h(n) = h(-n) for linear phase characteristics
4. Write the expression for H(z); this is non-causal
realization
5. To obtain causal realization H(z) = z
-(M-1)/2
H(z)

( ) ( ) ( 1) / 2 ( 1) / 2
0
d
h n h n for M n M
otherwise
= s s
=
FILTER TYPE
(IDEAL)
FREQUENCY RESPONSE IMPULSE RESPONSE

Low Pass


High Pass


Band Pass


Band Reject

( )
2 1
2 1
2
1
sin( ) 0
( )
/ 0
1
sin( ) 0
( )
1 / 0
1
sin( ) sin( ) 0
( )
/ 0
1
sin( ) s
( )
c
d
c
c
d
c
c c
d
c c
c
d
n n
h n n
n
n n
h n n
n
n n n
n
h n
n
n
n
h n
e
t
e t
e
t
e t
e e
t
e e t
e
t

>

>

( >

=


=
( )
1
2 1
in( ) 0
1 / 0
c
c c
n n
n
e
e e t

( >

( )
( )
( )
( )
1 2
1 2
1
0
1
0
1
0
1 &
0
c
d
c
d
c c
d
c c
d
H
otherwise
H
otherwise
H
otherwise
H
otherwise
e e
e
e e
e
e e e
e
e e e e
e
s

>

s s

s >

otherwise
for e H
j
d
0
4
3
4
1 ) (
=
s s =
t
e
t
e
Design an ideal bandpass filter with a frequency response:
Find the values of h(n) for M = 11 and plot the frequency
response.
1.0
H
d
(e
jw
)
-3/4
-/4 /4 3/4 -

/ 4 3 / 4
3 / 4 / 4
1
( ) ( )
2
1
2
1 3
sin sin , 0
4 4
11 ( ) ( ) | | 5
0
j j n
d d
j n j n
d
h n H e e d
e d e d
n n n n
n
truncating to samples we have h n h n for n
otherwise
t
e e
t
t t
e e
t t
e
t
e e
t
t t
t

=
(
= +
(

(
= s s =
(

= s
=
}
} }
Or by using the equation:
( )
2 1
2 1
1
sin( ) sin( ) 0
( )
/ 0
c c
d
c c
n n n
n
h n
n
e e
t
e e t

(
>

=

For n = 0 the value of h(n), using L-Hospitals rule


h(0) = 0.5
Other values of h(n) are evaluated from h(n)
expression
h(1) = h(-1) = 0
h(2) = h(-2) = -0.3183
h(3) = h(-3) = 0
h(4) = h(-4) = 0
h(5) = h(-5) = 0
( 1)/ 2
1
2 2
' 5 2 2
3 5 7
( ) (0) [ ( ){ }
0.5 0.3183( )
( ) [0.5 0.3183( )]
0.3183 0.5 0.3183
(0) (10) (1) (9) (2
M
n n
n
H z h h n z z
z z
the transfer function of the realizable filter is
H z z z z
z z z
the filter coefficients are
h h h h h



= + +
= +
= +
= +
= = = =

) (8) (4) (6) 0


(3) (7) 0.3183
(5) 0.5
h h h
h h
h
= = = =
= =
=
The transfer function of the filter is:
3
2
0
( ) ( )
1 1
( ) 2 ( ) cos
2 2
j
r
M
r
n
H H e
M M
H h h n n
oe
e e
e e

=
=
(
| | | |
= +
| | (
\ . \ .

The magnitude response function is


|H(e
j
)| = 0.5 0.6366 cos 2
Frequency Response of the Designed Filter
Shifting
Motivation: To counteract Gibbs phenomenon
) (e
IDEAL
H
2
1
) ( ) (

=
=

M
e H H
j
IDEAL d
o
e e
oe
}

= =
t
t
e
e e
t
e d e H H IDTFT n h
n j
d d d

) (
2
1
)] ( [ ) (
1 0 ), ( ) ( ) ( M- n n w n h n h
d
s s =
1 0 M- n s s
Ideal frequency response (given)
Step 1
Step 2
Step 3
Window function
symmetric about o over
0 otherwise
Rectangular Window:
1 0 1 ) ( s s = M n for n w
r
Exact transition width:
e
s
- e
p
= 1.8t/M
Min. stopband attenuation:
As=21dB
MATLAB function:
w=boxcar (M)
2
( ) 0.5 1 cos 0 1
1
han
n
w n for n M
M
t
| |
= s s
|

\ .
Hanning Window:
Exact transition width:
e
s
- e
p
= 6.2t/M
Min. stopband attenuation:
A
s
= 44dB
MATLAB function:
w=hann (M)
Hamming Window:
Exact transition width:
e
s
- e
p
= 6.6t/M
Min. stopband attenuation:
A
s
= 53dB
MATLAB function:
w=hamming (M)
2
( ) 0.54 0.46cos 0 1
1
ham
n
w n n M
M
t
= s s

Blackman Window:
Exact transition width:
e
s
- e
p
= 11t/M
Min. stopband attenuation:
A
s
= 74dB
MATLAB function:
w=blackman (M)
2 4
( ) 0.42 0.5cos 0.08cos 0 1
1 1
blk
n n
w n n M
M M
t t
= + s s

s s

s s

=
otherwise , 0
1
2
1
,
1
2
2
2
1
0 ,
1
2
) ( M n
M
M
n
M
n
M
n
n w
Bartlett Window:
Exact transition width:
e
s
- e
p
= 6.1t/M
Min. stopband attenuation:
A
s
= 25dB
MATLAB function:
w=bartlett (M)
Bartlett
Blackman
Hamming
Hanning
Rectangular
For M = 50
MATLAB function:
w = kaiser(M,beta)
1/ 2
2
0
0
2
1 (
1
1
[ ]
,
( ) 2
0 , otherwise
k
n
I
M
M
w n
n
I
o
o


(
| |


( `
|

\ .
(


) =

s

( )
2
0
1
1
1
! 2
k
k
x
I x
k

=
(
| |
= +
(
|
\ .
(

( )

0.05
0.05
0.05
0.4
Given , , ,
Determine A and such that
10 1
10 ,
10 1
20log where, min ,
0.1102( 8.7) , 50
0.5842( 21) 0.07886( 21) , 21 50
0.0 , 21
p
s
p
p s p s
A
A
s p
A
p s
A
A A
A A A
A
e e o o
o
o o
o o o o
o


= =
+
= =
>

= + s s

<

Determine such that


8

2 285
s p
M
A-
M
. ( - )
>
( ) ( ) ( ) ( )
( 1) / 2 ( 1) / 2
d
h n h n w n where w n is the window function
defined for M n M
=
s s
1. From the desired frequency response using inverse FT relation,
obtain h
d
(n)
2. Truncate the infinite length of the impulse response to
finite length with ( assuming M odd) choosing proper
window
3. Introduce h(n) = h(-n) for linear phase characteristics
4. Write the expression for H(z); this is non-causal realization
5. To obtain causal realization H(z) = z
-(M-1)/2
H(z)
2
( ) 0.5 1 cos 0 1
1
han
n
w n for n M
M
t
| |
= s s
|

\ .
3
( )
4 4
0 | |
4
j j
d
H e e for
e e
t t
e
t
e t

= s s
= < s
Design a filter with a frequency response:
using a Hanning
window with M = 7
The frequency response is having a term e
j(M-1)/2

which gives h(n) symmetrical about n = M-1/2 = 3
i.e we get a causal sequence.
/ 4
3
/ 4
1
( )
2
sin ( 3)
4
( 3)
(0) (6) 0.075
(1) (5) 0.159
(2) (4) 0.22
(3) 0.25
j j n
d
d d
d d
d d
d
h n e e d
n
n
this gives h h
h h
h h
h
t
e e
t
e
t
t
t

= =
= =
= =
=
}
The Hanning window function
values are given by
w
hn
(0) = w
hn
(6) =0
w
hn
(1)= w
hn
(5) =0.25
w
hn
(2)= w
hn
(4) =0.75
w
hn
(3)=1
h(n)=h
d
(n) w
hn
(n)
h(n)=[0 0.03975 0.165 0.25
0.165 0.3975 0]
Rationale: Given the desired frequency response, take
samples of the frequency response at regular intervals
and use IDFT to obtain the impulse response.
No. of samples = N
Samples are taken at the frequencies f
s




Impulse response computation:


1
(2 / )
0
1
( ) ( )
N
j N nk
k
h n H k e
N
t

=
=

/ 0,1,..., -1 (Type-1 design)
( 1/ 2) / 0,1,..., -1 (Type-2 design)
s
s
s
kF N k N
f
k F N k N
=

=

+ =

where H(k), k=0,1,,N-1 are the samples of the target


frequency response.








(a) Frequency response of an ideal low-pass filter. (b) Samples of the
frequency response. (c) Frequency response of the realized filter
/ 0,1,..., -1 (Type-1 design)
( 1/ 2) / 0,1,..., -1 (Type-2 design)
s
s
s
kF N k N
f
k F N k N
=

=

+ =

Design a low pass linear-phase FIR filter to have a passband


upto 5kHz filter. Assume a sampling frequency of 18kHz and
filter length=9.
( )
1
(2 / )
0
1
(2 / ) (2 / )
0
1
0
1
( ) ( )
1
( )
2
1
( ) cos (since h[n] is real)
N
j N nk
k
N
j k N j N nk
k
N
k
h n H k e
N
H k e e
N
k n
H k
N N
t
to t
t o

=
=
=
(
=
(

NOTE: For N=odd, the upper limit in the summation


should be (N-1)/2
Taking samples of the frequency response at intervals of kF
s
/N,
i.e every 2 kHz:
1 k=0,1,2
( )
0 k=3,4
1
4
2
H k
N
o

= =
IMPULSE RESPONSE COEFFICIENTS
h[0]=0.072522627=h[8]
h[1]=-0.111111111=h[7]
h[2]=-0.059120987=h[6]
h[3]=0.31993169=h[5]
h[4]=0.55555555
The general difference
equation for an IIR filter:
a
k
is the k-th feedback tap depending on
previous outputs. If a
k
= 0 then the filter is a FIR.
N is the number of feedback taps in the IIR
filter.
M is the number of feed-forward taps.
The
transfer
function:
1 1
[ ] [ ] [ ]
N M
k k
k k
y n a y n k b x n k
= =
= +

1
1
( )
( )
( )
1
N
k
k
k
M
k
k
k
b z
Y z
H z
X z
a z

=
= =
+

Some Analog Filter Design Methods:


Butterworth ---- maximally flat amplitude.
Chebyshev type I ---- equiripple in the passband.
Chebyshev type II ---- equiripple in the stopband.
Elliptic ---- equiripple in both the passband and stopband.
Passband is designed to be maximally flat.
The magnitude-squared function is of the form
where,
c
: Cutoff frequency
N: The order of the filter
( )
( )
( )
( )
2
2
2
2

(2 1)
2
1
1 /
1
1 /
( )
( )
, 0,1,...2 1
c
N
c
c
N
c
N
c
a
k
LHP poles
k N
j
N
k c
H j
j j
H s
s j
H s
s s
s e k N
t + +
O =
+ O O
=
+ O
O
=

= O =
[
2
2 2
2
2 2 1
1
| ( ) | ( )
1 [ ( / )]
1
| ( ) | ( )
1 [ ( / )]
c
N c
c
N c
H j Type I
C
H j Type II
C
c
c

O =
+ O O
O =
+ O O
Equiripple in the passband and
monotonic in the stopband.
Or equiripple in the stopband and
monotonic in the passband.

) ( 1
1
| ) ( |
2 2
2
O +
= O
N
c
U
j H
c
Equiripple both in passband and in the stopband
Requires the least order filter for the same specifications
Jacobian Elliptic function
(1) Convert the digital filter specifications into an analogue
prototype lowpass filter specifications.
(2) Determine the analogue lowpass filter
transfer function H
a
(s)
(3) Transform H
a
(s) by replacing the complex variable s
to the digital transfer function H(z)
Basic idea behind the conversion of H
a
(s)
into H(z) is to apply a mapping from the s-domain
to the z-domain so that essential properties of the
analogue frequency response are preserved.

Thus mapping function should be such that
Imaginary (j) axis in the s-plane be mapped
onto the unit circle of the z-plane
A stable analog transfer function be mapped
into a stable digital transfer function.
Preserves the shape of impulse response
,
,
sT
j
z e where
z re s j
T
e
o
e
=
= = + O
= O
k
s T
k
z e =
( )
1
1
1
k d
N
k
s T
k
TA
H z
e z

=
=

4. Transform analog poles {s


k
}
1. Choose T and determine the analog frequencies
2. Design an analog filter H
a
(s) using specifications
p
,
s
, A
p
, A
s

3. Partial fraction expansion
into digital poles to obtain
The transfer function:
/ , /
p p s s
T T e e O = O =
1
( )
N
k
a
k
k
A
H s
s s
=
=

( )
( )
0.89125 1 0 0.2
0.17783 0.3
j
j
H e
H e
e
e
e t
t e t
s s s s
s s s
( )
( )
0.89125 1 0 0.2
0.17783 0.3
H j
H j
t
t t
s O s s O s
O s s O s
Design LP IIR filter using Impulse invariance applied to
Butterworth with the following specifications:
Since sampling rate T
d
cancels out we can assume T=1
Map specifications to continuous time
Butterworth filter is monotonic so specifications will be satisfied
if
( ) ( )
0.2 0.89125 0.3 0.17783
c c
H j and H j t t > s
( )
( )
2
2
1
1 /
c N
c
H j
j j
O =
+ O O
2 2
2 2
0.2 1 0.3 1
1 1
0.89125 0.17783
N N
c c
and
t t
| | | |
| | | |
+ = + =
| | | |
O O
\ . \ .
\ . \ .
5.8858 6 0.70474
c
N and = ~ O =
( ) ( )
( )( )
1/12
/12 2 11
1 0,1,...,11
j k
k c c
s j e k
t +
= O = O =
( )
( )( )( )
2 2 2
0.12093
0.364 0.4945 0.9945 0.4945 1.3585 0.4945
H s
s s s s s s
=
+ + + + + +
Determine N and O
c
to satisfy both these constraints simultaneously
Poles of transfer function
The Transfer function
12 poles for the squared magnitude function
Select the 6 pole pairs in the left half of the s-plane
( )
1 1
1 2 1 2
1
1 2
0.2871 0.4466 2.1428 1.1455
1 1.2971 0.6949 1 1.0691 0.3699
1.8557 0.6303
1 0.9972 0.257
z z
H z
z z z z
z
z z


+
= +
+ +

+
+
Mapping to
z-domain
Preserves the system function representation
2 / ) ( 1
2 / ) ( 1
ST
sT
z

+
=
1
1
1
1 2

=
z
z
T
s
One to one mapping
1
1
2 1
1
z
s
T z

| |
=
|
+
\ .
( )
1
1
2 1
1
a
z
H z H
T z

(
| |
=
( |
+
\ .

T
d
cancels out so we can ignore it
1. Choose T and determine the analog frequencies
2
tan
2
p
p
T
e
| |
O =
|
\ .
2
tan
2
s
s
T
e
| |
O =
|
\ .
3. Apply Bilinear transformation
2. Design an analog filter H
a
(s) using specifications
p
,
s
, A
p
, A
s

Design a single- pole LP IIR digital filter with a 3-dB
bandwidth of 0.2, using the bilinear transformation
applied to the analog filter
where
c
is the 3-dB bandwidth of the analog filter.
Solution:
The digital filter is specified to have its -3-dB gain at
c
= 0.2.
( )
c
c
H s
s
O
=
+ O
2 0.65
tan0.1
c
T T
t O = =
At = 0, H(0)=1, and at = 0.2, we have H(0.2)= 0.707,
which is the desired response.
Frequency response
( )
( )
1
1
1
1
1
1
0.65 /
( )
0.65 /
2 1
,
1
2 1
1
0.245 1
( )
1 0.509
d
a
d
T
H s
s T
z
Now s
T z
z
H z H
T z
z
H z
z

=
+
| |
=
|
+
\ .
(
| |
=
( |
+
\ .

+
=

( )
0.245 1
( )
1 0.509
j
j
j
e
H e
e
e
e
e

+
=

( )
( )
0.89125 1 0 0.2
0.17783 0.3
j
j
H e
H e
e
e
e t
t e t
s s s s
s s s
( )
( )
2 0.2
0.89125 1 0 tan
2
2 0.3
0.17783 tan
2
H j
T
H j
T
t
t
| |
s O s s O s
|
\ .
| |
O s s O <
|
\ .
( )
( )
2
2
1
1 /
c
N
c
H jO =
+ O O
Design LP IIR filter using bilinear transformation applied
to Butterworth with the following specifications:
Apply bilinear transformation to specifications
We can assume T
d
=1 and apply the specifications to
2 2
2 2
2tan0.1 1 2tan0.15 1
1 1
0.89125 0.17783
N N
c c
and
t t
| | | |
| | | |
+ = + =
| |
| |
O O
\ . \ .
\ . \ .
To get
Solve N and O
c
( ) ( )
2 2
1 1
log 1 1
0.17783 0.89125
5.305 6
2log tan 0.15 tan 0.1
N
t t
(
| | | |
| | | |

( | |
| |
| |
\ . \ .
(
\ . \ .

= = ~
(

0.766
c
O =
( )
( )( )( )
2 2 2
0.20238
0.3996 0.5871 1.0836 0.5871 1.4802 0.5871
a
H s
s s s s s s
=
+ + + + + +
( )
( )
( )( )
( )
6
1
1 2 1 2
1 2
0.0007378 1
1 1.2686 0.7051 1 1.0106 0.3583
1

1 0.9044 0.2155
z
H z
z z z z
z z



+
=
+ +

+
Applying BLT yeilds:
( ) ( )
( )( )
1/12
/12 2 11
1 0,1,...,11
j k
k c c
s j e for k
t +
= O = O =
Finding pole-locations
Analog transfer-function

You might also like