Engee documentation

stft

The windowed Fourier transform.

Library

EngeeDSP

Syntax

Function call

  • s = stft(x,fs) — returns the OPF x with sampling rate fs.

  • s = stft(x,ts) — returns the OPF x with a sampling period ts.

  • s = stft(___,Name,Value) — sets additional parameters using name-value arguments. The values of such arguments include the window and the length of the FFT. These arguments can be added to any of the previous input syntaxes.

  • s,f = stft(___) — returns frequencies f, on which the OPF is calculated.

  • s,f,t = stft(___) — returns the time points at which the OPF is calculated.

  • stft(___) — without output arguments, plots the square of the OPF amplitude in decibels in the current graph window.

Arguments

Input arguments

# x — input signal

+ vector | the matrix

Details

An input signal specified as a vector or matrix.

If it is required that x and s had the same length, value (length(x)-noverlap)/(length(window)-noverlap) must be an integer. Use the argument Window to set the length window and the argument OverlapLength to ask noverlap.
  • If the input data contains multiple channels, specify x as a matrix, where each column corresponds to a channel.

Each signal channel x It must have a length greater than or equal to the length of the window.

Типы данных

Float64, Float32

Support for complex numbers

Yes

# fs — sampling rate
(default) | positive scalar

Details

The sampling rate, set as a positive scalar.

Типы данных

Float64, Float32

# ts is the sampling period

+ scalar

Details

The sampling period, set as a scalar.

Name-value input arguments

Specify optional argument pairs as Name,Value, where Name — the name of the argument, and Value — the appropriate value. Name-value arguments should be placed after other arguments, but the order of the pairs does not matter.

Use commas to separate the name and value, and Name put it in quotation marks.

# Window — spectral window

+ hann(128,"periodic") (by default) | vector

Details

The spectral window defined as a vector. If the argument is Window not specified or set as empty, the function uses a Hanna window of length 128. Length of the argument Window must be greater than or equal to 2.

For a list of available windows, see Windows - window functions.

Типы данных

Float64, Float32

# OverlapLength — the number of overlapping samples

+ 75% of the window length (by default) | a non-negative integer

Details

The number of overlapping samples specified as a positive integer less than the length of the argument Window. If the argument is OverlapLength omitted or empty, the function uses the largest integer smaller than 75% of the window length, which is 96 There are no default counts for the Hanna window.

Типы данных

Float64, Float32

# FFTLength — number of DFT points

+ 128 (by default) | a positive integer

Details

The number of DFT points, set as a positive integer. The value must be greater than or equal to the window length. If the length of the input signal is less than the length of the DFT, the data is padded with zeros.

Типы данных

Float64, Float32

# FrequencyRange — frequency range of OPF

+ "centered" (by default) | "twosided" | "onesided"

Details

The frequency range of the OPF, set as "centered", "twosided" or "onesided".

  • "centered" — calculate the two-sided centered OPF. If the value of the argument is FFTLength even, then s calculated in the interval rad/countdown. If the value of the argument is FFTLength If it’s an odd number, then s calculated in the interval rad/countdown. If time information is specified, then the intervals are cycles per unit of time and cycles per unit of time, respectively, where — effective sampling rate.

  • "twosided" — calculate the two-way OPF in the interval rad/countdown. If time information is specified, the interval is cycles per unit of time.

  • "onesided" — calculate the one-way OPF. If the value of the argument is FFTLength even, then s calculated in the interval rad/countdown. If the value of the argument is FFTLength If it’s an odd number, then s calculated in the interval rad/countdown. If time information is specified, then the intervals are cycles per unit of time and cycles per unit of time, respectively, where — effective sampling rate. This option is valid only for real signals.

If this argument is set to "onesided", function stft outputs values in the positive Nyquist band and does not save the total power.
Типы данных

Char, String

# OutputTimeDimension — time measurement of the output

+ "acrosscolumns" (by default) | "downrows"

Details

The time dimension of the output, set as "acrosscolumns" or "downrows". Set the value "downrows" if it is required that the time dimension s It was displayed in rows, and the frequency value was displayed in columns. Set the value "acrosscolumns" if it is required that the time dimension s It was displayed in columns, and the frequency value was displayed in rows. This input argument is ignored if the function is called without output arguments.

# out — type of output data

+ :data (by default) | :plot

Details

Type of output data:

  • :data — the function returns data;

  • :plot — the function returns a graph.

Output arguments

# s is the windowed Fourier transform
the matrix | three-dimensional array

Details

A windowed Fourier transform returned as a matrix or three-dimensional array. The time increases by columns s, and the frequency is in rows. The third dimension, if present, corresponds to the input channels.

  • If the signal is x has time counts, then s has columns where , — length of the argument Window, — length of the argument OverlapLength, and the symbols denote the function of rounding down to the nearest integer ( ).

  • Number of rows in s is equal to the value specified in the argument FFTLength.

Типы данных

Float64, Float32

# f — frequencies

+ vector

Details

The frequencies at which the OPF is calculated, returned as a vector.

Типы данных

Float64, Float32

# t — time points
vector

Details

The time points returned as a vector. Argument t contains time values corresponding to the centers of the data segments used to calculate estimates of the windowed power spectrum.

  • If the sampling rate is specified fs, then the vector contains the time values in seconds.

  • If the sampling period is specified ts, then the vector is an array with the same time format as the input data.

  • If no time information is specified, then the vector contains the numbers of the samples.

Типы данных

Float64, Float32

Additional Info

The windowed Fourier transform

Details

The windowed Fourier transform (OPF) is used to analyze the change in the frequency spectrum of a non-stationary signal over time. The square of the amplitude of the OPF is called the representation of the signal spectrogram in the time-frequency domain.

The OPF of the signal is calculated by moving the _ window of the analysis_ length based on the signal and the calculation of the discrete Fourier transform (DFT) of each segment of the window data. The window shifts according to the original signal with an interval of counts, which is equivalent to counts of overlap between adjacent segments. Most window functions taper towards the edges to avoid the Gibbs effect. The DFT of each window segment is added to a complex matrix containing the amplitude and phase for each time point and frequency. The OPF matrix has

columns where — signal length , and the symbols denote the function . The number of rows in the matrix is , i.e., the number of DFT points, for centered and two-sided transformations, and an odd number close to , for one-way transformations of real signals.

In the OPF matrix -th column

contains a DFT of window data centered relative to time :

stft en

Literature

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

  2. Sharpe, Bruce. Invertibility of Overlap-Add Processing. https://gauss256.github.io/blog/cola.html, accessed July 2019.

  3. Smith, Julius Orion. Spectral Audio Signal Processing. https://ccrma.stanford.edu/~jos/sasp/, online book, 2011 edition, accessed Nov 2018.