aboutsummaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2018-05-24 00:16:50 -0700
committerChris Robinson <[email protected]>2018-05-24 00:16:50 -0700
commit803d331711cf5c0ecd0796bf28e9c95cf3724198 (patch)
tree8874f59490749796c9b117d0ff8094930f2fd121 /common
parent422cf429e61c610f271a05c9b5ac44c60b7e58fe (diff)
Improve formatting of the hilbert function
Diffstat (limited to 'common')
-rw-r--r--common/alcomplex.c62
-rw-r--r--common/alcomplex.h12
2 files changed, 35 insertions, 39 deletions
diff --git a/common/alcomplex.c b/common/alcomplex.c
index 9cf9d9bd..d4045aeb 100644
--- a/common/alcomplex.c
+++ b/common/alcomplex.c
@@ -60,37 +60,33 @@ 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/(ALdouble)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 );
+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 cfd164b6..2418ce78 100644
--- a/common/alcomplex.h
+++ b/common/alcomplex.h
@@ -56,13 +56,13 @@ inline ALcomplex complex_mult(ALcomplex a, ALcomplex b)
void complex_fft(ALcomplex *FFTBuffer, ALsizei FFTSize, ALdouble Sign);
/**
- *Calculate the complex helical sequence (or discrete-time analytical signal)
- *of the given input using the discrete Hilbert transform (In-place algorithm).
- *Fills InOutBuffer[0...size-1] with the discrete-time analytical signal stored
- *in InOutBuffer[0...size-1]. InOutBuffer is an array of complex numbers,
- *size MUST BE power of two.
+ * 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 hilbert(ALsizei size, ALcomplex *InOutBuffer );
+void complex_hilbert(ALcomplex *Buffer, ALsizei size);
#ifdef __cplusplus
} // extern "C"