ml4gw.transforms.spectral
Classes
|
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 tofast_spectral_density()
.Note that the cross spectral density computation is currently only available for
fast_spectral_density()
. Iffast=False
and a second tensor is passed toSpectralDensity.forward
, # noqa E501 aNotImplementedError
will be raised.- Parameters:
sample_rate (
float
) -- Rate at which tensors passed toforward
will be sampledfftlength (
float
) -- Length of the window, in seconds, to use for FFT estimatesoverlap (
Optional
[float
]) -- Overlap between windows used for FFT calculation. If left asNone
, this will be set tofftlength / 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 lengthnperseg
. 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)