mirror of
https://github.com/aicodix/dsp.git
synced 2026-04-27 14:30:36 +00:00
added discrete Hilbert transform
This commit is contained in:
parent
999ee7d2be
commit
b857753ddf
2 changed files with 48 additions and 0 deletions
|
|
@ -60,6 +60,10 @@ Normalizers for [periodic](https://en.wikipedia.org/wiki/Periodic_function) sign
|
|||
|
||||
Fs/4 [Complex down conversion](https://en.wikipedia.org/wiki/Digital_down_converter)
|
||||
|
||||
### [hilbert.hh](hilbert.hh)
|
||||
|
||||
[Discrete Hilbert transform](https://en.wikipedia.org/wiki/Hilbert_transform#Discrete_Hilbert_transform)
|
||||
|
||||
### [fmd.hh](fmd.hh)
|
||||
|
||||
[Frequency modulation](https://en.wikipedia.org/wiki/Frequency_modulation) [demodulation](https://en.wikipedia.org/wiki/Demodulation) with and without [atan2](https://en.wikipedia.org/wiki/Atan2).
|
||||
|
|
|
|||
44
hilbert.hh
Normal file
44
hilbert.hh
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/*
|
||||
Discrete Hilbert transformation
|
||||
|
||||
Copyright 2020 Ahmet Inan <inan@aicodix.de>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "window.hh"
|
||||
|
||||
namespace DSP {
|
||||
|
||||
template <typename TYPE, int TAPS>
|
||||
class Hilbert
|
||||
{
|
||||
static_assert((TAPS-1) % 4 == 0, "TAPS-1 not divisible by four");
|
||||
typedef TYPE complex_type;
|
||||
typedef typename TYPE::value_type value_type;
|
||||
value_type real[TAPS];
|
||||
value_type imco[(TAPS-1)/4];
|
||||
value_type reco;
|
||||
public:
|
||||
Hilbert(value_type a = value_type(2))
|
||||
{
|
||||
Kaiser<value_type> win(a);
|
||||
reco = win((TAPS-1)/2, TAPS);
|
||||
for (int i = 0; i < (TAPS-1)/4; ++i)
|
||||
imco[i] = win((2*i+1)+(TAPS-1)/2, TAPS) * 2 / ((2*i+1) * Const<value_type>::Pi());
|
||||
}
|
||||
complex_type operator()(value_type input)
|
||||
{
|
||||
value_type re = reco * real[(TAPS-1)/2];
|
||||
value_type im = imco[0] * (real[(TAPS-1)/2-1] - real[(TAPS-1)/2+1]);
|
||||
for (int i = 1; i < (TAPS-1)/4; ++i)
|
||||
im += imco[i] * (real[(TAPS-1)/2-(2*i+1)] - real[(TAPS-1)/2+(2*i+1)]);
|
||||
for (int i = 0; i < TAPS-1; ++i)
|
||||
real[i] = real[i+1];
|
||||
real[TAPS-1] = input;
|
||||
return complex_type(re, im);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue