ssspy.algorithm#
ssspy.algorithm
provides algorithms related to source separation.
Algorithms#
- ssspy.algorithm.projection_back(data_or_filter, reference=None, reference_id=0)#
Projection back technique to restore scale ambiguity.
The implementation is based on [1].
- Parameters:
data_or_filter (numpy.ndarray) – Estimated spectrograms or demixing filters.
reference (numpy.ndarray, optional) – Reference spectrogram.
reference_id (int, optional) – Reference microphone index. Default:
0
.
- Return type:
ndarray
- Returns:
numpy.ndarray of rescaled estimated spectrograms or demixing filters.
Examples
When you give estimated spectrograms,
>>> import numpy as np >>> from ssspy.algorithm import projection_back >>> 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)) >>> demix_filter = \ ... rng.standard_normal((n_sources, n_channels)) \ ... + 1j * rng.standard_normal((n_sources, n_channels)) >>> spectrogram_est = demix_filter @ spectrogram_mix.transpose(1, 0, 2) >>> # (n_bins, n_sources, n_frames) -> (n_sources, n_bins, n_frames) >>> spectrogram_est = spectrogram_est.transpose(1, 0, 2) >>> spectrogram_est_scaled = \ ... projection_back(spectrogram_est, reference=spectrogram_mix, reference_id=0) >>> spectrogram_est_scaled.shape (2, 2049, 128)
When you give demixing filters,
>>> import numpy as np >>> from ssspy.algorithm import projection_back >>> 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)) >>> demix_filter = \ ... rng.standard_normal((n_sources, n_channels)) \ ... + 1j * rng.standard_normal((n_sources, n_channels)) >>> demix_filter_scaled = projection_back(demix_filter, reference_id=0) >>> spectrogram_est_scaled = demix_filter_scaled @ spectrogram_mix.transpose(1, 0, 2) >>> # (n_bins, n_sources, n_frames) -> (n_sources, n_bins, n_frames) >>> spectrogram_est_scaled = spectrogram_est_scaled.transpose(1, 0, 2) >>> spectrogram_est_scaled.shape (2, 2049, 128)