Short-time Fourier transform

`s = stft(x)`

`s = stft(x,fs)`

`s = stft(x,ts)`

`s = stft(___,Name,Value)`

`[s,f] = stft(___)`

`[s,f,t] = stft(___)`

`stft(___)`

specifies additional options using name-value pair arguments. Options include the FFT
window and length. These arguments can be added to any of the previous input
syntaxes.`s`

= stft(___,`Name,Value`

)

`stft(___)`

with no output arguments plots the
magnitude of the STFT in the current figure window. The STFT is plotted as two-sided and
centered.

The short-time Fourier transform (STFT) is used to analyze how the frequency content of a nonstationary signal changes over time.

The STFT of a signal is calculated by sliding an *analysis window* of
length $$M$$ over the signal and calculating the discrete Fourier transform of the
windowed data. The window hops over the original signal at intervals of $$R$$ samples. Most window functions taper off at the edges to avoid spectral
ringing. If a nonzero overlap length $$L$$ is specified, overlap-adding the windowed segments compensates for the
signal attenuation at the window edges. The DFT of each windowed segment is added to a matrix
that contains the magnitude and phase for each point in time and frequency. The number of rows
in the STFT matrix equals the number of DFT points, and the number of columns is given by

$$k=\lfloor \frac{{N}_{x}-L}{M-L}\rfloor ,$$

where $${N}_{x}$$ is the length of the original signal $$x(n)$$ and the ⌊⌋ symbols denote the floor function.

The STFT matrix is given by $$X(f)=\left[\begin{array}{ccccc}{X}_{1}(f)& {X}_{2}(f)& {X}_{3}(f)& \cdots & {X}_{k}(f)\end{array}\right]$$ such that the $$m$$th element of this matrix is

$${X}_{m}(f)={\displaystyle \sum _{n=-\infty}^{\infty}x(n)g(n-mR){e}^{-j2\pi fn}},$$

where

$$g(n)$$ — Window function of length $$M$$.

$${X}_{m}(f)$$ — DFT of windowed data centered about time $$mR$$.

$$R$$ — Hop size between successive DFTs. The hop size is the difference between the window length $$M$$and the overlap length $$L$$.

The magnitude squared of the STFT yields the `spectrogram`

representation of the power spectral density of the function.

[1] Mitra, Sanjit K.
*Digital Signal Processing: A Computer-Based Approach*. 2nd Ed. New
York: McGraw-Hill, 2001.

[2] Smith, J. O. *Spectral
Audio Signal Processing*. https://ccrma.stanford.edu/~jos/sasp/, online book, 2011 edition, accessed
Nov 2018.