# Finding maximum of sinc in 0..1

Started by September 5, 2017
```Hi folks,

the audio world is sort of obsessed with sort of "true peak level".
Unfortunately it is rather tricky to calculate, so it is calculated by
that's really not true peak level.

So how about the (nearly) correct value - if we take say 2 * N + 1 samples
around each sample S[0] (hence S[-N] .. S[N]), we can calculate any value
between S[0] and S[1] using sinc interpolation. All we need to do is to
calculate the maximum between these 2 samples.

Has anyone attempted to do it analytically (hence hopefully efficiently)?
I started messing with it and the derivatives (for the classic f' == 0)
are just way too ugly. Numeric approach could work, but the accuracy would
be lower again and it could take way too much CPU power.
---------------------------------------
Posted through http://www.DSPRelated.com
```
```On Tuesday, September 5, 2017 at 12:12:44 PM UTC-7, jungledmnc wrote:
> Hi folks,
>
> the audio world is sort of obsessed with sort of "true peak level".
> Unfortunately it is rather tricky to calculate, so it is calculated by
> oversampling to about 192kHz and taking the normal peak level. Sadly
> that's really not true peak level.
>
> So how about the (nearly) correct value - if we take say 2 * N + 1 samples
> around each sample S[0] (hence S[-N] .. S[N]), we can calculate any value
> between S[0] and S[1] using sinc interpolation. All we need to do is to
> calculate the maximum between these 2 samples.
>
> Has anyone attempted to do it analytically (hence hopefully efficiently)?
> I started messing with it and the derivatives (for the classic f' == 0)
> are just way too ugly. Numeric approach could work, but the accuracy would
> be lower again and it could take way too much CPU power.
> ---------------------------------------
> Posted through http://www.DSPRelated.com

It should be close enough to a parabola over a small region around the peak.
```
```On 2017-09-06, herrmannsfeldt@gmail.com <herrmannsfeldt@gmail.com> wrote:
> On Tuesday, September 5, 2017 at 12:12:44 PM UTC-7, jungledmnc wrote:
>> Hi folks,
>>
>> the audio world is sort of obsessed with sort of "true peak level".
>> Unfortunately it is rather tricky to calculate, so it is calculated by
>> oversampling to about 192kHz and taking the normal peak level. Sadly
>> that's really not true peak level.
>>
>> So how about the (nearly) correct value - if we take say 2 * N + 1 samples
>> around each sample S[0] (hence S[-N] .. S[N]), we can calculate any value
>> between S[0] and S[1] using sinc interpolation. All we need to do is to
>> calculate the maximum between these 2 samples.
>>
>> Has anyone attempted to do it analytically (hence hopefully efficiently)?
>> I started messing with it and the derivatives (for the classic f' == 0)
>> are just way too ugly. Numeric approach could work, but the accuracy would
>> be lower again and it could take way too much CPU power.
>> ---------------------------------------
>> Posted through http://www.DSPRelated.com
>
> It should be close enough to a parabola over a small region around the peak.

Nowhere near good enough. These are golden-eared audiophiles we're
talking about, the ones who can hear the difference between using
any old power cord for their amplifier and the ones costing \$10k
plus. I'm not joking (about the price).
```
```On Tuesday, September 5, 2017 at 8:20:59 PM UTC-5, Fred Smith wrote:

> Nowhere near good enough. These are golden-eared audiophiles we're
> talking about, the ones who can hear the difference between using
> any old power cord for their amplifier and the ones costing \$10k
> plus. I'm not joking (about the price).

First of all, what is the *true* value? You can say that the peak value of the source analog waveform is the true value, but as soon as you introduce an antialiasing filter (nowadays antialiasing filters generally have few, if any, analog components) that is no longer true. Sinc interpolation will give the optimum band-limited estimate, assuming that the passband is rectangular. But it's never actually rectangular. Oversampling and interpolating make their own similar assumptions. How can you know which one is closest to the *true* value when you don't know what the true value is?

Which brings me to the second point: all signals are noisy. You can only determine the actual peak value to within a tolerance dictated by the noise in its vicinity.

I have implemented 2nd-order and 4th-order parabolic estimators to find peak intersample values, and they are quite close to the full-on sinc estimation. Close enough? That's a judgment call. https://dspguru.com/dsp/howtos/how-to-interpolate-fft-peak/

```
```Well, I assume the oversampling filters used by any device afterwards
(D/A, lossy compression, which would cause some additional problems
though...) will be linear-phase (otherwise one can make no assumptions
after all).

If that would be true, resampling to any sampling rate would pick up
various points of the "virtual analog" waveform defined by the actual
samples S[i]. If we can find the actual maximum of this virtual analog
waveform, then no oversample can ever peak over 0dBFS.

The point of this true peak thingy is that the D/A is oversampling
internally, so in theory even if your waveform doesn't get over 0dBFS, the
oversampled waveform could. But since it is measured by oversampling to
192kHz, it only improves the estimate, but it doesn't really say the
correct value.

Additionally if we could measure the value accurately, we could use it for
actual true-peak limiting (as opposed to what true-peak limiting means now
- just oversampled limiting...).
---------------------------------------
Posted through http://www.DSPRelated.com
```
```I forgot - parabolic estimation may get you something, but these are not
fft bins, I don't think it would work close enough at all. One would need
to use like 30 samples (my guess from sinc coefficient tables I'm using
for actual interpolation).
---------------------------------------
Posted through http://www.DSPRelated.com
```
```On Wednesday, September 6, 2017 at 7:21:29 AM UTC-5, jungledmnc wrote:

> Well, I assume the oversampling filters used by any device afterwards
> (D/A, lossy compression, which would cause some additional problems
> though...) will be linear-phase (otherwise one can make no assumptions
> after all).

Linear phase is not enough to guarantee that the interpolated peak will resemble the actual peak. Filter impulse responses overshoot and ring.

```
```On Wednesday, September 6, 2017 at 7:24:37 AM UTC-5, jungledmnc wrote:

> I forgot - parabolic estimation may get you something, but these are not
> fft bins,

No, but the principle is the same. Duality applies.
```
```>On Wednesday, September 6, 2017 at 7:24:37 AM UTC-5, jungledmnc wrote:
>
>> I forgot - parabolic estimation may get you something, but these are
not
>> fft bins,
>
>No, but the principle is the same. Duality applies.

Could you be more specific about the "duality"? I may be missing some part
of information here.

As for linear-phase - if we assume there won't be any filtering (the
oversampling itself isn't filtering as it doesn't change the spectrum
content), then if we find the actual true peaks, then this should be the
real maximum for any oversampling rate imho and no overshoots can happen.
---------------------------------------
Posted through http://www.DSPRelated.com
```
```On Wednesday, September 6, 2017 at 12:12:25 PM UTC-5, jungledmnc wrote:

> Could you be more specific about the "duality"? I may be missing some part
> of information here.

You can interpolate between FFT bins or you can interpolate between samples. The mathematics are the same, only the domain changes.

> As for linear-phase - if we assume there won't be any filtering (the
> oversampling itself isn't filtering as it doesn't change the spectrum
> content), then if we find the actual true peaks, then this should be the
> real maximum for any oversampling rate imho and no overshoots can happen.

If you don't filter then your inserted samples are all zero-valued. That interpolation will be the same as if you didn't upsample at all.
```