On the amateur radio HF bands, operators need to tune their high power amplifiers that use vacuum tubes. The final impedance matching network needs to be retuned everytime the frequency of operation is changed by more than about 100 KHz. When an operator tunes his amplifier, the signal sounds like a sinewave at a frequency determined by the transmitter being tuned. Normally operators listen to make sure nobody is using the frequency before tuning up, but the way the ionesphere works, you often cannot hear an operator between 100 and maybe 500 miles away, because his signals bounce over you. This causes a rather frequent problem. You will be listening to a friend, and all of a subben a sinewave is drowning him out.

This demo shows how an adaptive LMS filter can be used to solve the problem.

In [1]:

```
% Demonstration of LMS algorithm for noise cancellation. Tuner upper problem.
% Rich Kozick, Spring 1997
% Rob Frohne's modifications for Macintosh 2000
% and Linux 2006 or so.
pkg load signal
clear all
mu = 0.1;
Fs=8000; % 8 Khz sampling for Linux.
T0 = 2; % 2 seconds
system("espeak 'Speak the signal.'");
st = record(T0,Fs);
%st=audioread('Hello.wav');
st=st(:,1);
system("espeak 'Here is the signal.'")
soundsc(st);
Ls = length(st);
T0=length(st)/Fs;
% Make the tuner upper noise or even several at the same time.
t=0:1/Fs:T0-1/Fs;
n = 5*(sin(2*pi*100*pi*t) + 5*cos(2*pi*600*t) + 4*sin(2*pi*850*t));
% Add him or them to the desired signal.
x = st' + n;
system("espeak 'Here is the noisy signal.'")
soundsc(x,Fs);
N = 64; % Length of adaptive filter
% LMS algorithm for adaptive noise cancellation
h = ones(N,1);
for k=N:Ls
xk = x(k:-1:(k-N+1));
y(k) = h'*xk';
e(k) = y(k);
h = h - 2*mu*e(k)*xk'/(xk*xk');
end
% The signal estimate is in the vector e
system("espeak 'Here is a scaled version of the tail of the cleaned signal.'");
skip =1000;
soundsc(e(skip:length(e)),Fs);
```

In [ ]:

```
```