# What are some really accurate ways to get the value of a peak (local maximum) given some points around it? (To be used for autocorrelation peaks.)

I have looked everywhere on the internet for this and, surprisingly, haven't found much useful information.

Given 3 or more points closest to a peak (local maximum) what are some of the most accurate techniques I can use to obtain the value of the peak. In fact, I would like the x axis coordinate of that peak to determine the exact peak locations of the autocorrelation function of a discrete signal.

The best I have been able to do is quadratic interpolation which fits a parabola between three points and finds the maximum as follows:

$$\begin{equation} x = \frac{1}{2} \frac{\alpha - \gamma}{\alpha - 2\beta + \gamma} \end{equation}$$

Equation obtained here.

I tried cubic interpolation but either I'm doing it wrong or it's just not more accurate than the quadratic interpolation.

Anyway, can I not get better accuracy than quadratic interpolation? I would appreciate even just the names of algorithms or links to resources I can look at. (PS: I have way more than just three points close to the true peak).

Edit:

I'm not sure about the exact model of the peak, but it's one obtained when you do the autocorrelation of a sinusoid. To be more specific, I would like to use autocorrelation to determine, as accurately as possible, the exact fundamental frequency of an electrical grid.

• that fully depends on your mathematical model of your peak; for example, a quadratic function around the peak in $x_0$, e.g. $f(x)-(x-x_0)^2$ would clearly fit well with quadratic interpolation; a $f(x)=-(x-x_0)^4$ less so, and a $f(x)=e^{(x-x_0)^2}$ not at all. You need a mathematical model of your function, or no statement can be made at all. The only thing that indicates a model so far is you saying "discrete signal", so I'll assume the signal is band-limited. But then there's nothing special about there being a peak between two samples at all: classical discrete signal theory applies: – Marcus Müller Jan 20 at 14:59
• use sinc interpolation to get the continuous-time waveform. Then, use as much precision approximating the position of the sinc series's local maximum. – Marcus Müller Jan 20 at 15:03
• Thanks for the response. I'm not too sure about the model of the peak, but it's one obtained when you do the autocorrelation of a sinusoid. To be more specific, I would like to use autocorrelation to determine, as accurately as possible, the exact fundamental frequency of an electrical grid. – Thomas Gwasira Jan 20 at 16:01

Assuming the autocorrelation of a sufficiently long piece of sinusoidal signal has a good SNR (which it probably will), yes, that quadratic interpolation is quite good, as the sinc (which is actually the interpolating function) is locally quite close to the shape of 1-x². I've done similar things to estimate locations from signal crosscorrelations.

It gets problematic when the noise in your sines is high, or when you try to achieve a resolution much smaller than the sample distance (as the sinc gets quite "flat" when you zoom into it around 0 – and thus, the smallest bit of numerical error or noise leads to a large mistake).

Often, people are pretty happy after sinc-interpolating their signals, and it's not a very computationally hard thing to do:

1. Take your signal, as is
2. DFT it (using the FFT of signal length)
3. add plenty of zeros to the DFT's end (e.g. to pad it to the next larger power of 2, which increases the length by some factor $$\alpha$$ of your choie)
4. take the inverse DFT (using the IFFT)
5. Do your crosscorrelation, without interpolating

Tadah, $$\alpha$$-increased resolution.

This isn't great in terms of estimation variance (Fisher information didn't change, since the signal energy stays the same).

Since you know you're dealing with a dominant sine, a parametric spectral estimator would perform well. For a line spectrum ESPRIT is an appropriate choice, but autoregressive models lead to other good approaches like Yule-Walker, etc. If you're working in a framework that can offer ESPRIT, I'd honestly try it.

• Thanks so much for this Marcus! This is really helpful. Just to follow up, is the shape of the waveform going to be a sinc? I still can't figure it out, it looks a lot like a modulated cosine when I did it in python as well as from this (Ctrl+F 'cosine'): sfprime.net/lls/pcs.htm So, I was now just trying to figure out what the underlying cosine function is and what the modulating function is (or if there's a way to remove the modulation). I'm just fresh out of varsity so I'm pretty much feeling my way through the darkness and have no clue what I'm doing. – Thomas Gwasira Jan 20 at 17:51
• I will definitely give sinc interpolation a go right now, but one of my worries is speed as well as whether going backward and forwards between the time and frequency domain would cause any new errors. – Thomas Gwasira Jan 20 at 17:53
• that going back and forth is really just interpolation. You don't lose any signal energy you had before. If your SNR is bad enough, spreading out the signal energy can actually lead to slightly increased estimator variance, especially in correlated noise, but I don't see how anything would go wrong here. Remember: any interpolation takes noisy values and guesses what happens inbetween; the sinc interpolation I described is optimal in terms of using every single sample to make the interpolation more reasonable (as opposed to, say, just the two neighboring samples), which reduces noise Var! – Marcus Müller Jan 20 at 18:00