aboutsummaryrefslogtreecommitdiffstats
path: root/common/alcomplex.c
diff options
context:
space:
mode:
authorRaulshc <[email protected]>2018-05-20 17:21:50 +0200
committerGitHub <[email protected]>2018-05-20 17:21:50 +0200
commitdd51ba396babac675846f14d9159e32c1c864cb8 (patch)
tree8cd44a3847a0c773488a2cb99b1ce3cb0bb93b72 /common/alcomplex.c
parentcd2fd126c4024f43730a7c857fca223b35fe0a5b (diff)
Common: Implement discrete Hilbert transform
Diffstat (limited to 'common/alcomplex.c')
-rw-r--r--common/alcomplex.c35
1 files changed, 35 insertions, 0 deletions
diff --git a/common/alcomplex.c b/common/alcomplex.c
index d68277e3..8a0786e9 100644
--- a/common/alcomplex.c
+++ b/common/alcomplex.c
@@ -59,3 +59,38 @@ void complex_fft(ALcomplex *FFTBuffer, ALsizei FFTSize, ALdouble Sign)
}
}
}
+
+/*Discrete Hilbert Transform (analytic signal form)*/
+void hilbert(ALsizei size, ALcomplex *InOutBuffer )
+{
+ ALsizei k;
+ const ALdouble inverse_size = 1.0/(ALfloat)size;
+
+ for ( k = 0; k < size;k++ )
+ InOutBuffer[k].Imag = 0.0;
+
+ complex_fft( InOutBuffer, size, 1.0 );
+
+ for( k = 0; k < size; k++ )
+ {
+ if( k == 0 || k == size/2 )
+ {
+ InOutBuffer[k].Real *= inverse_size;
+ InOutBuffer[k].Imag *= inverse_size;
+ }
+
+ else if ( k >=1 && k < size/2 )
+ {
+ InOutBuffer[k].Real *= 2.0*inverse_size;
+ InOutBuffer[k].Imag *= 2.0*inverse_size;
+ }
+
+ else
+ {
+ InOutBuffer[k].Real = 0.0;
+ InOutBuffer[k].Imag = 0.0;
+ }
+ }
+
+ complex_fft( InOutBuffer, size,-1.0 );
+}