snr#

diffsptk.SNR#

alias of SignalToNoiseRatio

class diffsptk.SignalToNoiseRatio(frame_length=None, full=False, reduction='mean', eps=1e-08)[source]#

See this page for details.

Parameters:
frame_lengthint >= 1 or None

Frame length, \(L\). If given, calculate segmental SNR.

fullbool

If True, include the constant term in the SNR calculation.

reduction[‘none’, ‘mean’, ‘sum’]

Reduction type.

epsfloat >= 0

A small value to prevent NaN.

forward(s, sn)[source]#

Calculate SNR.

Parameters:
sTensor [shape=(…,)]

Signal.

snTensor [shape=(…,)]

Signal plus noise.

Returns:
outTensor [shape=(…,) or scalar]

Signal-to-noise ratio.

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, sn, frame_length=None, full=False, reduction='mean', eps=1e-08)[source]#

Calculate SNR.

Parameters:
sTensor [shape=(…,)]

Signal.

snTensor [shape=(…,)]

Signal plus noise.

frame_lengthint >= 1 or None

Frame length, \(L\). If given, calculate segmental SNR.

fullbool

If True, include the constant term in the SNR calculation.

reduction[‘none’, ‘mean’, ‘sum’]

Reduction type.

epsfloat >= 0

A small value to prevent NaN.

Returns:
outTensor [shape=(…,) or scalar]

Signal-to-noise ratio.

See also

rmse