Harmonic ratio

`hr = harmonicRatio(audioIn,fs)`

`hr = harmonicRatio(audioIn,fs,Name,Value)`

specifies options using one or more `hr`

= harmonicRatio(`audioIn`

,`fs`

,`Name,Value`

)`Name,Value`

pair arguments.

```
hr =
harmonicRatio(audioIn,fs,'Window',rectwin(round(fs*0.1)),'OverlapLength',round(fs*0.05))
```

returns the harmonic ratio for the audio input signal sampled at `fs`

Hz.
The harmonic ratio is calculated for 100 ms rectangular windows with 50 ms
overlap.The harmonic ratio is calculated as described in [1]. The following algorithm is applied independently to each window of audio data. The normalized autocorrelation of the signal is determined as:

$$\Gamma (m)=\frac{{\displaystyle \sum _{n=1}^{N}s\left(n\right)s\left(n-m\right)}}{\sqrt{{\displaystyle \sum _{n=1}^{N}s{\left(n\right)}^{2}}{\displaystyle \sum _{n=0}^{N}s{(n-m)}^{2}}}}\text{\hspace{0.17em}}\text{\hspace{0.17em}}\text{for}\text{\hspace{0.17em}}\left(1\le m\le M\right)$$

where

*s*is a single frame of audio data with*N*elements.*M*is the maximum lag in the calculation. The maximum lag is 40 ms, which corresponds to a minimum fundamental frequency of 25 Hz.

A first estimate of the harmonic ratio is determined as the maximum of the normalized autocorrelation, within a given range:

$$\beta HR=\begin{array}{c}\mathrm{max}\\ {M}_{0}\le m\le M\end{array}\left\{\Gamma (m)\right\}$$

where *M*_{0} is the lower edge of the
search range, determined as the first zero crossing of the normalized autocorrelation.

Finally, the harmonic ratio estimate is improved using parabolic interpolation, as described in [2].

[1] Kim, Hyoung-Gook, Nicholas Moreau,
and Thomas Sikora. *MPEG-7 Audio and Beyond: Audio Content Indexing and
Retrieval*. John Wiley & Sons, 2005.

[2] Quadratic Interpolation of Spectral Peaks. Accessed October 11, 2018. https://ccrma.stanford.edu/~jos/sasp/Quadratic_Interpolation_Spectral_Peaks.html