You are on page 1of 7

Implementing Digital Two Pole Butterworth Filters

Why Bother with Butterworth Filters?


The first question should be why bother with 2 pole filters instead of the simple low pass
filter? The main reason is that each pole will attenuate frequencies above the corner
frequency at a rate of -20 db per decade. That is a factor of 10. Therefore a two pole filter
will attenuate frequencies 10 times higher than the corner frequency 100 time more.
The reason why one should use a Butterworth filter over a 2 pole low pass ( real ) filter is that
the Butterworth filter has a sharper corner and therefore doesn't affect those frequencies blow
the corner frequency as much. Notice that the phase lag isn't as great as the simple two
pole low pass filter below the corner frequency.

Two Pole Butterworth Bode Plots


ωc := 2 ⋅ π ⋅ 5 Cut off or corner frequency in radians per second.
The corner frequency should be at least 10 times
less than the sample frequency. This means
that sampling at 0.01 seconds, or 100 Hz, limits
the corner frequency to about 10 Hz.

Compare different filters

1
Tbw2( s) :=
2 Two Pole Butterworth filter
 s  + 2⋅  s  + 1
ω  ω 
 c  c
1
Tp1( s) :=
s Single pole low pass filter
+1
ωc
1
Tp2( s) :=
2 Two pole low pass filter
 s  + 2⋅  s  + 1
ω  ω 
 c  c
n
−2
64
n := 0 .. 256 hz := 10
n

( (
arg Tbw2 2 ⋅ π ⋅ j ⋅ hz ))
( ( ))
n
M bw2 := 20⋅ log Tbw2 2 ⋅ π j ⋅ hz Φ bw2 :=
n n n deg

( (
M p1 := 20⋅ log Tp1 2 ⋅ π j ⋅ hz
n ))
n Φ p1 :=
( (
arg Tp1 2 ⋅ π ⋅ j ⋅ hz
n ))
n deg

( (
M p2 := 20⋅ log Tp2 2 ⋅ π j ⋅ hz
n ))
n Φ p2 :=
( (
arg Tp2 2 ⋅ π ⋅ j ⋅ hz
n ))
n deg

(c) 2008 Peter Nachtwey 1/7 4/6/200912:05 PM


Delta Computer Systems, Inc.
Implementing Digital Two Pole Butterworth Filters

Magnitude
0

20
Magnitude

40

60
0.01 0.1 1 10 100

Frequency
2 Pole Butterworth
1 Pole Low Pass
2 Pole Low Pass

Phase
0
9
18
27
36
45
54
63
72
81
Phase

90
99
108
117
126
135
144
153
162
171
180
0.01 0.1 1 10 100

Frequency
2 Pole Butterworth
1 Pole Low Pass
2 Pole Low Pass

(c) 2008 Peter Nachtwey 2/7 4/6/200912:05 PM


Delta Computer Systems, Inc.
Implementing Digital Two Pole Butterworth Filters

Two Pole Butterworth Filter Implementation Using Matched Z Transforms


ωc := 2 ⋅ π ⋅ 5
Corner or cut off frequency in radians per second
2
ζ := 2
2 The damping factor is always
2
Τ := 0.02 Sample period.

The coefficients below were computes using matched z transforms, MZT, Euler's identity,and a
lot of substitution and simplification. The MZT technique does not introduce zeros in the z
domain or require frequency warping.
− 2⋅ ω c⋅ Τ ⋅ ζ
A2 := e A2 = 0.4112407014427743

− ω c⋅ Τ ⋅ ζ
A1 := −2 ⋅ e (
⋅ cos ζ ⋅ ωc⋅ Τ ) A1 = −1.1580458998309644

− ω c⋅ Τ ⋅ ζ − 2⋅ ω c⋅ Τ ⋅ ζ
B 0 := 1 − 2 ⋅ e ( )
⋅ cos ωc⋅ Τ ⋅ ζ + e B 0 = 0.2531948016118099

−A1 − A2 + B0 = 1 Verify, must add up to one

Verify Filter Design


Input frequency in radians per second.
ω := 2 ⋅ π ⋅ 1 Frequencies greater than ωc will be
attenuated

Time := 2 Duration of the simulation

Initialize filter, the first two filter values are


assumed to be 0.
n := 0 .. 1 y := 0 x := sin( ω⋅ n ⋅ Τ ) + rnorm( 1 , 0 , 0.1)
n n 0
Time
n := 2 .. Simulate for Time seconds.
Τ

x := sin( ω⋅ n ⋅ Τ ) + rnorm( 1 , 0 , 0.1) Input signal with 1 volt amplitude


