Created
December 3, 2013 19:23
-
-
Save kinnala/7775902 to your computer and use it in GitHub Desktop.
FFT w/ Hanning windowing (50% overlap of windows)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fft_hann(t,pt,M): | |
""" | |
Perform FFT with Hanning windowing, | |
50% overlap of 2^M+1 windows. | |
The resulting spectra are averaged. | |
""" | |
# Amplitude correction of Hanning | |
ampl_corr = 2. | |
# Signal length | |
N = pt.shape[1] | |
# Window length (amount of data pts/win) | |
n = 2*N/(2**M+2) | |
# Save spectra here | |
spectra = {} | |
# Loop over axes | |
for itr in [0,1,2]: | |
spectra[itr] = 0. | |
# Loop over windows | |
for jtr in range(0,2**M+1): | |
begin = jtr*n/2 | |
end = begin+n | |
spectra[itr] = (ampl_corr*np.abs(np.fft.fft(np.hanning(n)*pt[itr,begin:end])[0:n/2])/n*2.)**2+spectra[itr] | |
# Do the averaging (avg of squares) | |
spectra[itr] = np.sqrt(spectra[itr]/(2**M+1)) | |
# Frequencies | |
freq = np.fft.fftfreq(n,t[1]-t[0])[0:n/2] | |
return freq,spectra |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment