private static void naiveDft(double[] inreal, double[] inimag, double[] outreal, double[] outimag, bool inverse)
{
if (inreal.Length != inimag.Length || inreal.Length != outreal.Length
|| outreal.Length != outimag.Length)
throw new ArgumentException("Mismatched lengths");
int n = inreal.Length;
double coef = (inverse ? 2 : -2) * Math.PI;
for (int k = 0; k < n; k++)
{ // For each output element
double sumreal = 0;
double sumimag = 0;
for (int t = 0; t < n; t++)
{ // For each input element
double angle = coef * (int)((long)t * k % n) / n; // This is more accurate than t * k
sumreal += inreal[t] * Math.Cos(angle) - inimag[t] * Math.Sin(angle);
sumimag += inreal[t] * Math.Sin(angle) + inimag[t] * Math.Cos(angle);
}
outreal[k] = sumreal;
outimag[k] = sumimag;
}
}