Short-time Fourier transform
The Short-time Fourier transform, 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. 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.
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 of the resulting signal is taken as the window is slid along the time axis, resulting in a two-dimensional representation of the signal. Mathematically, this is written as:where is the window function, commonly a Hann window or Gaussian window centered around zero, and is the signal to be transformed. is essentially the Fourier Transform of, 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,, and frequency axis,, to suppress any jump discontinuity of the phase result of the STFT. The time index is normally considered to be "slow" time and usually not expressed in as high resolution as time.
Discrete-time STFT
In the discrete time case, the data to be transformed could be broken up into chunks or frames. 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:likewise, with signal x and window w. 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:
See also the modified discrete cosine transform, 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.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 method, which also allows for modifications to the STFT complex spectrum. This makes for a versatile signal processing method, referred to as the overlap and add with modifications method.Continuous-time STFT
Given the width and definition of the window function w, we initially require the area of the window function to be scaled so thatIt easily follows that
and
The continuous Fourier Transform is
Substituting x from above:
Swapping order of integration:
So the Fourier Transform can be seen as a sort of phase coherent sum of all of the STFTs of x. Since the inverse Fourier transform is
then x can be recovered from X as
or
It can be seen, comparing to above that windowed "grain" or "wavelet" of x is
the inverse Fourier transform of X for τ fixed.
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 or good time resolution. 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 is reached with a Gaussian window function, as the Gaussian minimizes the Fourier uncertainty principle. This is called the Gabor transform.
One can consider the STFT for varying window size as a two-dimensional domain, 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.
Example
Using the following sample signal that is composed of a set of four sinusoidal waveforms joined together in sequence. Each waveform is only composed of one of four frequencies. The definition of is: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.
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.
These N/2 coefficients represent the frequencies 0 to fs/2 and two consecutive coefficients are spaced apart by
fs/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 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.
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, as well as any other method of harmonic analysis on a signal of finite record-length.
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 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 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 functionConverting into the discrete form:
Suppose that
Then we can write the original function into
Direct implementation
Constraints
a. Nyquist criterion :FFT-based method
Constraint
a., where is an integerb.
c. Nyquist criterion :
Recursive method
Constraint
a., where is an integerb.
c. Nyquist criterion :
d. Only for implementing the rectangular-STFT
Rectangular window imposes the constraint
Substitution gives:
Change of variable for :
Calculate by the N-point FFT:
where
Applying the recursive formula to calculate