public void Test_FastFourierTransform_BasicInput() { var inputSample = new[] { new Complex(1, 0), new Complex(1, 0), new Complex(1, 0), new Complex(1, 0), new Complex(1, 0), new Complex(1, 0), new Complex(1, 0), new Complex(1, 0) }; FourierTransforms.FastFourierTransform(inputSample, 0, inputSample.Length); var expectedResult = new[] { new Complex(8, 0), new Complex(0, 0), new Complex(0, 0), new Complex(0, 0), new Complex(0, 0), new Complex(0, 0), new Complex(0, 0), new Complex(0, 0) }; Assert.IsTrue(inputSample.SequenceEqual(expectedResult)); }
public void Test_FastFourierTransform_SeparateSizeIsSmallerThan2() { var inputSample = new[] { new Complex(0, 0) }; FourierTransforms.FastFourierTransform(inputSample, 0, 1); Assert.IsTrue(inputSample.SequenceEqual(new Complex[] { new Complex(0, 0) })); }
public void Test_FastFourierTransform_InputSamplesNotPowerOfTwo() { var inputSample = new Complex[8]; Assert.Throws <ArgumentException>( () => FourierTransforms.FastFourierTransform(inputSample, 0, 10), "the number of inputSamples must be power of 2"); }
public void Test_FFT_VS_DFT() { var csvFilePath = Path.Combine( TestContext.CurrentContext.TestDirectory, @"TestData\Wave000.csv"); var inputSamplesList = CSVUtils.ReadCSVFile <CSVWaveRecord>(csvFilePath); var dftInputArray = inputSamplesList.Select(x => new Complex((double)x.Volts, 0)).ToArray(); Utils.PadWithZeros(inputSamplesList); var fftInputArray = inputSamplesList.Select(x => new Complex((double)x.Volts, 0)).ToArray(); FourierTransforms.DiscreteFourierTransform(dftInputArray); FourierTransforms.FastFourierTransform(fftInputArray, 0, fftInputArray.Length); }
public void Test_FastFourierTransform_Abraham() { var inputSample = new[] { new Complex(1, 0), new Complex(2, 0), new Complex(3, 0), new Complex(4, 0), }; FourierTransforms.FastFourierTransform(inputSample, 0, inputSample.Length); var expectedResult = new[] { new Complex(10, 0), new Complex(-2, 2), new Complex(-2, 0), new Complex(-1.9999999999999998, -2) }; Assert.IsTrue(inputSample.SequenceEqual(expectedResult)); }
static LinkedList <FrequencyMagnitude> FFT(string filePath, string ouputDirectoryPath) { var inputSamplesList = CSVUtils.ReadCSVFile <CSVWaveRecord>(filePath); Utils.PadWithZeros(inputSamplesList); var frequencyResolution = Utils.CalculateFrequencyResolution(inputSamplesList); var inputSamplesArray = inputSamplesList.Select(x => new Complex((double)x.Volts, 0)).ToArray(); FourierTransforms.FastFourierTransform(inputSamplesArray, 0, inputSamplesArray.Length); var size = inputSamplesArray.Length / 2; var leftHalfArray = new Complex[size]; Array.Copy(inputSamplesArray, leftHalfArray, size); inputSamplesArray = null; var intermediateFilePath = Path.Combine(ouputDirectoryPath, Path.GetFileName(filePath).Replace("Wave", "FFT")); Utils.printOutput(leftHalfArray, frequencyResolution, intermediateFilePath); return(Utils.GetFrequencyDomain(leftHalfArray, frequencyResolution)); }