getMagnitudes function
Implementation
List<double> getMagnitudes(List<int> fft) {
if (fft.isEmpty) return [];
final n = fft.length;
final magnitudes = List<double>.filled(n ~/ 2 + 1, 0);
magnitudes[0] = fft[0].abs().toDouble();
magnitudes[n ~/ 2] = fft[1].abs().toDouble();
for (int k = 1; k < n ~/ 2; k++) {
int i = k * 2;
final real = fft[i];
final imag = fft[i + 1];
magnitudes[k] = hypotenuse(real, imag).toDouble();
}
return magnitudes;
}