clc;
clear;
close all;
len_s=100000; % 信号长度
snr=0:2:20;%信噪比
len_snr=length(snr);
s2_1=zeros(1,4);
ber_zf=zeros(1,len_snr);
ber_zf_sic=zeros(1,len_snr);
ber_zf_chsic=zeros(1,len_snr);
for ii=1:len_snrerror_zf2=0;for i=1:len_ssn=randi([0,1],4,1); %产生随机信号mod_sn=pskmod(sn,2);sigma =sqrt(0.5.*10.^(-snr(ii)./10));%I,Q两路独立产生噪声Q_noise = randn(4, 1);I_noise = randn(4, 1);noise = complex(I_noise,Q_noise);noise = sigma.*noise;%高斯白噪声H=1/sqrt(2)*(randn(4,4) + 1i*randn(4,4));y1=H*mod_sn+noise;G=inv(H); %求逆 y1_1=G*y1;s=pskdemod(y1_1,2);%BPSK解调error_zf1=find(s~=sn);%错误判决error_zf2=length(error_zf1)+error_zf2;endber_zf(ii)=error_zf2./(len_s*4);
endfor ii=1:len_snrerror_zf22=0;for i=1:len_ssn2=randi([0,1],4,1); %产生随机信号mod_sn2=pskmod(sn2,2);sigma =sqrt(0.5.*10.^(-snr(ii)./10));%I,Q两路独立产生噪声Q_noise = randn(4, 1);I_noise = randn(4, 1);noise = complex(I_noise,Q_noise);noise = sigma.*noise;%高斯白噪声H=1/sqrt(2)*(randn(4,4) + 1i*randn(4,4));y2_1_1=H*mod_sn2+noise; %4*1for p=1:4G2=pinv(H); %伪逆矩阵w2_1=G2(p,:); %1*4y2_1_2=w2_1*y2_1_1;s2_1(p)=pskdemod(y2_1_2,2);%BPSK解调s2_1_1=pskmod(s2_1(p),2); %先检测第一个信号aH=s2_1_1.*H(:,p);y2_1_1= y2_1_1-aH;H(:,p)=zeros(4,1);enderror_zf21=find(s2_1.'~=sn2);%错误判决error_zf22=length(error_zf21)+error_zf22;endber_zf_sic(ii)=error_zf22./(len_s*4);
end
%选信号强度最大的
for ii=1:len_snrerror_zf22=0;for i=1:len_ssn2=randi([0,1],4,1); %产生随机信号mod_sn2=pskmod(sn2,2); %bpsk调制sigma =sqrt(0.5.*10.^(-snr(ii)./10));%I,Q两路独立产生噪声Q_noise = randn(4, 1);I_noise = randn(4, 1);noise = complex(I_noise,Q_noise);noise = sigma.*noise;%高斯白噪声H=1/sqrt(2)*(randn(4,4) + 1i*randn(4,4));y2_1_1=H*mod_sn2+noise;G3_1=zeros(4,4);for p=1:4G3=pinv(H);%伪逆矩阵sum1=sum(abs(G3+G3_1).^2,2);%对矩阵行求和[x,p1]=min(sum1); %G3_1(p1,:)=[1000 1000 1000 1000];w2_1=G3(p1,:);y2_1_2=w2_1*y2_1_1;s2_1(p1)=pskdemod(y2_1_2,2);%BPSK解调s2_1_1=pskmod(s2_1(p1),2);aH=s2_1_1.*H(:,p1);y2_1_1= y2_1_1-aH;H(:,p1)=zeros(4,1);enderror_zf21=find(s2_1.'~=sn2);%错误判决error_zf22=length(error_zf21)+error_zf22;endber_zf_chsic(ii)=error_zf22./(len_s*4);
endsemilogy(snr,ber_zf,'-k*',snr,ber_zf_sic,'-ko',snr,ber_zf_chsic,'-kx')grid onlegend('迫零检测算法','串行干扰消除算法','排序串行干扰消除算法')xlabel('信噪比snr')ylabel('误比特率')