You are on page 1of 17

Project 1 ECE 516 Adaptive digital filter

Noise Cancellation Using a Wiener Filter


Gabriele De Matteis
UIN: 656460884
Equality of cross correlations
Being :
x (n)=d(n)+
1
(n)
Consider the cross-correlation between x and
2
, r
x ,
2
r
x ,
2
=E{x(n)
2
*
(nk )}
With the substitution of x :
r
x ,
2
=E{
[
d (n)+
1
(n)
]

2
*
(nk )}=E{d(n)
2
*
(nk )+
1
(n)
2
*
(nk )}
considering d and
2
uncorrelated
E {d(n)
2
*
(nk )}=0
then follows:
r
x ,
2
=E{
1
(n)
2
*
(nk )}=r

1,

2
From that we can estimate the coefficient of the filter using the following equation:
R

2
w=r

1,

2
=r
x ,
2
and so
R

2
w=r
x ,
2
Autocorrelation values
he autocorrelation is com!uted b" the equation:
r

2
(k )=E{
2
(n)
2
*
(nk )}
he #alues com!uted res!ect to the lag k are:
k r(k)
0 1,5185
1 -0,9128
2 0,5439
3 -0,3288
4 0,2014
5 -0,1276
6 0,0705
7 -0,0396
8 0,0258
9 -0,0165
10 0,0234
11 -0,0256
12 0,0084
13 -0,0130
14 0,0254
15 -0,0254
16 0,0420
17 -0,0487
18 0,0395
19 -0,0238
Cross-correlation values
he cross-correlation is com!uted b" the equation
r
x ,
2
=E{x(n)
2
*
(nk )}
he #alues com!uted res!ect to the lag k are:
k p(k)
0 0,6523
1 0,5202
2 0,4127
3 0,3275
4 0,2658
5 0,2058
6 0,1578
7 0,1284
8 0,1041
9 0,0819
10 0,0787
11 0,0508
12 0,0329
13 0,0174
14 0,0310
15 0,0136
16 0,0375
17 0,0055
18 0,0142
19 0,0110
Autocorrelation and Cross-correlation for filter of order M =1
Autocorrelation Matrix
For $ % 1 the autocorrelation matri& R is 1x1 dimension so :
Cross-correlation Vector
For $ % 1 the cross-correlation #ector P is 1x1 dimension so :
Filter coefficient
R = 1,5185
P = 0,6523
W = 0,4296
Filter output and desired signal for filter order M = 1:
Autocorrelation and Cross-correlation for filter of order M = 6
Autocorrelation Matrix
For $ % ' the autocorrelation matri& R is 6x6 dimension so :
Cross-correlation Vector
For $ % ' the cross-correlation #ector P is 6x1 dimension so :
Filter coefficient
R= 1,5185 -0,9128 0,5439 -0,3288 0,2014 -0,1276
-0,9128 1,5185 -0,9128 0,5439 -0,3288 0,2014
0,5439 -0,9128 1,5185 -0,9128 0,5439 -0,3288
-0,3288 0,5439 -0,9128 1,5185 -0,9128 0,5439
0,2014 -0,3288 0,5439 -0,9128 1,5185 -0,9128
-0,1276 0,2014 -0,3288 0,5439 -0,9128 1,5185
P= 0,6523
0,5202
0,4127
0,3275
0,2658
0,2058
W = 1,0021
1,4018
1,1217
0,8961
0,7139
0,3849
Filter output and desired signal for filter order M = 6:
Autocorrelation and Cross-correlation for filter of order M = 12
Autocorrelation Matrix
For $ % 12 the autocorrelation matri& R is 12x12 dimension so :
Cross-correlation Vector
For $ % 12 the cross-correlation #ector P is 12x1 dimension so :
Filter coefficient
P= 0,6523
0,5202
0,4127
0,3275
0,2658
0,2058
0,1578
0,1284
0,1041
0,0819
0,0787
0,0508
R = 1,5185 -0,9128 0,5439 -0,3288 0,2014 -0,1276 0,0705 -0,0396 0,0258 -0,0165 0,0234 -0,0256
-0,9128 1,5185 -0,9128 0,5439 -0,3288 0,2014 -0,1276 0,0705 -0,0396 0,0258 -0,0165 0,0234
0,5439 -0,9128 1,5185 -0,9128 0,5439 -0,3288 0,2014 -0,1276 0,0705 -0,0396 0,0258 -0,0165
-0,3288 0,5439 -0,9128 1,5185 -0,9128 0,5439 -0,3288 0,2014 -0,1276 0,0705 -0,0396 0,0258
0,2014 -0,3288 0,5439 -0,9128 1,5185 -0,9128 0,5439 -0,3288 0,2014 -0,1276 0,0705 -0,0396
-0,1276 0,2014 -0,3288 0,5439 -0,9128 1,5185 -0,9128 0,5439 -0,3288 0,2014 -0,1276 0,0705
0,0705 -0,1276 0,2014 -0,3288 0,5439 -0,9128 1,5185 -0,9128 0,5439 -0,3288 0,2014 -0,1276
-0,0396 0,0705 -0,1276 0,2014 -0,3288 0,5439 -0,9128 1,5185 -0,9128 0,5439 -0,3288 0,2014
0,0258 -0,0396 0,0705 -0,1276 0,2014 -0,3288 0,5439 -0,9128 1,5185 -0,9128 0,5439 -0,3288
-0,0165 0,0258 -0,0396 0,0705 -0,1276 0,2014 -0,3288 0,5439 -0,9128 1,5185 -0,9128 0,5439
0,0234 -0,0165 0,0258 -0,0396 0,0705 -0,1276 0,2014 -0,3288 0,5439 -0,9128 1,5185 -0,9128
-0,0256 0,0234 -0,0165 0,0258 -0,0396 0,0705 -0,1276 0,2014 -0,3288 0,5439 -0,9128 1,5185
W = 1,0035
1,4048
1,1251
0,9004
0,7201
0,5754
0,4581
0,3639
0,2894
0,2300
0,1821
0,0977
Filter output and desired signal for filter order M = 12:
Comments on filter output
(t is !ossible to notice b" the !lots in the !re#ious !ages, that increasing the order of the filter results a better
estimation of the noise
1
) We can see also that if we increase the order to $ % 1* the estimated signal is
#er" #er" close to the desired one:
(t is interesting that running man" time the code the !arameters of the filter changes each one it has been run)
+robabl" that could be due to the number of the sam!les) heoreticall" ha#ing infinite sam!les the
coefficients of the filter should con#erge to a finite #alue, but actuall" ha#ing a finite number of sam!les that
don,t ha!!en) hat,s due to the statistical function used li-e correlations that are com!uted in time . since the
signal is ergodic/ with a finite number of sam!les) 0emember that for a non ergodic signal is not !ossible to
com!ute the statistical function in time but we ha#e to do this with the ensemble)
What times of applications might benefit from use of noise cancellation?
What are the situations where the proposed noise cancellation algorithm
would not work well? What are some of the assumptions made for the
proposed noise cancellation implementation?
he a!!lications in which it is !ossible to a!!l" that filter could be related for e&am!le to the
communication area if a connection is interested b" some interferences those could be remo#ed, or for
e&am!le it could be a sensor to measure the noise in an area and use the filter to reco#er the original signal
that is affected b" disturbances related to the noise measured: for e&am!le if someone use a micro!hone to
communicate could be used another micro!hone with different !arameter of the first one to measure the
noise in the area and b" the filter reco#er the original signal)
1!!lications that could not ha#e benefits could be a!!lications in which two noise
1
and
2
are
uncorrelated one to each other or better in which the" are generated with different reali2ation of the white
noise)
For e&am!le that ha!!ens if
1
and
2
are generated using two different reali2ation of white noise for
$%12
We can also see what ha!!ens in case the noise !ro!agation de!ends a lot b" his !re#ious sam!les, so that if
t he !a r a me t e r s of t he !r o!a ga t i on a r e ne a r t he uni t "
1
(n)=0)3
1
(n1)+(n)

