Skip to content

Instantly share code, notes, and snippets.

@grey-area
Created November 10, 2021 11:10
Show Gist options
  • Save grey-area/a764b70480851ff5c4b25d1b0acaeb7c to your computer and use it in GitHub Desktop.
Save grey-area/a764b70480851ff5c4b25d1b0acaeb7c to your computer and use it in GitHub Desktop.
import numpy as np
def real_forward_fft(x):
N = len(x) # length of input signal
K = N // 2 + 1 # length of resulting FFT
result = np.zeros(K, dtype=np.complex64)
for k in range(K):
val = 0.0
for n in range(N): # note, in Python j is the imaginary number sqrt(-1)
val += x[n] * np.exp(-1j * 2 * np.pi / N * k * n)
result[k] = val
return result
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment