dpnp.fft.fftfreq
- dpnp.fft.fftfreq(n, d=1.0, device=None, usm_type=None, sycl_queue=None)[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 a window 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
For full documentation refer to
numpy.fft.fftfreq
.- 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 ofdpctl.SyclDevice
corresponding to a non-partitioned SYCL device, an instance ofdpctl.SyclQueue
, or a Device object returned bydpnp.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 containing the sample frequencies.
- Return type:
dpnp.ndarray
See also
dpnp.fft.rfftfreq
Return the Discrete Fourier Transform sample frequencies (for usage with
dpnp.fft.rfft
anddpnp.fft.irfft
).
Examples
>>> import dpnp as np >>> signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5]) >>> fourier = np.fft.fft(signal) >>> n = signal.size >>> timestep = 0.1 >>> freq = np.fft.fftfreq(n, d=timestep) >>> freq array([ 0. , 1.25, 2.5 , 3.75, -5. , -3.75, -2.5 , -1.25])
Creating the output array on a different device or with a specified usm_type:
>>> x = np.fft.fftfreq(n, d=timestep) # default case >>> x.shape, x.device, x.usm_type ((8,), Device(level_zero:gpu:0), 'device')
>>> y = np.fft.fftfreq(n, d=timestep, device="cpu") >>> y.shape, y.device, y.usm_type ((8,), Device(opencl:cpu:0), 'device')
>>> z = np.fft.fftfreq(n, d=timestep, usm_type="host") >>> z.shape, z.device, z.usm_type ((8,), Device(level_zero:gpu:0), 'host')