TRES CODE Project05 - 2up
TRES CODE Project05 - 2up
where the notation hi = h[i] is used for clarity. The desired output is
The Task: Simple Echo Cancellation
the known transmitted signal value x[n], so the error in the filter output
at this instant is e[n] = x[n] − x̂[n]. We want to choose the hi
The aim of this project is to investigate methods of restoring signals
parameters such that the error is minimised.
that are corrupted by one or more echos. Echos commonly occur over
communications channels such as telephone and ADSL lines. A The squared error is
reasonable model of the echo process in the time domain is N
X
2 2
e [n] = (x[n] − x̂[n]) = (x[n] − hi y[n − i])2 ,
y[n] = x[n] + a1 x[n − nd ] + a2 x[n − 2nd ], i=0
where nd is the echo delay, and a1 and a2 are reflection coefficients for which we can use to work out how hi should be changed to decrease the
the first and second echo. The echo process can be thought of in terms error. The derivative of the squared error with regard to the impulse
of a system function H(z) = Y (z)/X(z), and the task of echo response value hj is
cancellation is to find the inverse function G(z) = 1/H(z). If all the N
!
parameters in the expression above are known, then this inverse can be de2 [n] X
= −2 x[n] − hi y[n − i] y[n − j] = −2e[n]y[n − j].
found analytically. dhj i=0
1 2
If this derivative is positive, then it means that e2 [n] will become bigger % Plotting
if hj is increased. We can then decrease the error by reducing hj . ev = [ev abs(en)];
In general we fix a step size ∆, and for each sample instant we modify if rem(i,100)==0 % too slow to plot every iteration
each hj according to subplot(2,1,1); plot(h); title(’Impulse response’);
subplot(2,1,2); plot(ev); title(’|error|’);
hj ← hj + 2∆e[n]y[n − j]. pause(0.001);
This is the Least Mean Squares (LMS) algorithm. For sufficiently small end
∆ and enough training data, the values of hj will converge to the point end
where on average de2 [n]/dhj = 0 for each j (i.e. where the squared error
Copy it into a Matlab script, run it, and try to understand it.
is minimised).
Some basic code that uses the LMS algorithm to determine a filter for Approach
echo cancellation follows:
The aim of this project is to explore the problem of echo cancellation.
% Pseudorandom sequence for training The implementation of the LMS algorithm in the previous section can
d = 100; % echo delay serve as a starting point, but you can look at alternative methods
gsig = randn(16000,1); instead if you prefer.
x = gsig(d+1:end); % desired echo-free signal
Some possibilities are:
y = gsig(d+1:end) + 0.4*gsig(1:end-d); % signal with echo
• Do a theoretical analysis of echo cancellation for known delay and
% Train using LMS reflection parameters. I briefly discussed an example in class, which
M = 3*d; % FIR filter length can be elaborated upon. In the non-adaptive case one can derive
delta = 0.0001; % LMS training step size the inverse system analytically.
h = zeros(M,1); % Initial filter IR values • Explore the adaptation parameter and the effect it has on rate of
ev = []; convergence.
for i=M+1:length(x)
• Explore the effect of different echo delays on the cancellation
xn = x(i); % desired sample value
process. Since the length of the FIR filter used to cancel the echos
yn = y(i-M+1:i);
must be substantially longer than the echo delay, the number of
xnhat = h’*yn; % filter output value
filter weights that the LMS algorithm has to estimate increases with
en = xn - xnhat; % current error
increasing delay.
h = h + delta*yn*en; % update
• The LMS formulation does not make use of the knowledge that the
3 4
signal is corrupted by an echo. It should therefore be possible to use
the algorithm as provided for restoring arbitrary channel distortion,
as long as it is time invariant. You could explore alternative uses for
the cancellation system provided.
• The length of the impulse response required to cancel a long delay
is large, so the computational expense becomes high. You could
make the computation more manageable by implementing
overlap-add or overlap-save FFT-based convolution. Alternatively,
I’ve seen interesting subband approaches which I know little about.