Beispiel #1
0
        /// <summary>
        /// Executes a two dimensional Fourier transformation.
        /// </summary>
        /// <param name="matrixProxy">The proxy containing the matrix data that should be transformed, as well as the row header column and column header column that can be used to determine the spacing between adjacent rows and columns.</param>
        /// <param name="options">The options for the Fourier transformation.</param>
        /// <param name="destinationTable">The destination table that is used to store the Fourier transformed values.</param>
        /// <exception cref="System.NotImplementedException">Data pretreatment has an order which is not implemented yet.</exception>
        public static void ExecuteFouriertransformation2D(DataTableMatrixProxy matrixProxy, RealFourierTransformation2DOptions options, DataTable destinationTable)
        {
            // preparation step

            if (!options.IsUserDefinedRowIncrementValue)
            {
                matrixProxy.TryGetRowHeaderIncrement(out var rowIncrementValue, out var rowIncrementMessage);
                options.RowIncrementValue   = rowIncrementValue;
                options.RowIncrementMessage = rowIncrementMessage;
            }

            if (!options.IsUserDefinedColumnIncrementValue)
            {
                matrixProxy.TryGetColumnHeaderIncrement(out var columnIncrementValue, out var columnIncrementMessage);
                options.ColumnIncrementValue   = columnIncrementValue;
                options.ColumnIncrementMessage = columnIncrementMessage;
            }

            var matrix = matrixProxy.GetMatrix((r, c) => new Altaxo.Calc.LinearAlgebra.DoubleMatrixInArray1DRowMajorRepresentation(r, c));

            var fft = new Altaxo.Calc.Fourier.RealFourierTransformation2D(matrix, true)
            {
                ColumnSpacing = options.RowIncrementValue,
                RowSpacing    = options.ColumnIncrementValue
            };

            if (options.DataPretreatmentCorrectionOrder.HasValue)
            {
                switch (options.DataPretreatmentCorrectionOrder.Value)
                {
                case 0:
                    fft.DataPretreatment += RealFourierTransformation2D.RemoveZeroOrderFromMatrixIgnoringInvalidElements;
                    break;

                case 1:
                    fft.DataPretreatment += RealFourierTransformation2D.RemoveFirstOrderFromMatrixIgnoringInvalidElements;
                    break;

                case 2:
                    fft.DataPretreatment += RealFourierTransformation2D.RemoveSecondOrderFromMatrixIgnoringInvalidElements;
                    break;

                case 3:
                    fft.DataPretreatment += RealFourierTransformation2D.RemoveThirdOrderFromMatrixIgnoringInvalidElements;
                    break;

                default:
                    throw new NotImplementedException(string.Format("Regression of order {0} is not implemented yet", options.DataPretreatmentCorrectionOrder.Value));
                }
            }

            if (options.ReplacementValueForNaNMatrixElements.HasValue)
            {
                Altaxo.Calc.LinearAlgebra.MatrixMath.ReplaceNaNElementsWith(matrix, options.ReplacementValueForNaNMatrixElements.Value);
            }
            if (options.ReplacementValueForInfiniteMatrixElements.HasValue)
            {
                Altaxo.Calc.LinearAlgebra.MatrixMath.ReplaceNaNAndInfiniteElementsWith(matrix, options.ReplacementValueForInfiniteMatrixElements.Value);
            }

            if (options.FourierWindow != null)
            {
                fft.DataPretreatment += options.FourierWindow.Apply;
            }

            fft.Execute();

            IMatrix <double>   resultMatrix;
            IROVector <double> rowFrequencies;
            IROVector <double> columnFrequencies;

            if (options.CenterResult)
            {
                fft.GetResultCentered(options.ResultingFractionOfRowsUsed, options.ResultingFractionOfColumnsUsed, options.OutputKind, out resultMatrix, out rowFrequencies, out columnFrequencies);
            }
            else
            {
                fft.GetResult(options.ResultingFractionOfRowsUsed, options.ResultingFractionOfColumnsUsed, options.OutputKind, out resultMatrix, out rowFrequencies, out columnFrequencies);
            }

            var matTableConverter = new Altaxo.Data.MatrixToDataTableConverter(resultMatrix, destinationTable);

            if (options.OutputFrequencyHeaderColumns)
            {
                matTableConverter.AddMatrixRowHeaderData(rowFrequencies, string.IsNullOrEmpty(options.FrequencyRowHeaderColumnName) ? "RowFrequencies" : options.FrequencyRowHeaderColumnName);
                matTableConverter.AddMatrixColumnHeaderData(columnFrequencies, string.IsNullOrEmpty(options.FrequencyColumnHeaderColumnName) ? "ColumnFrequencies" : options.FrequencyColumnHeaderColumnName);
            }

            if (options.OutputPeriodHeaderColumns)
            {
                matTableConverter.AddMatrixRowHeaderData(VectorMath.ToInverseROVector(rowFrequencies), string.IsNullOrEmpty(options.PeriodRowHeaderColumnName) ? "RowPeriods" : options.PeriodRowHeaderColumnName);
                matTableConverter.AddMatrixColumnHeaderData(VectorMath.ToInverseROVector(columnFrequencies), string.IsNullOrEmpty(options.PeriodColumnHeaderColumnName) ? "ColumnPeriods" : options.PeriodColumnHeaderColumnName);
            }

            matTableConverter.Execute();
        }
