View source: R/spectralDescr.R
| getHNR | R Documentation |
Calculates the harmonics-to-noise ratio (HNR), that is, the ratio of the
intensity of the harmonic component to the intensity of the noise
component, following Boersma (1993). Normally called internally by
analyze, but can also be called directly on a time series.
getHNR(
x = NULL,
samplingRate = NA,
acf_x = NULL,
lag_min = 2,
lag_max = NULL,
interpol = c("sinc", "spline", "parab", "none"),
wn = "hanning",
idx_max = NULL,
win_sinc = NULL
)
x |
a numeric vector (time series). Provide either |
samplingRate |
sampling rate, Hz |
acf_x |
pre-computed normalized autocorrelation of |
lag_min, lag_max |
minimum and maximum lag (in samples) to search
for the ACF peak. Defaults: |
interpol |
method of refining the peak location: |
wn |
window function applied to |
idx_max |
(internal) the lag of the ACF peak, if already known. Skips the peak search. |
win_sinc |
(internal) a pre-computed window of length
|
A list:
frequency (Hz) corresponding to the ACF peak
height of the ACF peak, 0 to 1
harmonics-to-noise ratio in dB:
10 * log10(max_acf / (1 - max_acf))
Boersma, P. (1993). Accurate short-term analysis of the fundamental frequency and the harmonics-to-noise ratio of a sampled sound. In Proceedings of the Institute of Phonetic Sciences (Vol. 17, No. 1193, pp. 97–110).
signal = sin(2 * pi * 150 * (1:16000) / 16000)
signal = signal / sqrt(mean(signal ^ 2))
noise = rnorm(16000)
noise = noise / sqrt(mean(noise ^ 2))
SNR = 40 # ground truth
s = signal + noise * 10 ^ (-SNR / 20)
soundgen:::getHNR(s, 16000, lag_min = 16000 / 1000,
lag_max = 16000 / 75, interpol = 'none')
soundgen:::getHNR(s, 16000, lag_min = 16000 / 1000,
lag_max = 16000 / 75, interpol = 'sinc')
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.