diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/alcomplex.c | 31 | ||||
-rw-r--r-- | common/alcomplex.h | 9 |
2 files changed, 40 insertions, 0 deletions
diff --git a/common/alcomplex.c b/common/alcomplex.c index d68277e3..d4045aeb 100644 --- a/common/alcomplex.c +++ b/common/alcomplex.c @@ -59,3 +59,34 @@ void complex_fft(ALcomplex *FFTBuffer, ALsizei FFTSize, ALdouble Sign) } } } + +void complex_hilbert(ALcomplex *Buffer, ALsizei size) +{ + const ALdouble inverse_size = 1.0/(ALdouble)size; + ALsizei todo, i; + + for(i = 0;i < size;i++) + Buffer[i].Imag = 0.0; + + complex_fft(Buffer, size, 1.0); + + todo = size >> 1; + Buffer[0].Real *= inverse_size; + Buffer[0].Imag *= inverse_size; + for(i = 1;i < todo;i++) + { + Buffer[i].Real *= 2.0*inverse_size; + Buffer[i].Imag *= 2.0*inverse_size; + } + Buffer[i].Real *= inverse_size; + Buffer[i].Imag *= inverse_size; + i++; + + for(;i < size;i++) + { + Buffer[i].Real = 0.0; + Buffer[i].Imag = 0.0; + } + + complex_fft(Buffer, size, -1.0); +} diff --git a/common/alcomplex.h b/common/alcomplex.h index cf4683fa..2418ce78 100644 --- a/common/alcomplex.h +++ b/common/alcomplex.h @@ -55,6 +55,15 @@ inline ALcomplex complex_mult(ALcomplex a, ALcomplex b) */ void complex_fft(ALcomplex *FFTBuffer, ALsizei FFTSize, ALdouble Sign); +/** + * Calculate the complex helical sequence (discrete-time analytical signal) of + * the given input using the discrete Hilbert transform (In-place algorithm). + * Fills Buffer[0...size-1] with the discrete-time analytical signal stored in + * Buffer[0...size-1]. Buffer is an array of complex numbers, size MUST BE + * power of two. + */ +void complex_hilbert(ALcomplex *Buffer, ALsizei size); + #ifdef __cplusplus } // extern "C" #endif |