From 7f4c3a651fdeb6037f2ee2f34e34cc70f6d7ded4 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Fri, 22 Feb 2019 09:05:07 +0100 Subject: [PATCH] added biquad highpass --- README.md | 4 ++-- biquad.hh | 22 ++++++++++++++++++++++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e317dfb..2bbc0f2 100644 --- a/README.md +++ b/README.md @@ -37,8 +37,8 @@ There is also support for cascading, to improve [roll-off](https://en.wikipedia. The following [infinite impulse response](https://en.wikipedia.org/wiki/Infinite_impulse_response) [digital biquad filter](https://en.wikipedia.org/wiki/Digital_biquad_filter) implementations are available: -* [second-order Butterworth low pass filter](https://en.wikipedia.org/wiki/Butterworth_filter) -* [2n-order Butterworth cascade of second-order low pass filters](https://en.wikipedia.org/wiki/Butterworth_filter) +* [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) ### [phasor.hh](phasor.hh) diff --git a/biquad.hh b/biquad.hh index e2db34a..c928b1e 100644 --- a/biquad.hh +++ b/biquad.hh @@ -37,6 +37,22 @@ public: a1a0 = a1 / a0; a2a0 = a2 / a0; } + void highpass(int n, int N, VALUE Q = Const::InvSqrtTwo()) + { + VALUE alpha = UnitCircle::sin(n, N) / (VALUE(2) * Q), + cn = UnitCircle::cos(n, N), + b0 = (VALUE(1) + cn) / VALUE(2), + b1 = -(VALUE(1) + cn), + b2 = (VALUE(1) + cn) / VALUE(2), + 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 @@ -59,6 +75,12 @@ public: cascade[i].lowpass(n, N, VALUE(1) / (VALUE(2) * UnitCircle::cos(2*i+1, 4*ORDER))); } + void highpass(int n, int N) + { + for (int i = 0; i < NUM; ++i) + cascade[i].highpass(n, N, VALUE(1) / (VALUE(2) * + UnitCircle::cos(2*i+1, 4*ORDER))); + } TYPE operator()(TYPE input) { for (int i = 0; i < NUM; ++i)