jax.scipy.signal.csd

Contents

jax.scipy.signal.csd#

jax.scipy.signal.csd(x, y, fs=1.0, window='hann', nperseg=None, noverlap=None, nfft=None, detrend='constant', return_onesided=True, scaling='density', axis=-1, average='mean')[source]#

Estimate the cross power spectral density, Pxy, using Welch’s method.

LAX-backend implementation of scipy.signal._spectral_py.csd().

The original SciPy function exhibits slightly different behavior between csd(x, x)` and `csd(x, x.copy())`. The LAX-backend version is designed to follow the latter behavior. For using the former behavior, call this function as csd(x, None).

Original docstring below.

Parameters:
  • x (array_like) – Time series of measurement values

  • y (array_like) – Time series of measurement values

  • fs (float, optional) – Sampling frequency of the x and y time series. Defaults to 1.0.

  • window (str or tuple or array_like, optional) – Desired window to use. If window is a string or tuple, it is passed to get_window to generate the window values, which are DFT-even by default. See get_window for a list of windows and required parameters. If window is array_like it will be used directly as the window and its length must be nperseg. Defaults to a Hann window.

  • nperseg (int, optional) – Length of each segment. Defaults to None, but if window is str or tuple, is set to 256, and if window is array_like, is set to the length of the window.

  • nfft (int, optional) – Length of the FFT used, if a zero padded FFT is desired. If None, the FFT length is nperseg. Defaults to None.

  • detrend (str or function or False, optional) – Specifies how to detrend each segment. If detrend is a string, it is passed as the type argument to the detrend function. If it is a function, it takes a segment and returns a detrended segment. If detrend is False, no detrending is done. Defaults to ‘constant’.

  • return_onesided (bool, optional) – If True, return a one-sided spectrum for real data. If False return a two-sided spectrum. Defaults to True, but for complex data, a two-sided spectrum is always returned.

  • scaling ({ 'density', 'spectrum' }, optional) – Selects between computing the cross spectral density (‘density’) where Pxy has units of V**2/Hz and computing the cross spectrum (‘spectrum’) where Pxy has units of V**2, if x and y are measured in V and fs is measured in Hz. Defaults to ‘density’

  • axis (int, optional) – Axis along which the CSD is computed for both inputs; the default is over the last axis (i.e. axis=-1).

  • average ({ 'mean', 'median' }, optional) – Method to use when averaging periodograms. If the spectrum is complex, the average is computed separately for the real and imaginary parts. Defaults to ‘mean’.

Return type:

tuple[Array, Array]

Returns:

  • f (ndarray) – Array of sample frequencies.

  • Pxy (ndarray) – Cross spectral density or cross power spectrum of x,y.

References

Parameters:

noverlap (int | None)