views:

359

answers:

3

Is there any form of short-time Fourier transform with corresponding inverse transform built into SciPy or NumPy or whatever?

There's the pyplot specgram function in matplotlib, which calls ax.specgram(), which calls mlab.specgram(), which calls _spectral_helper():

#The checks for if y is x are so that we can use the same function to
#implement the core of psd(), csd(), and spectrogram() without doing
#extra calculations.  We return the unaveraged Pxy, freqs, and t.

but

This is a helper function that implements the commonality between the 204 #psd, csd, and spectrogram. It is NOT meant to be used outside of mlab

I'm not sure if this can be used to do an STFT and ISTFT, though. Is there anything else, or should I translate something like this?

+1  A: 

I would definitely recommend using _spectral_helper() or copying the parts that you want from _spectral_helper() to form your own functions. To do the ISTFT I think that you just need to replace

fy = np.fft.fft(thisY, n=pad_to)

with

fy = np.fft.ifft(thisY, n=pad_to)
Justin Peel
I don't understand this function yet, but I don't think that would work. STFT produces a 2D array from a 1D array, and ISTFT produces a 1D array from a 2D array using an overlap-add method. I think there's more to it than just swapping out the function.
endolith
Yes, more changes are necessary. You need to sum over the correct axis, but there are other things that you would need to change as well. I would recommend looking at the link to the pytfd code that endolith posted. You may need to change some parts of it as well (such as sum along the correct axis), but it is closer to what you want.
Justin Peel
A: 

I also found this on GitHub, but it seems to operate on pipelines instead of normal arrays:

http://github.com/ronw/frontend/blob/master/basic.py#LID281

endolith
+1  A: 

Found another STFT, but no corresponding inverse function:

http://code.google.com/p/pytfd/source/browse/trunk/pytfd/stft.py

endolith