/// <summary> /// Gets an evaluation function depending on the requested type of output. /// </summary> /// <param name="kind">Requested type of output.</param> /// <returns>A function that takes the real part and the imaginary part of one Fourier transformation point and returns the requested output value.</returns> /// <exception cref="System.NotImplementedException">Triggered if the requested output type is not supported.</exception> private Func <double, double, double> GetEvalFunction(RealFourierTransformationOutputKind kind) { int numRows = NumberOfRows; int numCols = NumberOfColumns; // make this two variables local because they get included in the functions; double fac = 1.0 / (((double)numCols) * numRows); switch (kind) { case RealFourierTransformationOutputKind.RealPart: return((re, im) => re * fac); case RealFourierTransformationOutputKind.ImaginaryPart: return((re, im) => im * fac); case RealFourierTransformationOutputKind.Amplitude: return((re, im) => Math.Sqrt(re * re + im * im) * fac); case RealFourierTransformationOutputKind.Phase: return((re, im) => Math.Atan2(im, re)); case RealFourierTransformationOutputKind.Power: return((re, im) => (re * re + im * im) * fac * fac); default: throw new NotImplementedException(string.Format("The transformation kind {0} is not implemented!", kind)); } }
/// <summary> /// Gets a result of the Fourier transformation. Here, the row and column frequency of zero is located in the center of the matrix. /// </summary> /// <param name="rowFraction">Number (0..1) that designates the fraction of output row frequencies that should be included in the result.</param> /// <param name="columnFraction">Number (0..1) that designates the fraction of output column frequencies that should be included in the result.</param> /// <param name="kind">Requested type of output.</param> /// <param name="matrix">The matrix that accomodates the result.</param> /// <param name="rowFrequencies">Vector that accomodates the row frequencies.</param> /// <param name="columnFrequencies">Vector that accomodates the column frequencies.</param> /// <exception cref="System.InvalidOperationException">Before getting any result, you must execute the Fourier transformation first (by calling Execute).</exception> public void GetResultCentered(double rowFraction, double columnFraction, RealFourierTransformationOutputKind kind, out IMatrix <double> matrix, out IROVector <double> rowFrequencies, out IROVector <double> columnFrequencies) { GetResultCentered(rowFraction, columnFraction, GetEvalFunction(kind), out matrix, out rowFrequencies, out columnFrequencies); }
/// <summary> /// Gets a result of the Fourier transformation. Here, the row and column frequency of zero is located in the center of the matrix. /// </summary> /// <param name="rowFraction">Number (0..1) that designates the fraction of output row frequencies that should be included in the result.</param> /// <param name="columnFraction">Number (0..1) that designates the fraction of output column frequencies that should be included in the result.</param> /// <param name="kind">Requested type of output.</param> /// <param name="matrix">The matrix that accomodates the result.</param> /// <param name="rowFrequencies">Vector that accomodates the row frequencies.</param> /// <param name="columnFrequencies">Vector that accomodates the column frequencies.</param> /// <exception cref="System.InvalidOperationException">Before getting any result, you must execute the Fourier transformation first (by calling Execute).</exception> public void GetResultCentered(double rowFraction, double columnFraction, RealFourierTransformationOutputKind kind, out IMatrix matrix, out IROVector rowFrequencies, out IROVector columnFrequencies) { GetResultCentered(rowFraction, columnFraction, GetEvalFunction(kind), out matrix, out rowFrequencies, out columnFrequencies); }
/// <summary> /// Gets an evaluation function depending on the requested type of output. /// </summary> /// <param name="kind">Requested type of output.</param> /// <returns>A function that takes the real part and the imaginary part of one Fourier transformation point and returns the requested output value.</returns> /// <exception cref="System.NotImplementedException">Triggered if the requested output type is not supported.</exception> private Func<double, double, double> GetEvalFunction(RealFourierTransformationOutputKind kind) { int numRows = NumberOfRows; int numCols = NumberOfColumns; // make this two variables local because they get included in the functions; double fac = 1.0 / (((double)numCols) * numRows); switch (kind) { case RealFourierTransformationOutputKind.RealPart: return (re, im) => re * fac; case RealFourierTransformationOutputKind.ImaginaryPart: return (re, im) => im * fac; case RealFourierTransformationOutputKind.Amplitude: return (re, im) => Math.Sqrt(re * re + im * im) * fac; case RealFourierTransformationOutputKind.Phase: return (re, im) => Math.Atan2(im, re); case RealFourierTransformationOutputKind.Power: return (re, im) => (re * re + im * im) * fac * fac; default: throw new NotImplementedException(string.Format("The transformation kind {0} is not implemented!", kind)); } }