All problems
Digital Filter Step
Problem
Take one step of the first-order IIR filter y[n] = b0*x[n] + b1*x[n-1] - a1*y[n-1].
Given the current input x_n, the previous input x_prev, the previous output y_prev, and the coefficients b0, b1, a1, return y[n].
Hint
The feedback term enters with the sign of the difference-equation form, so subtract a1*y_prev.
Test cases
case 1
in: [1,0,0,1,0,0]
expected: 1
case 2
in: [1,1,0,1,1,0]
expected: 2
case 3
in: [1,1,2,0.5,-0.5,-1]
expected: 2
case 4
in: [0,1,1,1,0,-0.5]
expected: 0.5
Starter codePython
def digital_filter_step(x_n, x_prev, y_prev, b0, b1, a1):
# Your code here
pass4 test cases · run your code against them in the editor