B3 Iir

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

Biosignals & Biosystems

Block 3. Part II: IIR filter design

Gemma Piella
Departament de Tecnologies de la Informació i les Comunicacions
Universitat Pompeu Fabra, Barcelona, Spain
[email protected]
Contents

• IIR filters

• Design of IIR filters


– Bilinear transformation
– Impulse invariance
– Pole-zero placement
Review
LTI filter types

• Finite-duration Impulse Response (FIR)

y (n) = h(0) x(n) + h(1) x(n − 1) + ... + h( M − 1) x(n − ( M − 1))


with M -1 being the order of the filter
Advantages: always stable, the phase can be made exactly linear, we can approximate any
filter we want
Disadvantages: we need a lot of coefficients (M large) for good performance

• Infinite-duration Impulse Response (IIR)

y (n) + a1 y (n − 1) + ... + a N y (n − N ) = b0 x(n) + b1 x(n − 1) + ... + bM −1 x(n − ( M − 1))


Advantages: very selective with a few coefficients
Disadvantages: not necessarily stable, non-linear phase, impulse response of infinite duration
IIR design

• A practically realizable IIR filter (i.e., stable and causal)


cannot have a linear phase response

‒ Recall that if a filter has linear phase, then:

For each pole inside the unit circle, we would


H ( z ) =  z − ( M −1) H (1 / z ) have a pole outside the unit circle. Thus, either:
• If causal, the ROC would not include the unit
circle and the filter would not be stable.
• If stable, the ROC would be a ring and the
filter would not be causal.

‒ If we do not require causality, then it is possible to obtain a


stable linear-phase IIR filter
IIR design

Standard approach:

• Design an analog filter and then map it to a digital filter


– We can use analog techniques to design the filter

– To transform from analog to discrete:


⚫ Time-domain: impulse invariance, h(n) = T ha (t )
⚫ Frequency-domain: bilinear transform, H ( ) = T H a ( s )

Another approach, directly in the discrete domain:

• Pole-zero placement
Pole-Zero placement

• From knowledge of how pole/zero locations affect frequency


response, we can build filters by placement of poles & zeros
ς𝑀 −1
𝑘=1(1 − 𝑧𝑘 𝑧 )
𝐻(𝑧) = 𝐺 𝑁
ς𝑘=1(1 − 𝑝𝑘 𝑧 −1 )

2 zeros, 2 poles zk, pk real or conjugate pairs ROC: |z|>max(pk) | pk |<1

Examples: 2nd order real filters that are causal and stable

Low-pass High-pass filter Band-pass filter


Discretization of analog filters – freq. domain

1. Convert the digital filter specification into an analog prototype filter


specifications

2. Determine the analog filter system function


- The (analog) system function is the Laplace transform of the (analog) impulse response

3. Transform the analog system function (by replacing the complex variable) to
the digital system function

analog digital


 
  

s-plane z-plane

H a (s ) H (z ) H ( ) = H ( z ) z =e j
Causal stable region in s-plane: poles in the left-half plane
Discretization of analog filters – freq. domain

• Apply a mapping from the s-domain to the z-domain so


that essential properties of the analog frequency response
are preserved

‒ Imaginary axis (jΩ) in the s-plane mapped onto the unit circle
(|r|=1) of the z-plane
‒ A stable analog system function mapped into a stable digital
system function

z =1

s-plane z-plane
s =  + j z = re j
Bilinear transformation

• Such mapping is achieved by the bilinear transformation


2
s+
2 1 − z −1 T
s=  z= One-to-one
T 1 + z −1 s−
2 mapping

T: sampling period
T
H ( z ) = H a (s) | 2 1− z −1
s=
T 1+ z −1
z =1

s-plane z-plane

s =  + j z = re j
Bilinear transformation

1
Example. Given an analog filter 𝐻𝑎 (𝑠) = , use the bilinear
1+𝑠
transform to obtain a digital IIR filter. Consider T=1.

