public static void DFT(Complex[] data, Direction direction)
{
int n = data.Length;
double arg, cos, sin;
var dst = new Complex[n];
// for each destination element
for (int i = 0; i < dst.Length; i++)
{
dst[i] = Complex.Zero;
arg = -(int)direction * 2.0 * System.Math.PI * (double)i / (double)n;
// sum source elements
for (int j = 0; j < data.Length; j++)
{
cos = System.Math.Cos(j * arg);
sin = System.Math.Sin(j * arg);
double re = data[j].Real * cos - data[j].Imaginary * sin;
double im = data[j].Real * sin + data[j].Imaginary * cos;
dst[i] += new Complex(re, im);
}
}
// copy elements
if (direction == Direction.Forward)
{
// devide also for forward transform
for (int i = 0; i < data.Length; i++)
data[i] /= n;
}
else
{
for (int i = 0; i < data.Length; i++)
data[i] = dst[i];
}
}