fftr#

class diffsptk.RealValuedFastFourierTransform(fft_length: int, out_format: str | int = 'complex', learnable: bool = False, device: device | None = None, dtype: dtype | None = None)[source]#

See this page for details.

Parameters:
fft_lengthint >= 2

The FFT length, \(L\).

out_format[‘complex’, ‘real’, ‘imaginary’, ‘amplitude’, ‘power’]

The output format.

learnablebool

Whether to make the DFT basis learnable. If True, the module performs DFT rather than FFT.

devicetorch.device or None

The device of this module.

dtypetorch.dtype or None

The data type of this module.

forward(x: Tensor) Tensor[source]#

Compute FFT of a real signal.

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

The real input signal.

Returns:
outTensor [shape=(…, L/2+1)]

The output spectrum.

Examples

>>> x = diffsptk.ramp(1, 3)
>>> x
tensor([1., 2., 3.])
>>> fftr = diffsptk.RealValuedFastFourierTransform(8, out_format="real")
>>> y = fftr(x)
>>> y
tensor([ 6.0000,  2.4142, -2.0000, -0.4142,  2.0000])
diffsptk.functional.fftr(x: Tensor, fft_length: int | None = None, out_format: str = 'complex') Tensor[source]#

Compute FFT of a real signal.

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

The real input signal.

fft_lengthint >= 2 or None

The FFT length, \(L\).

out_format[‘complex’, ‘real’, ‘imaginary’, ‘amplitude’, ‘power’]

The output format.

Returns:
outTensor [shape=(…, L/2+1)]

The output spectrum.

See also

ifftr stft spec