1 1 + 𝑧 −1
𝐻 𝑧 = 𝐻𝑎 𝑠 | 2 1−𝑧 −1 = −1 =
𝑠=𝑇 2 1−𝑧 3 − 𝑧 −1
1+𝑧 −1 1+
𝑇 1 + 𝑧 −1
Bilinear transformation
For σ = 0,
[rad/s]
− j
2 1− e − c c 
j= +
T 1 + e − j
0

normalized frequency
−  − c 0 c   [rad]
Then
2  
= tg  
T 2
  T 
 = 2tg  −1
 2 

Pre-warped frequency

Ω ω

ω
Standard analog filters

• Butterworth 1
H a ( ) =
2
– Flat passband
1 + ( /  c )
2N
– Roll-of rate of 20N dB per decade
# poles, order
• Chebyshev
– Passband ripple (type I) or stopband ripple (type II)
– Sharper cut-off than Butterworth

• Elliptic
– Passband and stopband ripple
– Even sharper cut-off

• Bessel
– Linear phase response in the passband (thus no signal
distortion in passband)
– Wider transition band
Standard analog filters
Examples of 5th order (low-pass) filters (gain):


Standard analog filters

Butterworth
frequency response
for different orders N

 
What filter to choose?
YES
Linear
phase? FIR filter

NO

IIR filter

NO Narrow YES
Ripple transition High-order
OK? band? Butterworth

YES NO
Low-order
Narrowest YES Butterworth
possible Elliptic
transition?

NO
NO
Ripple Chebyshev II
in PB?

YES
NO
Ripple Chebyshev I
in SB?

YES
Elliptic
Frequency transformation

So far, we have focused on the design of low-pass IIR filters

➢ To design a high-pass, band-pass or band-stop filter, we start from a low-


pass prototype (e.g., Butterworth, Chebyshev, elliptic or Bessel) and then
apply a frequency transformation. Two alternatives:

• Frequency transformation in the analog domain to obtain the desired filter type,
and then convert such analog filter into a digital filter

• Frequency transformation in the digital domain: first convert the analog low-pass
prototype into a digital low-pass prototype, and then transform such digital
prototype into the desired digital filter type

These two methods are not equivalent; they result in different filters, except
for when using the bilinear transformation, in which case the resulting filters
are the same
Frequency transformation in the analog domain

Given a prototype low-pass analog filter 𝐻𝑎,𝑛𝑜𝑟𝑚 (𝑠) with cut-off frequency Ω𝑝
(typically Ω𝑝 =1), we can obtain a low-pass, high-pass, band-pass, or band-stop
filters with a different cut-off frequency:

𝛺l )
Step by step IIR design using bilinear transf.

1. Convert the digital filter specifications into an analog prototype filter


specifications
– Pre-warp the cut-off frequencies (or the lower and upper band edge frequencies for
band-pass and stop-band filters):
2  
= tg  
T 2

2. Determine the analog filter system function


– Choose the analog low-pass prototype 𝐻𝑎,𝑛𝑜𝑟𝑚 (𝑠) that fits the specifications
Frequency transformation (from the prototype 𝐻𝑎,𝑛𝑜𝑟𝑚 (𝑠) to the filter we want 𝐻𝑎 (𝑠);
see Table from previous slide)

3. Apply the bilinear transformation to the (freq. transformed) analog


system function:
H ( z ) = H a (s) | 2 1− z −1
s=
T 1+ z −1
Example
Determine the digital analog of the electrical RC filter. Consider a cut-off frequency of 30 Hz
and a sampling frequency of 150 Hz. 1
H a ,norm ( s ) =
1+ s
Step 0: Specifications of the digital filter in normalized frequency
30 2
c = 2 = rad
150 5
2  
Step 1: Specifications for analog filter from the transformation: = tan  
T 2
 2 
 c = 2 150 tan  =300  0.7265rad / sec
 10 
