# Echo cancelling using autocorrelation function

I was given a problem, but I couldn't solve. I did some researches but I still didn't figure it out. Here is the problem:

An audio signal $s(t)$ is generated by a speaker reflects in a wall with reflection coefficient $\mu (\mu < 1)$. The signal $x(t)$ is recorded by a microphone close to the speaker and far from the wall, after sampled, is given by:

$x(t) = s(t) + \mu s(t - k)$

Where $k$ is the delay given in samples due to the echo.

So, my goal here is to estimate $\mu$ and $k$, observing the autocorrelation function of $x(t)$, $r_{xx}(l)$, that can be writen in function of the autocorrelation function of $s(t)$, $r_{ss}(l)$. I was able to compute this autocorrelation function and I got:

$r_{xx}(l) = (1 + \mu^{2})r_{ss}(l) + \mu r_{ss}(l-k) + \mu r_{ss}(l+k)$

So, it obvious has three peaks: when $l = 0$, when $l = k$ and when $l = -k$.

Assuming that $r_{ss}(l) = 0$ for $|l| > k/10$, I think that I can obtain the value of k observing the side peaks, and the value of $\mu$ observing the central peak, but i wasn't able to formalize it mathematically. Could anyone help me to do so?

Haven't you already got it there?

$$\hat{k} = \arg \max_{l > \frac{k}{10}} r_{xx}(l)$$ and $$\hat{\mu} = \sqrt{\frac{r_{xx}(0) }{ r_{ss}(0) } - 1}$$

The R code below outputs the figure and:

"k Estimate: 613 vs 613 mu Estimate : 0.747619585689531 vs 0.768768"

R Code

# 26617

T <- 10000
mu <- 0.768768
k <- 613

s <- filter(runif(T,-1,1), rep(10/k,k/10), circular = TRUE)

x <- s + mu*c(rep(0,k),s[1:(T-k)])

par(mfrow=c(2,1))
r_xx = acf(x, lag.max=1000, type="covariance")

min_idx <- floor(k/10)
mx <- which.max(r_xx$acf[(min_idx+1):10000]) khat <- min_idx+mx-1 # R indices start from 1, not 0 points(min_idx+mx,r_xx$acf[khat], col="red", pch=19)

r_ss = acf(s, lag.max=1000, type="covariance")

muhat <- sqrt( r_xx$acf[1] / r_ss$acf[1] - 1 )
print(paste("k Estimate:" , khat, " vs " , k, " mu Estimate : ", muhat, " vs ", mu ))

• Thanks a lot! I didn't know how to write the estimation o k formally. Of u I was able to get that expression, but I was not really sure if it was right. I really appreciate your help. – JohnMarvin Oct 23 '15 at 17:53
• @JohnMarvin You're welcome! – Peter K. Oct 23 '15 at 18:31