ShortTimeFourierTransform - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim


SignalProcessing

  

ShortTimeFourierTransform

  

compute the short-time Fourier transform of a signal

 

Calling Sequence

Parameters

Options

Description

Examples

Compatibility

Calling Sequence

ShortTimeFourierTransform( signal, options )

Parameters

signal

-

1-D rtable or list of data

Options

• 

samplerate: Positive numeric value for the sampling rate. The default is 1.0.

• 

overlapsize: Non-negative integer which specifies the target minimum overlap size of the segments. The default is 0.

• 

segmentsize: Positive integer for the size of the overlapping segments. The default is the largest power of 2 that is not larger than the size of signal.

• 

fftnormalization: One of none, symmetric, or full, indicates the normalization to be applied when using the Fast Fourier Transform (FFT). The default is symmetric.

• 

temperendpoints: Either true or false, specifies whether the short-time power spectra are to be tempered at the endpoints. The default is false.

• 

window: Either a list, name, or string, specifies the windowing command to be applied to the overlapping segments. The default is "none" (for no windowing to be applied). If a list is passed, the first element provides the name of the windowing command, and any remaining terms are passed as options to the command.

• 

windownormalization: Either true or false, indicates if the windowing function is to be normalized. The default is true.

• 

frequencyunit: Unit which specifies the unit of frequency. The default is Unit(Hz). Either of the forms algebraic or Unit(algebraic) is accepted, and the unit must be convertible to a valid unit of frequency.

• 

timeunit: Unit which specifies the unit of time. The default is Unit(s). Either of the forms algebraic or Unit(algebraic) is accepted, and the unit must be convertible to a valid unit of time.

• 

powerscale: Unit which indicates the scaling, if any, to be applied to the power spectrum. Either of the forms algebraic or Unit(algebraic) is accepted, and the unit must be convertible to a valid unit of power (see below for more details). The default is Unit(1/Hz).

• 

downsample: Positive integer, which specifies the down-sample factor applied to the spectrogram. The default is 1.

• 

spectrogramoptions: List of additional plot options to be passed when creating the spectrogram. The default is [].

• 

output: The type of output. The supported options are:

– 

stft: Returns a Matrix of float[8] datatype containing the Short-Time Fourier Transform (STFT). This is the default.

– 

stps: Returns a Matrix of float[8] datatype containing the Short-Time Power Spectrum (STPS).

– 

signal: Returns a Matrix of float[8] or complex[8] datatype containing the signal, with each column representing a short-time segment.

– 

frequencies: Returns a Vector, of float[8] datatype and length the same as signal, containing the frequencies.

– 

times: Returns a Vector, of float[8] datatype and length the same as signal, containing the times.

– 

spectrogram: Returns the spectrogram of the STPS.

– 

record: Returns a record with the previous options.

– 

list of any of the above options: Returns an expression sequence with the corresponding outputs, in the same order.

Description

• 

The ShortTimeFourierTransform command takes a 1-D rtable or list signal, and computes the Short-Time Fourier Transform using the provided options.

• 

The STFT is calculated using the following steps:

1. 

Divide the signal into segments of equal size with equal or nearly equal overlaps.

2. 

Apply the windowing procedure to each segment.

3. 

Take the Discrete Fourier Transform (DFT) of each windowed segment.

4. 

Form the STFT Matrix, with each column corresponding to a segment.

• 

The values of a=overlapsize, b=segmentsize, and n=numelemssignal must satisfy 2n, 0a, 2b, a<b, and bn.

• 

Since the DFT will be computed for each segment, it is suggested that, for larger signal lengths, segmentsize be a power of 2 and no less than 4, so that the FFT will be utilized.

• 

The passed value of overlapsize is used to determine the number c of overlapping segments of size b=segmentsize. The values of b and c determine the smallest possible overlap size p and the excess number q of overlaps of size p+1. If we denote n=numelemssignal, then bc=n+pc1q+p+1q for the 1<c case. When c=1, there are no overlaps and the single segment is just the original signal.

• 

The value of window, when not passed as a list, should be the name or string, with or without the Window suffix, that corresponds to the windowing command. For example, to use a Hamming window, you can pass window=Hamming or window="HammingWindow". In both cases, the command SignalProcessing[HammingWindow] will be used internally. Similarly, you can pass window=["Exponential",0.5] or window=[ExponentialWindow,0.5] to use SignalProcessing[ExponentialWindow] with parameter value 0.5.

