Skip to content

Instantly share code, notes, and snippets.

@multivac61
Created December 18, 2015 11:07
Show Gist options
  • Save multivac61/979d86686748cb6bace7 to your computer and use it in GitHub Desktop.
Save multivac61/979d86686748cb6bace7 to your computer and use it in GitHub Desktop.
def freq_from_FFT(sig, fs):
# Compute Fourier transform of windowed signal
N = len(sig)
windowed = sig * blackmanharris(N)
X = np.abs(np.fft.rfft(windowed))
# Find the peak and interpolate
i = np.argmax(abs(X)) # Just use this for less-accurate, naive version
X[X == 0] = epsilon # Circumvent division by 0
true_i = interpolate(X, i)[0]
return fs * true_i / N
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment