public static void ShowRealFourierTransformDialog(DataColumn ycolumnToTransform) { var options = new RealFourierTransformOptions() { ColumnToTransform = ycolumnToTransform }; options.XIncrementMessage = DetermineXIncrement(ycolumnToTransform, out var xIncrementValue); options.XIncrementValue = xIncrementValue; if (Current.Gui.ShowDialog(ref options, "Choose fourier transform options", false)) { RealFourierTransform(options); } }
public static void RealFourierTransform(RealFourierTransformOptions options) { var yCol = options.ColumnToTransform; int fftLen = yCol.Count; double[] resultCol = new double[fftLen]; for (int i = 0; i < resultCol.Length; ++i) resultCol[i] = yCol[i]; var transform = new Calc.Fourier.RealFourierTransform(fftLen); transform.Transform(resultCol, Calc.Fourier.FourierDirection.Forward); var wrapper = new Calc.Fourier.RealFFTResultWrapper(resultCol); DataTable outputTable = null; switch (options.OutputPlacement) { case RealFourierTransformOutputPlacement.CreateInNewWorksheet: outputTable = new DataTable(); outputTable.Name = "Real FFT results"; Current.Project.DataTableCollection.Add(outputTable); Current.ProjectService.OpenOrCreateWorksheetForTable(outputTable); break; case RealFourierTransformOutputPlacement.CreateInSameWorksheet: outputTable = DataTable.GetParentDataTableOf(yCol); if (null == outputTable) throw new ArgumentException("Provided y-column does not belong to a data table."); break; default: throw new ArgumentOutOfRangeException("Unkown enum value: " + options.OutputPlacement.ToString()); } // create the x-Column first var freqCol = new DoubleColumn(); freqCol.AssignVector = wrapper.FrequenciesFromXIncrement(options.XIncrementValue); int outputGroup = outputTable.DataColumns.GetUnusedColumnGroupNumber(); outputTable.DataColumns.Add(freqCol, "Frequency", ColumnKind.X, outputGroup); // now create the other output cols if (options.Output.HasFlag(RealFourierTransformOutput.Re)) { var col = new DoubleColumn(); col.AssignVector = wrapper.RealPart; outputTable.DataColumns.Add(col, "Re", ColumnKind.V, outputGroup); } if (options.Output.HasFlag(RealFourierTransformOutput.Im)) { var col = new DoubleColumn(); col.AssignVector = wrapper.ImaginaryPart; outputTable.DataColumns.Add(col, "Im", ColumnKind.V, outputGroup); } if (options.Output.HasFlag(RealFourierTransformOutput.Abs)) { var col = new DoubleColumn(); col.AssignVector = wrapper.Amplitude; outputTable.DataColumns.Add(col, "Abs", ColumnKind.V, outputGroup); } if (options.Output.HasFlag(RealFourierTransformOutput.Phase)) { var col = new DoubleColumn(); col.AssignVector = wrapper.Phase; outputTable.DataColumns.Add(col, "Phase", ColumnKind.V, outputGroup); } if (options.Output.HasFlag(RealFourierTransformOutput.Power)) { var col = new DoubleColumn(); col.AssignVector = wrapper.Amplitude; col.Data = col * col; outputTable.DataColumns.Add(col, "Power", ColumnKind.V, outputGroup); } }
public static void ShowRealFourierTransformDialog(DataColumn ycolumnToTransform) { var options = new RealFourierTransformOptions() { ColumnToTransform = ycolumnToTransform }; double xIncrementValue; options.XIncrementMessage = DetermineXIncrement(ycolumnToTransform, out xIncrementValue); options.XIncrementValue = xIncrementValue; if (Current.Gui.ShowDialog(ref options, "Choose fourier transform options", false)) { RealFourierTransform(options); } }
public static void RealFourierTransform(RealFourierTransformOptions options) { var yCol = options.ColumnToTransform; int fftLen = yCol.Count; double[] resultCol = new double[fftLen]; for (int i = 0; i < resultCol.Length; ++i) { resultCol[i] = yCol[i]; } var transform = new Calc.Fourier.RealFourierTransform(fftLen); transform.Transform(resultCol, Calc.Fourier.FourierDirection.Forward); var wrapper = new Calc.Fourier.RealFFTResultWrapper(resultCol); DataTable outputTable = null; switch (options.OutputPlacement) { case RealFourierTransformOutputPlacement.CreateInNewWorksheet: outputTable = new DataTable { Name = "Real FFT results" }; Current.Project.DataTableCollection.Add(outputTable); Current.ProjectService.OpenOrCreateWorksheetForTable(outputTable); break; case RealFourierTransformOutputPlacement.CreateInSameWorksheet: outputTable = DataTable.GetParentDataTableOf(yCol); if (null == outputTable) { throw new ArgumentException("Provided y-column does not belong to a data table."); } break; default: throw new ArgumentOutOfRangeException("Unkown enum value: " + options.OutputPlacement.ToString()); } // create the x-Column first var freqCol = new DoubleColumn { AssignVector = wrapper.FrequenciesFromXIncrement(options.XIncrementValue) }; int outputGroup = outputTable.DataColumns.GetUnusedColumnGroupNumber(); outputTable.DataColumns.Add(freqCol, "Frequency", ColumnKind.X, outputGroup); // now create the other output cols if (options.Output.HasFlag(RealFourierTransformOutput.Re)) { var col = new DoubleColumn { AssignVector = wrapper.RealPart }; outputTable.DataColumns.Add(col, "Re", ColumnKind.V, outputGroup); } if (options.Output.HasFlag(RealFourierTransformOutput.Im)) { var col = new DoubleColumn { AssignVector = wrapper.ImaginaryPart }; outputTable.DataColumns.Add(col, "Im", ColumnKind.V, outputGroup); } if (options.Output.HasFlag(RealFourierTransformOutput.Abs)) { var col = new DoubleColumn { AssignVector = wrapper.Amplitude }; outputTable.DataColumns.Add(col, "Abs", ColumnKind.V, outputGroup); } if (options.Output.HasFlag(RealFourierTransformOutput.Phase)) { var col = new DoubleColumn { AssignVector = wrapper.Phase }; outputTable.DataColumns.Add(col, "Phase", ColumnKind.V, outputGroup); } if (options.Output.HasFlag(RealFourierTransformOutput.Power)) { var col = new DoubleColumn { AssignVector = wrapper.Amplitude }; col.Data = col * col; outputTable.DataColumns.Add(col, "Power", ColumnKind.V, outputGroup); } }