Short-time Fourier transform explained

The short-time Fourier transform (STFT) is a Fourier-related transform used to determine the sinusoidal frequency and phase content of local sections of a signal as it changes over time.[1] In practice, the procedure for computing STFTs is to divide a longer time signal into shorter segments of equal length and then compute the Fourier transform separately on each shorter segment. This reveals the Fourier spectrum on each shorter segment. One then usually plots the changing spectra as a function of time, known as a spectrogram or waterfall plot, such as commonly used in software defined radio (SDR) based spectrum displays. Full bandwidth displays covering the whole range of an SDR commonly use fast Fourier transforms (FFTs) with 2^24 points on desktop computers.

Forward STFT

Continuous-time STFT

Simply, in the continuous-time case, the function to be transformed is multiplied by a window function which is nonzero for only a short period of time. The Fourier transform (a one-dimensional function) of the resulting signal is taken, then the window is slid along the time axis until the end resulting in a two-dimensional representation of the signal. Mathematically, this is written as:

STFT\{x(t)\}(\tau,\omega)\equivX(\tau,\omega)=

infty
\int
-infty

x(t)w(t-\tau)e-idt

where

w(\tau)

is the window function, commonly a Hann window or Gaussian window centered around zero, and

x(t)

is the signal to be transformed (note the difference between the window function

w

and the frequency

\omega

).

X(\tau,\omega)

is essentially the Fourier transform of

x(t)w(t-\tau)

, a complex function representing the phase and magnitude of the signal over time and frequency. Often phase unwrapping is employed along either or both the time axis,

\tau

, and frequency axis,

\omega

, to suppress any jump discontinuity of the phase result of the STFT. The time index

\tau

is normally considered to be "slow" time and usually not expressed in as high resolution as time

t

. Given that the STFT is essentially a Fourier transform times a window function, the STFT is also called windowed Fourier transform or time-dependent Fourier transform.

Discrete-time STFT

See also: Modified discrete cosine transform. In the discrete time case, the data to be transformed could be broken up into chunks or frames (which usually overlap each other, to reduce artifacts at the boundary). Each chunk is Fourier transformed, and the complex result is added to a matrix, which records magnitude and phase for each point in time and frequency. This can be expressed as:

STFT\{x[n]\}(m,\omega)\equivX(m,\omega)=

infty
\sum
n=-infty

x[n]w[n-m]e-i

likewise, with signal

x[n]

and window

w[n]

. In this case, m is discrete and ω is continuous, but in most typical applications the STFT is performed on a computer using the fast Fourier transform, so both variables are discrete and quantized.

The magnitude squared of the STFT yields the spectrogram representation of the power spectral density of the function:

\operatorname{spectrogram}\{x(t)\}(\tau,\omega)\equiv|X(\tau,\omega)|2

See also the modified discrete cosine transform (MDCT), which is also a Fourier-related transform that uses overlapping windows.

Sliding DFT

If only a small number of ω are desired, or if the STFT is desired to be evaluated for every shift m of the window, then the STFT may be more efficiently evaluated using a sliding DFT algorithm.[2]

Inverse STFT

The STFT is invertible, that is, the original signal can be recovered from the transform by the inverse STFT. The most widely accepted way of inverting the STFT is by using the overlap-add (OLA) method, which also allows for modifications to the STFT complex spectrum. This makes for a versatile signal processing method,[3] referred to as the overlap and add with modifications method.

Continuous-time STFT

Given the width and definition of the window function w(t), we initially require the area of the window function to be scaled so that

infty
\int
-infty

w(\tau)d\tau=1.

It easily follows that

infty
\int
-infty

w(t-\tau)d\tau=1\forallt

and

x(t)=x(t)

infty
\int
-infty

w(t-\tau)d\tau=

infty
\int
-infty

x(t)w(t-\tau)d\tau.

The continuous Fourier transform is

X(\omega)=

infty
\int
-infty

x(t)e-idt.

Substituting x(t) from above:

X(\omega)=

infty
\int
-infty

\left[

infty
\int
-infty

x(t)w(t-\tau)d\tau\right]e-idt

=

infty
\int
-infty
infty
\int
-infty

x(t)w(t-\tau)e-id\taudt.

Swapping order of integration:

X(\omega)=

infty
\int
-infty
infty
\int
-infty