• 

To apply a window to a Vector V of length n, the window is first applied to another Vector W of size n and filled with ones, and then V is multiplied element-wise by W. When windownormalization=true, W is first normalized with respect to its Root Mean Square (RMS).

• 

The STPS is calculated from the STFT by taking the square of the absolute value of each element. To scale the STPS with the powerscale option, units which are dimensionally equivalent to the following are accepted:

• 

1: No further scaling is performed.

• 

1/Hz: The STPS is divided by r=samplerate.

• 

1/rad/Hz: STPS is divided by 2πr.

• 

dB: Each element u of STPS is replaced with 10log10u.

• 

dB/Hz: Each element u of STPS is replaced with 10log10ur.

• 

dB/rad/Hz: Each element u of STPS is replaced with 10log10u2πr.

• 

When temperendpoints=true, the values in the first and last rows of the unscaled STPS Matrix are halved. Note that the segment size must be three or more for tempering.

• 

The frequencies and times Vectors are of size n=numelemssignal, and have components defined by, respectively, Fi=i1rn and Ti=i1r, where r=samplerate.

• 

The samplerate option can also include a unit of frequency. If a unit is provided, and it differs from frequencyunit, then the sample rate will be converted to use the same unit as frequencyunit.

• 

If signal is an rtable of type AudioTools:-Audio, the sample rate is inferred from the attributes. Should samplerate also be passed, it will be overridden.

• 

When the signal is real-valued and thus the STPS is symmetric, the spectrogram will display only the first half of frequency components, and the remaining STPS will be doubled in value.

• 

Maple will attempt to coerce the provided signal to a 1-D Vector of either float[8] or complex[8] datatype, and an error will be thrown if this is not possible. For this reason, it is most efficient for the passed input to use this datatype.

• 

The input signal cannot have an indexing function, and must use rectangular storage.

• 

The ShortTimeFourierTransform command is not thread safe.

Examples

withSignalProcessing&colon;

Example 1

• 

Here, we will create a signal, and then find the STFT along with the spectrogram. First, create Vectors for the times and signal:

TVectorseq0..599&comma;datatype=float8

gt2cosπt5+9sin3πt4

gt2cosπt5+9sin3πt4

(1)

Xmapevalhfg&comma;T

• 

Second, define a sampling rate:

r1.0&colon;

• 

Third, we choose overlap and segment sizes:

a50&colon;

b64&colon;

• 

Finally, we find the STFT and spectrogram, which can be exported in a record, to prevent re-calculation:

RShortTimeFourierTransformX&comma;samplerate=r&comma;overlapsize=a&comma;segmentsize=b&comma;powerscale=dBHz&comma;output=record&colon;

Rstft

Rspectrogram

Example 2

• 

The signal can also originate from a WAV file recording of a violin:

withAudioTools&colon;

filecatkerneloptsdatadir&comma;kerneloptsdirsep&comma;audio&comma;kerneloptsdirsep&comma;ViolinThreePosVibrato.wav

file/maple/cbat/active/277864/data/audio/ViolinThreePosVibrato.wav

(2)

ViolinToMonoReadfile&comma;samples=1000..5000

ViolinSample Rate44100File FormatPCM File Bit Depth16Channels1Samples/Channel4001Duration0.09073s

(3)
• 

Visually:

a128&colon;

b256&colon;

ShortTimeFourierTransformViolin&comma;overlapsize=a&comma;segmentsize=b&comma;frequencyunit=kHz&comma;powerscale=dBHz&comma;output=spectrogram

• 

The spectrogram can be generated with less points by using down sampling. For instance, the following reduces the number of elements in each column of the STPS by a factor of 4:

ShortTimeFourierTransformViolin&comma;overlapsize=a&comma;segmentsize=b&comma;frequencyunit=kHz&comma;powerscale=dBHz&comma;downsample=4&comma;output=spectrogram

Compatibility

• 

The SignalProcessing[ShortTimeFourierTransform] command was introduced in Maple 2021.

• 

For more information on Maple 2021 changes, see Updates in Maple 2021.

See Also

AudioTools

SignalProcessing

SignalProcessing[FFT]

SignalProcessing[HammingWindow]

SignalProcessing[PowerSpectrum]

SignalProcessing[RootMeanSquare]

SignalProcessing[ShortTimeSpectralEntropy]

SignalProcessing[Spectrogram]

SignalProcessing[Welch]