Engee documentation

sinad

The ratio of the signal to the sum of noise and distortion.

Library

EngeeDSP

Syntax

Function call

  • r = sinad(x) — returns the ratio of the signal to the sum of noise and distortion (Signal to Noise And Distortion ratio, SINAD) in dBn for a real sinusoidal signal x. SINAD is determined using a modified periodogram of the same length as the input signal. The modified periodogram uses the Kaiser window with .

  • r = sinad(x,fs) — determines the sampling rate fs The input signal x. If the argument is fs not specified, the default sampling rate is 1.

  • r = sinad(pxx,f,"psd") — defines the input argument pxx as a one-way power spectral density (SPM) estimate. Argument f — the vector of frequencies corresponding to the estimates of the SPM in pxx.

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

  • r,totdistpow = sinad(___) — returns the total level of noise and harmonic distortion of the signal (in dB).

  • sinad(___, out=:plot) — plots the spectrum of the signal in the current graph window and marks its main component. The main component, the value of the constant component, and the noise are displayed in different colors. The SINAD value is displayed above the graph.

Arguments

Input arguments

# x is a real sinusoidal input signal

+ vector

Details

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

Типы данных

Float32, Float64

# fs — sampling rate
positive scalar

Details

The sampling rate, set as a positive scalar. 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 Hz.

# pxx — unilateral assessment of SPM

+ vector

Details

A one-sided estimate of the SPM, given as a real non-negative column vector.

The power spectral density should be expressed in linear units, not in decibels.

Типы данных

Float32, Float64

# f — cyclic frequencies

+ vector

Details

Cyclic frequencies corresponding to a one-sided SPM assessment pxx, specified as a row vector or column vector. The first element f must be equal to 0.

Типы данных

Float64, Float32

# sxx — power spectrum

+ A non-negative real vector is a row or a column vector

Details

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

The power spectrum should be expressed in linear units, not in decibels.

# rbw — resolution band

+ positive scalar

Details

The resolution band, set as a positive scalar. The resolution band is the product of the frequency resolution of the discrete Fourier transform and the equivalent noise band of the window.

Output arguments

# r is the ratio of the signal to the sum of noise and distortion

+ the real scalar

Details

The ratio of the signal to the sum of noise and distortion in dBn, returned as a real scalar.

# totdistpow — total power of noise and harmonic distortion of the signal

+ the real scalar

Details

The total power of noise and harmonic distortion of the signal, returned as a real scalar, expressed in dB.

Examples

SINAD for a single harmonic or single harmonic plus noise signal

Details

Let’s create two signals. Both signals have a fundamental frequency rad/counting with amplitude 1 and the first harmonic with frequency rad/counting with amplitude 0.025. One of the signals additionally contains additive white Gaussian noise with variance .

Let’s set the default settings of the random number generator to get reproducible results. Let’s define the SINAD for a signal without additive noise and compare the result with the theoretical SINAD.

import EngeeDSP.Functions: randn, sinad
using Random

n = 0:159
x = cos.(π/4*n) + 0.025 * sin.(π/2*n)

Random.seed!(123)

y = cos.(π/4*n) + 0.025 * sin.(π/2*n) + 0.05 * randn(length(n), 1)
r = sinad(x)
println("r = ", r[1])
r = 32.041199826559314
powfund = 1
powharm = 0.025^2
thSINAD = 10 * log10(powfund / powharm)
println("thSINAD = ", thSINAD)
thSINAD = 32.04119982655924

Let’s define SINAD for a sinusoidal signal with additive noise. We show how the inclusion of the theoretical variance of additive noise approximates SINAD.

r = sinad(y)
println("r = ", r[1])
r = 24.588862275561493
varnoise = 0.05^2
thSINAD = 10 * log10(powfund / (powharm + varnoise))
println("thSINAD = ", thSINAD)
thSINAD = 25.05149978319906

SINAD for a signal with a sampling frequency

Details

Let’s create a signal with a fundamental frequency 1 kHz and single amplitude, sampled with frequency 480 kHz. The signal additionally contains a first harmonic with an amplitude of 0.02 and additive white Gaussian noise with variance .

Let’s define SINAD and compare the result with the theoretical SINAD.

import EngeeDSP.Functions: randn, sinad
using Random

fs = 48e4
t = 0:1/fs:1-1/fs

Random.seed!(123)

x = cos.(2π*1000*t) + 0.02 * sin.(2π*2000*t) + 0.01 * randn(length(t), 1)
r = sinad(x, fs)
println("r = ", r[1])
r = 32.243478303520384
powfund = 1
powharm = 0.02^2
varnoise = 0.01^2
thSINAD = 10 * log10(powfund / (powharm + varnoise * (1 / fs)))
println("thSINAD = ", thSINAD)
thSINAD = 33.97939782477054

SINAD of the amplified signal

Details

Generate a sinusoid with frequency 2.5 kHz with sampling rate 50 kHz. Add Gaussian white noise with a standard deviation to the signal. 0.00005. Let’s pass the result through an amplifier with low nonlinearity. Let’s plot the SINAD graph.

import EngeeDSP.Functions: randn, polyval, sinad

fs = 5e4
f0 = 2.5e3
N = 1024
t = (0:N-1) / fs

ct = cos.(2π*f0*t)
cd_signal = ct + 0.00005 * randn(length(ct),1)

amp = [1e-5 5e-6 -1e-3 6e-5 1 25e-3]
sgn = polyval(amp, cd_signal)

sinad(sgn, fs, out=:plot)

sinad

The graph shows the spectrum used to calculate the ratio and the area considered as noise. The level of the constant component and the fundamental harmonic are excluded from the noise calculation. The main harmonic is marked.

Additional Info

Distortion measurement functions

Details

Functions sfdr, sinad and snr The response of a weakly linear system excited by a sine wave is measured.

When setting the input data in the time domain, the function sinad builds a periodogram using the Kaiser window with a large attenuation of the side lobes. To find the fundamental frequency, the algorithm searches the periodogram for the largest nonzero spectral component. Then it calculates the central moment of all neighboring intervals, monotonically decreasing with distance from the maximum. For detection, the main frequency must be at least in the second frequency range. The higher harmonics are at frequencies that are multiples of the fundamental frequency. If a harmonic is located in a monotonously decreasing region next to another one, 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 value in areas containing only noise and distortion. The constant component is excluded from the calculation. The noise at each point is determined by the calculated level or ordinate of the point, whichever is lower. The noise is then subtracted from the values of the signal and harmonics.

Function sinad It fails if the fundamental frequency is not the highest spectral component of the signal.

Make sure that the frequency components are sufficiently spaced to take into account the width of the side lobes of the Kaiser window. If this is not possible, you can use the flag "power" and calculate the periodogram with a different window.