clear all;
close all;
N=16;
d_lamda=0.5;
theta0=0;
thetaj=-3;
thetaj1=-3;
thetaj2=-25;
thetaj3=35;
theta=-90:1:90;
SNR=10;
JNR1=5;
JNR2=30;
JNR3=40;
Ns=100;
%nj=length(thetaj);
nj=1;
j=sqrt(-1);
as0=exp(j*2*pi*d_lamda*[0:N-1-1]'*sin(theta0*pi/180));
noise=0.707*(randn(N,Ns)+1i*randn(N,Ns));
amp_j1=10^(JNR1/20)*0.707*(randn(nj,Ns)+1i*randn(nj,Ns));
amp_j2=10^(JNR2/20)*0.707*(randn(nj,Ns)+1i*randn(nj,Ns));
amp_j3=10^(JNR3/20)*0.707*(randn(nj,Ns)+1i*randn(nj,Ns));
aj1=exp(j*2*pi*d_lamda*[0:N-1]'*sin(thetaj1*pi/180));
aj2=exp(j*2*pi*d_lamda*[0:N-1]'*sin(thetaj2*pi/180));
aj3=exp(j*2*pi*d_lamda*[0:N-1]'*sin(thetaj3*pi/180));
Xj=aj1*amp_j1+aj2*amp_j2+aj3*amp_j3+noise;
B=[1 -exp(-j*pi*sin(thetaj*pi/180)) 0 0 0 0 0 0 0 0 0 0 0 0 0 0;0 1 -exp(-j*pi*sin(thetaj*pi/180)) 0 0 0 0 0 0 0 0 0 0 0 0 0;0 0 1 -exp(-j*pi*sin(thetaj*pi/180)) 0 0 0 0 0 0 0 0 0 0 0 0;0 0 0 1 -exp(-j*pi*sin(thetaj*pi/180)) 0 0 0 0 0 0 0 0 0 0 0;0 0 0 0 1 -exp(-j*pi*sin(thetaj*pi/180)) 0 0 0 0 0 0 0 0 0 0;0 0 0 0 0 1 -exp(-j*pi*sin(thetaj*pi/180)) 0 0 0 0 0 0 0 0 0;0 0 0 0 0 0 1 -exp(-j*pi*sin(thetaj*pi/180)) 0 0 0 0 0 0 0 0;0 0 0 0 0 0 0 1 -exp(-j*pi*sin(thetaj*pi/180)) 0 0 0 0 0 0 0;0 0 0 0 0 0 0 0 1 -exp(-j*pi*sin(thetaj*pi/180)) 0 0 0 0 0 0;0 0 0 0 0 0 0 0 0 1 -exp(-j*pi*sin(thetaj*pi/180)) 0 0 0 0 0;0 0 0 0 0 0 0 0 0 0 1 -exp(-j*pi*sin(thetaj*pi/180)) 0 0 0 0;0 0 0 0 0 0 0 0 0 0 0 1 -exp(-j*pi*sin(thetaj*pi/180)) 0 0 0;0 0 0 0 0 0 0 0 0 0 0 0 1 -exp(-j*pi*sin(thetaj*pi/180)) 0 0;0 0 0 0 0 0 0 0 0 0 0 0 0 1 -exp(-j*pi*sin(thetaj*pi/180)) 0;0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -exp(-j*pi*sin(thetaj*pi/180))];
Xj=B*Xj;
Rin=1/Ns*(Xj*Xj');
Rin_inv=inv(Rin);
Wopt=Rin_inv*as0./(as0'*Rin_inv*as0);
W=as0;
atheta=exp(j*2*pi*d_lamda*[0:N-1-1]'*sin(theta*pi/180));
pattern1=abs(Wopt'*atheta);
pattern=abs(W'*atheta);
pattern1=20*log10(pattern1/(max(pattern1)));
pattern=20*log10(pattern/(max(pattern)));
plot(theta,pattern1);hold on;grid on;
plot(theta,pattern,'LineStyle','--');
legend('LCMV','CBF');
axis([-90 90 -90 0]);
xlabel('角度/degree');
ylabel('增益/dB');title('方向图对比');