2
(n)=0)3
2
(n1)+(n) :
he assum!tions done are ob#iousl" that noise
2
and signal d are uncorrelated) Further more the
!rocesses has been considered wide sense stationar" and ergodic)
MATLAB code:
%-------------------------------Parameters--------------------------------%
N = 10000; % Samples number
N_pl = 200; % Samples to plot
Nk = 19; % Shift number
N_sk = 20; % Autocorrelation samples
R = zeros(N_sk); % Autocorrelation matrix
M = [1; % Filter order
6;
12];

% Reference signal d(n) parameters
Om_0 = 0.05*pi; % Pulsation for the generation of the refernce signal d(n)
sup = pi; % Upper bound for the interval in which is distributed
% the random variable
inf = -pi; % Lower bound
phi = inf + (sup-inf).*rand(1,1); % Random variable generate as uniformly
% distrubution whithin the interval (-
pi,pi)

% White noise v(n) parameters
mn = 0; % Mean
var = 1; % Variance
% Noise: propagation path 1
wn11 = 0.8; % v1(n) = wn11*v1(n-1) + v(n)
% Noise: propagation path 2
wn21 = -0.6; % v2(n) = wn21*v2(n-1) + v(n)

%--------------------------------Signals----------------------------------%
% Reference d(n)
for i = 1:N
d(i) = sin((i-1) * Om_0 + phi); % Reference signal
end
% White Noise v(n)
v = mn + sqrt(var).*randn(N,1);
% Sensor 1 noise v1(n) = wn11*v1(n-1) + v(n)
v1(1) = v(1); % First value has to be set since
% there are not previous value of
% v1 so v1(0) = v(0)
% MATLAB has not 0 index so it is
% necessary to star from 1
for i = 2:N
v1(i) = wn11*v1(i-1) + v(i);
end
% Sensor 2 noise v2(n) = wn21*v2(n-1) + v(n)
v2(1) = v(1);
for i = 2:N
v2(i) = wn21*v2(i-1) + v(i);
end
% x(n) = d(n) + v1(n)
x = d + v1;
%----------------------------------Plots----------------------------------%
% Plot of first 200 samples of x and d
figure(1);
plot((1:N_pl),x(1:N_pl));
hold on
plot((1:N_pl),d(1:N_pl),'r');
title (' x(n) d(n) vs n','FontSize', 20)
xlabel('n','FontSize', 14)
legend('x','d')
hold off
% Plot of first 200 samples of v2
figure(2);
plot((1:N_pl),v2(1:N_pl));
title (' v2(n) vs n','FontSize', 20)
xlabel('n','FontSize', 14)
ylabel('v2(n)','FontSize', 14)
%-----------------------------Autocorrelation-----------------------------%
for k = 0:Nk %Computation of v2 autocorrelation "r"
sum = 0;
for n = (Nk+1): N
sum = sum + v2(n)*v2(n-k);
end
r(k+1) = sum/(N-N_sk);
end
r = r';
r %Print out the autocorrelation vector

