Skip to content
DeepForgeby svx
All problems
MediumCalculusca-177

Butterworth Order Calculation

Problem

The minimum Butterworth filter order meeting passband ripple Ap dB at wp and stopband attenuation As dB at ws is

n = ceil( log10((10^(As/10) - 1) / (10^(Ap/10) - 1)) / (2 * log10(ws / wp)) )

Given As > Ap >= 0 and ws > wp > 0, return n as a float.

Hint

The magnitude-squared response of an n-th order Butterworth filter is 1/(1 + (w/wp)^(2n)).

Test cases

case 1
in: [1,20,1,2]
expected: 5
case 2
in: [3,40,1,2]
expected: 7
case 3
in: [0.5,30,1,4]
expected: 4
case 4
in: [1,10,2,4]
expected: 3
Starter codePython
def butterworth_order(ap_db, as_db, wp, ws):
    # Your code here
    pass

4 test cases · run your code against them in the editor