({{, (RefLink[ShortTimeFourier, paclet:ref/ShortTimeFourier])[data] 
returns the short-time Fourier transform (STFT) of data as a (RefLink[ShortTimeFourierData, paclet:ref/ShortTimeFourierData]) object.}, {, (RefLink[ShortTimeFourier, paclet:ref/ShortTimeFourier])[data,n]
uses partitions of length n.}, {, (RefLink[ShortTimeFourier, paclet:ref/ShortTimeFourier])[data,n,d]
uses partitions with offset d.}, {, (RefLink[ShortTimeFourier, paclet:ref/ShortTimeFourier])[data,n,d,wfun]
applies a smoothing window wfun to each partition.}, {, (RefLink[ShortTimeFourier, paclet:ref/ShortTimeFourier])[data,n,d,wfun,m]
pads partitions with zeros to length m prior to the computation of the transform.}})

OpenersNotesSection(Spacer1)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.

(RefLink[ShortTimeFourier, paclet:ref/ShortTimeFourier])[data] computes the discrete Fourier transform (DFT) of partitions of data and returns a (RefLink[ShortTimeFourierData, paclet:ref/ShortTimeFourierData]) object.

Use (RefLink[Spectrogram, paclet:ref/Spectrogram]) on data or on the resulting (RefLink[ShortTimeFourierData, paclet:ref/ShortTimeFourierData]) object to plot the spectrogram.

(RefLink[ShortTimeFourier, paclet:ref/ShortTimeFourier])[data] uses partitions of length n=2^Round[(Subscript[log, 2])((Sqrt[m]))+1] and offset d=Round[n/3], where m is (RefLink[Length, paclet:ref/Length])[data].

