# True Peak detection

1. The signal is over-sampled to at least 192 kHz.
2. The over-sampled signal, a, passes through a low-pass filter with a half-poly-phase length of 12 and stop-band attenuation of 80 dB.
3. The filtered signal, b, is rectified and converted to the dBTP scale: c = 20×log10(∣b∣)
4. The true-peak is determined as the maximum of the converted signal, c.

My simple implementation:

f = "impulse_1.wav";
info = audioinfo (f);
p = 4;
q = 1;
Y = resample(X, p, q);
dBTP = 20 * log10( max(max(abs(Y))) );


results dBTP = 2.094 (for the file in code) which is close to the theoretical value (+2.098) mentioned on site where from the test audio file comes. For second test file there (impulse_2.wav) result is not as close to the theoretical value (+0.765) but shows +0.6662. Both measures seem to pass the error criteria TP standard gives (0.1dB).

I've read people use different types of interpolators and window functions in their implementations but, the results still have lots of variation as what this ISP/True Peak limiter test shows.

I did implement another test method by following instructions above:

p = 4;
Y1 = zeros(1, length(X)*p);
for i = (1:length(X))
Y1(i*p-(p-1))= X(i);
endfor

b = designMultirateFIR(p,1);
% b = designMultirateFIR(p,1,0.01,80)
Y1 = filter(b,1,Y1);

for i = 1:length(Y1)
m = 20*log10(abs(Y1(i)));
if m > max_tp
max_tp = m;
endif
endfor
max_tp


and ran the same test (but using various up-sampling factors) with results:

>> [dBTP, max_tp] = max_true_peak(2)
dBTP = 2.0940
max_tp = 2.0429
>> [dBTP, max_tp] = max_true_peak(3)
dBTP = 1.8681
max_tp = 1.8228
>> [dBTP, max_tp] = max_true_peak(4)
dBTP = 2.0940
max_tp = 2.0429
>> [dBTP, max_tp] = max_true_peak(5)
dBTP = 2.0129
max_tp = 1.9638
>> [dBTP, max_tp] = max_true_peak(6)
dBTP = 2.0940
max_tp = 2.0429
>> [dBTP, max_tp] = max_true_peak(7)
dBTP = 2.0526
max_tp = 2.0025
>> [dBTP, max_tp] = max_true_peak(8)
dBTP = 2.0940
max_tp = 2.0429


dBTP results got from 1st implementation.

It seems like the test files are working correctly for those even oversampling ratios only. I tried many parameters for low-pass implementation and found out that low-pass implementation effects the results quite a bit as well.

Now, my questions regarding those parts I don't understand. If I want to use interpolation and/or windowing to get the peak values ... .

1. is interpolation done in resampling process or after that (where exactly) ? Actually, I made another implementation where resampled data was interpolated using cubic spline interpolation to find the TP and it seemed to work otherwise but was really (too) slow operation.
2. if I want to try n tap FIR interpolator with x window over-sampled p times ... what does that actually mean (my initial guess: oversample using FIR interpolator, feed the result through window function)?
3. which windowing method would suite best in this task (TP measuring)
4. as metering should be fast (on-line processing), which oversampling and interpolation methods are best suitable
• How did you create the reference files and determined their "theoretical" peak amplitude? Sep 5, 2022 at 12:06
• @Jazzmaniac: that's in the "test audio file" link the OP included. This looks fine to me Sep 5, 2022 at 12:26

Is interpolation done in resampling process or after that (where exactly) ? Actually, I made another implementation where resampled data was interpolated using cubic spline interpolation to find the TP and it seemed to work otherwise but was really (too) slow operation.

It's just up-sampling, not full resampling. To up-sample by a factor of $$N$$, you insert $$N-1$$ zeros between the existing samples and than apply a low-pass filter (which does the actual interpolation). Splines can work here, but it really depends on the type of spline. For example pchip() would not work at all.

if I want to try n tap FIR interpolator with x window over-sampled p times ... what does that actually mean (my initial guess: oversample using FIR interpolator, feed the result through window function)?

This has nothing to do with windowing. You should NOT window the data in any shape or form. It's just over-sampling: insert zeros and low-pass filter.

which windowing method would suite best in this task (TP measuring)

None whatsoever.

as metering should be fast (on-line processing), which oversampling and interpolation methods are best suitable

The test signal that you have is really a pathological case with no real world significance. For most "normal signals" the variability will be a lot less. A more realistic worse case is a sine wave of $$f_s/4$$ where $$f_s$$ is the sample rate. Depending on the phase the true peak can be up $$\sqrt{2}$$ higher than the max digital amplitude. Oversampling by a factor of 2 reduces this to $$1.08$$ and oversampling by 4 reduces it to $$1.02$$. That's plenty.

As always your "best" choice will depend on the specific requirements and constraints of your application but oversampling by two with a moderate half-band filter will do a good job in most cases and be VERY fast and efficient. Oversampling by 4 and using two cascaded half-band filters will give excellent results at a moderate cost. Both implementations will benefit from adding about $$0.5dB$$ of margin and extra headroom.

• sorry the mix-up with terms (I had it in my head b/c of the Octave function name). My 2nd implementation is up-sampling as you describe. Yes, test signals are not the best ones but it is hard to find ones Octave audioread() accepts and ones I found came without calculations of theoretical results (if I had some higher math skills I could prepare more test cases with theoretical peak data calculated (based on calculations on vladgsound's site...)). Sep 6, 2022 at 5:49