Beruflich Dokumente
Kultur Dokumente
OF OSLO
Filter Design I
Sverre Holm
INF4480
Digital signalbehandling II
DEPARTMENT OF INFORMATICS
UNIVERSITY
OF OSLO
EKG signal i sty EKG signal i sty
Electrocardiogram (ECG
or EKG, abbreviated
f h G from the German
elektrokardiogramm)
m:\matlab\Aase- m:\matlab\Aase
EKG\Aase.m
Data fra Ottar Aase,
som den 8 oktober 1999 som den 8. oktober 1999
forsvarte sin avhandling
COMPUTER AIDED
DIAGNOSTICS OF
ACUTE CHEST PAIN ACUTE CHEST PAIN
Ullevl Universitets-
sykehus, Oslo
DEPARTMENT OF INFORMATICS
2
UNIVERSITY
OF OSLO
Filterdesign Filterdesign
1. Spesifikasjon
Kj d l Kjenne anvendelsen
Kjenne designmetoder (hva som er mulig, FIR/IIR)
2. Approksimasjon pp j
Fokus her
3. Analyse
Filt l ifi t i f k d t Filtre er som regel spesifisert i frekvensdomenet
Ogs analysere i tid (fase, forsinkelse, ...)
4. Realiseringg
DSP, FPGA, PC: Matlab, C, Java ...
DEPARTMENT OF INFORMATICS
3
UNIVERSITY
OF OSLO
Oppgave Oppgave
Designe FIR-filtre
Frekvenssampling (siste prioritet)
Vindusmetoden
Ekviripple Ekviripple
IIR-filtre
Transformerte standardfiltre: Butterworth, Tsjebysjeff,
elliptisk
Sammenligning
DEPARTMENT OF INFORMATICS
4
UNIVERSITY
OF OSLO
Sources Sources Sources Sources
The slides about Digital Filter Specifications
h b d t d f lid b S Mit have been adapted from slides by S. Mitra,
2001
Butterworth Chebychev etc filters are based Butterworth, Chebychev, etc filters are based
on Wikipedia
Builds on Oppenheim & Schafer with Buck: Builds on Oppenheim & Schafer with Buck:
Discrete-Time Signal Processing, 1999.
DEPARTMENT OF INFORMATICS
5
UNIVERSITY
OF OSLO
Ideal filters Ideal filters Ideal filters Ideal filters
Lavpass, hypass, bndpass, bndstopp
H
LP
(e
j
e
) H
HP
(e
j
e
)
1 1
t
e
0
ec
ec
t
t
e
0
ec
ec
t
H
BP
(e
j
e
)
H
BS
(e
j
e
)
1
1
1
DEPARTMENT OF INFORMATICS
6
t t
e
ec1
ec1
ec2
ec2 t t
e
ec1
ec1
ec2
ec2
UNIVERSITY
OF OSLO
Prototype low-pass filter Prototype low pass filter
All filter design methods are specificed for
l l low-pass only
It can be transformed into a high-pass filter
O i b l d i i i h h Or it can be placed in series with others to
form band-pass and band-stop filters
DEPARTMENT OF INFORMATICS
7
UNIVERSITY
OF OSLO
Digital Filter Specifications Digital Filter Specifications Digital Filter Specifications Digital Filter Specifications
As the impulse response corresponding to
h f th id l filt i l d f each of these ideal filters is noncausal and of
infinite length, these filters are not realizable
In practice the magnitude response In practice, the magnitude response
specifications of a digital filter in the passband
and in the stopband are given with some
acceptable tolerances
In addition, a transition band is specified
between the passband and stopband between the passband and stopband
DEPARTMENT OF INFORMATICS
8
UNIVERSITY
OF OSLO
Digital Filter Specifications Digital Filter Specifications Digital Filter Specifications Digital Filter Specifications
The magnitude response |G(e
je
)| of a digital
l filt b ifi d lowpass filter may be specified as:
DEPARTMENT OF INFORMATICS
9
UNIVERSITY
OF OSLO
Digital Filter Specifications Digital Filter Specifications Digital Filter Specifications Digital Filter Specifications
Passband: 0 e e
p
We require that |G(e
je
)| 1 with an error o
p
, i.e.,
p p
j
p
e G e e o o
e
s + s s , 1 ) ( 1
Stopband: e
s
e t
W i th t |G(
je
)| 0 ith o i
p p p
, ) (
We require that |G(e
je
)| 0 with an error o
s
, i.e.,
t e e o
e
s s s
j
e G , ) ( t e e o s s s
s s
e G , ) (
DEPARTMENT OF INFORMATICS
10
UNIVERSITY
OF OSLO
Digital Filter Specifications Digital Filter Specifications Digital Filter Specifications Digital Filter Specifications
e
p
- passband edge frequency
e
s
- stopband edge frequency
o
p
- peak ripple value in the passband
p
o
s
- peak ripple value in the stopband
Properties:
G(e
je
) is a periodic function of e
|G(e
je
)| of a real-coefficient digital filter is an even
function of e
Consequence: Filter specifications are given
only for 0 |e| t
DEPARTMENT OF INFORMATICS
11
UNIVERSITY
OF OSLO
Digital Filter Specifications Digital Filter Specifications Digital Filter Specifications Digital Filter Specifications
Specifications are often given in terms of loss
f ti function:
G(e)=-20 log
10
|G(e
je)
| in dB
Peak passband ripple
o
p
= -20log
10
(1-o
p
) dB o
p
20log
10
(1 o
p
) dB
Minimum stopband attenuation Minimum stopband attenuation
o
p
= -20log
10
(o
s
) dB
DEPARTMENT OF INFORMATICS
12
UNIVERSITY
OF OSLO
Digital Filter Specifications Digital Filter Specifications Digital Filter Specifications Digital Filter Specifications
Magnitude specifications may alternately be
i i li d f i di t d b l given in a normalized form as indicated below
DEPARTMENT OF INFORMATICS
13
UNIVERSITY
OF OSLO
Normalized frequencies Normalized frequencies
Real values
Real frequencies: f
p
, f
s
, f
sample
Angular frequencies: e=2tf
Normalized values Normalized values
Angular frequencies: e=0...2t where f
sample
2t
Normalized frequencies f=0 ... 2 where 2 is the sampling
frequency (0...1 is the useful range): MATLAB filter
design
DEPARTMENT OF INFORMATICS
16
UNIVERSITY
OF OSLO
FIR and IIR Digital Filter FIR and IIR Digital Filter FIR and IIR Digital Filter FIR and IIR Digital Filter
Difference equation
Transfer function Transfer function
General: IIR - Infinite Impulse Response
FIR Fi it I l R FIR - Finite Impulse Response
N=0, no feedback, always stable
DEPARTMENT OF INFORMATICS
17
UNIVERSITY
OF OSLO
Pol- og nullpunktsplassering Pol og nullpunktsplassering
Poler innenfor enhetssirkel Stabil og kausal
Poler og nullpunkter i kompleks konjugerte par Reell Poler og nullpunkter i kompleks konjugerte par Reell
impulsrespons
Alle nullpunkter finnes speilet om enhetssirkelen Liner
fase.
Viktig! Liner fase og reelle koeffisienter Nullpunkter
finnes i grupper av fire.
Alle nullpunkter er speilbildet av en pol Allpass system
Alle nullpunkter innenfor enhetssirkel Minimum fase
system og inversfilter eksisterer
Alle nullpunkter utenfor enhetssirkel Kausal maksimum
fase
DEPARTMENT OF INFORMATICS
18
UNIVERSITY
OF OSLO
DEPARTMENT OF INFORMATICS
19
UNIVERSITY
OF OSLO
Standard Analog Filter functions (magnitude)
DEPARTMENT OF INFORMATICS
20
UNIVERSITY
OF OSLO
Standard Analog Filter Functions Standard Analog Filter Functions
Butterworth filter
no gain ripple in pass band and stop band slow cutoff no gain ripple in pass band and stop band, slow cutoff
Chebyshev filter (Type I)
no gain ripple in stop band, moderate cutoff
Chebyshev filter (Type II) y ( yp )
no gain ripple in pass band, moderate cutoff
Elliptic filter
gain ripple in pass and stop band, fast cutoff
Bessel filter
no group delay ripple, no gain ripple in both bands, slow gain cutoff
Linkwitz-Riley filter
Used for crossover filters for loudspeakers
DEPARTMENT OF INFORMATICS
21
UNIVERSITY
OF OSLO
Laplace vs z-transform Laplace vs z transform
Laplace, s=o+jO:
Z-transform, z=e
je
:
Avbildning mellom s- og z-plan
ved biliner transform
DEPARTMENT OF INFORMATICS
22
UNIVERSITY
OF OSLO
Filter Slopes Filter Slopes
Decade: 10 x frequency, e.g. 100 Hz 1 kHz
i d d is one decade
Octave: 2 x frequency (octave=8 for the white
piano keys) e g 100 Hz > 200 Hz piano keys), e.g. 100 Hz -> 200 Hz
1. order filter: rolls off at 6 dB per octave (20 dB per
decade)
2. order filter: the response decreases at 12 dB per
octave (-40 dB per decade)
3. order at 18 dB, and so on.
DEPARTMENT OF INFORMATICS
23
UNIVERSITY
OF OSLO
Group Delay Group Delay
The group delay is the derivative of the phase
ith t t l f with respect to angular frequency
It is a measure of the distortion in the signal
introduced by phase differences for different introduced by phase differences for different
frequencies.
t
g
= -d[arg(H(e
je
))] / de
DEPARTMENT OF INFORMATICS
24
UNIVERSITY
OF OSLO
Butterworth Filter Butterworth Filter
Maximally flat (has no ripples) in the passband, and
rolls off towards zero in the stopband rolls off towards zero in the stopband.
When viewed on a logarithmic plot, the response
slopes off linearly towards negative infinity.
Butterworth filters have a monotonically changing
magnitude function with .
First described by British engineer Stephen First described by British engineer Stephen
Butterworth in "On the Theory of Filter Amplifiers",
Wireless Engineer, vol. 7, 1930, pp. 536-541.
DEPARTMENT OF INFORMATICS
25
UNIVERSITY
OF OSLO
3 Order Butterworth with e =1 3. Order Butterworth with e
p
1
DEPARTMENT OF INFORMATICS
26
UNIVERSITY
OF OSLO
Plot of the gain of Butterworth low-pass filters of orders 1 through 5.
DEPARTMENT OF INFORMATICS
27
Note that the slope is 20n dB/decade where n is the filter order.
UNIVERSITY
OF OSLO
Analog Butterworth Analog Butterworth
3. order passive low pass
filter (Cauer topology). ( p gy)
2. order active filter
(Sallen-Key topology)
DEPARTMENT OF INFORMATICS
28
UNIVERSITY
OF OSLO
Butterworth Butterworth
Frequency response:
Transfer function
Butterworth polynominals (n even, n odd)
DEPARTMENT OF INFORMATICS
29
UNIVERSITY
OF OSLO
Butterworth Butterworth
n Factors of Polynomial B
n
(s)
1 (s + 1)
2 s
2
+ 1 4142s + 1 2 s + 1.4142s + 1
3 (s + 1)(s
2
+ s + 1)
4 (s
2
+ 0.7654s + 1)(s
2
+ 1.8478s + 1)
5 (s + 1)(s
2
+ 0.6180s + 1)(s
2
+ 1.6180s + 1) ( )( )( )
DEPARTMENT OF INFORMATICS
30
UNIVERSITY
OF OSLO
Butterworth Filter Butterworth Filter
Nth order filter: all derivatives of the gain up
t d i l di th 2N 1th d i ti to and including the 2N-1th derivative are
zero at e=0, resulting in "maximal flatness".
In decibels the high frequency roll off is 20n In decibels, the high-frequency roll-off is 20n
dB/decade, or 6n dB/octave (not only
Butterworth all filters)
DEPARTMENT OF INFORMATICS
31
UNIVERSITY
OF OSLO
Chebyshev filter Chebyshev filter
Norsk: Tsjebysjeff
Steeper roll-off and more passband ripple (type I) or
stopband ripple (type II) than Butterworth filters.
Minimize the error between the idealized filter
characteristic and the actual, but with ripples in the
passband.
Named after Pafnuty Chebyshev (1821-1894) Named after Pafnuty Chebyshev (1821 1894)
0
is the cut-off frequency
DEPARTMENT OF INFORMATICS
44
UNIVERSITY
OF OSLO
Comparison Comparison
Butterworth: maximally flat amplitude response
Bessel: maximally flat group delay Bessel: maximally flat group delay
Compared with a Chebyshev Type I/Type II filter or an
elliptic filter, the Butterworth filter has a slower roll-off,
and thus will require a higher order to implement a
ti l t b d ifi ti particular stopband specification.
However, Butterworth filter will have a more linear
phase response in the passband than the Chebyshev
Type I/Type II and elliptic filters Type I/Type II and elliptic filters.
Chebyshev filters are sharper than the Butterworth
filter; they are not as sharp as the elliptic one, but they
show fewer ripples over the bandwidth.
Elliptic filters are sharper than all other filters, but they
show ripples on the whole bandwidth.
DEPARTMENT OF INFORMATICS
45
UNIVERSITY
OF OSLO
DEPARTMENT OF INFORMATICS
46
UNIVERSITY
OF OSLO
2-way loudspeakers y
Goal: Control of spatial response at
crossover frequency:
1 G i i i 1. Gain sums to unity in crossover
region
2-element array:
How to ensure steering straight g g
ahead in crossover region?
DEPARTMENT OF INFORMATICS
47
UNIVERSITY
OF OSLO
2-way loudspeaker
h t common phasecenter
Solutions with common phase center:
Coaxial
D'Appolito configuration: Tweeter positioned
between two low frequency drivers between two low frequency drivers.
Both are rather uncommon systems
DEPARTMENT OF INFORMATICS
48
Eltek AS, www.dynabel.no
UNIVERSITY
OF OSLO
Avoiding beaming in loudspeakers
h h t t when phase centers are apart
Goal: absence of sudden
change in directivity with g y
frequency.
Crossover filter must:
1. Sum to unity gain
2 E h f th 2. Ensure same phase for the
two drivers in crossover
region
DEPARTMENT OF INFORMATICS
49
UNIVERSITY
OF OSLO
Linkwitz-Riley Filter Linkwitz Riley Filter
A Linkwitz-Riley (L-R) filter is used in audio crossovers,
named after Siegfried Linkwitz and Russ Riley named after Siegfried Linkwitz and Russ Riley
S. Linkwitz, Activee Crossover Networks for Noncoincident
Drivers in Journ. Audio Eng. Soc., 24 (1), pp. 2-8; Jan 1976.
L R crossover = a low pass and a high pass L R filter L-R crossover = a low-pass and a high-pass L-R filter.
L-R = cascade of two Butterworth filters, each with 3
dB gain at the cut-off frequency (=Butterworth squared
filt ) filter).
The L-R filter has a 6 dB gain at the cutoff frequency.
The sum of the low-pass and high-pass outputs will be The sum of the low pass and high pass outputs will be
0 dB, so the crossover behaves like an all-pass filter:
flat amplitude response and a smoothly changing
phase response.
DEPARTMENT OF INFORMATICS
50
phase response.
UNIVERSITY
OF OSLO
Linkwitz-Riley filters orders 2 and 4 Linkwitz Riley filters, orders 2 and 4
DEPARTMENT OF INFORMATICS
51
UNIVERSITY
OF OSLO
Butterworth cross-over Butterworth cross over
DEPARTMENT OF INFORMATICS
52
Dennis A. Bohn, Linkwitz-Riley Crossovers: A Primer
http://www.rane.com/note160.html
UNIVERSITY
OF OSLO
Linkwitz-Riley crossover Linkwitz Riley crossover
DEPARTMENT OF INFORMATICS
53
UNIVERSITY
OF OSLO
Linkwitz-Riley 2 order
Key: Parallel phase functions
for the two branches
Linkwitz Riley 2. order
Amplitude Phase Group delay
4th-order Linkwitz-Riley (LR-4) filters is the de facto
standard for professional audio active crossovers.
DEPARTMENT OF INFORMATICS
54
UNIVERSITY
OF OSLO
Q value Q value
Quality factor higher Q for
sharper resonance
H
BP
(e
j
e
)
sharper resonance
Q = 2total energy stored /
energy lost in a single cycle t t
e
1
1
ec1
ec1
ec2
ec2
gy g y
A radio receiver with a high Q
would be more difficult to tune with
the necessary precision but would
H
LP
(e
j
e
)
the necessary precision, but would
do a better job of filtering out
signals from other stations that lay
nearby on the spectrum
1
e
nearby on the spectrum. t
e
0
ec
ec t
DEPARTMENT OF INFORMATICS
55
UNIVERSITY
OF OSLO
Q value for filters Q value for filters
A graph of a filter's gain
magnitude illustrating the magnitude, illustrating the
concept of -3 dB at a gain of
0.707 or half-power
bandwidth (Af) bandwidth (Af).
Q = f
0
/Af
DEPARTMENT OF INFORMATICS
56
UNIVERSITY
OF OSLO
2 Order High Pass Filter 2. Order High Pass Filter
f
0
=100 Hz
Critically damped y p
Q=1/2, -6 dB at f
0
Linkwitz-Riley (Butterworth
2
)
Best pulse response
Q=1/3
1/2
0.577
B l filt Bessel filter
Flattest passband frequency
response,
Q=1/2
1/2
0.707, -6 dB at f
0
Butterworth filter Butterworth filter
Closed box loudspeaker
Tuning of box volume vs. element
stiffness (surround, spider) and
mass
Q 1 2 more apparent bass Q 1.2 more apparent bass
Q 1: warm sound, saleable
Q 0.8 more detailed,
somewhat shallow
Q 0.5 overdamped
V Dickason: Loudspeaker Cookbok
DEPARTMENT OF INFORMATICS
57
V. Dickason: Loudspeaker Cookbok
UNIVERSITY
OF OSLO
2 Order High Pass Filter: phase 2. Order High Pass Filter: phase
Critically damped
Q 1/2 6 dB t f Q=1/2, -6 dB at f
0
Best pulse response
Q=1/3
1/2
0.577
Bessel filter
Phase is closest to a linear
function in passband
Flattest passband
frequency response,
Q=1/2
1/2
0.707, -6 dB at f
0
Butterworth filter
DEPARTMENT OF INFORMATICS
58
UNIVERSITY
OF OSLO
IIR filters IIR filters
DEPARTMENT OF INFORMATICS
59
UNIVERSITY
OF OSLO
Transform analog prototype to
di it l d i digital domain
s-plane to z-domain: s=o+jO z=e
je
Frequency axis: s=jO maps to |z|=1
Stability, causality maintained
O=0 e=0 always: LP LP
DEPARTMENT OF INFORMATICS
60
http://en.wikibooks.org/wiki/Digital_Signal_Processing/Bilinear_Transform
UNIVERSITY
OF OSLO
Transform from s-plane to z-plane Transform from s plane to z plane
1 Impulse invariance 1. Impulse invariance
Impulse response is a sampled version of the analog one
Aliasing as O=O
s
e=t
2. Bilinear transform
Let O=be mapped to e=t
N li t f t f H( ) t H( ) Nonlinear transform to go from H(s) to H(z)
DEPARTMENT OF INFORMATICS
61
UNIVERSITY
OF OSLO
Bilinear transform Bilinear transform
No aliasing, maintains stability and causality,
but warps frequency axis but warps frequency axis
Best for lowpass, as passband is little
distorted
For other filters, start with analog LP =>
digital LP => digital HP etc
http://wwwborescom/courses/intro/iir/5 warphtm
DEPARTMENT OF INFORMATICS
62
http://www.bores.com/courses/intro/iir/5_warp.htm
UNIVERSITY
OF OSLO
Matlab IIR Digital Filter Design Matlab IIR Digital Filter Design Matlab IIR Digital Filter Design Matlab IIR Digital Filter Design
Order Estimation
For IIR filter design using bilinear transformation,
MATLAB statements to determine the order and
bandedge are:
[N, Wn] = buttord(Wp, Ws, Rp, Rs);
[N, Wn] = cheb1ord(Wp, Ws, Rp, Rs);
[N W ] h b2 d(W W R R ) [N, Wn] = cheb2ord(Wp, Ws, Rp, Rs);
[N, Wn] = ellipord(Wp, Ws, Rp, Rs);
DEPARTMENT OF INFORMATICS
63
UNIVERSITY
OF OSLO
Matlab IIR Digital Filter Design Matlab IIR Digital Filter Design Matlab IIR Digital Filter Design Matlab IIR Digital Filter Design
Filter Design
For IIR filter design using bilinear transformation,
MATLAB statements to use are:
[b, a] = butter(N, Wn) , ,
[b, a] = cheby1(N, Rp, Wn)
[b, a] = cheby2(N, Rs, Wn)
[b, a] = ellip(N, Rp, Rs, Wn)
No need to think about bilinear transform
Transfer function can be computed using freqz(b a Transfer function can be computed using freqz(b, a,
w) where w is a set of angular frequencies
DEPARTMENT OF INFORMATICS
64
UNIVERSITY
OF OSLO
Matlab IIR Digital Filter Design Matlab IIR Digital Filter Design Matlab IIR Digital Filter Design Matlab IIR Digital Filter Design
Design an elliptic IIR lowpass filter with
F 0 8 kH F 1 kH F 4 kH 0 5 F
p
=0.8 kHz, F
s
=1 kHz, F
sample
=4 kHz, o
p
= 0.5
dB, o
s
=40 dB
Code fragments used are: Code fragments used are:
[N,Wn] = ellipord(0.8/(4/2), 1/(4/2), 0.5, 40);
Result: N=5 order Result: N=5. order
[b, a] = ellip(N, 0.5, 40, Wn);
DEPARTMENT OF INFORMATICS
65
UNIVERSITY
OF OSLO
Matlab IIR Digital Filter Design Matlab IIR Digital Filter Design Matlab IIR Digital Filter Design Matlab IIR Digital Filter Design
0
Elliptic IIR Lowpass Filter
-01
0
Passband Details
-20
G
a
i
n
,
d
B
-0.3
-0.2
-0.1
G
a
i
n
,
d
B
0 0.2 0.4 0.6 0.8 1
-60
-40
G
0 0.1 0.2 0.3 0.4
-0.5
-0.4
G
0 0.2 0.4 0.6 0.8 1
e/t
0 0.1 0.2 0.3 0.4
e/t
DEPARTMENT OF INFORMATICS
66