pwtools.signal.dft

pwtools.signal.dft(a, method='loop')[source]

Simple straightforward complex DFT algo.

Parameters:
  • a (numpy 1d array) –

  • method (string, {'matmul', 'loop'}) –

Return type:

(len(a),) array

Examples

>>> from scipy.fftpack import fft
>>> a=np.random.rand(100)
>>> sfft=fft(a)
>>> dfft1=dft(a, method='loop')
>>> dfft2=dft(a, method='matmul')
>>> np.testing.assert_array_almost_equal(sfft, dfft1)
>>> np.testing.assert_array_almost_equal(sfft, dfft2)

Notes

This is only a reference implementation and has it’s limitations.
‘loop’: runs looong
‘matmul’: memory limit
=> use only with medium size arrays

N = len(a) sqrt(complex(-1)) = np.sqrt(-1 + 0*j) = 1j

Forward DFT, see [2] and [3] , scipy.fftpack.fft():

y[k] = sum(n=0…N-1) a[n] * exp(-2*pi*n*k*j/N) k = 0 … N-1

Backward DFT, see [1] eq. 12.1.6, 12.2.2:

y[k] = sum(n=0…N-1) a[n] * exp(2*pi*n*k*j/N) k = 0 … N-1

The algo for method==’matmul’ is the matrix mult from [1], but as Forward DFT for comparison with scipy. The difference between FW and BW DFT is that the imaginary parts are mirrored at y=0.

References