clear,clc
m=8;%sensors
n=2;%sources
theta=[-10 20];%in angle
d=1/2;%1/2 lambada
N=500;%samples
L=100;%resolution in [-90'90']
%generate the source signals
s=2*round(rand(n,N))-1;
%generate the A matrix
A=exp(-j*2*pi*d*[0:m-1].'*sin(theta*pi/180));
%generate the noise component
e=0.1*(randn(m,N));
%generate the ULA data
Y=A*s+e;
%initialize weight matrix and associated parameters for RLS predictor
de=s(1,:);
w=zeros(m,1);
lambda=0.99;
delta=100;
P=1/delta*eye(m);
for k=1:N
v=P*Y(:,k);
u=1/lambda*v/(1+1/lambda*Y(:,k)'*v);
e(k)=de(k)-w'*Y(:,k);
w=w+u*conj(e(k));
P=1/lambda*(eye(m)-u*Y(:,k)')*P;
end
%beamforming using the RLS method
beam=zeros(1,L);
for i=1:L
a=exp(-j*2*pi*d*[0:m-1].'*sin(-pi/2+pi*(i-1)/L));
beam(i)=20*log10(abs(w'*a));
end
%plotting command followed
figure
angle=-90:180/L:(90-180/L);
plot(angle,beam);
xlabel('angle');
ylabel('幅度相应/dB');
grid
figure
for k=1:N
en(k)=abs(e(k));
end
plot(en);
xlabel('n');
ylabel('en');