Beispiel #2
0
		/// <summary>
		/// Executes a two dimensional Fourier transformation.
		/// </summary>
		/// <param name="matrixProxy">The proxy containing the matrix data that should be transformed, as well as the row header column and column header column that can be used to determine the spacing between adjacent rows and columns.</param>
		/// <param name="options">The options for the Fourier transformation.</param>
		/// <param name="destinationTable">The destination table that is used to store the Fourier transformed values.</param>
		/// <exception cref="System.NotImplementedException">Data pretreatment has an order which is not implemented yet.</exception>
		public static void ExecuteFouriertransformation2D(DataTableMatrixProxy matrixProxy, RealFourierTransformation2DOptions options, DataTable destinationTable)
		{
			// preparation step

			if (!options.IsUserDefinedRowIncrementValue)
			{
				double rowIncrementValue; string rowIncrementMessage;
				matrixProxy.TryGetRowHeaderIncrement(out rowIncrementValue, out rowIncrementMessage);
				options.RowIncrementValue = rowIncrementValue;
				options.RowIncrementMessage = rowIncrementMessage;
			}

			if (!options.IsUserDefinedColumnIncrementValue)
			{
				double columnIncrementValue; string columnIncrementMessage;
				matrixProxy.TryGetColumnHeaderIncrement(out columnIncrementValue, out columnIncrementMessage);
				options.ColumnIncrementValue = columnIncrementValue;
				options.ColumnIncrementMessage = columnIncrementMessage;
			}

			var matrix = matrixProxy.GetMatrix((r, c) => new Altaxo.Calc.LinearAlgebra.DoubleMatrixInArray1DRowMajorRepresentation(r, c));

			var fft = new Altaxo.Calc.Fourier.RealFourierTransformation2D(matrix, true);
			fft.ColumnSpacing = options.RowIncrementValue;
			fft.RowSpacing = options.ColumnIncrementValue;

			if (options.DataPretreatmentCorrectionOrder.HasValue)
			{
				switch (options.DataPretreatmentCorrectionOrder.Value)
				{
					case 0:
						fft.DataPretreatment += RealFourierTransformation2D.RemoveZeroOrderFromMatrixIgnoringInvalidElements;
						break;

					case 1:
						fft.DataPretreatment += RealFourierTransformation2D.RemoveFirstOrderFromMatrixIgnoringInvalidElements;
						break;

					case 2:
						fft.DataPretreatment += RealFourierTransformation2D.RemoveSecondOrderFromMatrixIgnoringInvalidElements;
						break;

					case 3:
						fft.DataPretreatment += RealFourierTransformation2D.RemoveThirdOrderFromMatrixIgnoringInvalidElements;
						break;

					default:
						throw new NotImplementedException(string.Format("Regression of order {0} is not implemented yet", options.DataPretreatmentCorrectionOrder.Value));
				}
			}

			if (options.ReplacementValueForNaNMatrixElements.HasValue)
				Altaxo.Calc.LinearAlgebra.MatrixMath.ReplaceNaNElementsWith(matrix, options.ReplacementValueForNaNMatrixElements.Value);
			if (options.ReplacementValueForInfiniteMatrixElements.HasValue)
				Altaxo.Calc.LinearAlgebra.MatrixMath.ReplaceNaNAndInfiniteElementsWith(matrix, options.ReplacementValueForInfiniteMatrixElements.Value);

			if (options.FourierWindow != null)
			{
				fft.DataPretreatment += options.FourierWindow.Apply;
			}

			fft.Execute();

			IMatrix resultMatrix;
			IROVector rowFrequencies;
			IROVector columnFrequencies;

			if (options.CenterResult)
				fft.GetResultCentered(options.ResultingFractionOfRowsUsed, options.ResultingFractionOfColumnsUsed, options.OutputKind, out resultMatrix, out rowFrequencies, out columnFrequencies);
			else
				fft.GetResult(options.ResultingFractionOfRowsUsed, options.ResultingFractionOfColumnsUsed, options.OutputKind, out resultMatrix, out rowFrequencies, out columnFrequencies);

			var matTableConverter = new Altaxo.Data.MatrixToDataTableConverter(resultMatrix, destinationTable);

			if (options.OutputFrequencyHeaderColumns)
			{
				matTableConverter.AddMatrixRowHeaderData(rowFrequencies, string.IsNullOrEmpty(options.FrequencyRowHeaderColumnName) ? "RowFrequencies" : options.FrequencyRowHeaderColumnName);
				matTableConverter.AddMatrixColumnHeaderData(columnFrequencies, string.IsNullOrEmpty(options.FrequencyColumnHeaderColumnName) ? "ColumnFrequencies" : options.FrequencyColumnHeaderColumnName);
			}

			if (options.OutputPeriodHeaderColumns)
			{
				matTableConverter.AddMatrixRowHeaderData(VectorMath.Divide(1, rowFrequencies), string.IsNullOrEmpty(options.PeriodRowHeaderColumnName) ? "RowPeriods" : options.PeriodRowHeaderColumnName);
				matTableConverter.AddMatrixColumnHeaderData(VectorMath.Divide(1, columnFrequencies), string.IsNullOrEmpty(options.PeriodColumnHeaderColumnName) ? "ColumnPeriods" : options.PeriodColumnHeaderColumnName);
			}

			matTableConverter.Execute();
		}