Skip to content

Instantly share code, notes, and snippets.

@hollance
Last active August 14, 2025 20:14
Show Gist options
  • Save hollance/5c524ab771de3b812a75fbcf383c601f to your computer and use it in GitHub Desktop.
Save hollance/5c524ab771de3b812a75fbcf383c601f to your computer and use it in GitHub Desktop.
One-pole low-pass cutoff calculation

Suppose we calculate our one-pole filter like so:

y = a0 * x + b1 * y_prev;

Then we can calculate the coefficients like so:

b1 = exp(-2.0 * M_PI * cutoff / sampleRate);
a0 = 1.0 - b1;

This is an approximate formula and the cutoff might be wrong for higher frequencies.

There is an exact formula that's a little more complicated but it will work better:

double omega = 2.0 * M_PI * cutoff / sampleRate;
double k = 2.0 - std::cos(omega);
b1 = k - std::sqrt(k * k - 1.0);
a0 = 1.0 - b1;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment