Sunteți pe pagina 1din 13

Adaptive Noise filter

Using LMS algorithm

Submitted by
 Arpit singh(15bec0298)
 Anirudh Sharma(15bec0349)
 Sujeet kumar(15bec0772)
Acknowledgement
I am extremely grateful, Thanikaiselvan V sir for giving me this golden
Opportunity for doing my project on this topic.

It would not have been possible to carry out this event without the
guidance and encouragement of my college teacher and PHD student
. I express my sincere gratitude towards him.
I also thank one and all, who have been directly or indirectly, involved in
successful completion of this project.
Contents
1 Introduction
2 Abstract
3 Block diagram of adaptive filter
4 matlab codes
5 LMS algorithm
6 Matlab code for implementation of LMS algorithm
7 Matlab results and graph
8 Matlab code for demonstration of LMS algorithm
9 Simulation and graph
10 Example of noise cancellation using LMS algorithm
Introduction
Adaptive filtering involves the changing of filter parameters (coefficients)
over time, to adapt to changing signal characteristics. Over the past three
decades, digital signal processors have made great advances in increasing
speed and complexity, and reducing power consumption. As a result, real-time
adaptive filtering algorithms are quickly becoming practical and essential for
the future of communications, both wired and wireless.
Adaptive filters self learn. As the signal into the filter continues, the adaptive
filter coefficients adjust themselves to achieve the desired result, such as
identifying an unknown filter or canceling noise in the input signal.

Abstract
Adaptive filters play an important role in modern day signal processing with applications such
as noise cancellation, signal prediction, adaptive feedback cancellation and echo cancellation.
The adaptive filters used in our thesis, LMS (Least Mean Square) filter and NLMS (Normalized
Least Mean Square) filter, are the most widely used and simplest to implement. The application
we tested in our thesis is noise cancellation. A detail study of both filters is done by taking into
account different cases. Broadly test cases were divided into two categories of stationary signal
and non-stationary signal to observe performance against the type of signal involved. Noise
variance was another factor that was considered to learn its effect. Also parameters of adaptive
filter, such as step size and filter order, were varied to study their effect on performance of
adaptive filters. The results achieved through these test cases are discussed in detail and will
help in better understanding of adaptive filters with respect to signal type, noise variance and
filter parameters.
Block diagram of adaptive filter

Using an Adaptive Filter to Remove Noise from an


Unknown System
LMS ALGORITHM
The LMS algorithm can be differentiated from the steepest descent method by term stop
chiastic gradient for which deterministic gradient works usually in recursive computation of
filter for inputs is used which is having the noteworthy feature of simplicity for which it is made
standard over other linear adaptive filtering algorithms.
The LMS algorithm needs two fundamental process on the signal and it is of linear type of
adaptive algorithm .
1. An residue error can be predicted by comparing the output from the linear filtering
phenomena and (2)
Accordingly response to the input signal with the necessary response of the signal. Mainly
above two parts are from filtering process. 2. Estimated error mainly takes part in generation of
updating filter vector in the automatic adjustment of the parametric model.
LMS adaptive filter code for basic signal
close all;
clear all;

t=1:0.025:5;
desired=5*sin(2*3.*t);

noise=5*sin(2*50*3.*t);

refer=5*sin(2*50*3.*t+ 3/20);

primary= desired+noise;

subplot(4,1,1);
plot(t,desired);
ylabel('desired');

subplot(4,1,2);
plot(t,refer);
ylabel('refer');

subplot(4,1,3);
plot(t,primary);
ylabel('primary');

order=2;
mu=0.005;
n=length(primary)
delayed=zeros(1,order);
adap=zeros(1,order);
cancelled=zeros(1,n);

for k=1:n,
delayed(1)=refer(k);
y=delayed*adap';
cancelled(k)=primary(k)-y;
adap = adap + 2*mu*cancelled(k) .* delayed;
delayed(2:order)=delayed(1:order-1);
end

subplot(4,1,4);
plot(t,cancelled);
ylabel('cancelled');

Matlab graph
Matlab code for demonstration of LMS
algorithm
clear all
close all
hold off
sysorder = 5 ;
N=2000;
inp = randn(N,1);
n = randn(N,1);
[b,a] = butter(2,0.25);
Gz = tf(b,a,-1);
h= [0.0976;
0.2873;
0.3360;
0.2210;
0.0964;];
y = lsim(Gz,inp);
n = n * std(y)/(10*std(n));
d = y + n;
totallength=size(d,1);
N=60 ;
w = zeros ( sysorder , 1 ) ;
for n = sysorder : N
u = inp(n:-1:n-sysorder+1) ;
y(n)= w' * u;
e(n) = d(n) - y(n) ;
if n < 20
mu=0.32;
else
mu=0.15;
end
w = w + mu * u * e(n) ;
end
for n = N+1 : totallength
u = inp(n:-1:n-sysorder+1) ;
y(n) = w' * u ;
e(n) = d(n) - y(n) ;
end
hold on
plot(d)
plot(y,'r');
title('System output') ;
xlabel('Samples')
ylabel('True and estimated output')
figure
semilogy((abs(e))) ;
title('Error curve') ;
xlabel('Samples')
ylabel('Error value')
figure
plot(h, 'k+')
hold on
plot(w, 'r*')
legend('Actual weights','Estimated weights')
title('Comparison of the actual weights and the estimated weights') ;
axis([0 6 0.05 0.35])

EXPLANATION OF CODE:
STEP 1: we took channel system order.

Step2 : Then choose Number of system points.

Step3: Then we choosed a random signal and a function given in code This
function is submitted to make inverse Z-transform (Matlab central file
exchange)

Step 4: Then add some noise.

Step 5: Take 60 points for training

Step 6: then we begin algorithm according to equations and block


diagram.

Step7: selecting correct step size(mu) Start with big mu for speeding the
convergence then slow down to reach the correct weights.

Step8 : check of results by plotting each seperatly.

Matlab graphs
Error graph
APPLICATION OF MATLAB IN NOISE
CANCELLATION USING MATLAB AND LMS ALORITHM

MATLAB CODE
close all;
clear all;
clc;
t=1:0.025:5;
desired=wavread('C:\Users\Sujeet\Downloads\looperman-a-1042109-0006554-
srob1234-all-you-got-d (1).wav');
noise=wavread('C:\Users\Sujeet\Downloads\noisewav.wav');
figure(1);
subplot(2,1,1);
plot(desired);
xlabel('desired');
subplot(2,1,2);
plot(noise);
xlabel('noise');
refer=wavread('C:\Users\Sujeet\Downloads\noisewav.wav');
[y,Fs,nb]=wavread('C:\Users\Sujeet\Downloads\looperman-a-1042109-0006554-
srob1234-all-you-got-d (1).wav');
[z,Fs1,nb1]=wavread('C:\Users\Sujeet\Downloads\noisewav.wav');
% audioplayer(y,Fs,nb)
audioplayer(z,Fs1,nb1)
lenY=size(y,1);
lenZ=size(z,1);
len=max(lenY,lenZ);
S=zeros(len,size(y,2));
S(1:lenY,:)=y;
S(1:lenZ,:)=S(1:lenZ,:)+z;
maxvalue=max(abs(S(:)));
S=S/maxvalue;
%sound(S,Fs,nb)
primary=desired+noise;
figure(2);
plot(primary);
xlabel('primary');
order=2;
mu=0.005;
n=length(primary)
delayed=zeros(1,order);
adap=zeros(1,order);
cancelled=zeros(1,n);
for k=1:n,
delayed(1)=refer(k);
y=delayed*adap';
cancelled(k)=primary(k)-y;
adap = adap + 2*mu*cancelled(k) .* delayed;
delayed(2:order)=delayed(1:order-1);
end

figure(3);
plot(cancelled);
% sound(cancelled,Fs,nb);
ylabel('cancelled');

S-ar putea să vă placă și