espnet2.gan_svs.visinger2.ddsp.remove_above_nyquist
Less than 1 minute
espnet2.gan_svs.visinger2.ddsp.remove_above_nyquist
espnet2.gan_svs.visinger2.ddsp.remove_above_nyquist(amplitudes, pitch, sampling_rate)
Remove frequencies above the Nyquist limit from the amplitude spectrum.
The Nyquist limit is defined as half the sampling rate. This function multiplies the amplitudes of harmonics whose corresponding pitches are below the Nyquist frequency by 1, while setting the amplitudes of harmonics whose pitches are above the Nyquist frequency to a small value (1e-4).
- Parameters:
- amplitudes (torch.Tensor) – A tensor containing the amplitudes of the harmonics. The shape should be (…, n_harm), where n_harm is the number of harmonics.
- pitch (torch.Tensor) – A tensor containing the fundamental frequency (pitch) for each harmonic. The shape should be (…,).
- sampling_rate (float) – The sampling rate of the signal.
- Returns: A tensor with the same shape as amplitudes, where amplitudes corresponding to harmonics above the Nyquist frequency have been reduced.
- Return type: torch.Tensor
Examples
>>> import torch
>>> amplitudes = torch.tensor([[0.5, 0.3, 0.2]])
>>> pitch = torch.tensor([440.0])
>>> sampling_rate = 1000.0
>>> result = remove_above_nyquist(amplitudes, pitch, sampling_rate)
>>> print(result)
tensor([[0.5000, 0.3000, 0.0001]])
NOTE
The function assumes that the last dimension of amplitudes corresponds to the harmonics and that pitch is appropriately broadcastable with amplitudes.