Example #1
0
  /**
   * 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);
  }
Example #2
0
  /**
   * 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 ComplexFloatMatrix complexDiscreteFourierTransform1d(ComplexFloatMatrix inputC) {
    if (inputC.rows != 1 && inputC.columns != 1)
      throw new IllegalArgumentException("Illegal input: Must be a vector");

    float len = Math.max(inputC.rows, inputC.columns);
    ComplexFloat c2 = new ComplexFloat(0, -2).muli((float) FastMath.PI).divi(len);
    ComplexFloatMatrix range = MatrixUtil.complexRangeVector(0, len);
    ComplexFloatMatrix matrix = exp(range.mmul(range.transpose().mul(c2)));
    ComplexFloatMatrix complexRet =
        inputC.isRowVector() ? matrix.mmul(inputC) : inputC.mmul(matrix);
    return complexRet;
  }
Example #3
0
  /**
   * 1d inverse discrete fourier transform see matlab's fft2 for more examples. Note that this will
   * throw an exception if the input isn't a vector
   *
   * @param inputC the input to transform
   * @return the inverse fourier transform of the passed in input
   */
  public static ComplexFloatMatrix complexInverseDisceteFourierTransform1d(
      ComplexFloatMatrix inputC) {
    if (inputC.rows != 1 && inputC.columns != 1)
      throw new IllegalArgumentException("Illegal input: Must be a vector");
    float len = MatrixUtil.length(inputC);
    ComplexFloat c2 = new ComplexFloat(0, -2).muli((float) FastMath.PI).divi(len);
    ComplexFloatMatrix range = MatrixUtil.complexRangeVector(0, (int) len);
    ComplexFloatMatrix div2 = range.transpose().mul(c2);
    ComplexFloatMatrix div3 = range.mmul(div2).negi();
    ComplexFloatMatrix matrix = exp(div3).div(len);
    ComplexFloatMatrix complexRet =
        inputC.isRowVector() ? matrix.mmul(inputC) : inputC.mmul(matrix);

    return complexRet;
  }