public void Complex_Inverse_Mix() { const int numSamples = 32; const int length = 2 * numSamples; double[] data = new double[length]; for (int i = 0; i < length; i += 2) { double z = (double)(i - numSamples) / numSamples; data[i] = 1.0 / ((z * z) + 1.0); data[i + 1] = z / ((z * z) + 1.0); } data[1] = 0.0; // periodic continuation; force odd _cft.Convention = TransformationConvention.Matlab; _cft.TransformForward(data); ComplexTestImagZero(data); /* Compare With MATLAB: * samples_t = 1.0i * ([-16:1:15] ./ 16) ./ (([-16:1:15] ./ 16) .^ 2 + 1.0) + 1.0 ./ (([-16:1:15] ./ 16) .^ 2 + 1.0) + samples_t(1) = real(samples_t(1)) + samples_f = fft(samples_t) */ Assert.That(data[0 * 2], NumericIs.AlmostEqualTo(25.128, 0.001), "MATLAB 1"); Assert.That(data[1 * 2], NumericIs.AlmostEqualTo(-11.118, 0.001), "MATLAB 2"); Assert.That(data[2 * 2], NumericIs.AlmostEqualTo(-2.7838, 0.0001), "MATLAB 3"); Assert.That(data[6 * 2], NumericIs.AlmostEqualTo(-0.80124, 0.00001), "MATLAB 7"); Assert.That(data[7 * 2], NumericIs.AlmostEqualTo(-0.64953, 0.00001), "MATLAB 8"); Assert.That(data[8 * 2], NumericIs.AlmostEqualTo(-0.53221, 0.00001), "MATLAB 9"); Assert.That(data[13 * 2], NumericIs.AlmostEqualTo(-0.1689, 0.0001), "MATLAB 14"); Assert.That(data[14 * 2], NumericIs.AlmostEqualTo(-0.1158, 0.0001), "MATLAB 15"); Assert.That(data[15 * 2], NumericIs.AlmostEqualTo(-0.065071, 0.00001), "MATLAB 16"); Assert.That(data[20 * 2], NumericIs.AlmostEqualTo(0.18904, 0.0001), "MATLAB 21"); Assert.That(data[21 * 2], NumericIs.AlmostEqualTo(0.2475, 0.0001), "MATLAB 22"); Assert.That(data[22 * 2], NumericIs.AlmostEqualTo(0.31196, 0.00001), "MATLAB 23"); Assert.That(data[29 * 2], NumericIs.AlmostEqualTo(1.4812, 0.0001), "MATLAB 30"); Assert.That(data[30 * 2], NumericIs.AlmostEqualTo(2.1627, 0.0001), "MATLAB 31"); Assert.That(data[31 * 2], NumericIs.AlmostEqualTo(3.8723, 0.0001), "MATLAB 32"); _cft.TransformBackward(data); // Compare with original samples for (int i = 0; i < length; i += 2) { double z = (double)(i - numSamples) / numSamples; Assert.That(data[i], NumericIs.AlmostEqualTo(1.0 / ((z * z) + 1.0), 0.00001), "Inv: Real: " + i); Assert.That(data[i + 1], NumericIs.AlmostEqualTo(i == 0 ? 0.0 : z / ((z * z) + 1.0), 0.00001), "Inv: Imag: " + i); } }
public static void IFFT(Complex[] xdata, int m) { var temp = new MathNet.Numerics.Complex[(int)Math.Pow(2, m)]; for (int i = 0; i < temp.Length; i++) { temp[i].Real = xdata[i].Real; temp[i].Imag = xdata[i].Imag; } cft.TransformBackward(temp); for (int i = 0; i < temp.Length; i++) { xdata[i].Real = temp[i].Real; xdata[i].Imag = temp[i].Imag; } }