clear all;
%samples=1500;
hfile='song2.wav';
sizeinfo = wavread(hfile, 'size');
samples = sizeinfo(1);
mu3=.8; %NLMS ALGORITHM
mse3=0;
factor=.001;
sigma2n=.01;
W=2.5;
for k=1:3;
h(k)=1/2*(1+cos(2*pi*(k-2)/W));
end
taps = 11; %Adaptive Filter Taps #
w3 = zeros(1,taps);%state of adaptive filter
D=7;
max_iterations = samples;
signal=sign(randn(1,samples));
desired=[zeros(1,D) signal];
noise=sqrt(sigma2n)*randn(1,samples);%noise added to signal
refsignal=filter(h,1,signal)+noise;
%NLMS
x=zeros(1,taps);
for i=1:max_iterations;
x=[x(2:taps) refsignal(i)];
y3(i)=w3*x';
norm=x*x';
e3(i)=desired(i)-y3(i);
w3 = w3+ mu3/(norm+factor)*e3(i)*x;
end
figure()
plot(signal)
xlabel('Number of Iterations ')
ylabel('Amplitude')
title('Input Signal')
grid on
figure()
stem(h)
xlabel('Number of Iterations ')
ylabel('Amplitude')
title('Channel Impulse Response')
grid on
figure()
plot(desired)
xlabel('Number of Iterations ')
ylabel('Amplitude')
title('Desired Signal')
grid on
figure()
plot(e3)
xlabel('Number of Iterations')
ylabel('Amplitude')
title('Estimation Error of NLMS Algorithm')
grid on