All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nd4j.linalg.fft.VectorIFFT Maven / Gradle / Ivy

There is a newer version: 1.0.0-M2.1
Show newest version
package org.nd4j.linalg.fft;

import com.google.common.base.Function;
import org.nd4j.linalg.api.complex.IComplexNDArray;
import org.nd4j.linalg.factory.Nd4j;
import org.nd4j.linalg.util.ComplexNDArrayUtil;

/**
 * Single ifft operation
 *
 * @author Adam Gibson
 */
public class VectorIFFT implements Function {


    private int n;
    private int originalN = -1;
    /**
     * Create a vector fft operation.
     * If initialized with  a nonzero number, this will
     * find the next power of 2 for the element and truncate the
     * return matrix to the original n
     * @param n
     */
    public VectorIFFT(int n) {
        this.n = n;
    }


    @Override
    public IComplexNDArray apply(IComplexNDArray ndArray) {
        //ifft(x) = conj(fft(conj(x)) / length(x)
        IComplexNDArray ret = new VectorFFT(n).apply(ndArray.conj()).conj().divi(Nd4j.complexScalar(n));
        return originalN > 0 ? ComplexNDArrayUtil.truncate(ret, originalN, 0) : ret;

    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy