stft

Short-Time Fourier Transform.

Syntax

st = stft(x)

st = stft(x,fs)

st = stft(x,fs,window)

st = stft(x,fs,window,overlap)

st = stft(x,fs,window,overlap,nfft)

st = stft(x,fs,window,overlap,nfft)

st = stft(x,fs,window,overlap,nfft,range)

[st,t,f] = stft(...)

Inputs

x
The signal to be transformed into the frequency domain.
Type: double
Dimension: vector
fs
The sampling frequency.
Default: 1 Hz.
Type: double
Dimension: scalar
window
The window size, or the window column vector.
Default: hann(256, 'periodic').
Type: integer | vec
Dimension: scalar | vector
overlap
The number of overlapping points in adjacent windows.
Default: 0.
Type: integer
Dimension: scalar
nfft
The size of the fft.
Default: the window length.
Type: integer
Dimension: scalar
range
The spectrum type. The options are as follows:
  • 'onesided' (default)
  • 'onesided_dB'
  • 'twosided'
The 'onesided' option returns the spectrum for the non-negative frequencies. With no return arguments, the magnitude of the two-sided spectrum is folded and then plotted.
The 'onesided_db' option returns the magnitude of the folded spectrum in decibels. With no return arguments, the result is plotted.
The 'twosided' option returns the full spectrum. With no return arguments, the result is plotted.
The 'onesided' and 'onesided_dB' options are only for real x, and are ignored otherwise.
Type: string

Outputs

st
The short-time fourier transform output, with segments stored by column.
t
The vector of times corresponding to the start of each column of st.
Type: vector
f
The vector of frequencies corresponding to each row of st.
Type: vector

Example

stft of a linear chirp signal.


f0 = 0;
f1 = 5;
T = 10;
c = (f1 - f0) / T;
t = [0:0.1:T-0.1];
x = sin(2 * pi * ((c/2)*t.^2 + f0*t));
stft(x, 10, 20, 14, 32, 'onesided');
        
Figure 1. stft figure 1


Comments

Default values are assigned to arguments with a [] input.

The function produces unnormalized spectral values with no compensation for the window bias. It may be useful to normalize st by sum(win), where win is the window vector.

The 'onesided' and 'onesided_dB'outputs have a length of nfft/2+1 if nfft is even, or (nfft+1)/2 if nfft is odd.

It is often recommended to remove the trend line prior to calling stft. The function does not automatically call detrend.