snr#
- diffsptk.SNR#
alias of
SignalToNoiseRatio
- class diffsptk.SignalToNoiseRatio(frame_length: int | None = None, full: bool = False, reduction: str = 'mean', eps: float = 1e-08)[source]#
See this page for details.
- Parameters:
- frame_lengthint >= 1 or None
The frame length in samples, \(L\). If given, calculate the segmental SNR.
- fullbool
If True, include the constant term in the SNR calculation.
- reduction[‘none’, ‘mean’, ‘sum’]
The reduction type.
- epsfloat >= 0
A small value to avoid NaN.
- forward(s: Tensor, sn: Tensor) Tensor[source]#
Calculate SNR.
- Parameters:
- sTensor [shape=(…, T)]
The signal.
- snTensor [shape=(…, T)]
The signal with noise.
- Returns:
- outTensor [shape=(…,) or scalar]
The SNR.
Examples
>>> import diffsptk >>> import torch >>> snr = diffsptk.SignalToNoiseRatio(full=True) >>> s = torch.tensor([0.1, -0.2, 0.3, -0.4, 0.5]) >>> n = s * 0.1 >>> y = snr(s, s + n) >>> y tensor(20.0000)
- diffsptk.functional.snr(s: Tensor, sn: Tensor, frame_length: int | None = None, full: bool = False, reduction: str = 'mean', eps: float = 1e-08) Tensor[source]#
Calculate SNR.
- Parameters:
- sTensor [shape=(…, T)]
The signal.
- snTensor [shape=(…, T)]
The signal with noise.
- frame_lengthint >= 1 or None
The frame length in samples, \(L\). If given, calculate the segmental SNR.
- fullbool
If True, include the constant term in the SNR calculation.
- reduction[‘none’, ‘mean’, ‘sum’]
The reduction type.
- epsfloat >= 0
A small value to avoid NaN.
- Returns:
- outTensor [shape=(…,) or scalar]
The SNR.
See also