From 8d3a6e83d8cd460b9b180523ce7b098c5a0c5c19 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Sun, 31 Mar 2019 21:59:16 +0200 Subject: [PATCH] added Hilbert transform filter --- README.md | 1 + filter.hh | 15 +++++++++++++++ 2 files changed, 16 insertions(+) diff --git a/README.md b/README.md index 94d06be..907af11 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ Implemented are the following [finite impulse response](https://en.wikipedia.org * [low-pass filter](https://en.wikipedia.org/wiki/Low-pass_filter) * [high-pass filter](https://en.wikipedia.org/wiki/High-pass_filter) * [band-pass filter](https://en.wikipedia.org/wiki/Band-pass_filter) +* [Hilbert-transform filter](https://en.wikipedia.org/wiki/Hilbert_transform) ### [ema.hh](ema.hh) diff --git a/filter.hh b/filter.hh index 39a23d2..cb7d8ec 100644 --- a/filter.hh +++ b/filter.hh @@ -87,5 +87,20 @@ public: } }; +template +struct HilbertTransform +{ + TYPE operator () (int n, int N) + { + if (N&1) { + int x = n - (N - 1) / 2; + return x&1 ? TYPE(2) / (Const::Pi() * TYPE(x)) : TYPE(0); + } else { + TYPE x = TYPE(n) - TYPE(0.5) * TYPE(N - 1); + return TYPE(1) / (Const::Pi() * x); + } + } +}; + }