/** * 1d discrete fourier transform, note that this will throw an exception if the passed in input * isn't a vector. See matlab's fft2 for more information * * @param inputC the input to transform * @return the the discrete fourier transform of the passed in input */ public static ComplexNDArray complexDiscreteFourierTransform1d(ComplexNDArray inputC) { if (inputC.shape().length != 1) throw new IllegalArgumentException("Illegal input: Must be a vector"); double len = Math.max(inputC.rows, inputC.columns); ComplexDouble c2 = new ComplexDouble(0, -2).muli(FastMath.PI).divi(len); ComplexDoubleMatrix range = MatrixUtil.complexRangeVector(0, len); ComplexDoubleMatrix matrix = exp(range.mmul(range.transpose().mul(c2))); ComplexDoubleMatrix complexRet = matrix.mmul(inputC); return ComplexNDArray.wrap(inputC, complexRet); }
/** * 1d discrete fourier transform, note that this will throw an exception if the passed in input * isn't a vector. See matlab's fft2 for more information * * @param inputC the input to transform * @return the the discrete fourier transform of the passed in input */ public static ComplexDoubleMatrix complexDiscreteFourierTransform1d(ComplexDoubleMatrix inputC) { if (inputC.rows != 1 && inputC.columns != 1) throw new IllegalArgumentException("Illegal input: Must be a vector"); double len = Math.max(inputC.rows, inputC.columns); ComplexDouble c2 = new ComplexDouble(0, -2).muli(FastMath.PI).divi(len); ComplexDoubleMatrix range = MatrixUtil.complexRangeVector(0, len); ComplexDoubleMatrix matrix = exp(range.mmul(range.transpose().mul(c2))); ComplexDoubleMatrix complexRet = inputC.isRowVector() ? matrix.mmul(inputC) : inputC.mmul(matrix); return complexRet; }