Professional Documents
Culture Documents
It is assumed that v(n), d(n), and e(n) may be directly measured, but s(n), h(n) and y(n) cannot.
As stated above, the goal of any adaptive noise-cancelling algorithm is to match the adaptive
filter, h'(n), to the actual impulse response of the system in question, h(n). If h'(n) is identical to
h(n), the output of the system, e(n) will simply be the desired signal, s(n).
Another way of stating this goal is that e(n) must be minimized. To understand why this is the
case, consider that,
d(n) = s(n) + y(n)
Eq. 1
therefore,
e(n) = s(n) + y(n) - y'(n)
Eq. 2
The closer that h'(n) matches h(n), the closer y'(n) matches y(n). If h'(n) = h(n), then y'(n) = y(n)
and equation 2 becomes e(n) = s(n), which is the desired signal.
There are multiple algorithms to implement adaptive noise cancelling filters, but the least mean
squares (LMS) method will be the focus of this report. Applications of adaptive noise
cancellation are often multi-dimensional, but for conceptual simplicity single-dimensional
cancellation is used in this report.
II. Applications
Example applications of adaptive filters for noise cancellation include a fighter pilot headset.
When a pilot's voice is picked up by a microphone, there may be additive noise that is caused by
cockpit noise being filtered through the pilot's helmet. The impulse response of the helmet may
not be known, and therefore adaptive filtering may be of use.
The desired signal plus filtered noise, d(n), can be picked up by the microphone inside the
helmet. The noise signal, v(n), may be obtained from a microphone inside the cockpit but
outside the helmet, and e(n) will be the output of the adaptive filter.
Another application of adaptive noise cancellation is in an auditorium. If the desired signal is the
voice of an orator, the orator's microphone may be used as d(n), while a microphone placed in a
different location in the auditorium may be v(n). The characteristics by which the auditorium
transmits unwanted noise to the microphone may change depending on the contents of the
auditorium, so adaptive filtering is a favorable solution.
= -2ejXj
an approximation of the gradient, the LMS algorithm will not perform as well when
implemented as it would in theory.
for n = 1:36000
%This if statement is included to make sure that the input is formatted
%appropriately for computational purposes. One step of the LMS
%algorithm involves the filter coefficient vector being multiplied by
%the input vector. Therefore the input vector must be equal to the
%size of the filter coefficient vector. If there have not yet been
%enough previous values to fill the input vector, it is padded with
%zeros
if n < p
input = [zeros(1,p-n),v(n:-1:1)];
else
input = v(n:-1:(n-p+1));
end
%The new output value, e(n) is calculated by applying the most recent
%iteration of the h'(n) filter to the system
e(n) = y(n) + s(n) - Hprime*(input.');
%The subsequent filter coefficients are calculated by adding the
%previous filter coefficients to the step size * the current error *
%the input to the system
Hprime = Hprime + 2*u*e(n)*input;
end
Eq. 6
The error signal e(n) was initialized to zero. The LMS simulation detailed above was then
executed.
The content of the onefive.wav file that was used for simulation can be seen below.
Signal Power
0.7
0.6
0.5
0.4
0.3
0.2
0.1
0
0.5
1.5
2
Sample #
2.5
3.5
4
4
x 10
Eq. 7
The graph below shows the Error2 of the adaptive filter output using an filter order of p=2.
Error w/ 2-pt IIR Filter, u = 0.01
0.7
0.6
0.5
Error2
0.4
0.3
0.2
0.1
0.5
1.5
2
Sample #
2.5
3.5
4
4
x 10
0.6
0.5
Error2
0.4
0.3
0.2
0.1
0.5
1.5
2
Sample #
2.5
3.5
4
4
x 10
1.2
Error2
0.8
0.6
0.4
0.2
0.5
1.5
2
Sample #
2.5
3.5
4
4
x 10
Error2
1.5
0.5
0.5
1.5
2
Sample #
2.5
3.5
4
4
x 10
0.6
0.5
Error2
0.4
0.3
0.2
0.1
0.5
1.5
2
Sample #
2.5
3.5
4
4
x 10
Finally, decreasing the step size even further to 0.001 yields a result with a very slow time of
convergence but a very small steady-state error.
Error w/ 5-pt IIR Filter, u = 0.001
0.7
0.6
0.5
Error2
0.4
0.3
0.2
0.1
0.5
1.5
2
Sample #
2.5
3.5
4
4
x 10
0.6
0.5
Error2
0.4
0.3
0.2
0.1
0.5
1.5
2
Sample #
2.5
3.5
4
4
x 10
Error2
0.25
0.2
0.15
0.1
0.05
0
0.5
1.5
2
Sample #
2.5
3.5
4
4
x 10
Figure 4 was generated with h'(n) trying to emulate an IIR filter defined by equation 7 detailed
previously. Figure 10 was generated using an FIR filter that has the same zeros, but has all of its
poles at 0. This filter is defined by
Eq. 10
It can be observed that the error with the FIR filter is less than half of the error with the IIR Filter
for most samples.
This effect is diminished, however, as the filter order increases. This is due to the fact that as
h'(n) increases in length, it becomes a better approximation of an IIR filter.
VIII. Conclusions
It has been shown that there is an ideal filter order for an LMS noise cancellation algorithm
implementation. A filter order that is too large may yield large errors at times when the signal
power increases rapidly but a filter order that is too small will have difficulty approximating a
long FIR filter or an IIR filter with acceptable error levels.
There is a tradeoff when selecting the step size of the algorithm between speed of convergence
and steady-state error. Additionally, a step size that is too large will cause the LMS algorithm to
become unstable altogether.
Finally, FIR systems are better approximated using an adaptive filter than IIR systems due to the
fact that adaptive filters must be FIR themselves.
IX. References
[1] Widrow, B., J. R. Glover, Jr., J. M. McCool, J. Kaunitz, C. S. Williams, R. H. Hearn, J. R.
Zeidler, Eugene Dong, Jr., and R. C. Goodlin. "Adaptive Noise Cancelling: Principles
and Applications." Proceedings of the IEEE63.12 (1975): 1692-716. IEEE Xplore. Web.
24 Feb. 2015.
[2] "Least Mean Squares Filter." Wikipedia. Wikimedia Foundation, n.d. Web. 04 May 2015.
[3] "Adaptive Filter." Wikipedia. Wikimedia Foundation, n.d. Web. 04 May 2015.
X. Appendices
Appendix 1: MatLab Code
%ECE 529 Semester Project: Adaptive Filtering for noise cancellation
%Read in the file to be used as s(n)
[s,fs,bits] = wavread('onefive.wav');
s = s.';
nmax = length(s)-1; % index for the last sample
%Plot the content of the signal
figure;
plot(s.^2);
title('onefive.wav Signal Content');
xlabel('Sample #');
ylabel('Signal Power');
%Create a vector with random numbers to be used for noise generation
w = rand(1,nmax+1);
%Pass the noise through a coloring filter that is described by
%H(z) = (1-c)/(1-cz^-1)
c = 0.3; %parameter for noise coloring
b = 1-c;
a = [1 -c];
v = filter(b,a,w);
%Take the colored noise and filter the noise signal through the
%transfer function H(z) = (z-0.7)(z-0.2)(z+0.5)/((z-0.3)(z+0.15)(z+0.75))
a = [1 0.6 -.1575 -.03375];
b = [1 -.4 -.31 .07];
y = filter(b,a,v);
%Create d(n) by adding the noise that has been filtered through H(z) to
%the desired signal s(n)
d = y + s;
%Create the adaptive filter array and step size
p = 20; %filter order
u = 0.01; %step size for the adaptive filter
Hprime = zeros(1,p);
%initialize the e output to zeros
e = zeros(1,36000);
%Run the LMS Algorithm for all samples
for n = 1:36000
%This if statement is included to make sure that the input is formatted
%appropriately for computational purposes. One step of the LMS
%algorithm involves the filter coefficient vector being multiplied by
%the input vector. Therefore the input vector must be equal to the
%size of the filter coefficient vector. If there have not yet been
%enough previous values to fill the input vector, it is padded with
%zeros
if n < p
input = [zeros(1,p-n),v(n:-1:1)];
else
input = v(n:-1:(n-p+1));
end
%The new output value, e(n) is calculated by applying the most recent
%iteration of the h'(n) filter to the system
e(n) = y(n) + s(n) - Hprime*(input.');
%The subsequent filter coefficients are calculated by adding the
%previous filter coefficients to the step size * the current error *
%the input to the system
Hprime = Hprime + 2*u*e(n)*input;
end
%Plot error results
figure
title('Error with various step sizes, 20-pt IIR Filter')
hold on;
error = e - s;
plot(error.^2)
title('Error w/ 20-pt IIR Filter, u = 0.01');
xlabel('Sample #');
ylabel('Error^2');