stft#

diffsptk.STFT#

alias of ShortTimeFourierTransform

class diffsptk.ShortTimeFourierTransform(frame_length, frame_period, fft_length, *, center=True, zmean=False, window='blackman', norm='power', eps=1e-09, relative_floor=None, out_format='power')[source]#

This module is a simple cascade of framing, windowing, and spectrum calculation.

Parameters:
frame_lengthint >= 1

Frame length, \(L\).

frame_peirodint >= 1

Frame period, \(P\).

fft_lengthint >= L

Number of FFT bins, \(N\).

centerbool

If True, assume that the center of data is the center of frame, otherwise assume that the center of data is the left edge of frame.

zmeanbool

If True, perform mean subtraction on each frame.

window[‘blackman’, ‘hamming’, ‘hanning’, ‘bartlett’, ‘trapezoidal’, ‘rectangular’]

Window type.

norm[‘none’, ‘power’, ‘magnitude’]

Normalization type of window.

epsfloat >= 0

A small value added to power spectrum.

relative_floorfloat < 0 or None

Relative floor in decibels.

out_format[‘db’, ‘log-magnitude’, ‘magnitude’, ‘power’, ‘complex’]

Output format.

forward(x)[source]#

Compute short-time Fourier transform.

Parameters:
xTensor [shape=(…, T)]

Waveform.

Returns:
outTensor [shape=(…, T/P, N/2+1)]

Spectrum.

Examples

>>> x = diffsptk.ramp(1, 3)
>>> x
tensor([1., 2., 3.])
>>> stft = diffsptk.STFT(frame_length=3, frame_period=1, fft_length=8)
>>> y = stft(x)
>>> y
tensor([[1.0000, 1.0000, 1.0000, 1.0000, 1.0000],
        [4.0000, 4.0000, 4.0000, 4.0000, 4.0000],
        [9.0000, 9.0000, 9.0000, 9.0000, 9.0000]])
diffsptk.functional.stft(x, *, frame_length=400, frame_period=80, fft_length=512, center=True, zmean=False, window='blackman', norm='power', eps=1e-09, relative_floor=None, out_format='power')[source]#

Compute short-time Fourier transform.

Parameters:
xTensor [shape=(…, T)]

Waveform.

frame_lengthint >= 1

Frame length, \(L\).

frame_peirodint >= 1

Frame period, \(P\).

fft_lengthint >= L

Number of FFT bins, \(N\).

centerbool

If True, assume that the center of data is the center of frame, otherwise assume that the center of data is the left edge of frame.

zmeanbool

If True, perform mean subtraction on each frame.

window[‘blackman’, ‘hamming’, ‘hanning’, ‘bartlett’, ‘trapezoidal’, ‘rectangular’]

Window type.

norm[‘none’, ‘power’, ‘magnitude’]

Normalization type of window.

epsfloat >= 0

A small value added to power spectrum.

relative_floorfloat < 0 or None

Relative floor in decibels.

out_format[‘db’, ‘log-magnitude’, ‘magnitude’, ‘power’, ‘complex’]

Output format.

Returns:
outTensor [shape=(…, T/P, N/2+1)]

Spectrum.

See also

frame window spec istft