x(t)w(t-\tau)e-idtd\tau

=

infty
\int
-infty

\left[

infty
\int
-infty

x(t)w(t-\tau)e-idt\right]d\tau

=

infty
\int
-infty

X(\tau,\omega)d\tau.

So the Fourier transform can be seen as a sort of phase coherent sum of all of the STFTs of x(t). Since the inverse Fourier transform is

x(t)=

1
2\pi
infty
\int
-infty

X(\omega)e+id\omega,

then x(t) can be recovered from X(τ,ω) as

x(t)=

1
2\pi
infty
\int
-infty
infty
\int
-infty

X(\tau,\omega)e+id\taud\omega.

or

x(t)=

infty
\int
-infty

\left[

1
2\pi
infty
\int
-infty

X(\tau,\omega)e+id\omega\right]d\tau.

It can be seen, comparing to above that windowed "grain" or "wavelet" of x(t) is

x(t)w(t-\tau)=

1
2\pi
infty
\int
-infty

X(\tau,\omega)e+id\omega.

the inverse Fourier transform of X(τ,ω) for τ fixed.

An alternative definition that is valid only in the vicinity of τ, the inverse transform is:

x(t)=

1
w(t-\tau)
1
2\pi
infty
\int
-infty

X(\tau,\omega)e+id\omega.

In general, the window function

w(t)

has the following properties:

(a) even symmetry:

w(t)=w(-t)

;

(b) non-increasing (for positive time):

w(t)\geqw(s)

if

|t|\leq|s|

;

(c) compact support:

w(t)

is equal to zero when |t| is large.

Resolution issues

One of the pitfalls of the STFT is that it has a fixed resolution. The width of the windowing function relates to how the signal is represented—it determines whether there is good frequency resolution (frequency components close together can be separated) or good time resolution (the time at which frequencies change). A wide window gives better frequency resolution but poor time resolution. A narrower window gives good time resolution but poor frequency resolution. These are called narrowband and wideband transforms, respectively.

This is one of the reasons for the creation of the wavelet transform and multiresolution analysis, which can give good time resolution for high-frequency events and good frequency resolution for low-frequency events, the combination best suited for many real signals.

This property is related to the Heisenberg uncertainty principle, but not directly – see Gabor limit for discussion. The product of the standard deviation in time and frequency is limited. The boundary of the uncertainty principle (best simultaneous resolution of both) is reached with a Gaussian window function (or mask function), as the Gaussian minimizes the Fourier uncertainty principle. This is called the Gabor transform (and with modifications for multiresolution becomes the Morlet wavelet transform).

One can consider the STFT for varying window size as a two-dimensional domain (time and frequency), as illustrated in the example below, which can be calculated by varying the window size. However, this is no longer a strictly time-frequency representation – the kernel is not constant over the entire signal.

Examples

When the original function is:

X(t,f)=

infty
\int
-infty

w(t-\tau)x(\tau)e-jd\tau

We can have a simple example:

w(t) = 1 for |t| smaller than or equal B

w(t) = 0 otherwise

B = window

Now the original function of the Short-time Fourier transform can be changed as

X(t,f)=

t+B
\int
t-B

x(\tau)e-jd\tau

Another example:

Using the following sample signal

x(t)

that is composed of a set of four sinusoidal waveforms joined together in sequence. Each waveform is only composed of one of four frequencies (10, 25, 50, 100 Hz). The definition of

x(t)

is:

x(t)=\begin{cases} \cos(2\pi10t)&0s\let<5s\\ \cos(2\pi25t)&5s\let<10s\\ \cos(2\pi50t)&10s\let<15s\\ \cos(2\pi100t)&15s\let<20s\\ \end{cases}

Then it is sampled at 400 Hz. The following spectrograms were produced:

The 25 ms window allows us to identify a precise time at which the signals change but the precise frequencies are difficult to identify. At the other end of the scale, the 1000 ms window allows the frequencies to be precisely seen but the time between frequency changes is blurred.

Other examples:

w(t)=exp(\sigma-t2)

Normally we call

exp(\sigma-t2)

a Gaussian function or Gabor function. When we use it, the short-time Fourier transform is called the "Gabor transform".

Explanation

It can also be explained with reference to the sampling and Nyquist frequency.

