dpnp.fft.rfftfreq

dpnp.fft.rfftfreq(n, d=1.0, device=None, usm_type=None, sycl_queue=None)[source]

Return the Discrete Fourier Transform sample frequencies (for usage with dpnp.fft.rfft, dpnp.fft.irfft).

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 a window length n and a sample spacing d:

f = [0, 1, ...,     n/2-1,     n/2] / (d*n)   if n is even
f = [0, 1, ..., (n-1)/2-1, (n-1)/2] / (d*n)   if n is odd

Unlike dpnp.fft.fftfreq the Nyquist frequency component is considered to be positive.

For full documentation refer to numpy.fft.rfftfreq.

Parameters:
  • n (int) -- Window length.

  • d (scalar, optional) -- Sample spacing (inverse of the sampling rate). Default: 1.0.

  • device ({None, string, SyclDevice, SyclQueue}, optional) -- An array API concept of device where the output array is created. The device can be None (the default), an OneAPI filter selector string, an instance of dpctl.SyclDevice corresponding to a non-partitioned SYCL device, an instance of dpctl.SyclQueue, or a Device object returned by dpnp.dpnp_array.dpnp_array.device property. Default: None.

  • usm_type ({None, "device", "shared", "host"}, optional) -- The type of SYCL USM allocation for the output array. Default: None.

  • sycl_queue ({None, SyclQueue}, optional) -- A SYCL queue to use for output array allocation and copying. The sycl_queue can be passed as None (the default), which means to get the SYCL queue from device keyword if present or to use a default queue. Default: None.

Returns:

f -- Array of length n//2 + 1 containing the sample frequencies.

Return type:

dpnp.ndarray

See also

dpnp.fft.fftfreq

Return the Discrete Fourier Transform sample frequencies (for usage with dpnp.fft.fft and dpnp.fft.ifft).

Examples

>>> import dpnp as np
>>> signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5, -3, 4])
>>> fourier = np.fft.fft(signal)
>>> n = signal.size
>>> sample_rate = 100
>>> freq = np.fft.fftfreq(n, d=1./sample_rate)
>>> freq
array([  0.,  10.,  20.,  30.,  40., -50., -40., -30., -20., -10.])
>>> freq = np.fft.rfftfreq(n, d=1./sample_rate)
>>> freq
array([ 0., 10., 20., 30., 40., 50.])

Creating the output array on a different device or with a specified usm_type:

>>> x = np.fft.rfftfreq(n, d=1./sample_rate) # default case
>>> x.shape, x.device, x.usm_type
((6,), Device(level_zero:gpu:0), 'device')
>>> y = np.fft.rfftfreq(n, d=1./sample_rate, device="cpu")
>>> y.shape, y.device, y.usm_type
((6,), Device(opencl:cpu:0), 'device')
>>> z = np.fft.rfftfreq(n, d=1./sample_rate, usm_type="host")
>>> z.shape, z.device, z.usm_type
((6,), Device(level_zero:gpu:0), 'host')