src/FFTUtils.js
function ifft2DArray(ft, ftRows, ftCols) {
    var tempTransform = new Array(ftRows * ftCols);
    var nRows = ftRows / 2;
    var nCols = (ftCols - 1) * 2;
    // reverse transform columns
    FFT.init(nRows);
    var tmpCols = {re: new Array(nRows), im: new Array(nRows)};
    var iRow, iCol;
    for (iCol = 0; iCol < ftCols; iCol++) {
        for (iRow = nRows - 1; iRow >= 0; iRow--) {
            tmpCols.re[iRow] = ft[(iRow * 2) * ftCols + iCol];
            tmpCols.im[iRow] = ft[(iRow * 2 + 1) * ftCols + iCol];
        }
        //Unnormalized inverse transform
        FFT.bt(tmpCols.re, tmpCols.im);
        for (iRow = nRows - 1; iRow >= 0; iRow--) {
            tempTransform[(iRow * 2) * ftCols + iCol] = tmpCols.re[iRow];
            tempTransform[(iRow * 2 + 1) * ftCols + iCol] = tmpCols.im[iRow];
        }
    }

    // reverse row transform
    var finalTransform = new Array(nRows * nCols);
    FFT.init(nCols);
    var tmpRows = {re: new Array(nCols), im: new Array(nCols)};
    var scale = nCols * nRows;
    for (iRow = 0; iRow < ftRows; iRow += 2) {
        tmpRows.re[0] = tempTransform[iRow * ftCols];
        tmpRows.im[0] = tempTransform[(iRow + 1) * ftCols];
        for (iCol = 1; iCol < ftCols; iCol++) {
            tmpRows.re[iCol] = tempTransform[iRow * ftCols + iCol];
            tmpRows.im[iCol] = tempTransform[(iRow + 1) * ftCols + iCol];
            tmpRows.re[nCols - iCol] = tempTransform[iRow * ftCols + iCol];
            tmpRows.im[nCols - iCol] = -tempTransform[(iRow + 1) * ftCols + iCol];
        }
        //Unnormalized inverse transform
        FFT.bt(tmpRows.re, tmpRows.im);

        var indexB = (iRow / 2) * nCols;
        for (iCol = nCols - 1; iCol >= 0; iCol--) {
            finalTransform[indexB + iCol] = tmpRows.re[iCol] / scale;
        }
    }
    return finalTransform;
}
function ifft2DArray(ft, ftRows, ftCols) {
    var tempTransform = new Array(ftRows * ftCols);
    var nRows = ftRows / 2;
    var nCols = (ftCols - 1) * 2;
    // reverse transform columns
    FFT.init(nRows);
    var tmpCols = {re: new Array(nRows), im: new Array(nRows)};
    var iRow, iCol;
    for (iCol = 0; iCol < ftCols; iCol++) {
        for (iRow = nRows - 1; iRow >= 0; iRow--) {
            tmpCols.re[iRow] = ft[(iRow * 2) * ftCols + iCol];
            tmpCols.im[iRow] = ft[(iRow * 2 + 1) * ftCols + iCol];
        }
        //Unnormalized inverse transform
        FFT.bt(tmpCols.re, tmpCols.im);
        for (iRow = nRows - 1; iRow >= 0; iRow--) {
            tempTransform[(iRow * 2) * ftCols + iCol] = tmpCols.re[iRow];
            tempTransform[(iRow * 2 + 1) * ftCols + iCol] = tmpCols.im[iRow];
        }
    }

    // reverse row transform
    var finalTransform = new Array(nRows * nCols);
    FFT.init(nCols);
    var tmpRows = {re: new Array(nCols), im: new Array(nCols)};
    var scale = nCols * nRows;
    for (iRow = 0; iRow < ftRows; iRow += 2) {
        tmpRows.re[0] = tempTransform[iRow * ftCols];
        tmpRows.im[0] = tempTransform[(iRow + 1) * ftCols];
        for (iCol = 1; iCol < ftCols; iCol++) {
            tmpRows.re[iCol] = tempTransform[iRow * ftCols + iCol];
            tmpRows.im[iCol] = tempTransform[(iRow + 1) * ftCols + iCol];
            tmpRows.re[nCols - iCol] = tempTransform[iRow * ftCols + iCol];
            tmpRows.im[nCols - iCol] = -tempTransform[(iRow + 1) * ftCols + iCol];
        }
        //Unnormalized inverse transform
        FFT.bt(tmpRows.re, tmpRows.im);

        var indexB = (iRow / 2) * nCols;
        for (iCol = nCols - 1; iCol >= 0; iCol--) {
            finalTransform[indexB + iCol] = tmpRows.re[iCol] / scale;
        }
    }
    return finalTransform;
}
function ifft2DArray ( ft , ftRows , ftCols ) { var tempTransform = new Array ( ftRows * ftCols ) ; var nRows = ftRows / 2 ; var nCols = ( ftCols - 1 ) * 2 ; // reverse transform columns FFT . init ( nRows ) ; var tmpCols = { re : new Array ( nRows ) , im : new Array ( nRows ) } ; var iRow , iCol ; for ( iCol = 0 ; iCol < ftCols ; iCol ++ ) { for ( iRow = nRows - 1 ; iRow >= 0 ; iRow -- ) { tmpCols . re [ iRow ] = ft [ ( iRow * 2 ) * ftCols + iCol ] ; tmpCols . im [ iRow ] = ft [ ( iRow * 2 + 1 ) * ftCols + iCol ] ; } //Unnormalized inverse transform FFT . bt ( tmpCols . re , tmpCols . im ) ; for ( iRow = nRows - 1 ; iRow >= 0 ; iRow -- ) { tempTransform [ ( iRow * 2 ) * ftCols + iCol ] = tmpCols . re [ iRow ] ; tempTransform [ ( iRow * 2 + 1 ) * ftCols + iCol ] = tmpCols . im [ iRow ] ; } } // reverse row transform var finalTransform = new Array ( nRows * nCols ) ; FFT . init ( nCols ) ; var tmpRows = { re : new Array ( nCols ) , im : new Array ( nCols ) } ; var scale = nCols * nRows ; for ( iRow = 0 ; iRow < ftRows ; iRow += 2 ) { tmpRows . re [ 0 ] = tempTransform [ iRow * ftCols ] ; tmpRows . im [ 0 ] = tempTransform [ ( iRow + 1 ) * ftCols ] ; for ( iCol = 1 ; iCol < ftCols ; iCol ++ ) { tmpRows . re [ iCol ] = tempTransform [ iRow * ftCols + iCol ] ; tmpRows . im [ iCol ] = tempTransform [ ( iRow + 1 ) * ftCols + iCol ] ; tmpRows . re [ nCols - iCol ] = tempTransform [ iRow * ftCols + iCol ] ; tmpRows . im [ nCols - iCol ] = - tempTransform [ ( iRow + 1 ) * ftCols + iCol ] ; } //Unnormalized inverse transform FFT . bt ( tmpRows . re , tmpRows . im ) ; var indexB = ( iRow / 2 ) * nCols ; for ( iCol = nCols - 1 ; iCol >= 0 ; iCol -- ) { finalTransform [ indexB + iCol ] = tmpRows . re [ iCol ] / scale ; } } return finalTransform ; }
Calculates the inverse of a 2D Fourier transform

@param ft
@param ftRows
@param ftCols
@return
Calculates the inverse of a 2D Fourier transform