Take a window of N samples from an arbitrary real-valued signal at sampling rate fs . Taking the Fourier transform produces N complex coefficients. Of these coefficients only half are useful (the last N/2 being the complex conjugate of the first N/2 in reverse order, as this is a real valued signal).

These N/2 coefficients represent the frequencies 0 to fs/2 (Nyquist) and two consecutive coefficients are spaced apart byfs/N Hz.

To increase the frequency resolution of the window the frequency spacing of the coefficients needs to be reduced. There are only two variables, but decreasing fs (and keeping N constant) will cause the window size to increase — since there are now fewer samples per unit time. The other alternative is to increase N, but this again causes the window size to increase. So any attempt to increase the frequency resolution causes a larger window size and therefore a reduction in time resolution—and vice versa.

Rayleigh frequency

As the Nyquist frequency is a limitation in the maximum frequency that can be meaningfully analysed, so is the Rayleigh frequency a limitation on the minimum frequency.

The Rayleigh frequency is the minimum frequency that can be resolved by a finite duration time window.[4] [5]

Given a time window that is Τ seconds long, the minimum frequency that can be resolved is 1/Τ Hz.

The Rayleigh frequency is an important consideration in applications of the short-time Fourier transform (STFT), as well as any other method of harmonic analysis on a signal of finite record-length.[6] [7]

Application

STFTs as well as standard Fourier transforms and other tools are frequently used to analyze music. The spectrogram can, for example, show frequency on the horizontal axis, with the lowest frequencies at left, and the highest at the right. The height of each bar (augmented by color) represents the amplitude of the frequencies within that band. The depth dimension represents time, where each new bar was a separate distinct transform. Audio engineers use this kind of visual to gain information about an audio sample, for example, to locate the frequencies of specific noises (especially when used with greater frequency resolution) or to find frequencies which may be more or less resonant in the space where the signal was recorded. This information can be used for equalization or tuning other audio effects.

Implementation

Original function

X(t,f)=

infty
\int
-infty

w(t-\tau)x(\tau)e-jd\tau

Converting into the discrete form:

t=n\Deltat,f=m\Deltaf,\tau=p\Deltat