1
Step 2: The normalized system function of an RC filter is H a ,norm ( s ) =
1+ s

Frequency transformation to a low-pass filter with  c = 300  0.7265rad / sec :

Ω𝑐 300 ⋅ 0.7265
𝐻𝑎 (𝑠) = 𝐻𝑎,𝑛𝑜𝑟𝑚 (𝑠)|𝑠= 𝑠 = =
Ω𝑐 𝑠 + Ω𝑐 𝑠 + 300 ⋅ 0.7265
Example

Step 3: Apply bilinear transform:

H ( z ) = H a (s) | 2 1− z −1
s=
T 1+ z −1

300  0.7265 300  0.7265 0.7265(1 + z −1 )


H ( z) = | 2 1− z −1 = −1
=
s + 300  0.7265 s = T 1+ z −1 1− z 1 − z −1 + 0.7265(1 + z −1 )
300. −1
+ 300  0.7265
1+ z

1 + 𝑧 −1 Note that from step 2 on, the


𝐻(𝑧) = result is independent of T
2.3764 − 0.3764𝑧 −1

The corresponding difference equation:


2.3764𝑦(𝑛) − 0.3764𝑦(𝑛 − 1) = 𝑥(𝑛) + 𝑥(𝑛 − 1)
Example

1 + 𝑧 −1
𝐻(𝑧) =
2.3764 − 0.3764𝑧 −1

x
Zeros: z=-1 z=-1
Poles: z=0.3764/2.3764 = 0.158
IIR filter (has
poles different
Since it is a causal filter, ROC: |z|>0.158 from 0 or ∞)

|z|=1 ROC, thus the filter is stable

No symmetries (1/0.158 is not a pole), it does not have lineal phase

1+𝑧 −1 1 𝑧 −1
𝐻 𝑧 = 2.3764−0.3764𝑧 −1 = 2.3764−0.3764𝑧 −1 + 2.3764−0.3764𝑧 −1

1/2.3764 𝑧 −1 /2.3764
= + 1−0.3764𝑧 −1/2.3764
1−0.3764𝑧 −1 /2.3764 As expected, infinite
duration impulse response
(IIR filter) and from h(n) we
h(n)=((0.158)nu(n)+ (0.158)n-1u(n-1))/2.3764
can also see that is causal
and stable
IIR design

Standard approach:

• Design an analog filter and then map it to a digital filter


– We can use analog techniques to design the filter

– To transform from analog to discrete:


⚫ Time-domain: impulse invariance, h(n) = T ha (t )
⚫ Frequency-domain: bilinear transform,

Another approach, directly in the discrete domain:

• Pole-zero placement
Impulse invariance method

Given ha (t ) , obtain h(n) by sampling:

ℎ(𝑛) = ℎ𝑎 (𝑛𝑇) FT of a
sampled
signal
Then,
1 𝜔 2𝜋𝑘
𝐻(𝜔) = ෍ 𝐻𝑎 ( + )
𝑇 𝑇 𝑇
𝑘

𝜋 1 𝜔
If 𝐻𝑎 (Ω) = 0 for Ω ≥ , then 𝐻(𝜔) = 𝐻𝑎 ( ) 𝜔 ≤𝜋
𝑇 𝑇 𝑇

1
Satisfies Nyquist-Shannon sampling theorem: = 𝐹𝑠 > 2𝐹𝑚𝑎𝑥
𝑇
Otherwise, there will be aliasing
Impulse invariance method

s-plane z-plane

𝜋
𝑇

𝜋

𝑇
many-to-one
mapping

Poles s in the continuous-time system are mapped to: z = e sT  = T

Exercise: how does this mapping compare to that of the bilinear transform?
Summary

• An IIR filter can provide similar magnitude response with fewer coeff., or lower
side-lobes for the same number of coeff. than a FIR filter

• A causal stable IIR filter cannot have linear phase

• An IIR filter can be designed by mapping an analog filter to digital. Common