n 0
with noise.
y := −A1⋅ y − A2⋅ y + B 0⋅ x
n n− 1 n− 2 n

(c) 2008 Peter Nachtwey 3/7 4/6/200912:05 PM


Delta Computer Systems, Inc.
Implementing Digital Two Pole Butterworth Filters

Butterworth
2

1
Input and Output

2
0 0.5 1 1.5 2

Time
Input
Output

(c) 2008 Peter Nachtwey 4/7 4/6/200912:05 PM


Delta Computer Systems, Inc.
Implementing Digital Two Pole Butterworth Filters

Two Pole Butterworth Filter Implementation Using Tustin's Approximation.

2  ωc⋅ Τ 
Perform frequency warping w := ⋅ tan  w = 32.49196962329063
Τ  2 

z−1
⋅ 
2
Tustin's approximation is . When the filter expressed as a
Τ z + 1
2 1
normalized filter the can also be combined with the term to yield
Τ w
 ωc⋅ Τ   z − 1   ωc⋅ Τ  z−1
cot  ⋅ . The cot  should be pre calculated so c⋅  
 2  z + 1  2  z + 1
can be substituted for s.
 ωc⋅ Τ 
c := cot 
 2  c = 3.077683537175253

Normalized 2nd Order Butterworth Filter.


1
H( s) = Two pole Butterworth
2 filter in the s domain.
1+ 2⋅ s + s

z−1
substitute , s = c⋅
z+1
1 1
H( z) = expand → H( z) =
2 2
1+ 2⋅ s + s float , 6 z − 1. ( z − 1.)
1. + 4.35250 ⋅ + 9.47218 ⋅
implicit z + 1. 2
( z + 1.)

1 Convert to z domain by substituting


H( z) = z−1
1 c⋅   for s.
2 z−1 2 ( z − 1)
2 z + 1
1 + 2 ⋅ c⋅ +c ⋅ See above for equation to calculate c.
z+1 2
(z + 1)

2
z + 2⋅ z + 1
H( z) =
1 1 Simplify
2 2 2 2 2 2 2 2
z + 2 ⋅ z + 1 + 2 ⋅ c⋅ z − 2 ⋅ c + c ⋅ z − 2 ⋅ c ⋅ z + c

2
z + 2⋅ z + 1
H( z) =
Collect in powers of z.
 1  1
 2  2
2 2 ( 2
 1 + c + 2 ⋅ c ⋅ z + 2 − 2 ⋅ c ⋅ z − 2 ⋅ c + 1 + c)2

(c) 2008 Peter Nachtwey 5/7 4/6/200912:05 PM


Delta Computer Systems, Inc.
Implementing Digital Two Pole Butterworth Filters

Calculate coefficients for


y = −A1⋅ y − A2⋅ y + B0⋅ x + B1⋅ x + B2⋅ x
n n− 1 n− 2 n n− 1 n− 2
2
2 − 2⋅ c
A1 := A1 = −1.142980502539901
1
2 2
1 + c + 2 ⋅c

1
2 2
−2 ⋅ c + 1 + c
A2 := A2 = 0.4128015980961886
1
2 2
1 + c + 2 ⋅c

1
B 0 := B 0 = 0.06745527388907192
1
2 2
1 + c + 2 ⋅c

2
B 1 := B 1 = 0.13491054777814385
1
2 2
1 + c + 2 ⋅c
1
B 2 := B 2 = 0.06745527388907192
1
2 2
1 + c + 2 ⋅c

−A1 − A2 + B0 + B 1 + B2 = 1

(c) 2008 Peter Nachtwey 6/7 4/6/200912:05 PM


Delta Computer Systems, Inc.
Implementing Digital Two Pole Butterworth Filters

Verify Filter Design

n := 0 .. 1 y := 0 Initialize
n

x := sin( ω⋅ n ⋅ Τ ) + rnorm( 1 , 0 , 0.2)


n 0

2
n := 2 .. Simulate for .1 seconds.
Τ

x := sin( ω⋅ n ⋅ Τ ) + rnorm( 1 , 0 , 0.2) Input signal with 1 volt amplitude.


n 0
Second order Butterworth
y := −A1⋅ y − A2⋅ y + B0⋅ x + B1⋅ x + B 2⋅ x
n n− 1 n− 2 n n− 1 n− 2 filter difference equation.

Butterworth
2

1
Output

2
0 0.5 1 1.5 2

Time
Input
Output

(c) 2008 Peter Nachtwey 7/7 4/6/200912:05 PM


Delta Computer Systems, Inc.

You might also like