ssspy.transform#

ssspy.transform provides transforms related to source separation.

Algorithms#

ssspy.transform.pca(input, ascend=True)#

Apply principal component analysis (PCA).

Parameters:
  • input (numpy.ndarray) – Input tensor.

  • ascend (bool) – If ascend=True, first channel corresponds to first principle component. Otherwise, last channel corresponds to first principle component.

Returns:

Output tensor. The type (real or complex) and shape are same as input.

Return type:

numpy.ndarray

Note

  • If input is 2D real tensor, it is regarded as (n_channels, n_samples).

  • If input is 3D complex tensor, it is regarded as (n_channels, n_bins, n_frames).

  • If input is 3D real tensor, it is regarded as (batch_size, n_channels, n_samples).

  • If input is 4D complex tensor, it is regarded as (batch_size, n_channels, n_bins, n_frames).

Examples

>>> import numpy as np
>>> from ssspy.transform import pca

>>> n_channels, n_bins, n_frames = 2, 2049, 128
>>> n_sources = n_channels
>>> rng = np.random.default_rng(42)

>>> spectrogram_mix = \
...     rng.standard_normal((n_channels, n_bins, n_frames)) \
...     + 1j * rng.standard_normal((n_channels, n_bins, n_frames))
>>> spectrogram_mix_ortho = pca(spectrogram_mix)
>>> spectrogram_mix_ortho.shape
(2, 2049, 128)
ssspy.transform.whiten(input)#

Apply whitening (a.k.a sphering).

Parameters:

input (numpy.ndarray) – Input tensor to be whitened.

Return type:

ndarray

Returns:

numpy.ndarray of Whitened tensor. The type (real or complex) and shape are same as input.

Note

  • If input is 2D real tensor, it is regarded as (n_channels, n_samples).

  • If input is 3D complex tensor, it is regarded as (n_channels, n_bins, n_frames).

  • If input is 3D real tensor, it is regarded as (batch_size, n_channels, n_samples).

  • If input is 4D complex tensor, it is regarded as (batch_size, n_channels, n_bins, n_frames).

Examples

>>> import numpy as np
>>> from ssspy.transform import whiten

>>> n_channels, n_bins, n_frames = 2, 2049, 128
>>> n_sources = n_channels
>>> rng = np.random.default_rng(42)

>>> spectrogram_mix = \
...     rng.standard_normal((n_channels, n_bins, n_frames)) \
...     + 1j * rng.standard_normal((n_channels, n_bins, n_frames))
>>> spectrogram_mix_whitened = whiten(spectrogram_mix)
>>> spectrogram_mix_whitened.shape
(2, 2049, 128)