# discussion lms algorithm echo cancellation

Status
Not open for further replies.

#### dervisakyuz

##### Junior Member level 2 pls dont recommend me "adaptive filter theory simon haykin" i have book but i cant do anything on matlab. i need helppppp

i add a lms for echo cancellation but how can enter the inputs(for example number of iterations,filter_size..) in order to find the outputs of function.Let us discuss and learn something on this algorithm.We can plot the output signals to see more effectively.

function [input_signal, error_signal, desired_signal, filter_output, impulse, filter_current, mse, db,db_avg]=LMS(filter_size, step_size, input_file, iterations)
% Function to perform the LMS algorithm on an input file.
% Inputs: Filter order, step size, input wav file, number of iterations.
% Outputs: Input signal, error estimation signal (echo cancelled), desired signal (echoed signal), adaptive filter output, real impulse response
% Estimation of impulse response, mean sqaure error, attenuation (dB), average attenuation.

% Create the impulse response for the desired signal
impulse=zeros(filter_size,1);
for (i=1:5)
impulse(((i-1)*filter_size/5)+1)=1/i;
end

% Convolve the impulse with the input signal to generate the desired signal
desired_signal = conv(input_signal, impulse);

% initialise adaptive filter impulse and input vector to zero vector of length specified at command line
filter_current = zeros(filter_size,1);
input_vector = zeros(filter_size, 1);

% Loop for number of iterations specified in command line.
for i=1:iterations
i
input_vector(1)=input_signal(i); % insert new sample at beginning of input vector.
filter_output(i)=dot(filter_current, input_vector); %Caluclate adaptive filter output
error= desired_signal(i)-filter_output(i) % Calculate estimation error
filter_current = filter_current + 2*step_size*error*input_vector; % Update filter taps by LMS recursion

% Shfit values ion vector along.
for j=filter_size:-1:2
input_vector(j)=input_vector(j-1);
end

error_signal(i)=error; % store estimation error
cost(i)=error*error; % calculate instantaneous cost sqaure error

if (i==1)
fc0=filter_current;
end
if (i==7500)
fc1=filter_current;
end
if (i==15000)
fc2=filter_current;
end
if (i==22500)
fc3=filter_current;
end
if (i==30000)
fc4=filter_current;
end
end

% Find moving average of error squared.
for i=1:iterations-100
mse(i)=mean(cost(i:i+100));

end

%find moving avarage of db attenuation (averaged to smooth output).
for i=1:iterations-2500
db(i)=-20*log10(mean(abs(desired_signal(i:i+2500)))'./mean(abs(error_signal(i:i+2500))));

end

%find total avarage db attenuation
db_avg=mean(db);

#### dervisakyuz

##### Junior Member level 2 no one dont care i think here

Status
Not open for further replies.