static LinkedList <FrequencyMagnitude> DFT(string filePath, string ouputDirectoryPath) { var inputSamplesList = CSVUtils.ReadCSVFile <CSVWaveRecord>(filePath); if (ZeroPadDFT) { Utils.PadWithZeros(inputSamplesList); } var frequencyResolution = Utils.CalculateFrequencyResolution(inputSamplesList); var inputSamplesArray = inputSamplesList.Select(x => new Complex((double)x.Volts, 0)).ToArray(); var dftValues = FourierTransforms.DiscreteFourierTransform(inputSamplesArray); inputSamplesArray = null; var size = dftValues.Length / 2; var leftHalfArray = new Complex[size]; Array.Copy(dftValues, leftHalfArray, size); dftValues = null; var intermediateFile = Path.Combine(ouputDirectoryPath, Path.GetFileName(filePath).Replace("Wave", "DFT")); Utils.printOutput(leftHalfArray, frequencyResolution, intermediateFile); return(Utils.GetFrequencyDomain(leftHalfArray, frequencyResolution)); }
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_WaveFormIntervals() { var csvFilePath = Path.Combine( TestContext.CurrentContext.TestDirectory, @"TestData\Wave000.csv"); var inputSamplesList = CSVUtils.ReadCSVFile <CSVWaveRecord>(csvFilePath); var seconds = inputSamplesList.Select(x => x.Seconds).ToArray(); var diffList = new LinkedList <decimal>(); for (int i = 1; i < seconds.Length; i++) { var diff = seconds[i] - seconds[i - 1]; diffList.AddLast(diff); } Assert.IsTrue(diffList.All(x => x >= 6E-8m && x <= 6.1E-8m)); }