approaches:
• Bilinear transformation:
2  
H ( z ) = H a (s) | 2 1− z −1 = tg   • No aliasing
s= T 2 • Freq. warping
T 1+ z −1

• Impulse invariance:
• Preserves shape of the filter ℎ𝑎 (𝑡)
ℎ(𝑛) = ℎ𝑎 (𝑛𝑇)  = T • Aliasing may occur

• More coeff.: closer to the desired response


• Wider transition band: less ripple in passband, more stopband attenuation
Preparing seminar 3

• BEFORE seminar 3:
– Read/study the lectures notes (block 3-part II) and complement them with
bibliography. Key ideas.
– Exercise 1 of SEMINAR 3
– Exercises of QUIZZES
– Solve whatever doubt that may arise

• BEFORE seminar 4:
– Study the lectures notes and complement them with bibliography. Go into
details.
– Remainder of exercises of SEMINAR 3
– Ask any remainder doubt!
Quizzes
1
• Determine the digital equivalent of the analog electrical RC filter: H a ,norm ( s ) =
1+ s
using the bilinear transform. Consider a cut-off frequency of 1 Hz and
a sampling frequency of 4 Hz. Write the difference equation.

Solution:
1
2 2𝜋⋅
Ω𝑐 = tan 4 =8
𝑇 2

Ω𝑐 8
𝐻𝑎 𝑠 = 𝐻𝑎,𝑛𝑜𝑟𝑚 (𝑠)ቚ 𝑠 = =
𝑠=
Ω𝑐
𝑠 + Ω𝑐 𝑠 + 8

𝐻 𝑧 = 𝐻𝑎 𝑠 | 2 1−𝑧 −1 = 0.5 + 0.5𝑧 −1


𝑠=
𝑇 1+𝑧 −1

𝑦(𝑛) = 0.5𝑥(𝑛) + 0.5𝑥(𝑛 − 1) Note that in this particular case, we got a


FIR filter, not an IIR.
• Repeat previous problem if we were to design a digital high-pass filter.

Solution:

Ω𝑐 𝑠
𝐻𝑎 𝑠 = 𝐻𝑎,𝑛𝑜𝑟𝑚 (𝑠)ቚ 1·8 = =
𝑠=
𝑠
𝑠 + Ω𝑐 𝑠 + 8

𝐻 𝑧 = 𝐻𝑎 𝑠 | 2 1−𝑧 −1 = 0.5 − 0.5𝑧 −1


𝑠=
𝑇 1+𝑧 −1

𝑦 𝑛 = 0.5𝑥 𝑛 − 0.5𝑥(𝑛 − 1)
1
• Consider the analog filter 𝐻𝑎 (𝑠) =
𝑠+3
, having the impulse response ha (t ) = e
−3t
u (t )
where u(t) is the step function. Assume T=0.1 seconds.

– Use the bilinear transform to transform the analog filter into a digital filter. Find the system
function and sketch its pole/zero diagram
– Use the impulse invariance method to obtain the impulse response h(n). Find the system
function and sketch its pole/zero diagram
– For the two digital filters obtained above, what is the difference between the frequency
responses?

• If the bilinear transform is applied to a stable analog filter, is it guaranteed that the
digital filter will be stable? Is a one-to-one mapping? Answer the same questions for
the case that the impulse invariance method is applied.

• Following scheme in slide 15, choose the suitable IIR filter if:
– We want to minimize the ripple both in the passband and the stopband
– We allow ripple in the stopband but not on the passband

• If s=σ+jΩ and z=rejω, then what is the condition on σ if r<1?


Solution:
1 + 𝑧 −1
– Using bilinear transform (slide 9): 𝐻 𝑧 = 𝐻𝑎 𝑠 | 2 1−𝑧 −1 =
𝑠=
𝑇 1+𝑧 −1
23 − 17𝑧 −1
⚫ Zero at z=-1 and pole at z=17/23.

