public static void Convolve(Complex[] x, Complex[] y, Complex[] result)
{
FFT(x, FourierTransform.Direction.Forward);
FFT(y, FourierTransform.Direction.Forward);
for (int i = 0; i < x.Length; i++)
{
double xreal = x[i].Real;
double ximag = x[i].Imaginary;
double yreal = y[i].Real;
double yimag = y[i].Imaginary;
double re = xreal * yreal - ximag * yimag;
double im = ximag * yreal + xreal * yimag;
x[i] = new Complex(re, im);
}
IDFT(x);
// Scaling (because this FFT implementation omits it)
for (int i = 0; i < x.Length; i++)
{
result[i] = x[i] / x.Length;
}
}