From: Francis Russell Date: Mon, 15 Apr 2013 17:57:01 +0000 (+0100) Subject: Add script to compare NumPy's FFT and explicit DFT matrix. X-Git-Url: https://git.unchartedbackwaters.co.uk/w/?a=commitdiff_plain;h=1f96f6d40051ba56051302cee2c385120bb12920;p=francis%2Flta.git Add script to compare NumPy's FFT and explicit DFT matrix. --- diff --git a/misc/fourier.py b/misc/fourier.py new file mode 100755 index 0000000..c13a9c0 --- /dev/null +++ b/misc/fourier.py @@ -0,0 +1,26 @@ +#!/usr/bin/env python + +from numpy import complex128, empty, e, pi +from numpy.random import random +from numpy.fft import fft +from numpy.linalg import norm + + +def constructDFT(size): + dft = empty([size, size], complex128) + + for row in range(0, size): + for col in range(0, size): + dft[row, col] = e ** (- 2j * pi * row * col / size) + + return dft + + +size = 10 +signal = random(size) * 2 - 1 +dft = constructDFT(size) + +numpy_dft = fft(signal) +explicit_dft = dft.dot(signal) + +print "Delta between DFTs: " + str(norm(numpy_dft - explicit_dft))