/// <summary>
/// Performs the transformation over a complex[] array.
/// </summary>
///
public static void FHT(Complex[] data, FourierTransform.Direction direction)
{
int N = data.Length;
// Forward operation
if (direction == FourierTransform.Direction.Forward)
{
// Makes a copy of the data so we don't lose the
// original information to build our final signal
Complex[] shift = (Complex[])data.Clone();
// Perform FFT
FourierTransform.FFT(shift, FourierTransform.Direction.Backward);
//double positive frequencies
for (int i = 1; i < (N/2); i++)
{
shift[i].Re *= 2.0;
shift[i].Im *= 2.0;
}
// zero out negative frequencies
// (leaving out the dc component)
for (int i = (N/2)+1; i < N; i++)
{
shift[i].Re = 0.0;
shift[i].Im = 0.0;
}
// Reverse the FFT
FourierTransform.FFT(shift, FourierTransform.Direction.Forward);
// Put the Hilbert transform in the Imaginary part
// of the input signal, creating a Analytic Signal
for (int i = 0; i < N; i++)
data[i].Im = shift[i].Im;
}
else // Backward operation
{
// Just discard the imaginary part
for (int i = 0; i < data.Length; i++)
data[i].Im = 0.0;
}
}