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 [scalar]
Frame length, \(L\). If given, calculates segmental SNR.
- fullbool [scalar]
If True, include the constant term in the SNR calculation.
- reduction[‘none’, ‘mean’, ‘sum’]
Reduction type.
- epsfloat >= 0 [scalar]
A small value to prevent NaN.
- forward(s, sn)[source]#
Calculate SNR.
- Parameters:
- sTensor [shape=(…,)]
Signal.
- snTensor [shape=(…,)]
Signal plus noise.
- Returns:
- yTensor [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)
See also