ShortTimeFourier[data]
returns the short-time Fourier transform (STFT) of data as a ShortTimeFourierData object.
ShortTimeFourier[data,n]
uses partitions of length n.
ShortTimeFourier[data,n,d]
uses partitions with offset d.
ShortTimeFourier[data,n,d,wfun]
applies a smoothing window wfun to each partition.
ShortTimeFourier[data,n,d,wfun,m]
pads partitions with zeros to length m prior to the computation of the transform.
ShortTimeFourier
ShortTimeFourier[data]
returns the short-time Fourier transform (STFT) of data as a ShortTimeFourierData object.
ShortTimeFourier[data,n]
uses partitions of length n.
ShortTimeFourier[data,n,d]
uses partitions with offset d.
ShortTimeFourier[data,n,d,wfun]
applies a smoothing window wfun to each partition.
ShortTimeFourier[data,n,d,wfun,m]
pads partitions with zeros to length m prior to the computation of the transform.
Details and Options
- The short-time Fourier transform (STFT) is a time-frequency representation of a signal and is typically used for transforming, filtering and analyzing the signal in both time and frequency.
- ShortTimeFourier[data] computes the discrete Fourier transform (DFT) of partitions of data and returns a ShortTimeFourierData object.
- Use Spectrogram on data or on the resulting ShortTimeFourierData object to plot the spectrogram.
- ShortTimeFourier[data] uses partitions of length
and offset
, where
is Length[data]. - The partition length n and offset d can be expressed as integer numbers (interpreted as number of samples) or as time or sample quantities.
- If necessary, fixed padding is used on the right to make all the partitions the same size.
- In ShortTimeFourier[data,n,d,wfun], the smoothing window wfun can be specified using a window function that will be sampled between
and
or a list of length n. The default window is DirichletWindow, which effectively does no smoothing. - The data can be any of the following:
-
list a vector of numerical data audio an Audio or Sound object video a Video object - For multichannel audio objects, the transform is computed over the sum of all channels.
- ShortTimeFourier accepts the FourierParameters option. The default setting is FourierParameters->{1,-1}.
Examples
open all close allBasic Examples (2)
Short-time Fourier transform of a sine wave:
ShortTimeFourier[{0, (1/Sqrt[2]), -1, (1/Sqrt[2]), 0, -(1/Sqrt[2]), 1, -(1/Sqrt[2])}, 4]Short-time Fourier transform of an audio signal:
ShortTimeFourier[\!\(\*AudioBox[""]\), 2048]Spectrogram[%]Scope (7)
Data (3)
Short-time Fourier transform of an audio recording:
ShortTimeFourier[Import["ExampleData/rule30.wav"]]Short-time Fourier transform of an array:
ShortTimeFourier[RandomReal[1, 100]]Short-time Fourier transform of the audio track of a video:
ShortTimeFourier[\!\(\*VideoBox[""]\)]Parameters (4)
By default, an automatic partition size is used:
data = Table[Sin[.5n ], {n, 0., 100.}];
ShortTimeFourier[data]Specify the number of samples in each partition:
ShortTimeFourier[data, 10]Specify the partition size using a time Quantity:
data = ExampleData[{"Audio", "MaleVoice"}];
ShortTimeFourier[data, Quantity[30, "Milliseconds"]]By default, an automatic partition offset is used:
data = Table[Sin[.5n ], {n, 0., 100.}];
ShortTimeFourier[data, 10]Specify the offset using the number of samples:
ShortTimeFourier[data, 10, 2]Specify the offset using a time Quantity:
data = ExampleData[{"Audio", "MaleVoice"}];
ShortTimeFourier[data, Quantity[30, "Milliseconds"], Quantity[10, "Milliseconds"]]Use Scaled to specify offset relative to the partition size:
data = ExampleData[{"Audio", "MaleVoice"}];
ShortTimeFourier[data, Quantity[30, "Milliseconds"], Scaled[1 / 3]]By default, no smoothing is applied to partitions:
data = Table[Sin[.5n ], {n, 0., 100.}];
ShortTimeFourier[data, 10, 2]Using None or DirichletWindow is equivalent to no smoothing:
ShortTimeFourier[data, 10, 2, None]Use a HannWindow as smoothing window function:
ShortTimeFourier[data, 10, 2, HannWindow]Use a precomputed list as smoothing window function:
window = Array[Sin, 10, {0., Pi}];
ShortTimeFourier[data, 10, 2, window]By default, partitions are not padded:
data = Table[Sin[.5n ], {n, 0., 100.}];
ShortTimeFourier[data, 10, 2, HannWindow]Pad each partition to be 20 samples long:
ShortTimeFourier[data, 10, 2, HannWindow, 20]Specify padding using a time Quantity:
data = ExampleData[{"Audio", "MaleVoice"}];
ShortTimeFourier[data, Quantity[30, "Milliseconds"], Quantity[10, "Milliseconds"], HannWindow, Quantity[50, "Milliseconds"]]Options (3)
FourierParameters (3)
a = ShortTimeFourier[{1, 0, 1, 0, 0, 1, 0, 0, 0, 1}, FourierParameters -> {1, 1}];
a["Data"]a = ShortTimeFourier[{1, 0, 1, 0, 0, 1, 0, 0, 0, 1}, FourierParameters -> {0, 1}];
a["Data"]%Sqrt[a["PartitionSize"]]a = ShortTimeFourier[{1, 0, 1, 0, 0, 1, 0, 0, 0, 1}, FourierParameters -> {-1, 1}];
a["Data"]Applications (6)
Compute the full short-time Fourier transform of a signal:
chirp = Table[Cos[200. π t + 2400. π t ^ 2], {t, 0., 1.6, 1 / 8000.}];stft = ShortTimeFourier[chirp]Plot of the magnitude of the ShortTimeFourier data:
Spectrogram[stft]Apply a smoothing window function:
ShortTimeFourier[chirp, Automatic, Automatic, HannWindow]//SpectrogramMagnitude spectrum of a single partition:
ListLinePlot[Abs[stft["Data"][[30]]]]Compute the full short-time Fourier transform of a signal:
a = Import["ExampleData/rule30.wav"];
stft = ShortTimeFourier[a, 1024, 512, HannWindow]Compute the magnitude spectrogram:
spectrogram = Abs[stft["Data"][[All, ;; Floor[stft["PartitionSize"] / 2 + 1]]]];
spectrogram//MatrixPlotCompute the power spectrogram:
powerSpectrogram = spectrogram ^ 2;
powerSpectrogram//MatrixPlotCompute the power spectrogram in decibels:
dbSpectrogram = 20Log10[powerSpectrogram];
dbSpectrogram//MatrixPlotCompute the forward and inverse short-time Fourier transform of a signal:
chirp = Table[Sin[ π t + 10. π t ^ 2], {t, 0., 1.6, 1 / 200.}];
chirp//ListLinePlotCompute the short-time Fourier transform:
stft = ShortTimeFourier[chirp, 100, 10, HannWindow]Approximate the inverse using InverseShortTimeFourier:
InverseShortTimeFourier[stft][[ ;; Length[chirp]]]//ListLinePlotchirp = Table[Sin[ π t + 10. π t ^ 2] + RandomReal[], {t, 0., 1.6, 1 / 200.}];
chirp//ListLinePlotCompute the full short-time Fourier transform of the signal:
stft = ShortTimeFourier[chirp, 100, 10, HannWindow];
stft//SpectrogramDefine a nonlinear function to squash low-amplitude components:
g[value_] := (value Abs[value]/Abs[value] + 20)
Plot[g[x], {x, 0, 10}]Apply the function to the short-time Fourier transform data:
stft["Data"] = Map[g, stft["Data"], {2}];
stft//SpectrogramInvert the short-time Fourier transform using InverseShortTimeFourier:
InverseShortTimeFourier[stft][[ ;; Length[chirp]]]//ListLinePlotChange the speed of an audio recording using different STFT partition offsets:
a = \!\(\*AudioBox[""]\);
stft = ShortTimeFourier[a, 1024, 128, HannWindow];Change the "PartitionOffset" property:
stft["PartitionOffset"] = 100Compute the inverse short-time Fourier transform to speed up the recording:
InverseShortTimeFourier[stft]Slow down an audio signal by resampling the short-time Fourier transform:
a = \!\(\*AudioBox[""]\);stft = ShortTimeFourier[a, 1024, 128, HannWindow]stft["Data"] = ArrayResample[stft["Data"], {300, 1024}];Compute the inverse short-time Fourier transform to get a slowed-down version of the original:
InverseShortTimeFourier[stft]Properties & Relations (2)
Short-time Fourier transform data is the same as the values computed by SpectrogramArray:
data = RandomReal[1, 200];ShortTimeFourier[data, 100, 10, HannWindow]["Data"] == SpectrogramArray[data, 100, 10, HannWindow]Spectrogram of the ShortTimeFourier is equivalent to Spectrogram of the original signal:
chirp = Table[Sin[ π t + 10. π t ^ 2], {t, 0., 1.6, 1 / 200.}];ShortTimeFourier[chirp, 100, 10, HannWindow]//SpectrogramSpectrogram[chirp, 100, 10, HannWindow]Notice that the default partitioning parameters are different:
Spectrogram[#, FrameTicks -> False]& /@ {chirp, ShortTimeFourier[chirp]}Text
Wolfram Research (2019), ShortTimeFourier, Wolfram Language function, https://reference.wolfram.com/language/ref/ShortTimeFourier.html (updated 2024).
CMS
Wolfram Language. 2019. "ShortTimeFourier." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/ShortTimeFourier.html.
APA
Wolfram Language. (2019). ShortTimeFourier. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/ShortTimeFourier.html
BibTeX
@misc{reference.wolfram_2026_shorttimefourier, author="Wolfram Research", title="{ShortTimeFourier}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/ShortTimeFourier.html}", note=[Accessed: 12-June-2026]}
BibLaTeX
@online{reference.wolfram_2026_shorttimefourier, organization={Wolfram Research}, title={ShortTimeFourier}, year={2024}, url={https://reference.wolfram.com/language/ref/ShortTimeFourier.html}, note=[Accessed: 12-June-2026]}