snr {bspec}R Documentation

Compute the signal-to-noise ratio (SNR) of a signal

Description

Compute the SNR for a given signal and noise power spectral density.

Usage

snr(x, psd, two.sided = FALSE)

Arguments

x

the signal waveform, a time series (ts) object.

psd

the noise power spectral density. May be a vector of appropriate length (length(x)/2+1) or a function of frequency.

two.sided

a logical flag indicating whether the psd argument is to be interpreted as a one-sided or a two-sided spectrum.

Details

For a signal s(t), the complex-valued discrete Fourier transform s(f) is computed along the Fourier frequencies f[j]=j/(N*delta_t) | j=0,...,N/2+1, where N is the sample size, and delta_t is the sampling interval. The SNR, as a measure of "signal strength" relative to the noise, then is given by

rho=sqrt(sum(abs(s(f))^2 / ((N/(4*delta_t)) * S1(f))),

where S1(f) is the noise's one-sided power spectral density. For more on its interpretation, see e.g. Sec. II.C.4 in the reference below.

Value

The SNR rho.

Author(s)

Christian Roever, christian.roever@med.uni-goettingen.de

References

Roever, C. A Student-t based filter for robust signal detection. Physical Review D, 84(12):122004, 2011. See also arXiv preprint 1109.0442.

See Also

matchedfilter, studenttfilter

Examples

# sample size and sampling resolution:
N       <- 1000
deltaT  <- 0.001

# For the coloured noise, use some AR(1) process;
# AR noise process parameters:
sigmaAR <- 1.0
phiAR   <- 0.9

# generate non-white noise
# (autoregressive AR(1) low-frequency noise):
noiseSample <- rnorm(10*N)
for (i in 2:length(noiseSample))
  noiseSample[i] <- phiAR*noiseSample[i-1] + noiseSample[i]
noiseSample <- ts(noiseSample, deltat=deltaT)

# estimate the noise spectrum:
PSDestimate <- welchPSD(noiseSample, seglength=1,
                        windowingPsdCorrection=FALSE)

# generate a (sine-Gaussian) signal:
t0    <- 0.6
phase <- 1.0
t <- ts((0:(N-1))*deltaT, deltat=deltaT, start=0)
signal <- exp(-(t-t0)^2/(2*0.01^2)) * sin(2*pi*150*(t-t0)+phase)
plot(signal)

# compute the signal's SNR:
snr(signal, psd=PSDestimate$power)

[Package bspec version 1.5 Index]