⚫ Causal filter, ROC: 𝑧 > 17/23 , which includes unit circle; thus, it is stable.

– Using the impulse invariance (slide 21): ℎ 𝑛 = ℎ𝑎 𝑛𝑇 = 𝑒 −0.3𝑛 𝑢(𝑛)


1
⚫ Thus, 𝐻(𝑧) =
1 − 𝑒 −0.3 𝑧 −1
⚫ Zero at z=0 and pole at z= 𝑒 −0.3 , ROC: 𝑧 > 𝑒 −0.3 , which includes unit circle; thus, it is stable

– The frequency response of the first will not have aliasing. It has a zero at w=𝜋. The
frequency response of the second will have aliasing since 𝐻𝑎 𝛺 is not bandlimited to 𝜋/T
• Both the bilinear transform and the impulse invariance method preserve stability
of the filter (see slide 8 and 22). The bilinear transform is a one-to-one (bijective)
mapping, whereas the impulse invariance method is not: it is a many-to-one
mapping.


– Butterworth filter has a frequency response that is maximally flat in both the passband
and the stopband.
– Chebyshev Type II has no ripple in the passband and has a sharper cut-off than the
Butterworth.

• σ <0. Causal stable analog filters have poles such that σ <0. They are mapped to
the interior of the unit circle and thus the digital filter will be causal and stable as
well.
Appendix
Review
LTI systems

For discrete-time signals and systems:

x(n) y(n)= x(n)*h(n)


LTI

δ(n) h(n)

𝐴𝑒 𝑗𝜔𝑛 𝐴𝑒 𝑗𝜔𝑛 𝐻(𝜔)

𝑧𝑛 𝑧 𝑛 𝐻(𝑧)

For continuous-time signals and systems:

xa(t) ya(t) =xa(t)*ha(t)


LTI

δ(t) ha(t)

𝐴𝑒 𝑗Ω𝑡 𝐴𝑒 𝑗Ω𝑡 𝐻𝑎 (Ω)


The Laplace transform

x(t) y(t)
ha(t)

st
• Let’s consider an input signal e (s is a complex freq. parameter: s =  + j )

y (t ) = x(t ) * ha (t ) =  ha ( ) x(t −  )d
−

=  ha ( )e s ( t − ) d
−
• Ha(s) is the Laplace transform of the
=   h a ( )e − s d e st

impulse response ha (t)
 − 
input
H a (s )
System function
The Laplace transform

The response of an LTI system with impulse response ha(t) to a complex exponential
st
input e is
y (t ) = H a ( s )e st
where s is a complex (frequency) parameter: s =  + j and

𝐻𝑎 (𝑠) = න ℎ𝑎 (𝑡)𝑒 −𝑠𝑡 𝑑𝑡
−∞

is the Laplace transform of ha(t)

When s is purely imaginary (s=jΩ), this is the Fourier transform of ha(t): Ha(Ω). Thus,
the Fourier transform is the Laplace transform when s is purely imaginary:


𝐻𝑎 (𝑠)ቚ = 𝐻𝑎 (Ω) = 𝐶𝑇𝐹𝑇{ℎ𝑎 (𝑡)} = න ℎ𝑎 (𝑡)𝑒 −𝑗Ω𝑡 𝑑𝑡
𝑠=𝑗Ω −∞
Relation between the s-plane and the z-plane

𝛺=0)

Relationship between the s-plane and the z-plane. The s-plane is a rectangular coordinate system with 𝜎 expressing the
distance along the real (horizontal) axis, and 𝛺 the distance along the imaginary (vertical) axis. In comparison, the z-plane
is in polar form, with r being the distance to the origin, and 𝜔 the angle measured to the positive horizontal axis. Vertical
lines in the s-plane correspond to circles in the z-plane.
Review TSiS

Relation between the DTFT and the CTFT

X  (F )
x (t )

X(ω)
F
 = 2
Fs

ω
-2π π 2π v

You might also like