X(n\Deltat,

infty
m\Delta
-infty

w((n-p)\Deltat)x(p\Delta

-j2\pipm\Deltat\Deltaf
t)e

\Deltat

Suppose that

w(t)\cong0for|t|>B,

B
\Deltat

=Q

Then we can write the original function into

X(n\Deltat,m\Deltaf)=

n+Q
\sum
p=n-Q

w((n-p)\Deltat)x(p\Delta

-j2\pipm\Deltat\Deltaf
t)e

\Deltat

Direct implementation

Constraints

a. Nyquist criterion (avoiding the aliasing effect):

\Deltat<

1
2\Omega
, where

\Omega

is the bandwidth of

x(\tau)w(t-\tau)

FFT-based method

Constraint

a.

\Deltat\Deltaf=\tfrac{1}{N}

, where

N

is an integer

b.

N\geq2Q+1

c. Nyquist criterion (avoiding the aliasing effect):

\Deltat<

1
2\Omega
,

\Omega

is the bandwidth of

x(\tau)w(t-\tau)

X(n\Deltat,m\Deltaf)=

n+Q
\sum
p=n-Q

w((n-p)\Deltat)x(p\Deltat)

-2\pijpm
N
e

\Deltat

ifwehaveq=p-(n-Q),thenp=(n-Q)+q

X(n\Deltat,m\Deltaf)=\Deltat

2\pij(Q-n)m
N
e
N-1
\sum
q=0
-2\pijqm
N
x
1(q)e

wherex1(q)=\begin{cases}w((Q-q)\Deltat)x((n-Q+q)\Deltat)&0\leqq\leq2Q\ 0&2Q<q<N\end{cases}

Recursive method

Constraint

a.

\Deltat\Deltaf=\tfrac{1}{N}

, where

N

is an integer

b.

N\geq2Q+1

c. Nyquist criterion (avoiding the aliasing effect):

\Deltat<

1
2\Omega
,

\Omega

is the bandwidth of

x(\tau)w(t-\tau)

d. Only for implementing the rectangular-STFT

Rectangular window imposes the constraint

w((n-p)\Deltat)=1

Substitution gives:

\begin{align} X(n\Deltat,m\Deltaf)&=

n+Q
\sum
p=n-Q

w((n-p)\Deltat)&x(p\Deltat)

-j2\pipm
N
e

\Deltat\\ &=

n+Q
\sum
p=n-Q

&x(p\Deltat)

-j2\pipm
N
e

\Deltat\\ \end{align}

Change of variable for :

X((n-1)\Deltat,m\Deltaf)=

n-1+Q
\sum
p=n-1-Q

x(p\Deltat)

-j2\pipm
N
e

\Deltat

Calculate

X(min{n}\Deltat,m\Deltaf)

by the N-point FFT:

X(n0\Deltat,m\Deltaf)=\Deltat

j2\pi(Q-n0)m
N
e
N-1
\sum
q=0

x1(q)

-j2\piqm
N
e

,    n0=min{(n)}

where

x1(q)=\begin{cases}x((n-Q+q)\Deltat)&q\leq2Q\ 0&q>2Q\end{cases}

Applying the recursive formula to calculate

X(n\Deltat,m\Deltaf)

X(n\Deltat,m\Deltaf)=X((n-1)\Deltat,m\Deltaf)-x((n-Q-1)\Deltat)

-j2\pi(n-Q-1)m
N
e

\Deltat+

-j2\pi(n+Q)m
N
x((n+Q)\Delta
t)e

\Deltat

Chirp Z transform

Constraint

\exp{(-j2\pipm\Deltat\Deltaf)}=\exp{(-j\pi

2\Delta
p
t\Delta

f)}

2\Delta
\exp{(j\pi(p-m)
t\Delta

f)}\exp{(-j\pi

2\Delta
m
t\Delta

f)}

so

X(n\Deltat,m\Deltaf)=\Deltat

n+Q
\sum
p=n-Q

w((n-p)\Deltat)x(p\Delta

-j2\pipm\Deltat\Deltaf
t)e

X(n\Deltat,m\Deltaf)=\Deltat

-j2\pi
2\Delta
m
t\Delta
f
e
n+Q
\sum
p=n-Q

w((n-p)\Deltat)x(p\Delta

-j\pi
2\Delta
p
t\Delta
f
t)e
j\pi
2\Delta
(p-m)
t\Delta
f
e

Implementation comparison

MethodComplexity
Direct implementation

O(TFQ)

FFT-based

O(TNlog2N)

Recursive

O(TF)

Chirp Z transform

O(TNlog2N)

See also

Other time-frequency transforms:

References

  1. Sejdić E. . Djurović I. . Jiang J. . 2009 . Time-frequency feature representation using energy concentration: An overview of recent advances . Digital Signal Processing . 19 . 1. 153–183 . 10.1016/j.dsp.2007.12.004. 2009DSP....19..153S .
  2. E. Jacobsen and R. Lyons, The sliding DFT, Signal Processing Magazine vol. 20, issue 2, pp. 74–80 (March 2003).
  3. Jont B. Allen . June 1977 . Short Time Spectral Analysis, Synthesis, and Modification by Discrete Fourier Transform . IEEE Transactions on Acoustics, Speech, and Signal Processing . ASSP-25 . 3 . 235–238 . 10.1109/TASSP.1977.1162950 .
  4. Kleinfeld . David . Mitra . Partha P. . March 2014 . 10.1101/pdb.top081075 . 3 . Cold Spring Harbor Protocols . pdb.top081075 . Spectral methods for functional brain imaging . 2014. 24591695 .
  5. Web site: What does "padding not sufficient for requested frequency resolution" mean? – FieldTrip toolbox.
  6. 2441488 . 18293071 . 10.1007/s10827-007-0066-2 . 25 . 1 . Biased competition through variations in amplitude of gamma-oscillations . 2008 . J Comput Neurosci . 89–107 . Zeitler M, Fries P, Gielen S .
  7. Wingerden. Marijn van. Vinck. Martin. Lankelma. Jan. Cyriel Pennartz. Pennartz. Cyriel M. A.. 2010-05-19. Theta-Band Phase Locking of Orbitofrontal Neurons during Reward Expectancy. Journal of Neuroscience. en. 30. 20. 7078–7087. 10.1523/JNEUROSCI.3860-09.2010. 0270-6474. 20484650. 6632657.

External links