ml4gw.transforms.spectral

Classes

SpectralDensity(sample_rate, fftlength[, ...])

Transform for computing either the power spectral density of a batch of multichannel timeseries, or the cross spectral density of two batches of multichannel timeseries.

class ml4gw.transforms.spectral.SpectralDensity(sample_rate, fftlength, overlap=None, average='mean', window=None, fast=False)

Bases: Module

Transform for computing either the power spectral density of a batch of multichannel timeseries, or the cross spectral density of two batches of multichannel timeseries.

On SpectralDensity.forward call, if only one tensor is provided, this transform will compute its power spectral density. If a second tensor is provided, the cross spectral density between the two timeseries will be computed. For information about the allowed relationships between these two tensors, see the documentation to fast_spectral_density().

Note that the cross spectral density computation is currently only available for fast_spectral_density(). If fast=False and a second tensor is passed to SpectralDensity.forward, # noqa E501 a NotImplementedError will be raised.

Parameters:
  • sample_rate (float) -- Rate at which tensors passed to forward will be sampled

  • fftlength (float) -- Length of the window, in seconds, to use for FFT estimates

  • overlap (Optional[float]) -- Overlap between windows used for FFT calculation. If left as None, this will be set to fftlength / 2.

  • average (str) -- Aggregation method to use for combining windowed FFTs. Allowed values are "mean" and "median".

  • window (Optional[Float[Tensor, '{int(fftlength*sample_rate)}']]) -- Window array to multiply by each FFT window before FFT computation. Should have length nperseg. Defaults to a hanning window.

  • fast (bool) -- Whether to use a faster spectral density computation that support cross spectral density, or a slower one which does not. The cost of the fast implementation is that it is not exact for the two lowest frequency bins.

forward(x, y=None)
Return type:

Union[Float[Tensor, 'frequency'], Float[Tensor, 'channel frequency'], Float[Tensor, 'batch channel frequency']]

Parameters:
  • x (Float[Tensor, 'time'] | Float[Tensor, 'channel time'] | Float[Tensor, 'batch channel time'])

  • y (Float[Tensor, 'time'] | Float[Tensor, 'channel time'] | Float[Tensor, 'batch channel time'] | None)