Engee documentation

snr

Page in progress.

Signal-to-noise ratio.

Library

EngeeDSP

Syntax

Function call

  • r = snr(xi,y) — returns the signal-to-noise ratio in decibels (dB) for the signal xi by calculating the ratio of its total square of the amplitude to the amplitude of the noise y:

    r = mag2db(rssq(xi(:))/rssq(y(:))).

    Argument y must have the same dimension as xi. Use this form if the input signal is not necessarily sinusoidal and you have an estimate of the noise level.

  • r = snr(x) — returns the signal-to-noise ratio in decibels relative to the carrier (dBn) of the real sinusoidal input signal x. The signal-to-noise ratio can be determined using a modified periodogram of the same length as the input signal. The modified periodogram uses a Kaiser window with a coefficient of . The result does not take into account the power of the first six harmonics, including the main one.

  • r = snr(x,fs,n) — returns the signal-to-noise ratio in dBn of the real sinusoidal input signal x, sampled with frequency fs. The calculation does not take into account the power contained in n lower harmonics, including the main one.

  • r = snr(pxx,f,"psd") — defines the input signal pxx as an estimate of one-sided spectral power Density (PSD). Argument f It is a vector of frequencies at which estimates occur. pxx. When calculating noise, the power of the first six harmonics, including the main one, is not taken into account.

  • r = snr(pxx,f,n,"psd") — determines the number of harmonics n, which are excluded when calculating the signal-to-noise ratio. Meaning n the default value is 6 and it includes the main harmonic.

  • r = snr(sxx,f,rbw,"power") — defines the input signal sxx as a one-way power spectrum of a real signal. The input signal rbw — this is the resolution band in which each power estimate is integrated.

  • r = snr(sxx,f,rbw,n,"power") — determines the number of harmonics n, which are excluded when calculating the signal-to-noise ratio. Meaning n the default value is 6 and it includes the main harmonic.

  • r = snr(___,"aliased") — removes harmonics of the fundamental frequency that fall within the Nyquist range. Use this option if the input sinusoidal signal has insufficient sampling. If this option is not specified or the value is set "omitaliases", the function will treat as noise any harmonics of the fundamental frequency that fall outside the Nyquist range.

  • r,noisepow = snr(___) — also returns the total noise power of the non-harmonic components of the signal.

  • snr(___) — in the absence of output arguments, plots the spectrum of the signal in the current graph window and marks its main characteristics. The function uses different colors to display the fundamental component, the value of the constant component, harmonics, and noise. The signal-to-noise ratio is displayed above the graph. This function works for all the syntaxes listed above, with the exception of snr(xi,y).

Arguments

Input arguments

# xi — input signal

+ vector | the matrix | N-dimensional array

Details

An input signal specified as a vector, matrix, or N-dimensional array.

Data types

Float64, Float32

Support for complex numbers

Yes

# y — noise level estimate

+ vector | the matrix | N-dimensional array

Details

An estimate of the noise in the input signal, specified as a vector, matrix, or N-dimensional array with the same dimensions as xi.

Data types

Float64, Float32

Support for complex numbers

Yes

# x is the real input sinusoidal signal

+ vector

Details

A real input sinusoidal signal specified as a row vector or column vector.

Data types

Float64, Float32

# fs — sampling rate
1 (default) | positive real scalar

Details

The sampling rate set as a positive number. The sampling rate is the number of samples per unit of time. If the unit of time is seconds, then the sampling frequency is measured in hertz.

Data types

Float64, Float32

# n is the number of harmonics

+ 6 (by default) | positive integer scalar

Details

The number of harmonics excluded from the signal-to-noise ratio calculation is set as a positive integer. The value of the argument n the default value is 6.

# pxx — estimation of one-sided spectral power density

+ vector

Details

An estimate of the one-sided spectral power density, given as a real non-negative column vector.

The power spectral density should be expressed in linear units, not in dB. Use the function db2pow to convert dB to power factor.

Data types

Float64, Float32

# f — cyclic frequencies

+ real-valued row vector or column vector

Details

Cyclic frequencies of one-way spectral power density estimation pxx, specified as a row vector or column vector. The first element of the argument f must be equal to 0.

Data types

Float64, Float32

# sxx — power spectrum

+ non-negative real-valued row vector or column vector

Details

The power spectrum, defined as a real non-negative row vector or column vector.

The power spectrum should be expressed in linear units, not in dB. Use the function db2pow to convert dB to power factor.

Data types

Float64, Float32

# rbw — permissive bandwidth

+ positive scalar

Details

The allowed bandwidth, defined as a positive number. The resolving bandwidth is the product of the frequency resolution of the discrete Fourier transform and the equivalent bandwidth of the window noise.

Data types

Float64, Float32

Output arguments

# r is the signal-to-noise ratio
real-valued scalar

Details

The signal-to-noise ratio returned as a real number expressed in dBn. The signal-to-noise ratio returns to dB if the input signal is not sinusoidal.

Data types

Float64, Float32

# noisepow — total noise power

+ real-valued scalar

Details

The total noise power of the inharmonic components of the input signal, returned as a real number.

Data types

Float64, Float32

Additional Info

Distortion measurement functions

Details

Functions sfdr, sinad and snr measure the response of a weakly linear system excited by a sine wave.

If there is input data in the time domain, the function snr builds a periodogram using the Kaiser window with a large attenuation of the side lobes. To find the fundamental frequency, the algorithm searches for the largest nonzero spectral component in the periodogram. Then it calculates the central moment of all neighboring intervals monotonically decreasing from the maximum. For detection, the main frequency must be in at least the second frequency range. The higher harmonics are at frequencies that are multiples of the fundamental frequency. If a harmonic is located within a monotonously decreasing region next to another harmonic, its power is considered to belong to the larger harmonic. This large harmonic may or may not be the main one.

The function estimates the noise level using the median power in areas containing only noise. The constant component is excluded from the calculation. The noise at each point is determined either by the estimated level or the ordinate of the point, whichever is lower. The noise is then subtracted from the values of the signal and harmonics.

Function snr It is not performed if the fundamental harmonic is not the highest spectral component of the signal.

Make sure that the frequency components are spaced sufficiently apart to match the width of the side lobe of the Kaiser window. If this is not possible, you can use the flag "power" and calculate the periodogram in another window.