diff --git a/README.md b/README.md index 38f0025..5c4ed86 100644 --- a/README.md +++ b/README.md @@ -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). diff --git a/blockdc.hh b/blockdc.hh new file mode 100644 index 0000000..5c56f07 --- /dev/null +++ b/blockdc.hh @@ -0,0 +1,34 @@ +/* +DC Blocker + +Copyright 2019 Ahmet Inan +*/ + +#pragma once + +namespace DSP { + +template +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; + } +}; + +} +