Computational scaling of DFT

Since the DFT can be formulated as a matrix-vector product, its brute force evaluation will require for each component the calculation of N products of two numbers and addition of \(N\) numbers. Thus, the cost of the DFT should scale with the square of the data dimension \(N\). In the following we check numerically the computational scaling by performing DFT on randomly generated vectors with increasing number of components.

import random

Ntest = 10
timings1 = []
dimension = []

for i in range(1, Ntest):
    f = [random.gauss(0, 1) for n in range(2**i)]
    timing = %timeit -o -n 1 dft1(f)
    dimension.append(2**i)
    timings1.append(timing.average)
plt.subplot(121)    
plt.plot(np.array(dimension), np.array(timings1), 'o', markersize=12, color='red')
plt.plot(np.array(dimension), np.array(timings1), color='red')
plt.xlabel("$N$")
plt.ylabel("Timing / s")

plt.subplot(122)
plt.plot(np.array(dimension)**2, np.array(timings1), 'o', markersize=12, color='red')
plt.plot(np.array(dimension)**2, np.array(timings1), color='red')

plt.xlabel("$N^2$")
plt.show()