import pyfar as pf
import numpy as np
n_samples = 64
delays = np.array([14, 22, 26, 30, 33])
amplitudes = np.array([-35, -22, -6, 0, -9], dtype=float)
ir = pf.signals.impulse(n_samples, delays, 10**(amplitudes/20))
ir.time = np.sum(ir.time, axis=0)
start_sample_est = pf.dsp.find_impulse_response_start(
    ir, threshold=20)
ax = pf.plot.time(
    ir, dB=True, unit='samples',
    label=f'peak samples: {delays}')
ax.axvline(
    start_sample_est, linestyle='-.', color='k',
    label=f'ir start sample: {start_sample_est}')
ax.axhline(
    20*np.log10(np.max(np.abs(ir.time)))-20,
    color='k', linestyle=':', label='threshold')
ax.legend()
