I am trying to evaluate the performance of an AEC by comparing the i/p and output wav file. I want to calculate echo return loss enhancement to predict how much(db) echo has been attenuated but i am not sure what would be right approach for that or is it possible or not, can we calculate in python?


1 Answer 1


You could use cross correlation for this purpose. For an uncorrelated signal $x(t)$, $\textrm{corr}(x(t), x(t + \Delta t)) = c \delta(\Delta t)$, i.e. an delayed impulse. This can be expanded to comprise multiple echoed copies

$$ \textrm{corr}\left( \sum_{i=0}^{N} a_i x(t + \Delta t_i), \sum_{j=0}^{N} b_j x(t + \Delta t_j) \right) = c \sum_{i=0}^{N} \sum_{j=0}^{N} a_i b_j \delta(\Delta t_i - \Delta t_j) $$

I remember from highschool physics books that if a delay is less than a certain amount, associated with the low frequency human hear response, (say 0.1 second), then it is not echo, it is reverberation. More objectively we could say that the audio signal will have a cross correlation that vanishes for lags larger than $L_x$.

You can have a measurement of the echo energy by the sum of the cross correlation with lag longer than $N_e$ from the maximum correlation. The maximum correlation will also provide a reference for synchronization of the two audio signals.

Putting this together you end up with a code like this

def measure_echo(a1, a2 = None):
    corr = signal.correlate(a1, a2 if a2 is not None else a1)
    lags = signal.correlation_lags(len(sig), len(sig_noise))
    # find the peak correlation (synchronize the signals)
    center = np.argmax(np.abs(corr)) 
    return np.sum(np.abs(corr**2))/np.sum(np.abs(corr[center-Ne+1:center+Ne]))
  • $\begingroup$ thank you so much for your reply, but can you help me with how to get avg power of an audio signal ( wav file). $\endgroup$
    – twinkle
    May 26, 2021 at 16:04
  • $\begingroup$ You load it, e.g with wavfile.read, then compute np.mean(x**2). $\endgroup$
    – Bob
    May 27, 2021 at 8:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.