added biquad highpass

This commit is contained in:
Ahmet Inan 2019-02-22 09:05:07 +01:00
commit 7f4c3a651f
2 changed files with 24 additions and 2 deletions

View file

@ -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)

View file

@ -37,6 +37,22 @@ public:
a1a0 = a1 / a0;
a2a0 = a2 / a0;
}
void highpass(int n, int N, VALUE Q = Const<VALUE>::InvSqrtTwo())
{
VALUE alpha = UnitCircle<VALUE>::sin(n, N) / (VALUE(2) * Q),
cn = UnitCircle<VALUE>::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<VALUE>::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<VALUE>::cos(2*i+1, 4*ORDER)));
}
TYPE operator()(TYPE input)
{
for (int i = 0; i < NUM; ++i)