Skip to content

Signal-to-Noise Ratio (SNR)

Reference

Signal to Noise Ratio.

nsnr(distorted, reference, normalization_db=75)

Calculate the normalized signal-to-noise ratio restricted to range of 0 to 1.

Source code in vibromaf/metrics/snr.py
def nsnr(
    distorted: np.array, reference: np.array, normalization_db: float = 75
) -> float:
    """Calculate the normalized signal-to-noise ratio restricted to range of 0 to 1."""
    return max(0.0, min(1.0, snr(distorted, reference) / normalization_db))

snr(distorted, reference)

Calculate the signal-to-noise ratio.

Parameters

  • distorted: np.array Distorted signal.
  • reference: np.array Reference signal.

Returns

  • float The SNR.
Source code in vibromaf/metrics/snr.py
def snr(distorted: np.array, reference: np.array) -> float:
    """Calculate the signal-to-noise ratio.

    Parameters
    ------
    * `distorted: np.array` Distorted signal.
    * `reference: np.array` Reference signal.

    Returns
    -------
    * `float` The SNR.
    """
    distorted = preprocess_input_signal(distorted, reference)
    return pow2db(signal_energy(reference) / signal_energy(distorted - reference))