def idft2(F, scale=False):

    c = F.swapaxes(0, 1)
    Columns = []
    for col in range(c.shape[0]):
        Columns.append(numerical.idft(c[col], False))

    x = np.array(Columns)

    r = x.swapaxes(0, 1)
    Rows = []
    for row in range(r.shape[0]):
        Rows.append(numerical.idft(r[row], False))

    fU = np.array(Rows)

    M = F.shape[0] * F.shape[1]
    scaleFactor = 1
    if (scale):
        scaleFactor = (1 / M)

    return fU * scaleFactor
Ejemplo n.º 2
0
def idft2(f, scale=True):
    """
    Function to evaluate the inverse of the dft for a 2D array.

    Args:
        f (2d-array): array to calculate the 2 dimensional dft of
        scale (optional[boolean]): scales the result by dividing it by the
                                    number of array elements

    Returns:
        2 dimensional array of inverse fourier transformation
    """

    # for every column, evaluate the dft
    columns = f.swapaxes(0,1)
    Columns = []
    for col in range(columns.shape[0]):
        Columns.append(numerical.idft(columns[col], False))

    newSpace = np.array(Columns)

    # for every row in the new space, evaluate the dft
    # swap the axes again to set it back to normal
    rows = newSpace.swapaxes(0,1)
    Rows = []
    for row in range(rows.shape[0]):
        Rows.append(numerical.idft(rows[row], False))

    finalSpace = np.array(Rows)

    M = f.shape[0]*f.shape[1]
    scaleFactor = 1
    if (scale):
        scaleFactor = (1/M)

    return finalSpace*scaleFactor
Ejemplo n.º 3
0
    return transform


"""
PYTHON TEST HARNESS
"""
if __name__ == '__main__':
    import numerical
    import numpy
    import time

    N = 2**12
    F = numpy.zeros(N, dtype=numpy.complex128)
    F[0] = 1

    repeats = 10
    print('Repetitions = {0}'.format(repeats))

    startTime = time.clock()
    for repeat in range(repeats):
        f = numerical.idft(F)
    string = 'Average time per transform = {0:.8f} [s] ({1}-point iDFT)'
    print(string.format((time.clock() - startTime) / repeats, len(F)))

    startTime = time.clock()
    for repeat in range(repeats):
        f = numpy.fft.ifft(F)
    string = 'Average time per transform = {0:.8f} [s] ({1}-point iFFT)'
    print(string.format((time.clock() - startTime) / repeats, len(F)))
Ejemplo n.º 4
0
    transform = swap(numerical.dft(swap(f)))/scaleFactor

    return transform
"""
PYTHON TEST HARNESS
"""
if __name__ == '__main__':
    import numerical
    import numpy
    import time

    N = 2**12
    F = numpy.zeros(N, dtype=numpy.complex128)
    F[0] = 1

    repeats = 10
    print('Repetitions = {0}'.format(repeats))

    startTime = time.clock()
    for repeat in range(repeats):
        f = numerical.idft(F)
    string = 'Average time per transform = {0:.8f} [s] ({1}-point iDFT)'
    print(string.format((time.clock() - startTime)/repeats, len(F)))

    startTime = time.clock()
    for repeat in range(repeats):
        f = numpy.fft.ifft(F)
    string = 'Average time per transform = {0:.8f} [s] ({1}-point iFFT)'
    print(string.format((time.clock() - startTime)/repeats, len(F)))