scipy.signal.stft
https://docs.scipy.org/doc/scipy-0.19.1/reference/generated/scipy.signal.stft.html
scipy.signal.stft(x,fs=1.0,window='hann',nperseg=256,noverlap=None,nfft=None,detrend=False,return_onesided=True,boundary='zeros',padded=True,axis=-1)[source]
Compute the Short Time Fourier Transform (STFT).
STFTs can be used as a way of quantifying the change of a nonstationary signal’s frequency and phase content over time.
Parameters:x: array_like
Time series of measurement values
fs: float, optional
Sampling frequency of thextime series. Defaults to 1.0.
window: str or tuple or array_like, optional
Desired window to use. Seeget_windowfor a list of windows and required parameters. Ifwindowis array_like it will be used directly as the window and its length must be nperseg. Defaults to a Hann window.
nperseg: int, optional
Length of each segment. Defaults to 256.
noverlap: int, optional
Number of points to overlap between segments. IfNone,noverlap=nperseg//2. Defaults toNone. When specified, the COLA constraint must be met (see Notes below).
nfft: int, optional
Length of the FFT used, if a zero padded FFT is desired. IfNone, the FFT length isnperseg. Defaults toNone.
detrend: str or function orFalse, optional
Specifies how to detrend each segment. Ifdetrendis a string, it is passed as thetypeargument to thedetrendfunction. If it is a function, it takes a segment and returns a detrended segment. IfdetrendisFalse, no detrending is done. Defaults toFalse.
return_onesided: bool, optional
IfTrue, return a one-sided spectrum for real data. IfFalsereturn a two-sided spectrum. Note that for complex data, a two-sided spectrum is always returned. Defaults toTrue.
boundary: str or None, optional
Specifies whether the input signal is extended at both ends, and how to generate the new values, in order to center the first windowed segment on the first input point. This has the benefit of enabling reconstruction of the first input point when the employed window function starts at zero. Valid options are['even','odd','constant','zeros',None]. Defaults to ‘zeros’, for zero padding extension. I.e.[1,2,3,4]is extended to[0,1,2,3,4,0]fornperseg=3.
padded: bool, optional
Specifies whether the input signal is zero-padded at the end to make the signal fit exactly into an integer number of window segments, so that all of the signal is included in the output. Defaults toTrue. Padding occurs after boundary extension, ifboundaryis notNone, andpaddedisTrue, as is the default.
axis: int, optional
Axis along which the STFT is computed; the default is over the last axis (i.e.axis=-1).
Returns:f: ndarray
Array of sample frequencies.
t: ndarray
Array of segment times.
Zxx: ndarray
STFT ofx. By default, the last axis ofZxxcorresponds to the segment times.
See also
istft
Inverse Short Time Fourier Transform
check_COLA
Check whether the Constant OverLap Add (COLA) constraint is met
welch
Power spectral density by Welch’s method.
spectrogram
Spectrogram by Welch’s method.
csd
Cross spectral density by Welch’s method.
lombscargle
Lomb-Scargle periodogram for unevenly sampled data
Notes
In order to enable inversion of an STFT via the inverse STFT inistft, the signal windowing must obey the constraint of “Constant OverLap Add” (COLA), and the input signal must have complete windowing coverage (i.e.(x.shape[axis]-nperseg)%(nperseg-noverlap)==0). Thepaddedargument may be used to accomplish this.
The COLA constraint ensures that every point in the input data is equally weighted, thereby avoiding aliasing and allowing full reconstruction. Whether a choice ofwindow,nperseg, andnoverlapsatisfy this constraint can be tested withcheck_COLA.
(Source code)