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 < n; i++)
{
dst[i] = Complex.Zero;
arg = -(int) direction*2.0*System.Math.PI*i/n;
// sum source elements
for (int j = 0; j < n; j++)
{
cos = System.Math.Cos(j*arg);
sin = System.Math.Sin(j*arg);
dst[i].Re += (data[j].Re*cos - data[j].Im*sin);
dst[i].Im += (data[j].Re*sin + data[j].Im*cos);
}
}
// copy elements
if (direction == Direction.Forward)
{
// devide also for forward transform
for (int i = 0; i < n; i++)
{
data[i].Re = dst[i].Re/n;
data[i].Im = dst[i].Im/n;
}
}
else
{
for (int i = 0; i < n; i++)
{
data[i].Re = dst[i].Re;
data[i].Im = dst[i].Im;
}
}
}