K idZddlmZmZmZmZmZddlmZm Z gdZ e efZ d dZ ee dd d Zee dd d Ze ddd Ze ddd Zy)z+ Discrete Fourier Transforms - _helper.py )arangeasarrayemptyintegerroll)array_function_dispatch set_module)fftshift ifftshiftfftfreqrfftfreqNc|fSN)xaxess W/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/numpy/fft/_helper.py_fftshift_dispatcherrs 4Kz numpy.fft)modulecDt|}|;tt|j}|jDcgc]}|dz }}nBt |t r|j|dz}n|Dcgc]}|j|dz}}t|||Scc}wcc}w)a Shift the zero-frequency component to the center of the spectrum. This function swaps half-spaces for all axes listed (defaults to all). Note that ``y[0]`` is the Nyquist component only if ``len(x)`` is even. Parameters ---------- x : array_like Input array. axes : int or shape tuple, optional Axes over which to shift. Default is None, which shifts all axes. Returns ------- y : ndarray The shifted array. See Also -------- ifftshift : The inverse of `fftshift`. Examples -------- >>> import numpy as np >>> freqs = np.fft.fftfreq(10, 0.1) >>> freqs array([ 0., 1., 2., ..., -3., -2., -1.]) >>> np.fft.fftshift(freqs) array([-5., -4., -3., -2., -1., 0., 1., 2., 3., 4.]) Shift the zero-frequency component only along the second axis: >>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3) >>> freqs array([[ 0., 1., 2.], [ 3., 4., -4.], [-3., -2., -1.]]) >>> np.fft.fftshift(freqs, axes=(1,)) array([[ 2., 0., 1.], [-4., 3., 4.], [-1., -3., -2.]]) rtuplerangendimshape isinstance integer_typesrrrdimshiftaxs rr r s\  A |U166]#%&WW-c-- D- ( ",01b!11 5$  .2s B0BcJt|}|>> import numpy as np >>> freqs = np.fft.fftfreq(9, d=1./9).reshape(3, 3) >>> freqs array([[ 0., 1., 2.], [ 3., 4., -4.], [-3., -2., -1.]]) >>> np.fft.ifftshift(np.fft.fftshift(freqs)) array([[ 0., 1., 2.], [ 3., 4., -4.], [-3., -2., -1.]]) rrr s rr r MsH  A |U166]#()03!800 D- (''$-1$%/341772;!#$44 5$  15s B2B ct|ts tdd||zz }t|t|}|dz dzdz}t d|t|}||d|t |dz dt|}|||d||zS) a 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 Parameters ---------- n : int Window length. d : scalar, optional Sample spacing (inverse of the sampling rate). Defaults to 1. device : str, optional The device on which to place the created array. Default: ``None``. For Array-API interoperability only, so must be ``"cpu"`` if passed. .. versionadded:: 2.0.0 Returns ------- f : ndarray Array of length `n` containing the sample frequencies. Examples -------- >>> import numpy as np >>> signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5], dtype=float) >>> 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, -2.5 , -1.25]) n should be an integer?)devicerrdtyper(N)rr ValueErrorrintr)ndr(valresultsNp1p2s rr r }sV a '122 Q-CAs6*G Q1 qA 1C /BGBQK !q& 1C 7BGABK S=rct|ts tdd||zz }|dzdz}td|t|}||zS)a. Return the Discrete Fourier Transform sample frequencies (for usage with rfft, 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 `fftfreq` (but like `scipy.fftpack.rfftfreq`) the Nyquist frequency component is considered to be positive. Parameters ---------- n : int Window length. d : scalar, optional Sample spacing (inverse of the sampling rate). Defaults to 1. device : str, optional The device on which to place the created array. Default: ``None``. For Array-API interoperability only, so must be ``"cpu"`` if passed. .. versionadded:: 2.0.0 Returns ------- f : ndarray Array of length ``n//2 + 1`` containing the sample frequencies. Examples -------- >>> import numpy as np >>> signal = np.array([-2, 8, 6, 4, 1, 0, 3, 5, -3, 4], dtype=float) >>> fourier = np.fft.rfft(signal) >>> n = signal.size >>> sample_rate = 100 >>> freq = np.fft.fftfreq(n, d=1./sample_rate) >>> freq array([ 0., 10., 20., ..., -30., -20., -10.]) >>> freq = np.fft.rfftfreq(n, d=1./sample_rate) >>> freq array([ 0., 10., 20., 30., 40., 50.]) r&r'rr)rr*)rrr,rr-)r.r/r(r0r2r1s rr r sOd a '122 Q-C Q AQV4G S=rr)r'N)__doc__ numpy._corerrrrrnumpy._core.overridesrr __all__r-rrr r r r rrrr:s>=E ;g -kB6 C6 r-kB, C, ^ K33l K66r