Skip to content

Instantly share code, notes, and snippets.

@itspacchu
Created July 11, 2020 10:02
Show Gist options
  • Save itspacchu/8da499ffd33d8d5cf42d4dedede24257 to your computer and use it in GitHub Desktop.
Save itspacchu/8da499ffd33d8d5cf42d4dedede24257 to your computer and use it in GitHub Desktop.
import numpy as np
def dft(x):
X = []
N = len(x)
for k in range(-N,N):
re = 0
im = 0
for n in range(0,N):
phi = (2*np.pi*k*n)/N
re += x[n]*np.cos(phi)
im -= x[n]*np.sin(phi)
re = re/N
im = im/N
freq = k
mag = abs(complex(re,im))
phase = np.arctan(im/re)
X.append([re,im,freq,mag,phase])
return X
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment