DSPRelated.com
Code

Full band Echo canceller

Senthilkumar December 28, 2011 Coded in Scilab

Full band echo canceller using Adaptive filer - scilab code

//Caption : FULL Band Echo Cnacellation using NLMS Adaptive Filter

clc;
//Reading a speech signal
[x,Fs,bits]=wavread("E:\4.wav");
order = 40;  // Adaptive filter order
x = x';
N = length(x);  //length of speech signal
//Delay introduced in echo path
delay = 100;   
//Echo at same speaker
xdelayed = zeros(1,N+delay);
for i = delay+1:N+delay
    xdelayed(i) = x(i-delay);
end
//Initialize the adaptive filter coefficients to zero
hcap = zeros(1,order);
//To avoid negative values generated during convolution
for i = 1:order-1
    xlms(i) = 0.0;
end
for i = order:N+order-1
    xlms(i) = x(i-order+1);
end
Power_X = pow_1(x,N);  //Average power of speech signal
//Calculation of step size of adaptive filter
delta = 1/(10*order*Power_X);
[x_out,Adapt_Filter_IR] = adapt_filt(xlms,xdelayed,hcap,delta,N,order)
figure(1)
subplot(3,1,1)
plot([1:N],x)
title('Speech Signal Generated by some Speaker A')
sound(x,Fs,16)
subplot(3,1,2)
plot([1:length(xdelayed)],xdelayed)
title('Echo signal of speaker A received by speaker A')
sound(xdelayed,Fs,16)
subplot(3,1,3)
plot([1:length(x_out)],x_out)
title('Echo signal at speaker A after using NLMS Adaptive filter Echo Canceller')
figure(2)
plot2d3('gnn',[1:length(Adapt_Filter_IR)],Adapt_Filter_IR)
title('Adaptive Filter (Echo Canceller) Impulse response')