added DC blocker

This commit is contained in:
Ahmet Inan 2019-02-24 17:24:25 +01:00
commit 73f69e0faa
2 changed files with 38 additions and 0 deletions

View file

@ -41,6 +41,10 @@ The following [infinite impulse response](https://en.wikipedia.org/wiki/Infinite
* [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)
### [blockdc.hh](blockdc.hh)
A [notch filter at DC](https://en.wikipedia.org/wiki/Band-stop_filter) helps removing [DC bias](https://en.wikipedia.org/wiki/DC_bias).
### [phasor.hh](phasor.hh)
[Numerically controlled oscillator](https://en.wikipedia.org/wiki/Numerically_controlled_oscillator) implemented using a [phasor](https://en.wikipedia.org/wiki/Phasor) and [complex multiplication](https://en.wikipedia.org/wiki/Complex_number#Multiplication) instead of a [lookup table](https://en.wikipedia.org/wiki/Lookup_table).

34
blockdc.hh Normal file
View file

@ -0,0 +1,34 @@
/*
DC Blocker
Copyright 2019 Ahmet Inan <inan@aicodix.de>
*/
#pragma once
namespace DSP {
template <typename TYPE, typename VALUE>
class BlockDC
{
TYPE x1, y1;
VALUE a, b;
public:
constexpr BlockDC() : x1(0), y1(0), a(0), b(0.5)
{
}
void samples(int s)
{
a = VALUE(s - 1) / VALUE(s);
b = (VALUE(1) + a) / VALUE(2);
}
TYPE operator()(TYPE x0)
{
TYPE y0 = b * (x0 - x1) + a * y1;
x1 = x0; y1 = y0;
return y0;
}
};
}