From 698ca426bd896131cc31aeec5097bdb358eacdf4 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Mon, 25 Feb 2019 15:23:31 +0100 Subject: [PATCH] added biquad bandpass filter --- README.md | 1 + biquad.hh | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/README.md b/README.md index 2673637..c88a39f 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,7 @@ The following [infinite impulse response](https://en.wikipedia.org/wiki/Infinite * [second-order Butterworth low or high pass filter](https://en.wikipedia.org/wiki/Butterworth_filter) * [2n-order Butterworth cascade of second-order low or high pass filters](https://en.wikipedia.org/wiki/Butterworth_filter) * [second-order notch filter](https://en.wikipedia.org/wiki/Band-stop_filter) +* [second-order bandpass filter](https://en.wikipedia.org/wiki/Band-pass_filter) ### [blockdc.hh](blockdc.hh) diff --git a/biquad.hh b/biquad.hh index d273acb..8a59327 100644 --- a/biquad.hh +++ b/biquad.hh @@ -69,6 +69,22 @@ public: a1a0 = a1 / a0; a2a0 = a2 / a0; } + void bandpass(int n, int N, VALUE Q) + { + VALUE alpha = UnitCircle::sin(n, N) / (VALUE(2) * Q), + cn = UnitCircle::cos(n, N), + b0 = alpha, + b1 = VALUE(0), + b2 = -alpha, + a0 = VALUE(1) + alpha, + a1 = -VALUE(2) * cn, + a2 = VALUE(1) - alpha; + b0a0 = b0 / a0; + b1a0 = b1 / a0; + b2a0 = b2 / a0; + a1a0 = a1 / a0; + a2a0 = a2 / a0; + } TYPE operator()(TYPE x0) { TYPE y0 = b0a0*x0 + b1a0*x1 + b2a0*x2