added Hilbert transform filter

This commit is contained in:
Ahmet Inan 2019-03-31 21:59:16 +02:00
commit 8d3a6e83d8
2 changed files with 16 additions and 0 deletions

View file

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

View file

@ -87,5 +87,20 @@ public:
}
};
template <typename TYPE>
struct HilbertTransform
{
TYPE operator () (int n, int N)
{
if (N&1) {
int x = n - (N - 1) / 2;
return x&1 ? TYPE(2) / (Const<TYPE>::Pi() * TYPE(x)) : TYPE(0);
} else {
TYPE x = TYPE(n) - TYPE(0.5) * TYPE(N - 1);
return TYPE(1) / (Const<TYPE>::Pi() * x);
}
}
};
}