Here's a version of getPeakIndices which will work. the above version will also sort the complex values, so the indices won't point to the right location anymore.
staticint[] getPeakIndices(Complex[] dtfme, int numPoints) { int n = dtfme.Length / 2; var magnitudes = dtfme.Take(n).Select((z) => z.Magnitude).ToArray(); var indices = Enumerable.Range(0, n).ToArray(); Array.Sort(magnitudes, indices); return indices.Reverse().Take(numPoints).ToArray(); }