# adaptive lms notch filter is IIR or FIR?

clear all

load data

Fs = 500;

N = 900;

i = [0 : N-1]';

xa(1:N)+5*sin(2*pi*50* i/Fs)+10*sin(2*pi*48* i/Fs);

u = sin(2*pi*50* i/Fs);

%adaptive filter architecture

L = 20;

step_size = 0.005;

w = zeros(1,L);

%run the adaptive filter

e(L) = x(L);

for k = L : N

regressor = flipud(u(k-L+ 1:k));

w = w + step_size * regressor' * e(k);

e(k+1) = x(k) - w * regressor;

end

%compute the spectrum of the initial signal and the filtered signal

f = [0 : Fs/N : Fs/2 - Fs/N]';

F = abs(fft(x));

E = abs(fft(e));

%plot

figure(1);

subplot(411) ;plot(x); title('initial signal');

subplot(412) ;plot(e(2:N+1)); title('initial signal after filtering');

subplot(413) ;plot(f,F( 1:length( f)));title( 'spectrum of initial signal');

subplot(414) ;plot(f,E( 1:length( f)));title( 'spectrum of initial signal after filtering');

figure(2);

plot(i/Fs,x,'b-',i/Fs,e(2:N+1),'r-')

the key to understanding this code, is first understanding the various signals that appear in it. First of all x is the initial signal containing a component of 50Hz which you want to remove by adaptive filtering. This signal will play the role of the desired signal. Since we want to remove the frequency component of 50Hz, the reference signal u must be a sinusoid of 50Hz. Now, the LMS adaptive filter will try to use the reference signal u and from it predict/estimate the desired signal x. So, the output of the adaptive filter, namely u*w, will be as close as possible to the desired signal x. But since u contains only one frequency, then the output of the adaptive filter will be an estimation of the corresponding frequency component in the desired signal, if such one exists. Consequently u*w will be an accurate approximation of the 50Hz component in x. Now, the error signal of the adaptive filter is simply e=x-u*w, but based on the above analysis e will be the initial signal with the 50Hz component removed! Now this process is an IIR process. One way to think of that is that the input to the overall system is x and the output is e. Hence the transfer function E(z)/D(z) should indicate whether the filtering is IIR or FIR. If you find this transfer function ("Fundamentals of Adaptive Filtering",Ali Sayed, problem 5.14/page 261), then this is a transfer function of an IIR notch filter! The derivation of the transfer function is somehow elaborate but you can try it anyway.

Manolis C. Tsakiris