for i = 1:N_sk % Generating Autocorrelation Matrix "R"
for j = i:N_sk
R(i,j) = r(j-i+1);
R(j,i) = R(i,j);
end
end
R

%-----------------------------Cross-correlation---------------------------%
for k = 0:Nk % Generating the crosscorrellation
sum = 0; % vector "p" of v2 and x
for n = (Nk+1): N
sum = sum + v2(n-k)*x(n);
end
p(k+1) = sum/(N-N_sk);
end
p = p';
p
%------------------------------Coefficients-------------------------------%
% Computation of the Wiener Filter coefficients by the Wiener Hopf
% equations Wo = R^(-1) * P where Wo is the optimum filter coefficients
% vector, R autocorrelation matrix and P crosscorrelation vector.
% Being M the order of the filter, vectors and matrix dimension are:
% Wo = 1XM
% R = MxM
% P = 1xM
% In our case M store the dimensions of the filters, so the filter
% coefficients are computed for each M(i) dimension stored in M vector
for i = 1:length(M)
W(i,1:M(i)) = inv(R(1:M(i),1:M(i)))*p(1:M(i));
end
%--------------------------v1 estimation & Plot---------------------------%
% The estimation of the noise v1 has been computed using the filter
% coefficients having v2 has input. In that way the output is related to
% the input values and filter coefficients as follows:
% v1(n) = w1 * v2(n) + w2 * v2(n-2) + ... + wM * v2(n-M+1)
% To have this it has been used an if condition to study the case in which
% the past value does not exist yet (for the samples form 1 to M) and
% than the general case for the samples form M to N. To do the computation
% it has been used the vector scalar product between coefficients vector W
% and the reverse vector of v2 samples. The samples n = 1 -> M has been
% computed, changing the lenght of the vectors at each step then, reached
% the M dimension, the samples of v2 has been considered shifted in time.
for i = 1:length(M)
for n=1:N
if n<=M(i)
v1_es(i,n) =W(i,1:n)*(v2(n:-1:1))';
else
v1_es(i,n) =W(i,1:M(i))*(v2(n:-1:(n-(M(i)-1))))';
end
end

R(1:M(i),1:M(i)) % Print out of the value used for each
p(1:M(i)) % filter order
W(i,1:M(i))




e(i,1:N) = x - v1_es(i,:); % That represent the extimation of d
% computed as e = x - v1(estimated)
figure(i+2);

plot(1:N_pl,e(i,1:N_pl));
hold on
plot(1:N_pl,d(1:N_pl),'r');
legend('e(n)','d(n)');
lenght = num2str(M(i));
text = strcat('M=',lenght);
title (text,'FontSize', 20)
xlabel('n','FontSize', 14)
hold off
end

You might also like