fftfreq

paddle.fft. fftfreq ( n: int, d: float = 1.0, dtype: DTypeLike | None = None, name: str | None = None, *, out: paddle.Tensor | None = None, device: PlaceLike | None = None, requires_grad: bool = False ) Tensor [source]

Return the Discrete Fourier Transform sample frequencies.

The returned float array f contains the frequency bin centers in cycles per unit of the sample spacing (with zero at the start). For instance, if the sample spacing is in seconds, then the frequency unit is cycles/second.

Given input length n and a sample spacing d:

f = [0, 1, ...,   n/2-1,     -n/2, ..., -1] / (d*n)   if n is even
f = [0, 1, ..., (n-1)/2, -(n-1)/2, ..., -1] / (d*n)   if n is odd
Parameters
  • n (int) – Dimension inputted.

  • d (float, optional) – Sample spacing (inverse of the sampling rate). Defaults is 1.

  • dtype (str, optional) – The data type of returns. Defaults is the data type of returns of paddle.get_default_dtype().

  • out (Tensor, optional) – The output tensor.

  • device (PlaceLike|None, optional) – The desired device of returned tensor. if None, uses the current device for the default tensor type (see paddle.device.set_device()). device will be the CPU for CPU tensor types and the current CUDA device for CUDA tensor types. Default: None.

  • requires_grad (bool, optional) – If autograd should record operations on the returned tensor. Default: False.

  • name (str, optional) – The default value is None. Normally there is no need for user to set this property. For more information, please refer to api_guide_Name.

Returns

Tensor. A tensor of length ‘n’ containing the sampling frequency.

Examples

>>> import paddle

>>> scalar_temp = 0.5
>>> fftfreq_xp = paddle.fft.fftfreq(5, d=scalar_temp)
>>> print(fftfreq_xp)
Tensor(shape=[5], dtype=float32, place=Place(cpu), stop_gradient=True,
[0., 0.40000001, 0.80000001, -0.80000001, -0.40000001])