The partition length n and offset d can be expressed as an integer number (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 (RefLink[ShortTimeFourier, paclet:ref/ShortTimeFourier])[data,n,d,wfun], the smoothing window wfun can be specified using a window function that will be sampled between -1/2 and 1/2 or a list of length n. The default window is (RefLink[DirichletWindow, paclet:ref/DirichletWindow]), which effectively does no smoothing.

The data can be any of the following:

For multichannel audio objects, the spectrogram is computed over the sum of all channels.

(RefLink[ShortTimeFourier, paclet:ref/ShortTimeFourier]) accepts the (RefLink[FourierParameters, paclet:ref/FourierParameters]) option. The default setting is (RefLink[FourierParameters, paclet:ref/FourierParameters])->{1,-1}.

OpenersPrimaryExamplesSection(Spacer1)Examples  (19)

OpenersExampleSection0(Spacer1)Basic 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[,2048]

Plot the result:

Spectrogram[%]

OpenersExampleSection1(Spacer1)Scope  (6)

OpenersExampleSubsection0(Spacer1)Data  (2)

Short-time Fourier of an audio recording:

ShortTimeFourier[Import["ExampleData/rule30.wav"]]

Short-time Fourier of an array:

ShortTimeFourier[RandomReal[1,100]]

OpenersExampleSubsection1(Spacer1)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 (RefLink[Quantity, paclet:ref/Quantity]):

data=ExampleData[{"Audio","MaleVoice"}];
ShortTimeFourier[data,(Quantity[30, "ms", milliseconds, "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 (RefLink[Quantity, paclet:ref/Quantity]):

data=ExampleData[{"Audio","MaleVoice"}];
ShortTimeFourier[data,(Quantity[30, "ms", milliseconds, "Milliseconds"]),(Quantity[10, "ms", milliseconds, "Milliseconds"])]

Use (RefLink[Scaled, paclet:ref/Scaled]) to specify offset relative to the partition size:

data=ExampleData[{"Audio","MaleVoice"}];
ShortTimeFourier[data,(Quantity[30, "ms", milliseconds, "Milliseconds"]),Scaled[1/3]]

By default, no smoothing is applied to partitions:

data=Table[Sin[.5n ],{n,0.,100.}];
ShortTimeFourier[data,10,2]

Using (RefLink[None, paclet:ref/None]) or (RefLink[DirichletWindow, paclet:ref/DirichletWindow]) is equivalent to no smoothing:

ShortTimeFourier[data,10,2,None]

Use a (RefLink[HannWindow, paclet:ref/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 (RefLink[Quantity, paclet:ref/Quantity]):

data=ExampleData[{"Audio","MaleVoice"}];
ShortTimeFourier[data,(Quantity[30, "ms", milliseconds, "Milliseconds"]),(Quantity[10, "ms", milliseconds, "Milliseconds"]),HannWindow,(Quantity[50, "ms", milliseconds, "Milliseconds"])]

OpenersExampleSection2(Spacer1)Options  (3)

OpenersExampleSubsection2(Spacer1)FourierParameters  (3)

No normalization:

a=ShortTimeFourier[{1,0,1,0,0,1,0,0,0,1},FourierParameters->{1,1}];
a["Data"]

Normalization by 1/(Sqrt[n]):

a=ShortTimeFourier[{1,0,1,0,0,1,0,0,0,1},FourierParameters->{0, 1}];
a["Data"]

%Sqrt[a["PartitionSize"]]

Normalization by 1/n:

a=ShortTimeFourier[{1,0,1,0,0,1,0,0,0,1},FourierParameters->{-1,1}];
a["Data"]

OpenersExampleSection3(Spacer1)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 (RefLink[ShortTimeFourier, paclet:ref/ShortTimeFourier]) data:

Spectrogram[stft]

Apply a smoothing window function:

ShortTimeFourier[chirp,Automatic,Automatic,HannWindow]//Spectrogram

Magnitude 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//MatrixPlot

Compute the power spectrogram:

powerSpectrogram=spectrogram^2;
powerSpectrogram//MatrixPlot

Compute the power spectrogram in decibels:

dbSpectrogram=20Log10[powerSpectrogram];
dbSpectrogram//MatrixPlot

Compute 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//ListLinePlot

Compute the short-time Fourier transform:

stft=ShortTimeFourier[chirp,100,10,HannWindow]

Approximate the inverse using (RefLink[InverseShortTimeFourier, paclet:ref/InverseShortTimeFourier]):

InverseShortTimeFourier[stft][[;;Length[chirp]]]//ListLinePlot

Denoise a chirp signal:

chirp=Table[Sin[ π t+10. π t^2]+RandomReal[],{t,0.,1.6,1/200.}];
chirp//ListLinePlot

Compute the full short-time Fourier transform of the signal:

stft=ShortTimeFourier[chirp,100,10,HannWindow];
stft//Spectrogram

Define 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//Spectrogram

Invert the short-time Fourier transform using (RefLink[InverseShortTimeFourier, paclet:ref/InverseShortTimeFourier]):

InverseShortTimeFourier[stft][[;;Length[chirp]]]//ListLinePlot

Change the speed of an audio recording using different STFT partition offsets:

a=;
stft=ShortTimeFourier[a,1024,128,HannWindow];

Change the "PartitionOffset" property:

stft["PartitionOffset"]=100

Compute 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=;

stft=ShortTimeFourier[a,1024,128,HannWindow]

Resample the data:

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]

OpenersExampleSection4(Spacer1)Properties & Relations  (2)

Short-time Fourier transform data is the same as the values computed by (RefLink[SpectrogramArray, paclet:ref/SpectrogramArray]):

data=RandomReal[1,200];

ShortTimeFourier[data,100,10,HannWindow]["Data"]==SpectrogramArray[data,100,10,HannWindow]

(RefLink[Spectrogram, paclet:ref/Spectrogram]) of the (RefLink[ShortTimeFourier, paclet:ref/ShortTimeFourier]) is equivalent to (RefLink[Spectrogram, paclet:ref/Spectrogram]) of the original signal:

chirp=Table[Sin[ π t+10. π t^2],{t,0.,1.6,1/200.}];

ShortTimeFourier[chirp,100,10,HannWindow]//Spectrogram

Spectrogram[chirp,100,10,HannWindow]

Notice that the default partitioning parameters are different:

Spectrogram[#,FrameTicks->False]&/@{chirp,ShortTimeFourier[chirp]}

({{DocumentationFooterIconsRelatedFunction.png, ({{See Also}, {(RefLink[InverseShortTimeFourier, paclet:ref/InverseShortTimeFourier])  ▪  (RefLink[ShortTimeFourierData, paclet:ref/ShortTimeFourierData])  ▪  (RefLink[SpectrogramArray, paclet:ref/SpectrogramArray])  ▪  (RefLink[Spectrogram, paclet:ref/Spectrogram])  ▪  (RefLink[Fourier, paclet:ref/Fourier])  ▪  (RefLink[Partition, paclet:ref/Partition])  ▪  (RefLink[CepstrogramArray, paclet:ref/CepstrogramArray])  ▪  (RefLink[AudioSpectralMap, paclet:ref/AudioSpectralMap])  ▪  (RefLink[AudioSpectralTransformation, paclet:ref/AudioSpectralTransformation])  ▪  (RefLink[DiscreteWaveletTransform, paclet:ref/DiscreteWaveletTransform])}})}})

({{DocumentationFooterIconsRelatedGuide.png, ({{Related Guides}, {▪(RefLinkPlain[Fourier Analysis, paclet:guide/FourierAnalysis])}, {▪(RefLinkPlain[Signal Processing, paclet:guide/SignalProcessing])}, {▪(RefLinkPlain[Audio Representation, paclet:guide/AudioRepresentation])}, {▪(RefLinkPlain[Audio Processing, paclet:guide/AudioProcessing])}, {▪(RefLinkPlain[Summation Transforms, paclet:guide/SummationTransforms])}})}})