Skip to content

Commit

Permalink
Fix IIR coefficient python script
Browse files Browse the repository at this point in the history
The Stabilizer firmware expects "a" coefficients with negative signs.
Also fixed a typo in the highpass b0 coefficient.
  • Loading branch information
Fabian Schmid committed Nov 11, 2024
1 parent c822733 commit 08181b7
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions py/stabilizer/iir_coefficients.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,18 +141,18 @@ def lowpass_coefficients(args):
b0 = args.K * (f0_bar / (1 + f0_bar))
b1 = args.K * f0_bar / (1 + f0_bar)

return [b0, b1, 0, a1, 0]
return [b0, b1, 0, -a1, 0]


def highpass_coefficients(args):
"""Calculate high-pass IIR filter coefficients."""
f0_bar = pi * args.f0 * args.sample_period

a1 = (1 - f0_bar) / (1 + f0_bar)
b0 = args.K * (f0_bar / (1 + f0_bar))
b0 = args.K / (1 + f0_bar)
b1 = - args.K / (1 + f0_bar)

return [b0, b1, 0, a1, 0]
return [b0, b1, 0, -a1, 0]


def allpass_coefficients(args):
Expand All @@ -164,7 +164,7 @@ def allpass_coefficients(args):
b0 = args.K * (1 - f0_bar) / (1 + f0_bar)
b1 = - args.K

return [b0, b1, 0, a1, 0]
return [b0, b1, 0, -a1, 0]


def notch_coefficients(args):
Expand All @@ -179,7 +179,7 @@ def notch_coefficients(args):
b1 = - (2 * args.K * (1 - f0_bar ** 2)) / denominator
b2 = args.K * (1 + f0_bar ** 2) / denominator

return [b0, b1, b2, a1, a2]
return [b0, b1, b2, -a1, -a2]


def pid_coefficients(args):
Expand Down Expand Up @@ -216,7 +216,7 @@ def pid_coefficients(args):
b = [i/a[0] for i in b]
a = [i/a[0] for i in a]
assert a[0] == 1
return b + [-ai for ai in a[1:]]
return b + a[1:]


def _main():
Expand Down

0 comments on commit 08181b7

Please sign in to comment.