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

>>> s = diffsptk.nrand(4)
>>> s
tensor([-0.5804, -0.8002, -0.0645,  0.6101,  0.4396])
>>> n = diffsptk.nrand(4) * 0.1
>>> n
tensor([ 0.0854,  0.0485, -0.0826,  0.1455,  0.0257])
>>> snr = diffsptk.SignalToNoiseRatio(full=True)
>>> y = snr(s, s + n)
>>> y
tensor(16.0614)
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

rmse