%分别利用Kernel LSM求出最佳波束赋形权重w。
close all
clear all
clc
M=8; %M表示天线数目
N=2000; %N表示迭代次数
Na=180;
theta=linspace(0,pi,Na);
j=sqrt(-1);
f=2e9;
lamda=3e8/f;
d=lamda/2;
k=2*pi/lamda;
REPEAT = 10;
mu_LMP1 = 0.002;
mu_LMS = 0.002;
mu_LMP3 = 0.002;
mu_LMP4 = 0.002;
np = 0.8;
smin=-1; %信号的最小值
smax=1; %信号的最大值
imin=-1; %干扰的最小值
imax=1; %干扰的最大值
% N_amp=0.5; %随机噪声幅度
theta_s=50*pi/180; %波束方向
theta_i=80*pi/180;%干扰方向
theta_i2=100*pi/180;%干扰方向
M_1=[0:M-1]';
a=exp(-j*k*d*M_1*cos(theta)); %均匀线阵导引矢量
a_s=exp(-j*k*d*M_1*cos(theta_s));
a_i=exp(-j*k*d*M_1*cos(theta_i));
a_i2=exp(-j*k*d*M_1*cos(theta_i2));
T = 1E-3;
t = (1:N)*T/N;
it = 1:N;
E_LMS = zeros(N,1);
E_LMP1 = zeros(N,1);
E_LMP3 = zeros(N,1);
E_LMP4 = zeros(N,1);
W_LMS = zeros(M,1);
W_LMP1 = zeros(M,1);
W_LMP3 = zeros(M,1);
W_LMP4 = zeros(M,1);
BER_LMP1 = 0;
BER_LMS = 0;
BER_LMP3 = 0;
BER_LMP4 = 0;
for repeat = 1:REPEAT
disp(repeat)
%S = cos(2*pi*t/T).^2;
u = randn(1,N)>0;
w = randn(1,N)>0;
% S = 2*u-1;%+(2*w-1)*j;
S = qammod(randint(1,N,4),4)/(sqrt(2));
I = qammod(randint(1,N,4),4)/(sqrt(2));
I2 = qammod(randint(1,N,4),4)/(sqrt(2));
% S=smin+(smax-smin)*randn(1,N)+j*(smin+(smax-smin)*randn(1,N));%随机产生N个信号作为有用信号并存储于S。
% I=imin+(imax-imin)*randn(1,N)+j*(smin+(smax-smin)*rand(1,N));%随机产生N个信号作为干扰信号并存储于I。
%x=a_s*S+0.1*randn(M,N);
%x=a_s*S+a_i*I+0.1*randn(M,N);
x=a_s*S+a_i*I+a_i2*I2;
%noise = noise/norm(noise)*10^(-SNR_DB /20)*norm(x);
% noise = np * (laprnd(M,N,0,1)+j*laprnd(M,N,0,1));
% noise = np * (uniform(M,N,-1,1)+j*uniform(M,N,-1,1));
noise = np * (randn(M,N)+j*randn(M,N));
% noise = np*[normrnd(-0.5,1,M/2,N);normrnd(0.5,1,M/2,N)];
% noise = noise(randperm(M),randperm(N));
% %
% alpha=1.5;beta=0;gmma=0.1;delta=0;
% noise = np*(stblrnd(alpha,beta,gmma,delta,[M,N])+j*stblrnd(alpha,beta,gmma,delta,[M,N]));
%X=x+0.001*stblrnd(alpha,beta,gmma,delta,[M,N]);
% X=x+0.1*(randn(M,N)+j*randn(M,N));
%X=x;
X =x+noise;
%% %%%%%%%%%%%%%%%%%%% LMS %%%%%%%%%%%%%%%%%%%%%%%%%%%
y_LMS = zeros(N,1);
e_LMS = zeros(N,1);
w_LMS = zeros(M,1);
for n = 1:N
% Rxx_LMS=X(:,n)*X(:,n)';
% Trace_Rxx_LMS=trace(Rxx_LMS);
% mu_LMS = 1/(2*Trace_Rxx_LMS);
y_LMS(n)=w_LMS'*X(:,n);
e_LMS(n) = S(n) - y_LMS(n);
w_LMS = w_LMS + mu_LMS*conj(e_LMS(n))*X(:,n)/2;
end
E_LMS = E_LMS+e_LMS;
W_LMS = W_LMS+w_LMS;
%%%%%%%%%%%%%%%%%% LMS end %%%%%%%%%%%%%%%%%%
%% %%%%%%%%%%%%%%%%%%% LMP1 %%%%%%%%%%%%%%%%%%%%%%%%%%%
y_LMP1 = zeros(N,1);
e_LMP1 = zeros(N,1);
w_LMP1 = zeros(M,1);
for n = 1:N
% Rxx_LMS=X(:,n)*X(:,n)';
% Trace_Rxx_LMS=trace(Rxx_LMS);
% mu_LMS = 1/(2*Trace_Rxx_LMS);
y_LMP1(n)=w_LMP1'*X(:,n);
e_LMP1(n) = S(n) - y_LMP1(n);
w_LMP1 = w_LMP1 + mu_LMP1*conj(sign(e_LMP1(n)))*X(:,n);
end
E_LMP1 = E_LMP1+e_LMP1;
W_LMP1 = W_LMP1+w_LMP1;
%%%%%%%%%%%%%%%%%% LMP1 %%%%%%%%%%%%%%%%%%
%% %%%%%%%%%%%%%%%%%%% LMP3 %%%%%%%%%%%%%%%%%%%%%%%%%%%
y_LMP3 = zeros(N,1);
e_LMP3 = zeros(N,1);
w_LMP3 = zeros(M,1);
for n = 1:N
% Rxx_LMS=X(:,n)*X(:,n)';
% Trace_Rxx_LMS=trace(Rxx_LMS);
% mu_LMS = 1/(2*Trace_Rxx_LMS);
y_LMP3(n)=w_LMP3'*X(:,n);
e_LMP3(n) = S(n) - y_LMP3(n);
w_LMP3 = w_LMP3 + mu_LMP3*(abs(e_LMP3(n)))^2*conj(sign(e_LMP3(n)))*X(:,n)/3;
end
E_LMP3 = E_LMP3+e_LMP3;
W_LMP3 = W_LMP3+w_LMP3;
%%%%%%%%%%%%%%%%%% LMP3 %%%%%%%%%%%%%%%%%%
%% %%%%%%%%%%%%%%%%%%% LMP4 %%%%%%%%%%%%%%%%%%%%%%%%%%%
y_LMP4 = zeros(N,1);
e_LMP4 = zeros(N,1);
w_LMP4 = zeros(M,1);
for n = 1:N
% Rxx_LMS=X(:,n)*X(:,n)';
% Trace_Rxx_LMS=trace(Rxx_LMS);
% mu_LMS = 1/(2*Trace_Rxx_LMS);
y_LMP4(n)=w_LMP4'*X(:,n);
e_LMP4(n) = S(n) - y_LMP4(n);
w_LMP4 = w_LMP4 + mu_LMP4*(abs(e_LMP4(n)))^3*conj(sign(e_LMP4(n)))*X(:,n)/4;
end
E_LMP4 = E_LMP4+e_LMP4;
W_LMP4 = W_LMP4+w_LMP4;
%%%%%%%%%%%%%%%%%% LMP4 %%%%%%%%%%%%%%%%%%
%% BER(decision part)
y_LMP1_norm = y_LMP1.'; % normalize the output
y_LMP1_norm = sign(real(y_LMP1_norm))+j*sign(imag(y_LMP1_norm)); %symbol detection
y_s_LMP1 = y_LMP1_norm/(sqrt(2)) - S(1:N); % error detection
BER_LMP1 = BER_LMP1+(length(find(y_s_LMP1~=0)))/length(y_s_LMP1); % SER calculation
y_LMS_norm = y_LMS.'; % normalize the output
y_LMS_norm = sign(real(y_LMS_norm))+j*sign(imag(y_LMS_norm)); %symbol detection
y_s_LMS = y_LMS_norm/(sqrt(2)) - S(1:N); % error detection
BER_LMS = BER_LMS+(length(find(y_s_LMS~=0)))/length(y_s_LMS); % SER calculation
y_LMP3_norm = y_LMP3.'; % normalize the output
y_LMP3_norm = sign(real(y_LMP3_norm))+j*sign(imag(y_LMP3_norm)); %symbol detection
y_s_LMP3 = y_LMP3_norm/(sqrt(2)) - S(1:N); % error detection
BER_LMP3 = BER_LMP3+(length(find(y_s_LMP3~=0)))/length(y_s_LMP3); % SER calculation
y_LMP4_norm = y_LMP4.'; % normalize the output
y_LMP4_norm = sign(real(y_LMP4_norm))+j*sign(imag(y_LMP4_norm)); %symbol detection
y_s_LMP4 = y_LMP4_norm/(sqrt(2)) - S(1:N); % error detection
BER_LMP4 = BER_LMP4+(length(find(y_s_LMP4~=0)))/length(y_s_LMP4); % SER calculation
end
e_LMS = E_LMS./REPEAT;
e_LMP1 = E_LMP1./REPEAT;
e_LMP3 = E_LMP3./REPEAT;
e_LMP4 = E_LMP4./REPEAT;
w_LMP1 = W_LMP1./REPEAT;
w_LMS = W_LMS./REPEAT;
w_LMP3 = W_LMP3./REPEAT;
w_LMP4 = W_LMP4./REPEAT;
BER_LMP1 = BER_LMP1/REPEAT;
BER_LMS = BER_LMS/REPEAT;
BER_LMP3 = BER_LMP3/REPEAT;
BER_LMP4 = BER_LMP4/REPEAT;
BER_LMP1
BER_LMS
BER_LMP3
BER_LMP4
% figure(1)
% plot(1:N,abs(S),'r-*',1:N,abs(y_Kernel),'g-o');
% title('估计信号与期望信号')
% legend('实际信号','估计信号')
figure
% plot(abs(e_Kernel.^2),'r','LineWidth',2);
% hold on
% plot(abs(e_LMS.^2),'LineWidth',2);
semilogy(abs(e_LMP1.^2),'r','LineWidth',2);
hold on
semilogy(abs(e_LMS.^2),'k','LineWidth',2);
hold on
semilogy(abs(e_LMP3.^2),'b','LineWidth',2);
hold on
semilogy(abs(e_LMP4.^2),'g','LineWidth',2);
legend('LMP1','LMS','LMP3','LMP4')
set(gca, 'FontSize', 14);
set(gca, 'FontName', 'Arial');
f_LMS =w_LMS'*a;
f_LMP1 =w_LMP1'*a;
f_LMP3 =w_LMP3'*a;
f_LMP4 =w_LMP4'*a;
figure(2)
K_LMP1=abs(f_LMP1);
K_LMP3=abs(f_LMP3);
K_LMP4=abs(f_LMP4);
K_LMS=abs(f_LMS);
K_LMP1=20*log10(K_LMP1/max(K_LMP1(:)));
K_LMP3=20*log10(K_LMP3/max(K_LMP3(:)));
K_LMP4=20*log10(K_LMP4/max(K_LMP4(:)));
K_LMS=20*log10(K_LMS/max(K_LMS(:)));
theta = theta*180/pi;
plot(theta,K_LMP1,'r','LineWidth',2);
hold on
plot(theta,K_LMS,'k','LineWidth',2);
hold on
plot(theta,K_LMP3,'b','LineWidth',2);
hold on
plot(theta,K_LMP4,'g','LineWidth',2);
grid on,
axis([0 180 -80 0]);
% set(gca, 'FontSize', 14);
% set(gca, 'FontName', 'Arial');
legend('LMP1','LMS','LMP3','LMP4')
figure
plot(y_LMS/(sqrt(2)),'o')