From: Farha on
Hi,
The code i have attached is working properly but the problem is with system identification,my unknown plant values r not matchin with the weight vectors,problem is with adaptation,can any one help me,only 2 weights r matchin with unknown,not workin for 4 ,8..

close all;
clear all;
clc;
fm=input('enter the frequency');
fs=6*fm;
n=input('enter the input sequence number');
for i=1:n,
x(i)=sin(2*pi*i*fm/fs);
end
lx=length(x);
w=[.1 .1];% .1 .1]; %weight vector
M=length(w);
p1=[1 2];% 3 4]; %unknown plant weight
lp=length(p1);
N=2*M;
L=N-M+1;
NB=lx/M-1; %number of blocks
w1=[w,zeros(1,L-1)];
Wf=fft(w1,N);
b=(NB*L)+L;
for p=1:n
x2(p)=(x(p)*x(p))/2;
end;
x3=sum(x2);
x4=x3/n; %Power Calculation
u=0.1/((M)*(x4)); %power mu
if (b>lx)
P=b-lx;
x1=[x zeros(1,P)];
else
x1=x;
end
d1=conv(x,p1); %convolution of input with unknown plant
d=[d1 zeros(1,b-length(d1))]; %extended desired vector
x2=[zeros(1,M-1) x1(1:L)]; %padding M-1 zeros to input(overlap save method)
X=fft(x2,N); %Convert to Frequency domain
Y=X.*Wf; %Convolute
y=ifft(Y,N); %Convert Back to time domain
y1=y(M:N);
y2=y1;
for i=1:L,
e(i)=d(i)-y1(i);
end
e2=e; %Error Calculation
e1=[zeros(1,M-1) e];
Ef=fft(e1);
H = conj(X).*Ef; %Convolution of error with conjugate of X
h=ifft(H,N);
h1=[h(1:M) zeros(1,L-1)];
H1=fft(h1,N);
Wf= Wf+(2*(u/L)*H1); %Weight updation in frequency domain
for i=1:NB %Repeat the loop for complete number of Blocks
x2= x1(((i*L)-M+2):((i*L)+L));
X=fft(x2,N);
Y=X.*Wf;
y=ifft(Y, N);
y1=y(M:N);
y2=[y2 y1];
for j=1:L,
e(j)=d((i*L)+j)-y1(j);
end
e2=[e2 e];
e1=[zeros(1,M-1) e];
Ef=fft(e1);
H=conj(X).*Ef;
h=ifft(H,N);
h1=[h(1:M) zeros(1,L-1)];
H1=fft(h1,N);
Wf=Wf+(2*(u/L)*H1);
end
y2=y2(1:lx);
e2=e2(1:lx);
x1=x1(1:lx);
d=d(1:lx);
plot(y2);figure(1);
hold on
plot(e2,'r');
plot(d,'g');
figure(2)
title('FBLMS');xlabel('number of samples'); ylabel('magnitude');
subplot(4,1,1);plot(x1);xlabel('input samples');ylabel('magnitude');
subplot(4,1,2);plot(d,'g');xlabel('desired samples');ylabel('magnitude');
subplot(4,1,3); plot(e2,'m');xlabel('error');ylabel('magnitude');
subplot(4,1,4);plot(y2,'k');xlabel('output');ylabel('magnitude');