Skip to content

psambit9791/pysnr

Repository files navigation

PySNR

Build Status PyPI PyPI - Python Version Documentation Status Downloads DOI License: MIT

PySNR is a Python library which provides a suite of tools for performing various types of noise analysis on signals. PySNR aims to provide five main functionalities:

  • SNR (Signal to Noise Ratio)
  • THD (Total Harmonic Distortion)
  • SINAD (Signal to Noise and Distortion Ratio)
  • TOI (Third Order Intercept)
  • SFDR (Spurious Free Dynamic Range)

The following sections elaborate on each of these utilities further.

Signal to Noise Ratio (SNR)

This calculates the signal-to-noise ratio of an input signal. Signal-to-Noise ratio is defined as the ratio between the power of the desired signal to the power of the background noise.

If the noise magnitude is provided along with the signal, the SNR is calculated using the following formula: $$20 \log_{10}\left({\frac{\sqrt{\sum signal^2}}{\sqrt{\sum noise^2}}}\right)$$

If the noise magnitude is not provided, a modified periodogram is computed using a Kaiser window with $\beta = 38$ and the SNR is computed using the power of fundamental frequency and the power of the signal after removing the top 6 harmonics. The formula used in this case is: $$10 \log_{10}\left({\frac{\sqrt{\sum signal^2}}{\sqrt{\sum noise^2}}}\right)$$

The SNR value can also be computed by providing the periodograms of power spectral density $(V^{2}/Hz)$ or power spectrum $(V^{2})$. In case of power spectrum periodograms,the resolution bandwidth needs to be provided as well. Utilities provide the enbw() function which computes the estimated noise bandwidth for assessing the resolution bandwidth.

Total Harmonic Distortion (THD)

This calculates the total harmonic distortion of a signal. Total harmonic distortion is defined as the ratio of the power of the harmonics to the power of the fundamental frequency.

A modified periodogram is computed using a Kaiser window with $\beta = 38$ and this information is then used to determine the fundamental frequency and its harmonics. The formula used for computing the THD is: $$\frac{\sqrt{V^2_{H_1} + V^2_{H_2} + V^2_{H_3} + ...}}{V_{H_0}}$$

The THD value can also be computed by providing the periodograms of power spectral density $(V^{2}/Hz)$ or power spectrum $(V^{2})$. In case of power spectrum periodograms, the resolution bandwidth needs to be provided as well. Utilities provide the enbw() function which computes the estimated noise bandwidth for assessing the resolution bandwidth.

Signal to Noise and Distortion Ratio (SINAD)

This calculates the signal-to-noise-and-distortion ratio of a signal. SINAD is defined as the ratio between the power of the signal's fundamental frequency to the power of the background noise and harmonics.

A modified periodogram is computed using a Kaiser window with $\beta = 38$ and this information is then used to determine the fundamental frequency and its harmonics. The formula used for computing the SINAD is: $$\frac{P_{fundamental}}{P_{noise} + P_{harmonics}}$$

The SINAD value can also be computed by providing the periodograms of power spectral density $(V^{2}/Hz)$ or power spectrum $(V^{2})$. In case of power spectrum periodograms, the resolution bandwidth needs to be provided as well. Utilities provide the enbw() function which computes the estimated noise bandwidth for assessing the resolution bandwidth.

Third Order Intercept (TOI)

This calculates the third order intercept point for a signal. There are six third-order intermodulation points from the top two dominant frequencies $F_1$ and $F_2$ (fundamental signals) — $3F_1$, $3F_2$, $2F_1 + F_2$, $2F_2 + F_1$, $2F_1 - F_2$ and $2F_2 - F_1$. Amongst these, the hardest to handle are $2F_1 - F_2$ and $2F_2 - F_1$ because of how c lose they are to the fundamental signals. TOI helps us compute the point at which the power of the third order products intercepts the power of the fundamental signals. In real world devices, this does not happen because the output power is limited; hence, the TOI is a theoretical value. TOI helps evaluate the linearity of the signal source. The higher the TOI, the better the linearity with lower levels of intermodulation distortion.

A modified periodogram is computed using a Kaiser window with $\beta = 38$ and this information is then used to identify the two dominant frequencies $F_1$ and $F_2$ which is considered the fundamental signal. The formula used for computing the TOI is: $$\overline{P_{fundamental}} + \frac{\overline{P_{fundamental}} - \overline{P_{intermodulation}}}{2}$$

The TOI value can also be computed by providing the periodograms of power spectral density $(V^{2}/Hz)$ or power spectrum $(V^{2})$. In case of power spectrum periodograms, the resolution bandwidth needs to be provided as well. Utilities provide the enbw() function which computes the estimated noise bandwidth for assessing the resolution bandwidth.

Spurious Free Dynamic Range (SFDR)

This calculates the spurious free dynamic range of a signal. SFDR is defined as the strength ratio of the fundamental signal to the strongest spurious signal.

A modified periodogram is computed using a Kaiser window with $\beta = 38$ and this information is then used to determine the fundamental frequency and its harmonics. The formula used for computing the SFDR is: $$10 \log_{10}\left({\frac{P_{fundamental}}{P_{spurious}}}\right)$$

The SFDR value can also be computed by providing the periodograms of power spectral density $(V^{2}/Hz)$ or power spectrum $(V^{2})$. In case of power spectrum periodograms, the resolution bandwidth needs to be provided as well. Utilities provide the enbw() function which computes the estimated noise bandwidth for assessing the resolution bandwidth.

Installation and Usage

Currently PySNR can be installed from pypi. TO install, use the following command:

pip install pysnr

To have a more detailed understanding of using the library, please refer to the usage and API Reference.

Citation

If you are using this software in your research, please use the following citation:

@software{sambit_paul_2022_6725547,
  author       = {Sambit Paul},
  title        = {psambit9791/pysnr: First Release},
  month        = jun,
  year         = 2022,
  publisher    = {Zenodo},
  version      = {0.0.1},
  doi          = {10.5281/zenodo.6725547},
  url          = {https://doi.org/10.5281/zenodo.6725547}
}

License

This project is licensed under the MIT License - see the LICENSE file for details.
You are free to use, modify and distribute this software, as long as the copyright header is left intact.

About

Suite of tools for noise analysis in Python

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages